@jotiotech/node-red-bj-parser

1.1.1 • Public • Published

BJ parser

  • parser form binary to simple json format

FIXES

  • $val variable does not always work in set action, behavior is not consistent
  • improper handling of repeat will lead to infinite loop and crash of whole Node-RED

ROOT

  • list all all rules
  • global scope for rule name

Attributes

  • name
    • OPTIONAL; default: ""
    • only for login purpose
  • version
    • OPTIONAL; default: ""
    • only for login purpose
  • schemaVersion
    • OPTIONAL; default: "1.0"
  • rule: - see RULE

Structure

{
		name: <STRING>,
		version: <STRING>,
		schemaVersion: <STRING>,
		rule: <RULE>
}

Example

{
		rule: {
			 A: ...,
			 B: ...
		}
}

RULE

  • base node structure responsible for part of incoming message

Attributes

  • set
    • see RULE.SET,
  • subParsing
    • see RULE.SUBPARSING,
  • valMask:
    • OPTIONAL;
    • mask for $val variable in next
  • next: <RULE.NEXT>
    • OPTIONAL; default: return $in
    • define witch portion of in_bin will be returned from this rule
    • VAR: $in, $val, $len

Structure

<STRING-rule name>: {
		set: <RULE.SET>,
		subParsing: <RULE.SUBPARSING>,
		valMask: <MASK_EXP>
		next: <MASK_EXP>
}

Example

 A: {
		set: ...,
		subParsing: ...,
		valMask:
		next: ...
}

RULE.SET

  • set parameters in out_json

Attributes (in array element)

  • valMask
    • WARN: Does not work, sometimes error of val not existing is thrown
    • VAR: $in, $len
    • mask for $val variable
  • target
    • path in out_json, where value will be written
  • type
    • OPTIONAL; default: use values from action, val
    • list of available valu (multiple elements can be executed)
  • type.selector
    • OPTIONAL; default: TRUE (works as else)
    • VAR: $in, $val, $len
    • if true, element will be executed
  • type.action
    • OPTIONAL; default: SET
    • action performed on atribute in json
  • type.val
    • VAR: $in, $val, $len
    • value for action
  • single
    • OPTIONAL; default: FALSE
    • has meaning only if type is set
    • if true, only fist selected value with executed
  • action
    • OPTIONAL; default: SET
    • interpreted only if
    • action performed on atribute in json
  • val
    • OPTIONAL; default: use values from type
    • will be executed only if type is not set
    • VAR: $in, $val, $len
    • value for action

Structure

{
		valMask: <MASK_EXP>,
		target: <JSON_PATH>,
		single: <BOOL>,
		type:
		{
				selector: <BOOL_EXP>,
				action: <SET_ACTION_ENUM>,
				val: <ANY_EXP>
		}[],
		action: <SET_ACTION_ENUM>,
		val: <ANY_EXP>
}[]

Example

[
		{
				valMask: "0(12 + 1)1(3)",
				target: "perName",
				type: [
						{
								selector: "@eql($val, 0)",
								action: "SET",
								val: "'INTERNAL'"
						},
						{
								selector: "@eql($val, 1)",
								action: "SET",
								val: "'A'"
						}
				]
		}
]

RULE.SUBPARSING

  • parse next part of in_bin

Attributes (in array element)

  • valMask
    • OPTIONAL
    • VAR: $in, $i, $len
    • mask for $val variable
  • selector
    • OPTIONAL; default: TRUE (works as else)
    • VAR: $in, $i, $val, $len
    • if true, element will be executed
  • targetRule
    • rule, that will be executed
  • chroot
    • OPTIONAL; default: ""
    • VAR: $i, $val
    • path to new root path in out_json in sub rule
  • subMask
    • binary that will be passed to sub rule
    • VAR: $in, $i, $len
  • newIn
    • OPTIONAL; default: $ret
    • VAR: $in, $i, $len, $ret, $rvser
    • binary that will become new $in variable
  • repeatMax
    • OPTIONAL; default: InF
    • skip this subrule, if number of times this subrule was already called is greater or equal of this value (in this subparsing, in this call)
  • repeatMaxGlob
    • OPTIONAL; default: InF
    • skip this subrule, if number of times any subrule was already called is greater or equal of this value (in this subparsing, in this call)
  • repeat
    • OPTIONAL; default: FALSE (if repeatMax or repeatMaxGlob are set)
    • do not break after subrule is executed

Structure

{
		valMask: <MASK_EXP>,
		selector: <BOOL_EXP>,
		targetRule: <STRING-rule name>,
		chroot: <JSON_PATH>,
		subMask: <MASK_EXP>,
		newIn: <BIN_EXP>,
		repeatMax: <INT>,
		repeatMaxGlob: <INT>,
		repeat: <BOOL>
}[]

Example

