knxultimate
Version:
KNX IP protocol implementation for Node. This is the ENGINE of Node-Red KNX-Ultimate node.
90 lines • 3.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const KnxLog_1 = require("../KnxLog");
const utils_1 = require("../utils");
const logger = (0, KnxLog_1.module)('DPT242');
const config = {
id: 'DPT242',
formatAPDU(value) {
if (!value) {
logger.error('cannot write null value');
}
else {
if (typeof value === 'object' &&
(0, utils_1.hasProp)(value, 'isColorValid') &&
(0, utils_1.hasProp)(value, 'isBrightnessValid') &&
(0, utils_1.hasProp)(value, 'x') &&
value.x >= 0 &&
value.x <= 65535 &&
(0, utils_1.hasProp)(value, 'y') &&
value.y >= 0 &&
value.y <= 65535 &&
(0, utils_1.hasProp)(value, 'brightness') &&
value.brightness >= 0 &&
value.brightness <= 100) {
}
else {
logger.error('Must supply an value {x:0-65535, y:0-65535, brightness:0-100, isColorValid:true/false, isBrightnessValid:true/false}');
}
const bufferTotal = Buffer.alloc(6);
const bufX = Buffer.alloc(2);
const bufY = Buffer.alloc(2);
const bufBrightness = Buffer.alloc(2);
const isColorValid = value.isColorValid ? '1' : '0';
const isBrightnessValid = value.isBrightnessValid ? '1' : '0';
bufX.writeUInt16BE(value.x);
bufY.writeUInt16BE(value.y);
bufBrightness.writeUInt16BE(value.brightness);
bufBrightness[0] = parseInt(`000000${isColorValid}${isBrightnessValid}`, 2);
bufferTotal[0] = bufX[0];
bufferTotal[1] = bufX[1];
bufferTotal[2] = bufY[0];
bufferTotal[3] = bufY[1];
bufferTotal[4] = bufBrightness[1];
bufferTotal[5] = bufBrightness[0];
return bufferTotal;
}
return null;
},
fromBuffer(buf) {
if (buf.length !== 6) {
logger.error('Buffer should be 6 bytes long, got', buf.length);
return null;
}
const bufTotale = buf.toString('hex');
const x = bufTotale.substring(0, 4);
const y = bufTotale.substring(4, 8);
const brightness = bufTotale.substring(8, 10);
const CB = bufTotale.substring(10, 12);
const isColorValid = (0, utils_1.hex2bin)(CB).substring(6, 7) === '1';
const isBrightnessValid = (0, utils_1.hex2bin)(CB).substring(7, 8) === '1';
const ret = {
x: parseInt(x, 16),
y: parseInt(y, 16),
brightness: parseInt(brightness, 16),
isColorValid,
isBrightnessValid,
};
return ret;
return null;
},
basetype: {
bitlength: 3 * 16,
valuetype: 'basic',
desc: 'RGB xyY',
help: `// Each color in a range between 0 and 65535, brightness 0 and 100%, isColorValid true and isBrightnessValid true
msg.payload={x:500, y:500, brightness:80, isColorValid:true, isBrightnessValid:true};
return msg;`,
},
subtypes: {
600: {
desc: 'RGB xyY',
name: 'RGB color xyY',
unit: '',
scalar_range: [,],
range: [,],
},
},
};
exports.default = config;
//# sourceMappingURL=dpt242.js.map