How to use the open-sml.SmlFile function in open-sml

To help you get started, we’ve selected a few open-sml examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Apollon77 / smartmeter-obis / lib / protocols / SmlProtocol.js View on Github external
SmlProtocol.prototype.handleMessage = function handleMessage(message) {
    message = message.toString('hex');
    var regMessage = message.match(regCompleteMsg);
    if (!regMessage || !regMessage[1]) {
        this.callUserCallback(new Error('Message ' + message + 'invalid'), null);
        return null;
    }

    var smlFile = new OpenSml.SmlFile();

    var idx = message.indexOf(regMessage[1]);
    if (this.options.debug === 2) this.options.logger('MSG IDX ' + idx);
    try {
        smlFile.parse(Buffer.from(regMessage[1], 'hex'));
    }
    catch (err) {
        smlFile = null;
        this.callUserCallback(new Error('Error while parsing SML message: ' + err + ': Message: ' + regMessage[1]), null);
        if (idx !== -1) {
            return Buffer.from(message.substr(idx+regMessage[1].length), 'hex');
        }
        return null;
    }

    if (this.options.debug === 2) this.options.logger('SML MESSAGE: ' + smlFile.toString());

open-sml

Smart Message Language Implementation

MIT
Latest version published 3 years ago

Package Health Score

46 / 100
Full package analysis

Popular open-sml functions