[
		{
				valMask: "0(8)1(4)",
				selector: "@eql($val, 2)",
				subMask: "0(16)1($len)",
				newIn: "@maskB('1(16)', $in) : $ret",
				targetRule: "parsUTC_root",
				chroot: "timestamp",
				repeat: true,
				repeatMax: 1
		},
		{
				valMask: "1(8)",
				selector: "@eql($val, 0x01)",
				subMask: "0(16)1($len)",
				newIn: "$rvsub : $ret",
				targetRule: "temp",
				repeat: false
		}
]

MASK_EXP

  • expression that will be expanded to binary mask
  • if expression is shorter than input msg, remaining bit of input will be ignored
  • if expression is longer than input msg, excessive bits of expression will be ignored
  • sequence of 1 or 0 characters, expression in bracket will be evaluated as <NUM_EXP> and will use previous character that many times

Example

"0(8)1100(0)1($len)" // expands to "0000000011011111111..."

JSON_PATH

  • define path to in json tree
  • .., . can be used

Example

"./A/B/B/.././C[$i][2*3]" // expands to A/B/C( as array )/${i}( as array )/6

SET_ACTION_ENUM

  • SET
    • create new atribute (if exist error)
  • ADD
    • += (if do not exist, init whit 0)
  • APPEND
    • add element to list (if do not exist, init with [])

Variable

  • val
    • type: int
    • default: -1
    • resulting integer from valMask atribute
  • len
    • type: int
    • deprecated
    • OLD: number of bits in in_bin
    • NEW: -1
  • in
    • type: binary
    • full binary in current rule
    • will be rewritten after sub rule completely finish (in will become value from newIn atr)
  • i
    • type: int
    • number of sub rule are already complete finished in current rule
    • counting from 0
  • ret
    • type: binary
    • value returned from sub rule from next atribute
  • rvsub
    • type: binary
    • inverse binary mask from selector atribute
    • TODO: add it (not implemented)

StD Variable

  • true: true (boolean)
  • false: false (boolean)
  • nan: NaN (number)
  • null: null (any)

Operators

  • +, -, *, \
    • std. math operators (not for string)
  • (...)
    • std. bracket
  • &, |
    • not implemented
    • bin and, or
  • :
    • binary concat
  • &&, ||
    • std bool operators
  • ==, >, >=, <, <=
    • std bool operators

Functions

  • eql
    • RET:
    • ATR: ,
    • js: ===
  • more
    • RET:
    • ATR: ,
    • js: >
  • less
    • RET:
    • ATR: ,
    • js: <
  • toBool
    • RET:
    • ATR:
    • if empty or 0 => false, else true
  • toInt16
    • RET:
    • ATR:
    • convert to signed 16bit integer
  • toInt16LE
    • RET:
    • ATR:
    • convert to signed 16bit integer, little endian
  • toInt32
    • RET:
    • ATR:
    • convert to signed 32bit integer
  • toInt32LE
    • RET:
    • ATR:
    • convert to signed 32bit integer, little endian
  • toFloat
    • RET:
    • ATR:
    • convert to 32bit float
  • toFloatLE
    • RET:
    • ATR:
    • convert to 32bit float, little endian order
  • toIntBCD2Digit
    • RET:
    • ATR:
    • convert to integer from 2 digit BCD (8bit number)
  • toIntBCD4Digit
    • RET:
    • ATR:
    • convert to integer from 4 digit BCD (16bit number)
  • toIntBCD6Digit
    • RET:
    • ATR:
    • convert to integer from 6 digit BCD (24bit number)
  • toIntBCD8Digit
    • RET:
    • ATR:
    • convert to integer from 8 digit BCD (32bit number)
  • toIntBCD10Digit
    • RET:
    • ATR:
    • convert to integer from 10 digit BCD (40bit number)
  • toIntBCD12Digit
    • RET:
    • ATR:
    • convert to integer from 12 digit BCD (48bit number)
  • toUtf8
    • RET:
    • ATR:
    • convert bin to string (if binary do not have whole number of bits pass end with zeros)
  • mask
    • RET:
    • ATR: <MASK_EXP>,
    • apply mask to binary and returns number
  • maskB
    • RET:
    • ATR: <MASK_EXP>,
    • apply mask to binary and returns binary
  • getAtr
    • RET:
    • ATR: <JSON_PATH>
    • not implemented
    • get atribute from out_json
  • parseUTC_5b
    • RET:
    • ATR:
    • std conversion
  • toHex
    • RET:
    • ATR: <MASK_EXP>
    • convert binary in ranges specified by mask to hex string
    • WARN: alway pick length in mask divisible by 8
  • parseMBUS
    • RET:
    • ATR: <MASK_EXP>
    • parse given part of message as MBUS message, only long frame is supported and header must be included
  • toAscii
    • RET:
    • ATR: <MASK_EXP>
    • convert binary in ranges specified by mask to ascii string
    • WARN: alway pick length in mask divisible by 8

Readme

Keywords

Package Sidebar

Install

npm i @jotiotech/node-red-bj-parser

Weekly Downloads

80

Version

1.1.1

License

MIT

Unpacked Size

174 kB

Total Files

31

Last publish

Collaborators

  • zkolar
  • havrak
  • vojta-novak
  • krivik