Skip to content

Commit

Permalink
Fixed dedoding of NaN values, fixed flags for compatibility mode
Browse files Browse the repository at this point in the history
  • Loading branch information
matthias-bs committed Jun 5, 2024
1 parent f4543b7 commit ec54934
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions scripts/uplink_formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
// 20240603 Added sensor battery status flags (compatibility mode)
// Added command Added CMD_GET_SENSORS_STAT and sensor status decoder
// 20240604 Added suppression of invalid value in unixtime decoder
// 20240605 Fixed dedoding of NaN values, fixed flags for compatibility mode
//
// ToDo:
// -
Expand Down Expand Up @@ -192,7 +193,7 @@ function decoder(bytes, port) {
dateObj = new Date(bytesToInt(bytes) * 1000);
let time = dateObj.toISOString();
let timestamp = bytesToInt(bytes);
if (SKIP_INVALID_SIGNALS && timestamp === 0xFFFFFFFF) {
if (SKIP_INVALID_SIGNALS && timestamp == -1) {
return NaN;
}
return { time: time, timestamp: timestamp };
Expand Down Expand Up @@ -386,7 +387,7 @@ function decoder(bytes, port) {
var e = bits >>> 23 & 0xff;
var m = (e === 0) ? (bits & 0x7fffff) << 1 : (bits & 0x7fffff) | 0x800000;
var f = sign * m * Math.pow(2, e - 150);
if (e === 0x7F && m !== 0) {
if (f == 0x40000000) {
return NaN;
}
return f.toFixed(1);
Expand Down Expand Up @@ -466,6 +467,7 @@ function decoder(bytes, port) {
if (COMPATIBILITY_MODE) {
var ws_dec_ok = true;
var s1_dec_ok = true;
var ls_dec_ok = true;
var ble_ok = true;
}
var decodedValues = mask
Expand All @@ -476,10 +478,12 @@ function decoder(bytes, port) {
if (COMPATIBILITY_MODE) {
// Check if the decoded value is NaN
var name = names[idx] || idx;
if (name.startsWith('ws_') && (name != "ws_uv")) {
//if (name == "ws_humidity") {
if ((name == "ws_temp_c") || (name == "ws_humidity") || (name == "ws_rain_mm") || (name.startsWith('ws_wind_'))) {
ws_dec_ok = false;
}
if ((name == "lgt_strike_count") || (name == "lgt_storm_dist_km")) {
ls_dec_ok = false;
}
if (name.startsWith('soil1_')) {
s1_dec_ok = false;
}
Expand All @@ -500,6 +504,7 @@ function decoder(bytes, port) {
if ((port == 1) && COMPATIBILITY_MODE) {
//decodedValues.status = {}; // Create a status object in the decoded values
decodedValues.status.ws_dec_ok = ws_dec_ok;
decodedValues.status.ls_dec_ok = ls_dec_ok;
decodedValues.status.s1_dec_ok = s1_dec_ok;
decodedValues.status.ble_ok = ble_ok;
}
Expand Down

0 comments on commit ec54934

Please sign in to comment.