diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index daca5a875..3f690bb47 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -58,12 +58,15 @@ function Module() { Osci: 27000000, Freq: 50 } + this.Board_Servo = { Pulse_Min: 150, Pulse_Max: 600, us_Min: 400, - us_Max: 2100 + us_Max: 2100, + angle: 90 } + this.Board_LED_Strip = { En:0, sample: 0, @@ -133,7 +136,9 @@ Module.prototype.init = function(handler, config) { this.remoteDataSet[index+6] = (this.Board_Servo.us_Min>>8)&0xff; this.remoteDataSet[index+7] = (this.Board_Servo.us_Max)&0xff; - this.remoteDataSet[index+8] = (this.Board_Servo.us_Max>>8)&0xff; + this.remoteDataSet[index+8] = (this.Board_Servo.us_Max>>8)&0xff; + + this.remoteDataSet[index+9] = (this.Board_Servo.angle)&0xff; } // led @@ -203,10 +208,14 @@ slave 모드인 경우 duration 속성 간격으로 지속적으로 기기에 Module.prototype.requestLocalData = function() { var queryString = []; var data = this.remoteDataSet; // Module 객체의 dataset table read. max length 200 + var checksum = 0; for (var index = 0; index < this.avatarBotDataSet; index++) { var query = (data[index])&0xff; queryString.push(query); // 1byte + checksum += query; } + checksum = (checksum)&0xff; + queryString.push(checksum); // 1byte /* for(var i=0; i<(data.length/10); i++) { @@ -222,13 +231,20 @@ Module.prototype.requestLocalData = function() { }; // 하드웨어에서 온 데이터 처리 +/* Module.prototype.handleLocalData = function(data) { var self = this; for (var i = 0; i < data.length; i++) { self.dataSet[self.dataSet_index+i] = data[i]; } - - + console.log('data length ', data.length); + for(var j=0; j<21; j++) + { + let i = j*10; + console.log('data ',i, ': ', self.dataSet[i], self.dataSet[i+1], self.dataSet[i+2], self.dataSet[i+3], self.dataSet[i+4], self.dataSet[i+5], + self.dataSet[i+6], self.dataSet[i+7], self.dataSet[i+8], self.dataSet[i+9]); + } + if(self.dataSet[0] === 0x99 && self.dataSet[1] === 0x01 && self.dataSet[2] === 0x01 && self.dataSet[3] === self.avatarBotDataSet) { self.dataSet_index = self.dataSet_index + data.length; @@ -250,6 +266,57 @@ Module.prototype.handleLocalData = function(data) { }; +*/ +Module.prototype.handleLocalData = function(data) { + var self = this; + // data.length => 211 + var checksum = 0; + var getChecksum = 0; + for (var i = 0; i < data.length; i++) { + if(self.dataSet.length > i) + { + self.dataSet[self.dataSet_index+i] = data[i]; + checksum += data[i]; + }else{ + // last buffer + getChecksum = data[i]; + } + } + + checksum = (checksum)&0xff; + + /* + console.log('data length ', data.length, ', checksum = ', checksum, ', getChecksum = ', getChecksum); + for(var j=0; j<21; j++) + { + let i = j*10; + console.log('data ',i, ': ', self.dataSet[i], self.dataSet[i+1], self.dataSet[i+2], self.dataSet[i+3], self.dataSet[i+4], self.dataSet[i+5], + self.dataSet[i+6], self.dataSet[i+7], self.dataSet[i+8], self.dataSet[i+9]); + } + */ + + if(self.dataSet[0] === 0x99 && self.dataSet[1] === 0x01 && self.dataSet[2] === 0x01 && self.dataSet[3] === self.avatarBotDataSet && getChecksum == checksum) + { + self.dataSet_index = self.dataSet_index + (data.length-1); + }else{ + self.dataSet_index = 0; + return; + } + + if(self.dataSet_index == self.avatarBotDataSet){ + self.originParsing(self.dataSet); + self.dataSet_index = 0; + self.dataSet[0] = 0; // clear + self.dataSet[1] = 0; // clear + self.dataSet[2] = 0; // clear + self.dataSet[3] = 0; // clear + // + // console.log('[jhkim] handleLocalData - dataSet_index[11] = ', self.dataSet[11]); + } + + +}; + /* Original Parsing FF 55 ~ */ Module.prototype.originParsing = function(data) { diff --git a/app/modules/avatarbot.json b/app/modules/avatarbot.json index 9e55ad445..9f717ada8 100644 --- a/app/modules/avatarbot.json +++ b/app/modules/avatarbot.json @@ -4,6 +4,7 @@ "en": "AvatarBot", "ko": "AvatarBot" }, + "category": "board", "platform": ["win32", "darwin"], "icon" : "avatarbot.png", "module": "avatarbot.js", @@ -13,18 +14,17 @@ "translate": "Arduino compatible driver" }, "reconnect" : true, - "firmware": "http://avatarmecha.ddns.net:5050/sharing/iCuhzvxcu", "select_com_port":true, "entry": { "protocol": "json" }, "hardware": { - "type": "serial", + "type": "bluetooth", "control": "slave", - "duration": 500, + "duration": 300, "vendor": ["Arduino", "wch.cn", "FTDI"], - "baudRate": 460800, - "lostTimer": 1000, + "baudRate": 1000000, + "lostTimer": 2000, "firmwarecheck": false } } diff --git a/app/modules/avatarbot.png b/app/modules/avatarbot.png index 1f886c8a2..abc8a8196 100644 Binary files a/app/modules/avatarbot.png and b/app/modules/avatarbot.png differ diff --git a/app/modules/jcboard.js b/app/modules/jcboard.js index 17ac30020..bf9260071 100644 --- a/app/modules/jcboard.js +++ b/app/modules/jcboard.js @@ -73,8 +73,8 @@ Module.prototype.handleLocalData = function(data) { }; Module.prototype.requestRemoteData = function(handler) { - handler.write('A0', !!(this.sensorData[6] & 0x01)); - handler.write('A1', !!(this.sensorData[6] & 0x02)); + handler.write('A0', (this.sensorData[6] & 0x01)==0x01? 1 : 0); + handler.write('A1', (this.sensorData[6] & 0x02)==0x02? 1 : 0); handler.write('A2', this.sensorData[7]); handler.write('A3', this.sensorData[8]); handler.write('A4', this.sensorData[9]); diff --git a/app/modules/jdcode.js b/app/modules/jdcode.js index 0cc9c0e23..87404bb14 100644 --- a/app/modules/jdcode.js +++ b/app/modules/jdcode.js @@ -247,12 +247,12 @@ Module.prototype.handleLocalData = function(data) { }); if(dongleData[1] == (sum&0xFF)){ deviceType = 2; - sensorData[6] = true; + sensorData[6] = 1; sensorData[15] = dongleData[5]; sensorData[7] = dongleData[9]; sensorData[8] = dongleData[7]; sensorData[9] = dongleData[8]; - sensorData[10] = (dongleData[3]&0x03)? false : true; + sensorData[10] = (dongleData[3]&0x03)? 0 : 1; sensorData[16] = dongleData[10]; sensorData[17] = dongleData[11]; sensorData[18] = dongleData[12]; diff --git a/app/modules/robodog.js b/app/modules/robodog.js new file mode 100644 index 000000000..142c8f05b --- /dev/null +++ b/app/modules/robodog.js @@ -0,0 +1,175 @@ +function Module() { + this.cmdData = [0x26, 0xA8, 0x14, 0x81, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + this.sensorData = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + this.dongleData = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + this.robodog_head = [0x26, 0xA8, 0x14, 0x8A]; + this.rk_cnt = 0; + this.pktCnt = -1; + this.pktLength = 6; + this.ledPacket = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + this.txCnt = 0; +} + +Module.prototype.init = function(handler, config) { +}; + +Module.prototype.requestInitialData = function() { + return null; +}; + +Module.prototype.checkInitialData = function(data, config) { + return true; +}; + +Module.prototype.validateLocalData = function(data) { + return true; +}; + + + +function checksum(cmd){ + let sum = 0; + + cmd.forEach(function (value, idx) { + if(idx > 5) + sum += value; + }); + return sum&0xFF; +} + + + /////////////// 엔트리에서 받은 데이터에 대한 처리 ///////////////////// +Module.prototype.handleRemoteData = function(handler) { + let cmd = handler.read('CMD'); + + if(typeof cmd !== 'object') + return; + + this.cmdData = cmd.slice(); + if(this.cmdData[14] > 0){ + if(this.cmdData[14] == 2){ + this.ledPacket[0] = (this.cmdData[14]&0xC0) | 0x82; + this.ledPacket[1] = this.ledPacket[1] | 0x80; + for(let n=0; n<16; n++) + this.ledPacket[2+n] = this.cmdData[24+n]; + } + if(this.cmdData[14] == 3){ + this.ledPacket[0] = (this.cmdData[14]&0xC0) | 0x83; + this.ledPacket[1] = this.ledPacket[1] | 0x80; + for(let n=0; n<16; n++) + this.ledPacket[2+n] = this.cmdData[24+n]; + } + if(this.cmdData[14] == 4){ + this.ledPacket[1] = (this.cmdData[14]&0xC0) | 0x44; + this.ledPacket[0] = this.ledPacket[0] | 0x40; + for(let n=0; n<16; n++) + this.ledPacket[18+n] = this.cmdData[24+n]; + } + } + else{ + this.ledPacket[0] = 0; + this.ledPacket[1] = 0; + } +}; + + + //////////////// 하드웨어로 보낼 데이터 로직 ///////////// +Module.prototype.requestLocalData = function() { + if(((this.ledPacket[0]&0xC0) == 0xC0) || ((this.ledPacket[1]&0xC0) == 0xC0)){ + if((this.txCnt%2) == 0){ + this.cmdData[14] = this.ledPacket[0]; + for(let n=0; n<16; n++) + this.cmdData[24+n] = this.ledPacket[2+n]; + } + else{ + this.cmdData[14] = this.ledPacket[1]; + for(let n=0; n<16; n++) + this.cmdData[24+n] = this.ledPacket[18+n]; + } + this.cmdData[5] = checksum(this.cmdData); + this.txCnt += 1; + } + return this.cmdData; +}; + +///////////// 하드웨어에서 온 데이터 처리 /////////////////// +Module.prototype.handleLocalData = function(data) { + let sensorData = this.sensorData; + let dongleData = this.dongleData; + let pktLength = this.pktLength; + + let robodog_head = this.robodog_head; + data.forEach(function (value) { + this.rk_cnt = (value==robodog_head[this.rk_cnt])? this.rk_cnt+1 : 0; + if(this.rk_cnt == 4){ + this.rk_cnt = 0; + this.pktCnt = 0; + } + else if(this.pktCnt >= 0){ + if(this.pktCnt == 0) + pktLength = ((value>0) && (value<19))? value-4 : 16; + dongleData[4+this.pktCnt++] = value; + } + + if(this.pktCnt == pktLength){ + this.pktCnt = -1; + var sum = 0; + dongleData.forEach(function (value, idx) { + if(idx > 5) + sum += value; + }); + if(dongleData[5] == (sum&0xFF)){ + dongleData.forEach(function (value, idx) { + sensorData[idx] = value; + }); + } + } + }); + this.pktLength = pktLength; +}; + +function unsingToSign8(data) +{ + return data>127? data-256 : data; +} +function unsingToSign16(data) +{ + return data>32767? data-65536 : data; +} + +///////////// 엔트리로 전달할 데이터 /////////////////////////// +Module.prototype.requestRemoteData = function(handler) { + handler.write("SENSORDATA", this.sensorData); + handler.write('BATTERY', this.sensorData[6]); + handler.write('TOF', this.sensorData[7]); + handler.write('ROLL', unsingToSign8(this.sensorData[8])); + handler.write('PITCH', unsingToSign8(this.sensorData[9])); + handler.write('YAW', unsingToSign16(this.sensorData[10] + this.sensorData[11]*256)); + handler.write('RB0', this.sensorData[12]>127? this.sensorData[12]-256 : this.sensorData[12]); + handler.write('RB1', this.sensorData[13]>127? this.sensorData[13]-256 : this.sensorData[13]); + handler.write('RB2', this.sensorData[14]>127? this.sensorData[14]-256 : this.sensorData[14]); + handler.write('RB3', this.sensorData[15]>127? this.sensorData[15]-256 : this.sensorData[15]); + handler.write('BUTTON', this.sensorData[16]); + handler.write('RB_WATCHDOG', this.sensorData[17]); + handler.write('RB4', this.sensorData[18]>127? this.sensorData[18]-256 : this.sensorData[18]); + handler.write('RB5', this.sensorData[19]>127? this.sensorData[19]-256 : this.sensorData[19]); +}; + +Module.prototype.reset = function() { + this.cmdData = [0x26, 0xA8, 0x14, 0x81, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64, 0x64]; + this.sensorData = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]; + this.ledPacket = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + console.log("reset"); +}; + +module.exports = new Module(); diff --git a/app/modules/robodog.json b/app/modules/robodog.json new file mode 100644 index 000000000..82cfbc47d --- /dev/null +++ b/app/modules/robodog.json @@ -0,0 +1,26 @@ +{ + "id": "1D0501", + "name": { + "en": "RoboDog", + "ko": "로보독" + }, + "category": "robot", + "platform": ["win32", "darwin"], + "icon": "robodog.png", + "module": "robodog.js", + "url": "http://www.junilab.co.kr", + "driver": { + "win32-ia32": "JuniLab/dongleSetup.bat", + "win32-x64": "JuniLab/dongleSetup.bat" + }, + "reconnect": true, + "hardware": { + "type": "serial", + "control": "slave", + "duration": 32, + "vendor": "Junilab_Inc", + "pnpId": "0226", + "baudRate": 19200, + "firmwarecheck": false + } +} diff --git a/app/modules/robodog.png b/app/modules/robodog.png new file mode 100644 index 000000000..592b3163f Binary files /dev/null and b/app/modules/robodog.png differ diff --git a/app/modules/robolink_ZumiMini.js b/app/modules/robolink_ZumiMini.js index 27997ada8..48f0b2864 100644 --- a/app/modules/robolink_ZumiMini.js +++ b/app/modules/robolink_ZumiMini.js @@ -247,11 +247,11 @@ class ZumiMini extends BaseModule { this.inputData.pInfo = data[this.INFO]; this.inputData.pSize = data[this.P_SIZE]; this.inputData.pStat = data[this.P_STAT]; - this.inputData.irSensor.FL = data[this.IR]; - this.inputData.irSensor.FR = data[this.IR + 1]; - this.inputData.irSensor.BL = data[this.IR + 2]; - this.inputData.irSensor.BM = data[this.IR + 3]; - this.inputData.irSensor.BR = data[this.IR + 4]; + this.inputData.irSensor.FL = data[this.IR]*4; + this.inputData.irSensor.FR = data[this.IR + 1]*4; + this.inputData.irSensor.BL = data[this.IR + 2]*4; + this.inputData.irSensor.BM = data[this.IR + 3]*4; + this.inputData.irSensor.BR = data[this.IR + 4]*4; this.inputData.faceDetect.DETECT = data[this.FD]; this.inputData.faceDetect.CX = data[this.FD + 1]; this.inputData.faceDetect.CY = data[this.FD + 2]; diff --git a/app/modules/robolink_ZumiMini.json b/app/modules/robolink_ZumiMini.json index c30036100..ba0749563 100644 --- a/app/modules/robolink_ZumiMini.json +++ b/app/modules/robolink_ZumiMini.json @@ -16,7 +16,7 @@ "url": "https://www.robolink.co.kr/", "email": "asteam@robolink.co.kr", "reconnect": true, - "selectPort": true, + "selectPort": false, "hardware": { "type": "serial", "control": "master", @@ -27,7 +27,7 @@ "dataBits": 8, "stopBits": 1, "byteDelimiter": [255, 255], - "vendor": "robolink", + "vendor": ["ROBOLINK", "wch.cn"], "firmwarecheck": false, "bufferSize": 1024, "flowControl": "none"