How use biguint64 in buffer.parser

I need to parse a group of bits among 5 bytes, so, I need to use the format biguint64(be), however, I get an error.

"TypeError: Cannot read property 'bind' of undefined"

The group of interest is the following (in italic)

0101 1001 11001010 01001010 10110011 111 01101 (plus two additional bytes)

I've inserted this mask and there is not option for scale

0xFFFFFFFE0000000

Is it better to use uint32(be) even the bits are among 5 bytes insted of 4 or less? Please, I need some help here. NOTE: I also tried uint32(be)

Biguint64 is problematic. The node-red debug cannot display them (thats why you get an error) OR your nodejs version is not new enough (no bigint support)

If you just want 5 bits spread out across 5 words, you could use BOOL or 16BIT then access the bits as bools or 0/1s

If you want to make a value from 5 bits across 5 bytes (most strange) them I would probably get 5 bytes and then use a function node to extract the bits and combine them into a number using masks and bit shifts.

Can I use BOOL or 16BIT inside the same buffer parser node or I need to do it outside? I would like to accomplish it using the same node.

The first and last (fifth word are splitted in half, the three middle ones are full hex.

Of course. Give it a go.

I can't understand this statement.

Perhaps if you can provide sample data and a specification there is a simple answer.

I would need sample input data, which bytes & bits to use, the final value to output.

This is a string input

return {"payload":{"link_type":"LINKTYPE_ETHERNET","pcap_header":{"tv_sec":1604796151,"tv_usec":651857,"caplen":141,"len":141},"payload":{"dhost":{"addr":[128,120,113,67,87,122]},"shost":{"addr":[8,0,39,206,160,222]},"ethertype":2048,"vlan":null,"payload":{"version":4,"headerLength":20,"diffserv":0,"length":127,"identification":39821,"flags":{"reserved":false,"doNotFragment":true,"moreFragments":false},"fragmentOffset":0,"ttl":64,"protocol":17,"headerChecksum":24686,"saddr":{"addr":[192,168,1,55]},"daddr":{"addr":[84,88,40,59]},"payload":{"sport":445,"dport":445,"length":107,"checksum":16111,"data":[255,255,255,255,255,255,8,0,39,206,160,222,137,71,17,0,26,1,32,80,0,128,0,45,1,0,0,0,8,0,39,206,160,222,167,132,17,153,25,84,8,250,206,69,32,241,1,240,7,204,0,0,0,0,7,209,0,0,2,2,0,0,0,224,148,21,0,89,202,74,179,237,146,185,39,0,0,0,0,0,48,212,30,0,225,31,192,250,126,191,233,237,7,55,254,235,255,246,0]}}}},"topic":"enp0s3","_msgid":"d4caea19.3a07d8","var1":255,"var2":250};

The two variables missing are latitude and longitude with the following (the italic ones):

latitude
|offset |Value DEC| Value BIN |
|67|89|01011001||||
|68|202|11001010||||
|69|74|01001010||||
|70|179|10110011||||
|71|237|11101101||

The resulting BIN 1001110010100100101010110011111

with output 1314018719

Longitude
|offset |Value DEC| Value BIN |
|71|237|11101101||
|72|146|10010010||||
|73|185|10111001||||
|74|39|00100111||||
|75|0|00000000||

The resulting BIN 01101100100101011100100100111000

The output 1821755704

Are you 100% certain the values you want are 2 values that start and end in the middle of a byte?
also, Latitude has 31 bits and Longitude has 32 bits!?? I find this quite odd.

Latitude

byte  67        68        69        70        71                     
bin   xxxx 1001 1100 1010 0100 1010 1011 0011 111x xxxx

Longitude

byte  71        72        73        74        75                     
bin   xxx0 1101 1001 0010 1011 1001 0010 0111 000x xxxx

Where is this data coming from?

Do you have control over its format or is the incoming data format locked / proprietary?

If you have any control whatsoever, I would strongly recommend the following (in order of best to "a bit better")

  1. If you can send data in JSON format with "actual values" (instead of bytes) - none of this would be necessary
  2. If you can send or get data in XML format with "actual values" (instead of bytes) - none of this would be necessary
  3. If you can send or get data in a CSV or TSV format - much of this would not be necessary
  4. If the data is from a PLC, please byte align (and pad where necessary to achieve byte alignment)
  5. If the data is coming from a program that can only transmit bytes & you have access to source, again, please re-align the bytes.

image

The source is open following ASN.1 UPER format. I cannot control the bit position. Is it possible to send, for instance, the latitude split in two integers and merge them in a function node?

Of course...

image

// byte  67        68        69        70        71
// bin   xxxx 1001 1100 1010 0100 1010 1011 0011 111x xxxx
// mask  0    F    F    F    F    F    F    F    E    0
// 1314018719
msg.payload.Lattiude = (msg.payload.LatHi  << 3) + (msg.payload.LatLo >> 5)

// byte  71        72        73        74        75                     
// bin   xxx0 1101 1001 0010 1011 1001 0010 0111 000x xxxx
// mask  1    F    F    F    F    F    F    F    E    0
// 1821755704
msg.payload.Longitude = (msg.payload.LonHi << 3) + (msg.payload.LonLo >> 5)
return msg;
[{"id":"31ef54c0.333eec","type":"inject","z":"e39accec.112de","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[255,255,255,255,255,255,8,0,39,206,160,222,137,71,17,0,26,1,32,80,0,128,0,45,1,0,0,0,8,0,39,206,160,222,167,132,17,153,25,84,8,250,206,69,32,241,1,240,7,204,0,0,0,0,7,209,0,0,2,2,0,0,0,224,148,21,0,89,202,74,179,237,146,185,39,0,0,0,0,0,48,212,30,0,225,31,192,250,126,191,233,237,7,55,254,235,255,246,0]","payloadType":"bin","x":850,"y":60,"wires":[["c37385ab.059b58"]]},{"id":"c37385ab.059b58","type":"buffer-parser","z":"e39accec.112de","name":"","data":"payload","dataType":"msg","specification":"spec","specificationType":"ui","items":[{"type":"uint32be","name":"LatHi","offset":67,"length":1,"offsetbit":0,"scale":1,"mask":"0x0FFFFFFF"},{"type":"uint8","name":"LatLo","offset":71,"length":1,"offsetbit":0,"scale":1,"mask":"0xE0"},{"type":"uint32be","name":"LonHi","offset":71,"length":1,"offsetbit":0,"scale":1,"mask":"0x1FFFFFFF"},{"type":"uint8","name":"LonLo","offset":75,"length":1,"offsetbit":0,"scale":1,"mask":"0xE0"}],"swap1":"","swap2":"","swap3":"","swap1Type":"swap","swap2Type":"swap","swap3Type":"swap","msgProperty":"payload","msgPropertyType":"str","resultType":"keyvalue","resultTypeType":"output","multipleResult":false,"setTopic":true,"x":1020,"y":60,"wires":[["5774845e.9d79fc"]]},{"id":"5774845e.9d79fc","type":"function","z":"e39accec.112de","name":"","func":"\n// byte  67        68        69        70        71\n// bin   xxxx 1001 1100 1010 0100 1010 1011 0011 111x xxxx\n// mask  0    F    F    F    F    F    F    F    E    0\n// 1314018719\nmsg.payload.Lattiude = (msg.payload.LatHi  << 3) + (msg.payload.LatLo >> 5)\n\n// byte  71        72        73        74        75                     \n// bin   xxx0 1101 1001 0010 1011 1001 0010 0111 000x xxxx\n// mask  1    F    F    F    F    F    F    F    E    0\n// 1821755704\nmsg.payload.Longitude = (msg.payload.LonHi << 3) + (msg.payload.LonLo >> 5)\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":120,"wires":[["441864a.e7bd49c"]]},{"id":"441864a.e7bd49c","type":"debug","z":"e39accec.112de","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1040,"y":120,"wires":[]}]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.