UNPKG

@eflexsystems/node-open-protocol

Version:

A library to interface with Power Tools using the Atlas Copco Open Protocol

87 lines (62 loc) 1.66 kB
//@ts-check /* Copyright: (c) 2018-2020, Smart-Tech Controle e Automação GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt) */ /** * @class * @name MID0081 * @param {object} MID0081 * @param {string} MID0081.time */ const helpers = require("../helpers.js"); const processParser = helpers.processParser; const serializerField = helpers.serializerField; function parser(msg, opts, cb) { let buffer = msg.payload; msg.payload = {}; let position = { value: 0 }; msg.revision = msg.revision || 1; switch (msg.revision) { case 1: processParser(msg, buffer, "time", "string", 19, position, cb) && cb(null, msg); break; default: cb(new Error(`[Parser MID${msg.mid}] invalid revision [${msg.revision}]`)); break; } } function serializer(msg, opts, cb) { let buf; let statusprocess = false; let position = { value: 0 }; msg.revision = msg.revision || 1; switch (msg.revision) { case 1: buf = Buffer.alloc(19); position.value = 19; statusprocess = serializerField(msg, buf, "time", "string", 19, position, cb); if (!statusprocess) { return; } msg.payload = buf; cb(null, msg); break; default: cb(new Error(`[Serializer MID${msg.mid}] invalid revision [${msg.revision}]`)); break; } } function revision() { return [1]; } module.exports = { parser, serializer, revision };