@eflexsystems/node-open-protocol
Version:
A library to interface with Power Tools using the Atlas Copco Open Protocol
85 lines (62 loc) • 1.66 kB
JavaScript
//@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 MID0074
* @param {object} MID0074
* @param {string} MID0074.errorCode
*/
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, "errorCode", "string", 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:
buf = Buffer.alloc(4);
position.value = 4;
statusprocess = serializerField(msg, buf, "errorCode", "string", 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
};