Skip to content

Commit

Permalink
Extended payload formatter for new features (#842)
Browse files Browse the repository at this point in the history
Co-authored-by: Jaime Trinidad <[email protected]>
  • Loading branch information
oholthau and Jaime-Trinidad authored Nov 14, 2024
1 parent de6a2c2 commit 0e1fc8a
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion vendor/plenom/busylight.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,68 @@ function decodeUplink(input) {
errors: []
};
}
else if (input.bytes.length == 25)
{
switch (input.bytes[24])
{
case 0x01:
reason="Power On Reset";
break;
case 0x02:
reason="Brownout 1.2V";
break;
case 0x04:
reason="Brownout 3.3V";
break;
case 0x10:
reason="External Reset";
break;
case 0x20:
reason="WatchDog Timer triggered";
break;
case 0x40:
reason="Software";
break;
case 0x80:
reason="Backup";
break;
}
return {
data: {
RSSI: byteArrayToLong(input.bytes, 0),
SNR: byteArrayToLong(input.bytes, 4),
messages_received: byteArrayToLong(input.bytes, 8),
messages_send: byteArrayToLong(input.bytes, 12),
lastcolor_red: input.bytes[16],
lastcolor_blue: input.bytes[17],
lastcolor_green: input.bytes[18],
lastcolor_ontime: input.bytes[19],
lastcolor_offtime: input.bytes[20],
sw_rev: input.bytes[21],
hw_rev: input.bytes[22],
adr_state: input.bytes[23],
last_reset_reason: reason
},
warnings: [],
errors: []
};
}
else if (input.bytes.length == 10)
{
return {
data: {
messages_send: byteArrayToLong(input.bytes, 0),
lastcolor_red: input.bytes[4],
lastcolor_blue: input.bytes[5],
lastcolor_green: input.bytes[6],
lastcolor_ontime: input.bytes[7],
lastcolor_offtime: input.bytes[8],
last_reset_reason: input.bytes[9]
},
warnings: [],
errors: []
};
}
else
{
return {data: {
Expand Down Expand Up @@ -48,8 +110,10 @@ function encodeDownlink(input) {
}

function decodeDownlink(input) {

if (input.bytes.length == 5)
{
return {

data: {
red: input.bytes[0],
green: input.bytes[2],
Expand All @@ -60,4 +124,22 @@ function decodeDownlink(input) {
warnings: [],
errors: []
}
}
else if (input.bytes.length == 6)
{
return {

data: {
red: input.bytes[0],
green: input.bytes[2],
blue: input.bytes[1],
ontime: input.bytes[3],
offtime: input.bytes[4],
immediate_uplink: input.byte[5]
},
warnings: [],
errors: []
}
}
}

0 comments on commit 0e1fc8a

Please sign in to comment.