UNPKG

@eflexsystems/node-open-protocol

Version:

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

89 lines (62 loc) 1.67 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 MID9997 * @param {object} MID9997 * @param {number} MID9997.midNumber */ 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, "midNumber", "number", 4, 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: position.value = 4; buf = Buffer.alloc(4); statusprocess = serializerField(msg, buf, "midNumber", "number", 4, 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 };