revised decoder.js
This commit is contained in:
parent
41b0c0b98f
commit
3df6fefe06
|
@ -44,7 +44,7 @@ uint32_t sts_hmac_verify(void)
|
||||||
|
|
||||||
ret = memcmp(hmac_result.hmac_tag, (void *)sts_ac_code, sizeof(sts_ac_code));
|
ret = memcmp(hmac_result.hmac_tag, (void *)sts_ac_code, sizeof(sts_ac_code));
|
||||||
hmac_result.ac_pass = (ret == 0x0)?1U:0U;
|
hmac_result.ac_pass = (ret == 0x0)?1U:0U;
|
||||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\nHMAC Verify Success = %u \r\n", hmac_result.ac_pass);
|
APP_LOG(TS_OFF, VLEVEL_H, "\r\nHMAC Verify Success = %u \r\n", hmac_result.ac_pass);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2214,9 +2214,6 @@ void OnRestoreSTSCFGContextProcess(void)
|
||||||
|
|
||||||
OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
|
OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
|
||||||
|
|
||||||
|
|
||||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\n ================ STS SERVICE MASK --1 = %d \r\n", sts_service_mask);
|
|
||||||
|
|
||||||
if ((sts_cfg_nvm.ac[0] ==0x0 )&& (sts_cfg_nvm.ac[19]==0x0))
|
if ((sts_cfg_nvm.ac[0] ==0x0 )&& (sts_cfg_nvm.ac[19]==0x0))
|
||||||
{
|
{
|
||||||
//OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
|
//OnTxPeriodicityChanged(APP_TX_DUTYCYCLE); // in msec unit
|
||||||
|
@ -2243,8 +2240,6 @@ void OnRestoreSTSCFGContextProcess(void)
|
||||||
sts_work_mode = sts_cfg_nvm.work_mode;
|
sts_work_mode = sts_cfg_nvm.work_mode;
|
||||||
sts_service_mask = sts_cfg_nvm.sts_service_mask;
|
sts_service_mask = sts_cfg_nvm.sts_service_mask;
|
||||||
|
|
||||||
APP_LOG(TS_OFF, VLEVEL_L, "\r\n ================ STS SERVICE MASK --2 = %d \r\n", sts_service_mask);
|
|
||||||
|
|
||||||
#ifdef STS_TMG
|
#ifdef STS_TMG
|
||||||
/*
|
/*
|
||||||
volatile uint8_t averageTempThreshold;
|
volatile uint8_t averageTempThreshold;
|
||||||
|
|
45
decoder.js
45
decoder.js
|
@ -1,3 +1,8 @@
|
||||||
|
// Decode decodes an array of bytes into an object.
|
||||||
|
// - fPort contains the LoRaWAN fPort number
|
||||||
|
// - bytes is an array of bytes, e.g. [225, 230, 255, 0]
|
||||||
|
// - variables contains the device variables e.g. {"calibration": "3.5"} (both the key / value are of type string)
|
||||||
|
// The function must return an object, e.g. {"temperature": 22.5}
|
||||||
function Decode(fPort, data, variables) {
|
function Decode(fPort, data, variables) {
|
||||||
if (fPort === 13) {
|
if (fPort === 13) {
|
||||||
return [
|
return [
|
||||||
|
@ -21,17 +26,19 @@ function Decode(fPort, data, variables) {
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
// Heart-beat port with LED state and remaining battery level % only
|
||||||
else if (fPort === 14) {
|
else if (fPort === 14) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
led_state: (bytes[0] & 0x7f) === 0 ? "Off" : "On",
|
led_state: (bytes[0] & 0x7f) === 0 ? "Off" : "On",
|
||||||
battery_level: bytes[1] + "%",
|
battery_level: bytes[1] + " %",
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
// fPort: 1, uplink of control command
|
||||||
else if (fPort === 1) {
|
else if (fPort === 1) {
|
||||||
|
|
||||||
|
// 0x56, report HW/SW version of node
|
||||||
if (bytes[0] === 0x56) {
|
if (bytes[0] === 0x56) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
@ -42,6 +49,7 @@ function Decode(fPort, data, variables) {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
// 0x53, report seft testing result
|
||||||
else if (bytes[0] === 0x53) {
|
else if (bytes[0] === 0x53) {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
@ -51,11 +59,44 @@ function Decode(fPort, data, variables) {
|
||||||
hw_code: bytes[4],
|
hw_code: bytes[4],
|
||||||
battery_level: bytes[5] + "%",
|
battery_level: bytes[5] + "%",
|
||||||
size_value: bytes[6],
|
size_value: bytes[6],
|
||||||
|
average_temp: (bytes[7] + bytes[8] / 100) + "C",
|
||||||
|
center_temp: (bytes[9] + bytes[10] / 100) + "C",
|
||||||
|
min_temp: (bytes[11] + bytes[12] / 100) + "C",
|
||||||
|
max_temp: (bytes[13] + bytes[14] / 100) + "C",
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// 0x43, report config of node
|
||||||
|
else if (bytes[0] === 0x43) {
|
||||||
|
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
mtm_code_1: bytes[1],
|
||||||
|
mtm_code_2: bytes[2],
|
||||||
|
sw_code: bytes[3],
|
||||||
|
hw_code: bytes[4],
|
||||||
|
uplink: bytes[5],
|
||||||
|
uplink_unit: bytes[6],
|
||||||
|
heart_beat_interval: bytes[7],
|
||||||
|
heart_beat_interval_unit: bytes[8],
|
||||||
|
work_mode: bytes[9],
|
||||||
|
service_mask: bytes[10],
|
||||||
|
size_value: bytes[12],
|
||||||
|
// key parameters
|
||||||
|
averageTempThreshold: (bytes[14]) + " C",
|
||||||
|
// emmisivity for water 0.96, human 0.92
|
||||||
|
emmisivityThreshold: (bytes[16] / 100),
|
||||||
|
humanTempThreshold: (bytes[18]) + " C",
|
||||||
|
waterTempThreshold: (bytes[20] / 10) + " C",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
// 0x59,0x44 report configed heart-beat interval
|
||||||
if (bytes[0] === 0x59) {
|
if (bytes[0] === 0x59) {
|
||||||
if (bytes[1] === 0x44) {
|
if (bytes[1] === 0x44) {
|
||||||
return [
|
return [
|
||||||
|
|
Loading…
Reference in New Issue