UNPKG

knxultimate

Version:

KNX IP protocol implementation for Node. This is the ENGINE of Node-Red KNX-Ultimate node.

63 lines 2.32 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("../utils"); const KnxLog_1 = require("../KnxLog"); const logger = (0, KnxLog_1.module)('DPT18'); const config = { id: 'DPT18', formatAPDU: (value) => { if (!value) { logger.warn('cannot write null value'); return null; } const apdu_data = Buffer.alloc(1); if (typeof value === 'object' && (0, utils_1.hasProp)(value, 'save_recall') && (0, utils_1.hasProp)(value, 'scenenumber')) { if (value.scenenumber > 64 || value.scenenumber < 1) { logger.error('scenenumber must between 1 and 64'); return null; } const sSceneNumberbinary = ((value.scenenumber - 1) >>> 0).toString(2); const sVal = `${value.save_recall}0${sSceneNumberbinary.padStart(6, '0')}`; apdu_data[0] = parseInt(sVal, 2); return apdu_data; } logger.error('Must supply a value object of {save_recall, scenenumber}'); return null; return null; }, fromBuffer: (buf) => { if (buf.length !== 1) { logger.error('Buffer should be 1 byte long, got', buf.length); return null; } const sBit = parseInt(buf.toString('hex').toUpperCase(), 16) .toString(2) .padStart(8, '0'); return { save_recall: Number(sBit.substring(0, 1)), scenenumber: parseInt(sBit.substring(2), 2) + 1, }; return null; }, basetype: { bitlength: 8, valuetype: 'composite', desc: '8-bit Scene Activate/Learn + number', help: `// To save and recall scene, use payload:{"ave_recall:0, scenenumber:2} // save_recall = 0 recalls the scene // save_recall = 1 saves the scene // scenenumber is the number of the scene to be recalled or saved return {payload:{save_recall:0, scenenumber:2}};`, helplink: 'https://github.com/Supergiovane/node-red-contrib-knx-ultimate/wiki/-Sample---Control-a-scene-actuator', }, subtypes: { '001': { desc: 'DPT_SceneControl', name: 'Scene control', }, }, }; exports.default = config; //# sourceMappingURL=dpt18.js.map