Нашел ошибку в работе приложения под винду. Оно передаёт комманду 80 00 00 00 11 41 00 00 BC 00 31 00 00 08!!! 03 06 00 00 00 01 00 42 а должно 80 00 00 00 11 41 00 00 BC 00 31 00 00 07!!! 03 06 00 00 00 01 00 42. Видимо 07 и 08 это именно модели пульта. Хотя хз. Там вообще напутано с командами...
Теперь надо понять как это всё привязать к МД.. Может кто-то помочь прикрутить яваскрипт к мд?:))
'use strict';
var dgram = require('dgram');
var debug=false;
var DEFAULT_HOST ;
var DEFAULT_PORT ;
var DEFAULT_REPEATS=3 ;
var PREAMPLE = [0x80,0x00,0x00,0x00,0x11]
var FILLER = 0x00
var CMDS={
ON: [0x31,0,0,0x08,0x04,0x01,0,0,0],
OFF: [0x31,0,0,0x08,0x04,0x02,0,0,0],
NIGHT: [0x31,0,0,0x08,0x04,0x05,0,0,0],
WHITEON: [0x31,0,0,0x08,0x05,0x64,0,0,0],
REG: [0x33,0,0,0,0,0,0,0,0,0],
BON: [0x31,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00],
BOFF:[0x31,0x00,0x00,0x00,0x03,0x04,0x00,0x00,0x00],
BWHITE:[0x31 ,0x00 ,0x00 ,0x00 ,0x03 ,0x05 ,0x00 ,0x00 ,0x00],
};
var socket;
var zoneCtlRGBWWFactory=function(zoneID){
var color=0x7A;
var brightness=0x32;
//var saturation=0x32;
//var colorTemp=0x4B;
var zone=zoneID;
if(zone > 4 || zone <0 ) console.log("invalid zone");
return {
on: function(){
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00, zoneID];
},
off: function(){
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x02, 0x00, 0x00, 0x00, zoneID];
},
nightMode: function() {
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x06, 0x00, 0x00, 0x00, zoneID];
},
whiteMode:function() {
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x05, 0x00, 0x00, 0x00, zoneID];
},
brightnessUp:function(){
brightness=Math.min(brightness+5,0x64);
return [0x31, 0x00, 0x00, 0x07, 0x02, brightness, 0x00, 0x00, 0x00, zoneID]
},
brightnessDown:function(){
brightness=Math.max(brightness-5,0x00);
return [0x31, 0x00, 0x00, 0x07, 0x02, brightness, 0x00, 0x00, 0x00, zoneID]
},
brightnessSet:function(b){
brightness=Math.max(b,0x00);
brightness=Math.min(b,0xFF);
return [0x31, 0x00, 0x00, 0x07, 0x02, brightness, 0x00, 0x00, 0x00, zoneID]
},
colorUp:function(){
color=Math.min(color+5,0xFF);
return [0x31, 0x00, 0x00, 0x07, 0x01, color, color, color, color, zoneID]
},
colorDown:function(){
color=Math.max(color-5,0x00);
return [0x31, 0x00, 0x00, 0x07, 0x01, color, color, color, color, zoneID]
},
colorSet:function(c){
color=c;
return [0x31, 0x00, 0x00, 0x07, 0x01, color, color, color, color, zoneID]
},
colorRGB:function(rgb){
return rgbHandler(rgb,this);
},
mode:function(mode){
return [0x31, 0x00, 0x00, 0x07, 0x04, mode, 0x00, 0x00, 0x00, zoneID]
},
modeSpeedUp:function(){
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x03, 0x00, 0x00, 0x00, zoneID]
},
modeSpeedDown:function(){
return [0x31, 0x00, 0x00, 0x07, 0x03, 0x04, 0x00, 0x00, 0x00, zoneID]
},
link:function(){
console.log("link not captured");
return [0x3D,0,0,0x07,0,0,0,0,0,zoneID]
},
unlink:function(){
console.log("link not captured");
return [0x3E,0,0,0x07,0,0,0,0,0,zoneID]
},
command(fnName,arg){
if (this[fnName]) {
var cmds=this[fnName](arg);
if (Array.isArray(cmds) && Array.isArray(cmds[0])){
cmds.forEach(function(elem){sendCmd(elem)})
} else {
sendCmd(cmds);//single cmd`
}
}
}
}
}
var baseCtlFactory=function(){
var color=0x7A;
var brightness=0x32;
var zoneID=0x01;
return {
on:function(){return [0x31,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x00,zoneID]},
off:function(){return [0x31,0x00,0x00,0x00,0x03,0x04,0x00,0x00,0x00,zoneID]},
whiteMode:function(){return [0x31 ,0x00 ,0x00 ,0x00 ,0x03 ,0x05 ,0x00 ,0x00 ,0x00,zoneID]},
brightnessUp:function(){
brightness=Math.min(brightness+5,0x64);
return [0x31,0x00,0x00,0x00,0x02,brightness,0x00,0x00,0x00,zoneID]
},
brightnessDown:function(){
brightness=Math.max(brightness-5,0x00);
return [0x31,0x00,0x00,0x00,0x02,brightness,0x00,0x00,0x00,zoneID]
},
brightnessSet:function(b){
brightness=Math.max(b,0x00);
brightness=Math.min(b,0xFF);
return [0x31,0x00,0x00,0x00,0x02,brightness,0x00,0x00,0x00,zoneID]
},
colorUp:function(){
color=Math.min(color+5,0xFF);
return [0x31,0x00,0x00,0x00,0x01,color,color,color,color,zoneID]
},
colorDown:function(){
color=Math.max(color-5,0x00);
return [0x31,0x00,0x00,0x00,0x01,color,color,color,color,zoneID]
},
colorSet:function(c){
color=c;
return [0x31,0x00,0x00,0x00,0x01,color,color,color,color,zoneID]
},
colorRGB:function(rgb){
return rgbHandler(rgb,this);
},
mode:function(mode){
return [0x31,0x00,0x00,0x00,0x04,mode,0,0,0,zoneID]
},
command(fnName,arg){
if (this[fnName]) {
var cmds=this[fnName](arg);
if (Array.isArray(cmds) && Array.isArray(cmds[0])){
cmds.forEach(function(elem){sendCmd(elem)})
} else {
sendCmd(cmds);//single cmd`
}
}
}
}
};
var bridgeID;
var bridgeID2;
var seqNum=0x02;
var sendCmd = function(CMD,repeats){
if (typeof repeats === 'undefined') { repeats = DEFAULT_REPEATS};
var out=[];
//console.log("#"+WB.toString('hex')+"-"+CMD.toString("hex"));
out=out.concat(PREAMPLE,bridgeID,bridgeID2,0x00,seqNum,FILLER,CMD)
var chkSum=calcCheckSum(out);
out = out.concat(chkSum);
//console.log(JSON.stringify(out));
if (debug) console.log("#"+out.toString('hex'));
out=new Buffer(out);
seqNum=(seqNum+1)%256;
if(debug) console.log("Sending: " + out.toString('hex'));
for (var i=0;i {
//console.log('Received %d bytes from %s:%d\n',
// msg.length, rinfo.address, rinfo.port);
var hmsg=msg.toString('hex');
var resp=(msg.toString('hex').substring(0,10));
if (_func[resp]) {
_func[resp](msg)
} else {
console.log("Unknown code");
console.log(hmsg);
}
});
var initiate=function(host,port){
//socket.send(payload,0,payload.length,DEFAULT_PORT,DEFAULT_HOST,function(a,b){});
DEFAULT_HOST=host;
DEFAULT_PORT=port;
//socket.bind();
//socket.bind(DEFAULT_PORT);
var payload=new Buffer([0x20,0x00,0x00,0x00,0x16,0x02,0x62,0x3a,0xd5,0xed,0xa3,0x01,0xae,0x08,0x2d,0x46,0x61,0x41,0xa7,0xf6,0xdc,0xaf,0xfe,0xf7,0x00,0x00,0x1e]);
if (debug) console.log(payload.toString('hex'));
sendFrame(payload);
};
exports.initiate= initiate;
exports.baseCtlFactory= baseCtlFactory;
exports.zoneCtlRGBWFactory= zoneCtlRGBWFactory;
exports.zoneCtlRGBWWFactory= zoneCtlRGBWWFactory;
exports.sendCmd= sendCmd;
Я правда не уверен, что это всё правильно написано. Там есть описание того, как это должно работать - отправка запрососв и тд. Но я вообще в программировании не силён