Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Image Added

Milesight Codec Uplink Decoder

Code Block
languagejs
function Decode(fPort, bytes) {
    switch (fPort) {
        case 1:
            {
                var output = {
                    Current_Valve_Position: bytes[0],
                    Flow_Sensor_Raw: bytes[1] * 0.5,
                    Flow_Temperature: bytes[2] * 0.5,
                    Ambient_Sensor_Raw: bytes[3] * 0.25,
                    Ambient_Temperature: bytes[4] * 0.25,
                    Energy_Storage: bytes[5] >> 6 & 0x01,
                    Harvesting_Active: bytes[5] >> 5 & 0x01,
                    Ambient_Sensor_Failure: bytes[5] >> 4 & 0x01,
                    Flow_Sensor_Failure: bytes[5] >> 3 & 0x01,
                    Radio_Communication_Error: bytes[5] >> 2 & 0x01,
                    Received_Signal_Strength: bytes[5] >> 1 & 0x01,
                    Motor_Error: bytes[5] >> 0 & 0x01,
                    Storage_Voltage: Number((bytes[6] * 0.02).toFixed(2)),
                    Average_Current_Consumed: bytes[7] * 10,
                    Average_Current_Generated: bytes[8] * 10,
                    Reference_Completed: bytes[9] >> 4 & 0x01,
                    Operating_Mode: bytes[9] >> 7 & 0x01,
                    Storage_Fully_Charged: bytes[9] >> 6 & 0x01,
                }
                if (bytes.length == 11) {
                    var um = bytes[9] & 0x03
                    if (um == 0) {
                        var uv = bytes[10]
                    }
                    else {
                        var uv = bytes[10] * 0.5
                    }
                    output.User_Mode = um
                    output.User_Value = uv
                }
                return output;
            }
        default:
            return {
                errors: ['unknown FPort'],
            };
    }

}