/* ___ ___ _ __ ___ _______ _ __ ___ ___ / __|/ _ \ '_ \ / _ \_ / _ \ '_ ` _ \ / _ \ \__ \ __/ | | | __// / __/ | | | | | (_) | |___/\___|_| |_|\___/___\___|_| |_| |_|\___/ Senstick Pure Battery SPU11B HW 1.1 - FW 1.1 */ function decodeUplink(input) { const bytes = input.bytes; const port = input.fPort; var Status; var Temperature; var Humidity; var AirPressure; var TVOC; var IAQ; var CO2; var Voltage; // Data Packet if (port == 2) { if (bytes.length == 10) { Temperature = (bytes[0] << 8) + bytes[1]; Humidity = (bytes[2] << 8) + bytes[3]; AirPressure = (bytes[4] << 8) + bytes[5]; CO2 = (bytes[6] << 8) + bytes[7]; Voltage = (bytes[8] << 8) + bytes[9]; return { data: { Temperature: sintToDec(Temperature), Humidity: Humidity / 100.0, AirPressure: AirPressure / 10.0, CO2: CO2, Voltage: Voltage }, warnings: [], errors: [] }; } else if (bytes.length == 11) { Status = bytes[0]; Temperature = (bytes[1] << 8) + bytes[2]; Humidity = (bytes[3] << 8) + bytes[4]; AirPressure = (bytes[5] << 8) + bytes[6]; CO2 = (bytes[7] << 8) + bytes[8]; Voltage = (bytes[9] << 8) + bytes[10]; return { data: { Status: Status, Temperature: sintToDec(Temperature), Humidity: Humidity / 100.0, AirPressure: AirPressure / 10.0, CO2: CO2, Voltage: Voltage }, warnings: [], errors: [] }; } else if (bytes.length == 12) { Temperature = (bytes[0] << 8) + bytes[1]; Humidity = (bytes[2] << 8) + bytes[3]; AirPressure = (bytes[4] << 8) + bytes[5]; TVOC = (bytes[6] << 8) + bytes[7]; CO2 = (bytes[8] << 8) + bytes[9]; Voltage = (bytes[10] << 8) + bytes[11]; return { data: { Temperature: sintToDec(Temperature), Humidity: Humidity / 100.0, AirPressure: AirPressure / 10.0, TVOC: TVOC / 100.0, CO2: CO2, Voltage: Voltage }, warnings: [], errors: [] }; } else if (bytes.length == 13) { Status = bytes[0]; Temperature = (bytes[1] << 8) + bytes[2]; Humidity = (bytes[3] << 8) + bytes[4]; AirPressure = (bytes[5] << 8) + bytes[6]; TVOC = (bytes[7] << 8) + bytes[8]; CO2 = (bytes[9] << 8) + bytes[10]; Voltage = (bytes[11] << 8) + bytes[12]; return { data: { Status: Status, Temperature: sintToDec(Temperature), Humidity: Humidity / 100.0, AirPressure: AirPressure / 10.0, TVOC: TVOC / 100.0, CO2: CO2, Voltage: Voltage }, warnings: [], errors: [] }; } } // Config packet else if (port == 3) { if (bytes.length == 11) { Status = bytes[0]; var ZmodOnPlusPacketConfirm = bytes[1]; var DataRatePlusADR = bytes[2]; var SendPeriod = bytes[3]; var LedMidThreshold = bytes[4]; var LedHighThreshold = bytes[5]; var LedIntensity = bytes[6]; var FamilyId = bytes[7]; var ProductId = bytes[8]; var HardwareVersion = bytes[9]; var FirmWareVersion = bytes[10]; var ADRon = Boolean(DataRatePlusADR & (1 << 7)); var DataRate = (DataRatePlusADR & 0x7F); var ZMODon = Boolean(ZmodOnPlusPacketConfirm & (1 << 7)); var PacketConfirm = (ZmodOnPlusPacketConfirm & 0x7F); return { data: { Status: Status, PacketConfirm: PacketConfirm, DataRate: DataRate, ADRon: ADRon, ZMODon: ZMODon, SendPeriod: SendPeriod, LedMidThreshold: LedMidThreshold * 10.0, LedHighThreshold: LedHighThreshold * 10.0, LedIntensity: LedIntensity, FamilyId: FamilyId, ProductId: ProductId, HardwareVersion: HardwareVersion / 10.0, FirmWareVersion: FirmWareVersion / 10.0 }, warnings: [], errors: [] }; } } } function sintToDec(T){ if (T > 32767) { return ((T - 65536) / 100.0); } else { return (T / 100.0); } }