How to use open-sml - 3 common examples

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
return Buffer.from(message.substr(idx+regMessage[1].length), 'hex');
        }
        return null;
    }

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

    var result = {};
    var crcCheck = true; // we ignore whole-Message CRC (smlFile.valid;) only check detail CRCs
    if (crcCheck) {
        for (var msg in smlFile.messages) {
            if (smlFile.messages[msg].getMessageTag() === OpenSml.Constants.GET_LIST_RESPONSE) {
                crcCheck &= smlFile.messages[msg].isValid();
                if (smlFile.messages[msg].isValid()) Object.assign(result, this.prepareResult(smlFile.messages[msg].getMessageBody().getValList()));
            }
            else if (smlFile.messages[msg].getMessageTag() === OpenSml.Constants.GET_PROFILE_LIST_RESPONSE) {
                crcCheck &= smlFile.messages[msg].isValid();
                if (smlFile.messages[msg].isValid()) Object.assign(result, this.prepareResult(smlFile.messages[msg].getMessageBody().getPeriodList()));
            }
    	}
    }
    if (Object.keys(result).length === 0) {
        if (!crcCheck) {
            if (!this.options.protocolSmlIgnoreInvalidCRC) {
                smlFile = null;
                this.callUserCallback(new Error('Message CRC-Check invalid -> no data available'), null);
                if (idx !== -1) {
                    return Buffer.from(message.substr(idx+regMessage[1].length), 'hex');
                }
                return null;
            }
            else {
github Apollon77 / smartmeter-obis / lib / protocols / SmlProtocol.js View on Github external
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());

    var result = {};
    var crcCheck = true; // we ignore whole-Message CRC (smlFile.valid;) only check detail CRCs
    if (crcCheck) {
        for (var msg in smlFile.messages) {
            if (smlFile.messages[msg].getMessageTag() === OpenSml.Constants.GET_LIST_RESPONSE) {
                crcCheck &= smlFile.messages[msg].isValid();
                if (smlFile.messages[msg].isValid()) Object.assign(result, this.prepareResult(smlFile.messages[msg].getMessageBody().getValList()));
            }
            else if (smlFile.messages[msg].getMessageTag() === OpenSml.Constants.GET_PROFILE_LIST_RESPONSE) {
                crcCheck &= smlFile.messages[msg].isValid();
                if (smlFile.messages[msg].isValid()) Object.assign(result, this.prepareResult(smlFile.messages[msg].getMessageBody().getPeriodList()));
            }
    	}
    }
    if (Object.keys(result).length === 0) {
        if (!crcCheck) {
            if (!this.options.protocolSmlIgnoreInvalidCRC) {
                smlFile = null;
                this.callUserCallback(new Error('Message CRC-Check invalid -> no data available'), null);
                if (idx !== -1) {
                    return Buffer.from(message.substr(idx+regMessage[1].length), 'hex');
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