Maybe this helps, it is an extract of my “FieldTester Plus Parser”.
Loss rate calculation is not working well, it depends on fCnt and an internal counter of the flow.
Switch Fieldtester from LinkCheck to Fieldtester Plus Function
By default the Fieldtester works in LinkCheck mode.
To switch to Fieldtester Plus functionality the Gateway Extension will send a downlink on fPort 10.
When using other back-ends, this downlink must be sent to force the Fieldtester into Fieldtester Plus mode;
Downlink (HEX) 76312E312E30
fPort 10
Uplink format
Byte 0 to 5 ==> Fieldtester location
// decode bytes
var lonSign = (bytes[0] >> 7) & 0x01 ? -1 : 1;
var latSign = (bytes[0] >> 6) & 0x01 ? -1 : 1;
var encLat = ((bytes[0] & 0x3f) << 17) + (bytes[1] << 9) + (bytes[2] << 1) + (bytes[3] >> 7);
var encLon = ((bytes[3] & 0x7f) << 16) + (bytes[4] << 8) + bytes[5];
// get tester location
data.latitude = latSign * (encLat * 108 + 53) / 10000000;
data.longitude = lonSign * (encLon * 215 + 107) / 10000000;
Byte 6 & 7 ==> unused in this decoder
Byte 8 & 9 ==> packet number, used for calculation of packet loss rate
Downlink format
Byte 0 & 1 ==> packet loss rate (calculated from fCnt and counter of NodeRED flow, not accurate)
// Get packet loss rate
var packet_num = bytes[8] << 8;
packet_num = packet_num + bytes[9];
var loss_rate = getLossRate(packet_num);
Byte 2 ==> max RSSI
if (gateway.rssi > data.max_rssi) data.max_rssi = gateway.rssi;
Byte 3 ==> min distance
Byte 4 ==> max distance
if ((data.has_gps) && (gateway.location)) {
var distance = parseInt(circleDistance(data, gateway.location));
node.warn("Calc distance " + distance);
if (distance < data.min_distance) data.min_distance = distance;
if (distance > data.max_distance) data.max_distance = distance;
}
Byte 5 ==> number of gateways & sequenceID
((data.num_gateways << 4) & 0xFF) + (sequence_id >> 4),
Byte 6 ==> sequence ID
sequence_id & 0x0F,
Byte 7 ==> max SNR
if (gateway.snr > data.max_snr) data.max_snr = gateway.snr;
Byte 8 to 10 ==> last 3 digits of gateway ID. Normally the GW ID with the Fieldtester extension, here taken from the last gateway in the gateway list.
data.gw_id_1, data.gw_id_2, data.gw_id_3
Output buffer creation:
data.buffer = Buffer.from([
(loss_rate >> 8) & 0x00FF,
loss_rate & 0xFF,
parseInt(data.max_rssi + 200, 10) & 0xFF,
min_distance,
max_distance,
((data.num_gateways << 4) & 0xFF) + (sequence_id >> 4), // create new GW number << 4 + sequenceID >> 4
sequence_id & 0x0F,
parseInt(data.max_snr, 10) & 0xFF,
data.gw_id_1, data.gw_id_2, data.gw_id_3
])
I attached the whole flow here.
node-red-parse-uplink-flow.zip (2.3 KB)