NETVOX - R313Da

Sensor

Codec Description

Codec for NETVOX - R313Da (v1.0.0).

Codec Preview

/* * TagoIO Decoders - (https://tago.io/) * ------------------- * Generated by :: tagoio * Generated at :: Thu Jun 29 2023 19:27:08 GMT+0000 (Coordinated Universal Time) * Machine :: fred - Node.js v18.16.0 * ------------------- */ const bcd2number_r313da = function(bcd) { let n = 0; let m = 1; for(let i = 0; i < bcd.length; i += 1){ n += (bcd[bcd.length - 1 - i] & 0x0f) * m; n += (bcd[bcd.length - 1 - i] >> 4 & 0x0f) * m * 10; m *= 100; } return n; }; function decode_r313da(bytes, port) { switch(port){ case 6: return decode_port6_rd313da(bytes); case 7: return decode_port7_rd313da(bytes); default: throw new Error("no port configured"); } } function decode_port6_rd313da(bytes) { const data = []; const cmd = bytes[2]; switch(cmd){ case 0x00: data.push({ variable: "software_version", value: bytes[3] / 100 }); data.push({ variable: "hardware_version", value: bytes[4] }); data.push({ variable: "datecode", value: bcd2number_r313da(bytes.slice(5, 9)) }); return data; case 0x01: data.push({ variable: "battery", value: bytes[3] / 10, unit: "v" }); data.push({ variable: "status", value: bytes[4] == 0x00 ? "off" : "on" }); return data; } } function decode_port7_rd313da(bytes) { const data = []; const cmd = bytes[0]; switch(cmd){ case 0x81: data.push({ variable: "cmd", value: "config_report_rsp" }); data.push({ variable: "status", value: bytes[2] == 0x00 ? "success" : "failure" }); return data; case 0x82: data.push({ variable: "cmd", value: "read_config_report_rsp" }); data.push({ variable: "min_time", value: Number(bytes[2] << 8) + Number(bytes[3]), unit: "s" }); data.push({ variable: "max_time", value: Number(bytes[4] << 8) + Number(bytes[5]), unit: "s" }); data.push({ variable: "battery_change", value: bytes[6] / 10, unit: "v" }); return data; case 0x83: data.push({ variable: "cmd", value: "set_restore_report_rsp" }); data.push({ variable: "status", value: bytes[2] == 0x00 ? "success" : "failure" }); return data; case 0x84: data.push({ variable: "restore_report_set", value: bytes[2] == 0x00 ? "Do_not_report_when_sensor_restore" : "report_when_sensor_restore" }); return data; default: data.push({ variable: "failure", value: "command_configuration" }); return null; } } const payload_r313da = payload.find((x)=>x.variable === "payload_raw" || x.variable === "payload" || x.variable === "data" || x.variable === "payload_hex"); const port_r313da = payload.find((x)=>x.variable === "port" || x.variable === "FPort" || x.variable === "fPort" || x.variable === "fport")?.value; if (payload_r313da && port_r313da) { try { const buffer = Buffer.from(payload_r313da.value, "hex"); const data = decode_r313da(buffer, Number(port_r313da)); payload = payload.concat(data.map((x)=>({ ...x, serie: payload_r313da.group, time: payload_r313da.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.

Community Feedback