knxultimate
Version:
KNX IP protocol implementation for Node. This is the ENGINE of Node-Red KNX-Ultimate node.
77 lines • 2.85 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const KnxLog_1 = require("../KnxLog");
const utils_1 = require("../utils");
const logger = (0, KnxLog_1.module)('DPT235');
const config = {
id: 'DPT235',
formatAPDU(value) {
try {
const apdu_data = Buffer.alloc(6);
if (typeof value === 'object' &&
(0, utils_1.hasProp)(value, 'activeElectricalEnergy') &&
(0, utils_1.hasProp)(value, 'tariff') &&
(0, utils_1.hasProp)(value, 'validityTariff') &&
(0, utils_1.hasProp)(value, 'validityEnergy')) {
const nbuff = Buffer.alloc(4);
nbuff.writeInt32BE(value.activeElectricalEnergy);
apdu_data[0] = nbuff[0];
apdu_data[1] = nbuff[1];
apdu_data[2] = nbuff[2];
apdu_data[3] = nbuff[3];
const tariff = parseInt(value.tariff);
apdu_data[4] = tariff;
const validity = parseInt(`000000${value.validityTariff ? '1' : '0'}${value.validityEnergy ? '1' : '0'}`, 2);
apdu_data[5] = validity;
return apdu_data;
}
logger.error('Must supply a payload like, for example: {activeElectricalEnergy:1540, tariff:20, validityTariff:true, validityEnergy:true}');
}
catch (error) {
logger.error(`exports.formatAPDU error ${error.message}`);
}
return null;
},
fromBuffer(buf) {
try {
const activeElectricalEnergy = buf.subarray(0, 4).readInt32BE();
const tariff = parseInt(buf.subarray(4, 5)[0]);
const validity = (0, utils_1.hex2bin)(buf.subarray(5, 6)[0].toString(16));
const validityTariff = validity.substring(6, 7) === '1';
const validityEnergy = validity.substring(7, 8) === '1';
return {
activeElectricalEnergy,
tariff,
validityTariff,
validityEnergy,
};
}
catch (error) {
logger.error(`exports.fromBuffer error ${error.message}`);
}
return null;
},
basetype: {
bitlength: 48,
valuetype: 'basic',
desc: '6 octect Tariff_ActiveEnergy',
help: `// Set the ActiveElectricalEnergy, Tariff and Validity of Tariff and Validity of Energy
msg.payload = {
activeElectricalEnergy:1540,
tariff:20,
validityTariff:true,
validityEnergy:true
};
return msg;`,
helplink: '',
},
subtypes: {
'001': {
desc: 'DPT_Tariff_ActiveEnergy',
name: 'Tariff of active Energy (Energy+Tariff+Validity)',
unit: 'Tariff',
},
},
};
exports.default = config;
//# sourceMappingURL=dpt235.js.map