/* _____ _____ __ _ __ / ___/___ ____ ____ ___ ____ ___ ____ / ___/___ ____ _____/ /_(_)____/ /__ \__ \/ _ \/ __ \/_ / / _ \/ __ `__ \/ __ \\__ \/ _ \/ __ \/ ___/ __/ / ___/ //_/ ___/ / __/ / / / / /_/ __/ / / / / / /_/ /__/ / __/ / / (__ ) /_/ / /__/ ,< /____/\___/_/ /_/ /___/\___/_/ /_/ /_/\____/____/\___/_/ /_/____/\__/_/\___/_/|_| Senstick SPM10 HW 1.0 - FW 1.0 */ function decodeUplink(input) { const bytes = input.bytes; const port = input.fPort; var Status; var PulseCount; var BatteryLevel; // Alarm Packet if (port == 1) { if (bytes.length == 1) { Status = bytes[0]; return { data: { Status: Status }, warnings: [], errors: [] }; } } // Data Packet else if (port == 2) { if (bytes.length == 5) { PulseCount = ((bytes[0] << 24) + (bytes[1] << 16) + (bytes[2] << 8) + bytes[3])>>>0; BatteryLevel = bytes[4]; return { data: { PulseCount: PulseCount, BatteryLevel: map(BatteryLevel, 0, 255, 800, 1800) }, warnings: [], errors: [] }; } else if (bytes.length == 6) { Status = bytes[0]; PulseCount = ((bytes[1] << 24) + (bytes[2] << 16) + (bytes[3] << 8) + bytes[4])>>>0; BatteryLevel = bytes[5]; return { data: { Status: Status, PulseCount: PulseCount, BatteryLevel: map(BatteryLevel, 0, 255, 800, 1800) }, warnings: [], errors: [] } } } // If Config packet else if ((port == 3) || (port == 4)) { Status = bytes[0]; var SendPeriod = bytes[1]; var HeartbeatPeriod = bytes[2]; var PulseMultiplier = (bytes[3] << 8) + bytes[4]; var CounterAlert = (bytes[5] << 8) + bytes[6]; var MoveThr = bytes[7]; var PacketConfirm = bytes[8]; var DataRatePlusADR = bytes[9]; var FamilyId = bytes[10]; var ProductId = bytes[11]; var HW = bytes[12]; var FW = bytes[13]; var ADRon = Boolean(DataRatePlusADR & (1 << 7)); var DataRate = (DataRatePlusADR & 0x7F); return { data: { Status: Status, SendPeriod: SendPeriod, HeartbeatPeriod: HeartbeatPeriod, Resolution: PulseMultiplier, LevelAlert: CounterAlert, MoveThr:MoveThr, PacketConfirm: PacketConfirm, DataRate: DataRate, ADRon: ADRon, FamilyId: FamilyId, ProductId: ProductId, HW: HW/10, FW: FW/10 }, warnings: [], errors: [] }; } } function map(x, in_min, in_max, out_min, out_max){ var temp = ((x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min); temp = temp.toFixed(); return (temp); }