Skip to content

Commit

Permalink
Updated Chirpstack V3, V4 and TTN basic translators uptill R14.
Browse files Browse the repository at this point in the history
  • Loading branch information
dparyani committed Apr 20, 2024
1 parent 4c546dc commit 5bef434
Show file tree
Hide file tree
Showing 48 changed files with 6,084 additions and 7,788 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
Filename|Product Application|Versions|CRCs
chirpstack-v3/Lifefinder-R13.js|Lifefinder|R13|3321548430
chirpstack-v3/Lifefinder-squad-R13.js|Lifefinder-squad|R13|3505805917
chirpstack-v3/Airport-int-R11-to-R13.js|Airport-int|R13 R12 R11|1695912328
chirpstack-v3/Airport-int-R13.js|Airport-int|R13|1872032769
chirpstack-v3/Radiotest-measure-R12-to-R13.js|Radiotest-measure|R13 R12|190349531
chirpstack-v3/Square-air-R13.js|Square-air|R13|472391447
chirpstack-v3/Square-air-R11-to-R12.js|Square-air|R12 R11|915094797
chirpstack-v3/Puck-radar-R13.js|Puck-radar|R13|561898260
chirpstack-v3/Puck-radar-R11-to-R12.js|Puck-radar|R12 R11|1325798073
chirpstack-v3/Square-comfort-R11-to-R12.js|Square-comfort|R12 R11|3530880224
chirpstack-v3/Square-comfort-R13.js|Square-comfort|R13|4174894842
chirpstack-v3/Lifefinder-wifi-R13.js|Lifefinder-wifi|R13|691254335
chirpstack-v3/Puck-radar-fast-rejoin-R12.js|Puck-radar-fast-rejoin|R12|729172455
chirpstack-v3/Puck-radar-fast-rejoin-R13.js|Puck-radar-fast-rejoin|R13|1121182195
chirpstack-v3/Sniffer-R12-to-R13.js|Sniffer|R13 R12|1047034189, 3509502476
chirpstack-v3/Digital-gpio-R13.js|Digital-gpio|R13|1617091456, 1835511761, 3497448490
chirpstack-v3/Square-comfort-sound-R11-to-R12.js|Square-comfort-sound|R12 R11|2387046759
chirpstack-v3/Square-comfort-sound-R13.js|Square-comfort-sound|R13|2766427005
chirpstack-v3/Lifefinder-motion-R13.js|Lifefinder-motion|R13|3031484599
chirpstack-v3/US-Frequency-hop-test-R12-to-R13.js|US-Frequency-hop-test|R13 R12|3999624005
Filename,Product Application,Versions,CRCs
chirpstack-v3/Airport-int-R11-to-R14.js,Airport-int,R11 R12 R13 R14,1695912328|1872032769
chirpstack-v3/Default-R11-to-R14.js,Default,R11 R12 R13 R14,2132727044
chirpstack-v3/Digital-gpio-R11-to-R14.js,Digital-gpio,R11 R12 R13 R14,1617091456|3497448490
chirpstack-v3/Gnss-autonomous-test-R11-to-R14.js,Gnss-autonomous-test,R11 R12 R13 R14,1815337626
chirpstack-v3/Heartstarter-R11-to-R14.js,Heartstarter,R11 R12 R13 R14,1727723267
chirpstack-v3/Lifefinder-R11-to-R14.js,Lifefinder,R11 R12 R13 R14,47853213|3321548430
chirpstack-v3/Lifefinder-motion-R11-to-R14.js,Lifefinder-motion,R11 R12 R13 R14,1938827428|3031484599
chirpstack-v3/Lifefinder-squad-R11-to-R14.js,Lifefinder-squad,R11 R12 R13 R14,399948366|3505805917
chirpstack-v3/Lifefinder-wifi-R11-to-R14.js,Lifefinder-wifi,R11 R12 R13 R14,691254335|3994244140
chirpstack-v3/Motion-measure-R11-to-R14.js,Motion-measure,R11 R12 R13 R14,2297466901
chirpstack-v3/Puck-radar-R13-to-R14.js,Puck-radar,R13 R14,561898260
chirpstack-v3/Puck-radar-R11-to-R12.js,Puck-radar,R11 R12,1325798073
chirpstack-v3/Puck-radar-fast-rejoin-R12.js,Puck-radar-fast-rejoin,R12,729172455
chirpstack-v3/Puck-radar-fast-rejoin-R13-to-R14.js,Puck-radar-fast-rejoin,R13 R14,1121182195
chirpstack-v3/Square-air-R11-to-R14.js,Square-air,R11 R12 R13 R14,472391447|915094797|4002204643
chirpstack-v3/Square-comfort-R14.js,Square-comfort,R14,2696231198
chirpstack-v3/Square-comfort-R11-to-R13.js,Square-comfort,R11 R12 R13,3530880224|4174894842
chirpstack-v3/Square-comfort-sound-R11-to-R14.js,Square-comfort-sound,R11 R12 R13 R14,517999093|2387046759|2766427005
chirpstack-v3/Tracker-R11-to-R14.js,Tracker,R11 R12 R13 R14,489186430
chirpstack-v3/Tracker-stats-R11-to-R14.js,Tracker-stats,R11 R12 R13 R14,1711284143
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function translate(iotnode) {
{
1695912328: {
name: "Airport-int",
versions: "R13 R12 R11",
versions: "R11 R12 R13 R14",
mapData: "M output temp 176 0xb0 0.01 + M output averageTemp 177 0xb1 0.01 + M input tempHysteresis 178 0xb2 0.01 + M input averageTempIntervalHours 160 0xa0 1 + M output tempAlarm 128 0x80 1 + M input tempAlarmLowLevel 161 0xa1 1 + M input tempAlarmHighLevel 162 0xa2 1 + M input motionThreshold_mm_s2 179 0xb3 1 + M input limitedScanChannels 184 0xb8 1 + M input fullScanChannels 185 0xb9 1 + M output motionCount 186 0xba 1 + M input quarterlyScanBudget 163 0xa3 1 + M input maxBudget 180 0xb4 1 + M input singleWifiScanAgain_minutes 164 0xa4 1 + M input minimumWifiCount 165 0xa5 1 + M input fullWifiScan_minutes 166 0xa6 1 + M input gpsScan_minutes 167 0xa7 1 + M input motionCountEnabled 168 0xa8 1 + M input abandonedCartTime_minutes 181 0xb5 1 + M output abandonedCart 169 0xa9 1 + M output batteryPercent 170 0xaa 1"
}
};
Expand Down Expand Up @@ -179,8 +179,7 @@ function translate(iotnode) {

var schemaInfo = {};
if (schema[rulesCrc32]) {
// there is a known schema for this node, use it [TBD how to handle conflicting
// CRCs]
// there is a known schema for this node, use it
schemaInfo = {
appName: schema[rulesCrc32].name,
schema: schema[rulesCrc32].mapData,
Expand All @@ -190,7 +189,7 @@ function translate(iotnode) {
console.log("Unknown application with CRC32: " + rulesCrc32);
}

var translatorVersion = "0.1.52"; // Replaced when creating new CRC based basic translators
var translatorVersion = "0.1.54"; // Replaced when creating new CRC based basic translators
if (data.length < 8) {
var resultVsm = {}; // This new object will hold the combined properties.

Expand Down Expand Up @@ -286,19 +285,13 @@ function translate(iotnode) {
var exp = (fp >> 10) & 0x1f;
var base = fp & 0x3ff
if (0 == exp)
return neg ?
-base :
base;
return neg ? -base : base;
else if (1 == exp) { // compressed
var value = (0x400 + base);
return neg ?
-value :
value;
return neg ? -value : value;
} else { // Round to center of interval
var value = ((0x400 + base) << (exp - 1)) + (1 << (exp - 2));
return neg ?
-value :
value;
return neg ? -value : value;
}
}

Expand All @@ -316,9 +309,8 @@ function translate(iotnode) {
return byte;
}

// Determine latest value on each field in time series, return that as a result
// object
var createResultFromTimeSeries = function (iotnode, series) {
// Determine latest value on each field in time series, return that as a result object
var createResultFromTimeSeries = function(iotnode, series) {
var timestamps = iotnode.timestamps;
var result = {
output: {},
Expand All @@ -339,7 +331,6 @@ function translate(iotnode) {
var name = keys[k];
if (timestamps.hasOwnProperty(name)) {
var lastSampvartime = new Date(timestamps[name]);
//if (lastSampvartime.getTime() < sampvartimestamp.getTime()) {
if (lastSampvartime < sampvartimestamp) {
timestamps[name] = sampvartimestamp; // Avoid overwrite from this series
result.timestamps[name] = sampvartimestamp;
Expand Down Expand Up @@ -387,17 +378,13 @@ function translate(iotnode) {
break;
}
} else { // Compressed format
timesize = (head & 0x80) ?
1 :
0;
timesize = (head & 0x80) ? 1 : 0;
}
var confirmed = true;
var decompressvalue = false;
if (compressed && ((head & 0x40) == 0)) {
datasize = 0; // No data representation, value is 0
confirmed = (head & 32) ?
false :
true;
confirmed = (head & 32) ? false : true;
} else {
switch ((head >> 3) & 7) {
case 0:
Expand Down Expand Up @@ -461,14 +448,12 @@ function translate(iotnode) {
pos += 2;
break;
case 1:
age_s = compressed ?
decode_uint32_8_t(data[pos]) * 2 :
(data[pos]);
age_s = compressed ? decode_uint32_8_t(data[pos]) * 2 : (data[pos]);
pos++;
break;
case 0:
age_ms += 1;
break; // Adding a syntetic time difference because Yggio will not record multiple events at same time
break; // Adding a syntetic time difference
}
time_s -= age_s; // Go back in time

Expand All @@ -477,7 +462,7 @@ function translate(iotnode) {
case 4:
value = (data[pos + 0] << 24) | (data[pos + 1] << 16) | (data[pos + 2] << 8) | (data[pos + 3]);
pos += 4;
break; // TODO: Handle negative values
break;
case 2:
if (decompressvalue) {
value = decode_int32_16_t(data[pos + 0] << 8) | (data[pos + 1]);
Expand Down Expand Up @@ -506,7 +491,6 @@ function translate(iotnode) {
output: valuestruct
}
};
// console.log(sample);
timeseries.push(sample);
} else {
console.log("No symbol table entry for message id " + (kind + 128) + " value " + value);
Expand Down Expand Up @@ -567,7 +551,6 @@ function translate(iotnode) {
.macAddress
.substring(15, 17);
hex += hexRSSI + hexSSID;
// console.log("Rssi", ap.signalStrength, hexRSSI, "Ssid", hexSSID);
}
return hex;
}
Expand All @@ -589,9 +572,7 @@ function translate(iotnode) {
var result = {
gnss: {}
};
var bIsStreamHeader = data[0] & 0x80 ?
true :
false;
var bIsStreamHeader = data[0] & 0x80 ? true : false;
var gnssCaptureGpsTime = 0;
if (bIsStreamHeader) {
if (data.length < 10) {
Expand All @@ -601,9 +582,7 @@ function translate(iotnode) {
}
var bContainsAssistPosition = bIsStreamHeader && (data[0] & 0x40);
var bWasAutonomousScan = bIsStreamHeader && (data[0] & 0x20);
result.gnss.autonomous = bWasAutonomousScan ?
1 :
0;
result.gnss.autonomous = bWasAutonomousScan ? 1 : 0;
result.gnss.streamSize = ((data[0] & 0x1f) << 8) | data[1];
pos += 2;

Expand All @@ -612,21 +591,16 @@ function translate(iotnode) {
pos += 4;

if (bContainsAssistPosition) {
var lat16 = ((data[pos] & 0x80 ?
0xFFFF << 16 :
0) | (data[pos] << 8) | data[pos + 1]);
var lat16 = ((data[pos] & 0x80 ? 0xFFFF << 16 : 0) | (data[pos] << 8) | data[pos + 1]);
pos += 2;
var lon16 = ((data[pos] & 0x80 ?
0xFFFF << 16 :
0) | (data[pos] << 8) | data[pos + 1]);
var lon16 = ((data[pos] & 0x80 ? 0xFFFF << 16 : 0) | (data[pos] << 8) | data[pos + 1]);
pos += 2;
// The below is magic: Convert from LR1110 driver 6.0 representation as used in
// va-gnss-stream.c
// The below is magic: Convert from LR1110 driver 6.0 representation as used in va-gnss-stream.c
result.gnss.assistanceLatitude = 90.0 * lat16 / 2048.0;
result.gnss.assistanceLongitude = 180.0 * lon16 / 2048.0;
} else {
result.gnss.assistanceLatitude = 0; // TBD: how to erase field so not old field remains - this is a bug
result.gnss.assistanceLongitude = 0; // TBD: how to erase field so not old field remains - this is a bug
result.gnss.assistanceLatitude = 0;
result.gnss.assistanceLongitude = 0;
}
var hex = "";
for (var i = pos + 1; i < data.length; ++i) // Note: skip first byte
Expand Down Expand Up @@ -675,7 +649,7 @@ function translate(iotnode) {
result.gnss.assistanceLongitude = iotnode.gnss.assistanceLongitude;
result.gnss.timestamp = new Date(1000 * (gnssCaptureGpsTime + UNIX_GPS_EPOCH_OFFSET)).toISOString();

var hex = iotnode.gnss.incompleteHex; // NOTE: Translators must be able to trust read-after-write semantics for iotnode
var hex = iotnode.gnss.incompleteHex;
for (var i = pos; i < data.length; ++i)
hex += encode_uint8_hex(data[i]);
if (hex.length / 2 === iotnode.gnss.streamSize - 1) {
Expand Down Expand Up @@ -718,8 +692,7 @@ function translate(iotnode) {
var lon16 = ((data[10] & 0x80 ?
0xFFFF << 16 :
0) | (data[10] << 8) | data[11]);
// The below is magic: Convert from LR1110 driver 6.0 representation as used in
// va-gnss-stream.c
// The below is magic: Convert from LR1110 driver 6.0 representation as used in va-gnss-stream.c
result.gnss.assistanceLatitude = 90.0 * lat16 / 2048.0;
result.gnss.assistanceLongitude = 180.0 * lon16 / 2048.0;

Expand Down Expand Up @@ -774,8 +747,8 @@ function translate(iotnode) {
if (data.length < 5)
return null;
var linktime = 1000 * ((data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]);
if (linktime > time)
return null; // No future uplinks, thankyou very much
if (linktime > time)
return null; // No future uplinks
var linkport = data[4];
var linkdecoder = mapPortToDecode[linkport];
if (!linkdecoder)
Expand Down Expand Up @@ -848,8 +821,7 @@ function translate(iotnode) {
return {
result: {
vsm: {
networkPowered: data[0] === 0 ?
1 : 0,
networkPowered: data[0] === 0 ? 1 : 0,
batteryPercent: data[0]
}
}
Expand Down Expand Up @@ -1022,8 +994,7 @@ function translate(iotnode) {
return decimalArray;
}

// Generate a symbol table from the nodes vsm.schema field (todo: reference
// database of known CRCs to know?)
// Generate a symbol table from the nodes vsm.schema field
function mkSymbolTable(iotnode) {
var symbolTable = {};

Expand Down Expand Up @@ -1090,7 +1061,6 @@ function translate(iotnode) {
type: type,
scale: scale
};
// console.log("added " + id + ": " + name + " (" + type + ") scale: " + scale);
}
return symbolTable;
}
Expand Down
Loading

0 comments on commit 5bef434

Please sign in to comment.