/* _____ _____ __ _ __ / ___/___ ____ ____ ___ ____ ___ ____ / ___/___ ____ _____/ /_(_)____/ /__ \__ \/ _ \/ __ \/_ / / _ \/ __ `__ \/ __ \\__ \/ _ \/ __ \/ ___/ __/ / ___/ //_/ ___/ / __/ / / / / /_/ __/ / / / / / /_/ /__/ / __/ / / (__ ) /_/ / /__/ ,< /____/\___/_/ /_/ /___/\___/_/ /_/ /_/\____/____/\___/_/ /_/____/\__/_/\___/_/|_| Senstick STF30 HW 3.0 - FW 2.0 */ function decodeUplink(input) { const bytes = input.bytes; const port = input.fPort; var Status; var VBAT; var P_TEMP; var P_VOLT; var NTC_RES; var VDDA; // Alert 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 == 12) { P_TEMP = (bytes[0] << 8) + bytes[1]; P_VOLT = (bytes[2] << 8) + bytes[3]; NTC_RES = (bytes[4] << 24) + (bytes[5] << 16) + (bytes[6] << 8) + bytes[7]; VDDA = (bytes[8] << 24) + (bytes[9] << 16) + (bytes[10] << 8) + (bytes[11]); return { data: { P_TEMP: sintToDec(P_TEMP), P_VOLT: P_VOLT, NTC_RES: NTC_RES, VDDA: VDDA }, warnings: [], errors: [] } } else if (bytes.length == 15) { Status = bytes[0]; VBAT = (bytes[1] << 8) + bytes[2]; P_TEMP = (bytes[3] << 8) + bytes[4]; P_VOLT = (bytes[5] << 8) + bytes[6]; NTC_RES = (bytes[7] << 24) + (bytes[8] << 16) + (bytes[9] << 8) + bytes[10]; VDDA = (bytes[11] << 24) + (bytes[12] << 16) + (bytes[13] << 8) + bytes[14] ; return { data: { Status: Status, VBAT: VBAT, P_TEMP: sintToDec(P_TEMP), P_VOLT: P_VOLT, NTC_RES: NTC_RES, VDDA: VDDA }, warnings: [], errors: [] } ; } } // Config packet else if (port == 3) { Status = bytes[0]; var SendPeriod = bytes[1]; var MovementThreshold = bytes[2]; var PacketConfirm = bytes[3]; var DataRatePlusADR = bytes[4]; var FamilyId = bytes[5]; var ProductId = bytes[6]; var HW = bytes[7]; var FW = bytes[8]; var ADRon = Boolean(DataRatePlusADR & (1 << 7)); var DataRate = (DataRatePlusADR & 0x7F); return { data: { Status: Status, SendPeriod: SendPeriod, MovementThreshold: MovementThreshold, PacketConfirm: PacketConfirm, DataRate: DataRate, ADRon: ADRon, FamilyId: FamilyId, ProductId: ProductId, HW: HW/10, FW: FW/10 }, warnings: [], errors: [] }; } } function sintToDec(T){ if (T > 32767) { return ((T - 65536) / 100.0); } else { return (T / 100.0); } }