79 lines
2.6 KiB
Plaintext
79 lines
2.6 KiB
Plaintext
function Decode(fPort, data, variables) {
|
|
if (fPort === 20) {
|
|
return [
|
|
{
|
|
led_state: bytes[0]===0?"Off":"On",
|
|
mtm_code_1:bytes[1],
|
|
mtm_code_2:bytes[2],
|
|
hw_code:bytes[3],
|
|
battery_level:bytes[4]+"%",
|
|
size_value:bytes[5],
|
|
duration: bytes[6]+"Sec",
|
|
x_freq: (bytes[7] << 8 | bytes[8])+" Hz",
|
|
y_freq: (bytes[9] << 8 | bytes[10])+" Hz",
|
|
z_freq: (bytes[11] << 8 | bytes[12])+" Hz",
|
|
x_amp: (bytes[13] << 8 | bytes[14])+" Mag",
|
|
y_amp: (bytes[15] << 8 | bytes[16])+" Mag",
|
|
z_amp: (bytes[17] << 8 | bytes[18])+" Mag"
|
|
}
|
|
];
|
|
}
|
|
|
|
else if (fPort === 21) {
|
|
return [
|
|
{
|
|
led_state: bytes[0]===0?"Off":"On",
|
|
battery_level: bytes[1]+"%",
|
|
}
|
|
];
|
|
}
|
|
else if (fPort === 1) {
|
|
|
|
if (bytes[0] === 0x56) {
|
|
return [
|
|
{
|
|
mtm_code_1: bytes[1],
|
|
mtm_code_2: bytes[2],
|
|
HW_Version: "HW:"+bytes[3],
|
|
SW_Version:"SW"+bytes[4]+":"+bytes[5]+":"+bytes[6]+":"+bytes[7],
|
|
}
|
|
];
|
|
}
|
|
else if (bytes[0] === 0x53) {
|
|
return [
|
|
{
|
|
mtm_code_1:bytes[1],
|
|
mtm_code_2:bytes[2],
|
|
sw_code:bytes[3],
|
|
hw_code:bytes[4],
|
|
battery_level:bytes[5]+"%",
|
|
size_value:bytes[6],
|
|
x_freq: (bytes[7] << 8 | bytes[8])+" Hz",
|
|
y_freq: (bytes[9] << 8 | bytes[10])+" Hz",
|
|
z_freq: (bytes[11] << 8 | bytes[12])+" Hz",
|
|
x_amp: (bytes[13] << 8 | bytes[14])+" Mag",
|
|
y_amp: (bytes[15] << 8 | bytes[16])+" Mag",
|
|
z_amp: (bytes[17] << 8 | bytes[18])+" Mag",
|
|
x_raw: (bytes[19] << 8 | bytes[20])+" amp",
|
|
y_raw: (bytes[21] << 8 | bytes[22])+" amp",
|
|
z_raw: (bytes[23] << 8 | bytes[24])+" amp",
|
|
}
|
|
];
|
|
|
|
}
|
|
|
|
if (bytes[0] === 0x59) {
|
|
if (bytes[1] === 0x44) {
|
|
return [
|
|
{
|
|
HB_interval: (bytes[2]-0x30)*10 + (bytes[3]-0x30),
|
|
HB_interval_unit: String.fromCharCode(bytes[4]),
|
|
}
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|