Steve-Mcl / node-red-contrib-buffer-parser

A node-red node to convert values in a buffer, integer array or hex string into many different data type(s). Supports Big/Little Endian, BCD, byte swapping and much more.
MIT License
24 stars 8 forks source link

Int output missing? #19

Open KSumwalt opened 9 months ago

KSumwalt commented 9 months ago

Is the option to output an Int missing? I have an array of bytes: [13,28,2,65,0,0,0,1] The first two (13 and 28) represent an integer value of (13265)+28 or 3473 The next two (2 and 65) represent (2256)+65 or 577 The fifth stands alone The sixth and seventh represent a value (0 in this case) and the last, eighth item represents a value.

I thought if Int was available, I would get 3473 and 577 for the first two items when outputting a key/value. Instead, the best I can get is an array of the 2 values which makes up each item. Am I missing something?

image

Steve-Mcl commented 9 months ago

I thought if Int was available, I would get 3473 and 577 for the first two items when outputting a key/value. Instead, the best I can get is an array of the 2 values which makes up each item

As the built in documentation states, length is: "The quantity of items to be returned. e.g. 6 bools or 12 floats or 34 int32s"

So in your screenshot, in the 1st item, you asked the buffer parser to read 2 integers (16bits) starting at byte 0.

Then you have the 2nd item starting at byte 4.

In short, length should always be 1 unless you want to read multiple/an array of selected type.

KSumwalt commented 9 months ago

Sorry, but I am not following. My first item needs to use the first 2 bytes supplied. I have data sent to me in an array of 8 bytes. It represents 5 values. Battery - 2 bytes Distance - 2 bytes Interrupt - 1 byte Temperature - 2 bytes Flag - 1 byte

So the first two (bytes 0 and 1) represent an integer for the Battery. Bytes 2 and 3 also represent an int but for a returned Distance.

using the array of bytes with values of [13,28,2,65,0,0,0,1] I am trying to get payload.battery = 3473 (ACUTALLY it would end up being a float 3.473 but I see the Scale will get me there) payload.distance = 577 payload.interrupt = 0 payload.temperature = 0 payload.flag = 0

I guess I am misunderstanding how I would get these, assuming the contrib is capable of doing such. Perhaps my assumption is off? Or is it reading these as ints and I need to set them as something else first?

Steve-Mcl commented 9 months ago

My first item needs to use the first 2 bytes supplied

By specifying int16 (aka a 16bit integer, aka 2 bytes) you are asking the buffer parser to read 2 bytes from the input buffer starting at byte 0 (bytes 0~1)

When you set the length to 2, you are telling the buffer parser to grab 2 of them (i.e byes 0~3)

values of [13,28,2,65,0,0,0,1] I am trying to get payload.battery = 3473

13,28 equals 4904 or byte reversed, 10259 NOT 3473 - try for yourself: https://www.rapidtables.com/convert/number/hex-to-decimal.html

perhaps the number is encoded or is an analog value that needs scaling?