Payload uplink decoder

Hi, would someone be willing to write me here an uplink decoder for ultrasonic sensor as described below ? I would need to read Distance and Battery. I’m using this for another model but it doesn’t work for this one. I’ve been struggling with this for too long. :frowning:

This one not working still print bad value

function Decoder(bytes) {
var dist = ((bytes[5] << 8) | bytes[6]);
var batt = ((bytes[3] << 8) | bytes[4]);
return {
distance: (dist),
battery: (batt),
};
}

Value Description new sensor
B0 INFO BYTE, Information byte
B1 SNR, Signal To Noise Radio value
B2 DATA BYTE, Data Format Byte
B3 Battery Voltage, HB mV
B4 Battery Voltage, LB
B5 Distance HB cm
B6 Distance LB

Old sensor miniUNI Ultrasonic (SolidusTech) payload structure

B1
Battery voltage
0x00
to 0xFF Byte x 30 =
voltage mV
B2
Transceiver chip temperature
0x00 to 0xFF
Byte
128 = temper ature [°C]
B3
Distance
MSB 0x00 to 0xFF
B4
Distance
L SB 0x00 to 0xFF
B5
Infobyte
0x00 to 0xFF

This one works

function Decoder(bytes) {
var dist = (290 - ((bytes[5] << 8) | bytes[6]));
var batt = (((bytes[0]) * 30 ) / 1000);
return {
distance: (dist),
battery: (batt),
};
}

Would be helpful if you told us the details of the ‘models’… do they both use the same encoder?

In exchange for?

What are you struggling with on this? Best to share so that any volunteers can avoid those issues.

Not much structure in that post, please can you edit it in to a table.