st-one-io / node-open-protocol

This node is an implementation of the Atlas Copco's Open Protocol. This node was created by Smart-Tech as part of the ST-One project.
GNU General Public License v3.0
39 stars 38 forks source link

Ability to access raw data from all MIDs sent or received #14

Closed ferm10n closed 5 years ago

ferm10n commented 5 years ago

This adds the ability for OpParser to be used without the LinkLayer. My team found this useful for debugging purposes, and being able to pipe messages that are already serialized through it. The main goal for this was to get raw data logged for every MID exchanged between node and the tool.

Example usage:

const conn = new openProtocol.SessionControlClient({
    stream: socket,
    rawData: true
});

// log messages sent from controller (tool)
conn.on('data', data => {
    console.log('CONTROLLER', data); // CONTROLLER { ... _raw: ... }
});

// log messages sent from integrator (node)
const opWriteInspector = new openProtocol.OpenProtocolParser({
    rawData: true
});
const midWriteInspector = new openProtocol.MIDParser();
conn.ll.opSerializer.pipe(opWriteInspector);
opWriteInspector.pipe(midWriteInspector);
midWriteInspector.on('data', data => {
    console.log('INTEGRATOR', data); // INTEGRATOR { ... _raw: ... }
});

(some white spaces were trimmer too)

gfcittolin commented 5 years ago

I've just fixed a condition where, when node is under pressure, it would buffer the incoming messages in a single chunk and the content of _raw would therefore span multiple telegrams instead of the current one. Thank you, you contribution is very much appreciated.

ferm10n commented 5 years ago

Oh nice, how did you catch that? And thanks, I'm glad to help out. This package has been a godsend, honestly!

gfcittolin commented 5 years ago

Just by checking the code. I've had this kind of problem before, and it popped out of screen for me :)

Glad it's being helpful. What are you currently working with/on? Drop me a message or an e-mail, maybe we can have a talk and share some experiences ;)

ferm10n commented 5 years ago

Sounds good! just sent you an email