Uplink payload decoding function (example)
function
isKthBitSet
(byte, k){
return
byte & (
1
<< k);
}
function
decodeErrors
(errorByte){
var
errors = {};
if
(isKthBitSet(errorByte,
0
))
errors[
"WDT_RESET"
] =
"System reset has been triggered due to an"
+
" unexpected error. "
;
if
(isKthBitSet(errorByte,
1
))
errors[
"LORA_LOW_POWER_FAIL"
] =
"Embedded LoRa module failed to"
+
" enter sleep mode. If possible, please restart the device."
;
if
(isKthBitSet(errorByte,
2
))
errors[
"BATTERY"
] =
"System failed to read voltage from the battery."
+
" If possible, please restart the device."
;
if
(isKthBitSet(errorByte,
3
))
errors[
"TOF_TIMEOUT"
] =
"System failed to get a response from the"
+
" onboard ToF distance sensor. If possible, please restart the device."
;
return
errors;
}
function
decodeLevelPercentage
(level){
if
(level ===
255
)
return
"LEVEL_ERROR"
;
return
level;
}
function
decodeDistance
(distance){
if
(distance ===
0
)
return
"TARGET_TOO_CLOSE"
;
if
(distance ===
65535
)
return
"TARGET_TOO_FAR"
;
if
(distance ===
1
)
return
"INVALID_READING"
;
return
distance;
}
Copyright © Terabee 2021
Terabee, 90 Rue Henri Fabre
01630, St Genis-Pouilly, France (next to CERN)
34/36