Sensor
/* * TagoIO Decoders - (https://tago.io/) * ------------------- * Generated by :: tagoio * Generated at :: Fri Aug 25 2023 19:37:29 GMT+0000 (Coordinated Universal Time) * Machine :: fred - Node.js v18.16.0 * ------------------- */ function Decoder_smilioaction(input) { switch(input[0]){ case 0x01: return decodeFrame01_smilioaction(input); case 0x02: return decodeFrame02or03_smilioaction(input); case 0x03: return decodeFrame02or03_smilioaction(input); case 0x40: return decodeFrame40_smilioaction(input); case 0x10: return decodeFrameCode_smilioaction(input); case 0x30: return decodeFrameCode_smilioaction(input); case 0x11: return decodeFrameCode_smilioaction(input); case 0x13: return decodeFrameCode_smilioaction(input); case 0x31: return decodeFrameCode_smilioaction(input); case 0x33: return decodeFrameCode_smilioaction(input); default: throw new Error("unknown dataframe code (first two digits of payload)"); } } function decodeFrame01_smilioaction(bytes) { const data = []; data.push({ variable: "battery_idle", value: bytes[1] << 8 | bytes[2], unit: "mV" }); data.push({ variable: "battery_emission", value: bytes[3] << 8 | bytes[4], unit: "mV" }); return data; } function decodeFrame02or03_smilioaction(bytes) { const data = []; let i = 1; while(i < bytes.length){ data.push({ variable: `counter_button_${(i + 1) / 2}`, value: bytes[i] << 8 | bytes[i + 1] }); i += 2; } return data; } function decodeFrame40_smilioaction(bytes) { const data = []; data.push({ variable: "button_push_status_1", value: bytes[2] ? "pushed" : "not pushed" }); data.push({ variable: "button_push_status_2", value: bytes[4] ? "pushed" : "not pushed" }); data.push({ variable: "button_push_status_3", value: bytes[6] ? "pushed" : "not pushed" }); data.push({ variable: "button_push_status_4", value: bytes[8] ? "pushed" : "not pushed" }); data.push({ variable: "button_push_status_5", value: bytes[10] ? "pushed" : "not pushed" }); return data; } function decodeFrameCode_smilioaction(bytes) { const data = []; data.push({ variable: "acknowledgment_1", value: (bytes[0] & 0xf0) >> 4 == 3 ? "acknowledged" : "unacknowledged" }); data.push({ variable: "acknowledgment_2", value: (bytes[0] & 0x0f) == 3 ? "acknowledged" : "unacknowledged" }); data.push({ variable: "time_it_took_to_upload_code", value: bytes.readUInt16BE(1), unit: "minutes" }); data.push({ variable: "time_since_last_code_upload", value: bytes.readUInt16BE(6), unit: "minutes" }); data.push({ variable: "code_1", value: Number(bytes.slice(4, 7).toString("hex")) }); data.push({ variable: "code_2", value: Number(bytes.slice(7, 10).toString("hex")) }); return data; } const payload_smilioaction = payload.find((x)=>x.variable === "payload_raw" || x.variable === "payload" || x.variable === "data"); if (payload_smilioaction) { try { const buffer = Buffer.from(payload_smilioaction.value, "hex"); const data = Decoder_smilioaction(buffer); payload = payload.concat(data.map((x)=>({ ...x, serie: payload_smilioaction.group, time: payload_smilioaction.time }))); } catch (error) { console.error(error); payload = [ { variable: "parse_error", value: error.message } ]; } } //#sourceMappingURL=data:application/json;charset=utf-8;base64,IntcInZlcnNpb25cIjozLFwic291cmNlc1wiOltdLFwibmFtZXNcIjpbXSxcIm1hcHBpbmdzXCI6XCJcIixcImZpbGVcIjpcInN0ZG91dFwifSI=
This codec is sourced from TagoIO Github. All rights belong to TagoIO Github.
This codec is licensed under the GNU General Public License v3 (GPL v3). Modifications, if any, are clearly marked. You are free to use, modify, and distribute the codec under the terms of GPL v3.