...
Milesight Codec Uplink Decoder
Code Block | ||
---|---|---|
| ||
function Decode(fPort, bytes) {
switch (fPort) {
case 1:
{
var output = {};
var decoded = {};
decoded.DEV_EUI = LoRaObject.devEUI;
decoded.RSSI = LoRaObject.rxInfo[0].rssi;
decoded.SNR = LoRaObject.rxInfo[0].loRaSNR;
decoded.Data = LoRaObject.data;
decoded.ADR = LoRaObject.txInfo.adr;
decoded.coderate = LoRaObject.txInfo.codeRate;
decoded.FCnt = LoRaObject.fCnt;
decoded.Port = LoRaObject.fPort;
decoded.Frequency = LoRaObject.txInfo.frequency;
decoded.Modulation = LoRaObject.txInfo.dataRate.modulation;
decoded.Bandwidth = LoRaObject.txInfo.dataRate.bandwidth;
decoded.SpreadingFactor = LoRaObject.txInfo.dataRate.spreadFactor;
output.Current_Valve_Position = bytes[0];
output.Flow_Sensor_Raw = bytes[1] * 0.5;
output.Flow_Temperature = bytes[2] * 0.5;
output.Ambient_Sensor_Raw = bytes[3] * 0.25;
output.Ambient_Temperature = bytes[4] * 0.25;
output.Energy_Storage = bytes[5] >> 6 & 0x01;
output.Harvesting_Active = bytes[5] >> 5 & 0x01;
output.Ambient_Sensor_Failure = bytes[5] >> 4 & 0x01;
output.Flow_Sensor_Failure = bytes[5] >> 3 & 0x01;
output.Radio_Communication_Error = bytes[5] >> 2 & 0x01;
output.Received_Signal_Strength = bytes[5] >> 1 & 0x01;
output.Motor_Error = bytes[5] >> 0 & 0x01;
output.Storage_Voltage = Number((bytes[6] * 0.02).toFixed(2));
output.Average_Current_Consumed = bytes[7] * 10;
output.Average_Current_Generated = bytes[8] * 10;
output.Reference_Completed = bytes[9] >> 4 & 0x01;
output.Operating_Mode = bytes[9] >> 7 & 0x01;
output.Storage_Fully_Charged = bytes[9] >> 6 & 0x01;
if (bytes.length === 11) {
var um = bytes[9] & 0x03;
var uv = (um === 0) ? bytes[10] : bytes[10] * 0.5;
output.User_Mode = um;
output.User_Value = uv;
}
return {status: decoded, uplink_decoded: output};
}
default:
return {
errors: ['unknown FPort'],
};
}
}
|