diff --git a/app/modules/pingpong_base.js b/app/modules/pingpong_base.js index 087e3b811..dfd700e1b 100644 --- a/app/modules/pingpong_base.js +++ b/app/modules/pingpong_base.js @@ -8,9 +8,6 @@ class PingpongBase extends BaseModule { this.send_cmd = {}; this.cmd_seq = 0; - this.isDraing = false; - this.sendBuffer = []; - this.sp = null; this.isCubeConnecting = false; this.isCheckConnecting = false; @@ -31,41 +28,15 @@ class PingpongBase extends BaseModule { let result = null; if (method === 'connect') { - result = Buffer.from([ - 0xdd, - 0xdd, - grpid, - 0x00, - 0x00, - 0x00, - 0xda, - 0x00, - 0x0b, - 0x00, - 0x00, - ]); + result = Buffer.from([0xdd, 0xdd, grpid, 0x00, 0x00, 0x00, 0xda, 0x00, 0x0b, 0x00, 0x00]); //result[2] = this.groupId; } else if (method === 'disconnect') { result = Buffer.from([0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xa8, 0x00, 0x0a, 0x01]); //result = Buffer.from('ffffffff0000a8000a01', 'hex'); } else if (method === 'checkdongle') { - result = Buffer.from([ - 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x01, 0xda, 0x00, 0x0b, 0x00, 0x0d, - ]); + result = Buffer.from([0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x01, 0xda, 0x00, 0x0b, 0x00, 0x0d]); } else if (method === 'setMultirole') { - result = Buffer.from([ - 0xff, - 0xff, - 0x00, - 0xff, - this.cubeCount << 4, - 0x00, - 0xad, - 0x00, - 0x0b, - 0x0a, - 0x00, - ]); + result = Buffer.from([0xff, 0xff, 0x00, 0xff, this.cubeCount << 4, 0x00, 0xad, 0x00, 0x0b, 0x0a, 0x00]); if (grpid > 0) { result[2] = grpid; result[9] = 0x1a; @@ -98,12 +69,12 @@ class PingpongBase extends BaseModule { // 연결 후 초기에 송신할 데이터가 필요한 경우 사용합니다. requestInitialData(sp, payload) { //console.log('P:requestInitialData: '); - const grpid = payload.match(/[0-7]{1,2}$/g); + let grpid = payload.match(/[0-7]{1,2}$/g); if (grpid == null) { console.warn('Wrong group id inputted', payload); return null; } - const grpno = parseInt(grpid[0], 16); + let grpno = parseInt(grpid[0], 16); return this.makePackets('setMultirole', grpno); } @@ -129,7 +100,7 @@ class PingpongBase extends BaseModule { this.checkBuffer = Buffer.from(data); } - const payload = this.checkBuffer; + let payload = this.checkBuffer; if (payload.length >= 9) { const packetSize = payload.readInt16BE(7); @@ -158,36 +129,24 @@ class PingpongBase extends BaseModule { // 엔트리에서 받은 데이터에 대한 처리 handleRemoteData(handler) { + //console.log('P:handle RemoteData: ', handler); + this.send_cmd = handler.read('COMMAND'); if (this.send_cmd) { - //console.log('P:handleRemoteData: ', this.send_cmd); - if (this.send_cmd.id == -1) { - this.cmd_seq = 0; - //console.log('P:handleRemoteData RD: CLEAR'); - } else if (this.send_cmd.id != this.cmd_seq) { + if (this.send_cmd.id > this.cmd_seq) { this.cmd_seq = this.send_cmd.id; - this.sendBuffer.push(Buffer.from(this.send_cmd.data)); - //const sendBuffer = Buffer.from(this.send_cmd.data); + const sendBuffer = Buffer.from(this.send_cmd.data); + this.sp.write(sendBuffer); + //console.log('D:send PACKET: %s ', this.dbgHexstr(sendBuffer)); + } else if (this.send_cmd.id == -1) { + this.cmd_seq = 0; + //console.log('P:handle RD: CLEAR'); } } } // 하드웨어 기기에 전달할 데이터 requestLocalData() { - const self = this; - if (!this.isDraing && this.sendBuffer.length > 0) { - this.isDraing = true; - const msg = this.sendBuffer.shift(); - //console.log('P:requestLocalData() : ', msg, this.sendBuffer.length); - this.sp.write(msg, () => { - if (self.sp) { - self.sp.drain(() => { - self.isDraing = false; - }); - } - }); - } - return null; } diff --git a/app/modules/pingpong_g1.js b/app/modules/pingpong_g1.js index d2d9f5f48..c30e194c0 100644 --- a/app/modules/pingpong_g1.js +++ b/app/modules/pingpong_g1.js @@ -8,9 +8,6 @@ class PingpongG1 extends BaseModule { this.send_cmd = {}; this.cmd_seq = 0; - this.isDraing = false; - this.sendBuffer = []; - this.sp = null; this.isCubeConnecting = false; this.isCheckConnecting = false; @@ -44,32 +41,27 @@ class PingpongG1 extends BaseModule { let result = null; if (method === 'connect') { - result = Buffer.from([ - 0xdd, - 0xdd, - grpid, - 0x00, - 0x00, - 0x00, - 0xda, - 0x00, - 0x0b, - 0x00, - 0x00, - ]); + result = Buffer.from([0xdd, 0xdd, grpid, 0x00, 0x00, 0x00, 0xda, 0x00, 0x0b, 0x00, 0x00]); //result[2] = this.groupId; } else if (method === 'disconnect') { result = Buffer.from([0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0xa8, 0x00, 0x0a, 0x01]); //result = Buffer.from('ffffffff0000a8000a01', 'hex'); } else if (method === 'checkdongle') { - result = Buffer.from([ - 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x01, 0xda, 0x00, 0x0b, 0x00, 0x0d, - ]); + result = Buffer.from([0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x01, 0xda, 0x00, 0x0b, 0x00, 0x0d]); } else if (method === 'setColorLed') { result = Buffer.from('ffff00070000ce000e0200000750', 'hex'); } else if (method === 'getSensorData') { result = Buffer.from([ - 0xff, 0xff, 0xff, 0xff, 0x00, 0xc8 /* continuous sampling*/, 0xb8, 0x00, 0x0b, 20, + 0xff, + 0xff, + 0xff, + 0xff, + 0x00, + 0xc8 /* continuous sampling*/, + 0xb8, + 0x00, + 0x0b, + 20, 0x01, ]); } @@ -122,18 +114,18 @@ class PingpongG1 extends BaseModule { // 연결 후 초기에 송신할 데이터가 필요한 경우 사용합니다. requestInitialData(sp, payload) { //console.log('P:requestInitialData: '); - const grpid = payload.match(/[0-7]{1,2}$/g); + let grpid = payload.match(/[0-7]{1,2}$/g); if (grpid == null) { console.warn('Wrong group id inputted', payload); return null; } - const grpno = parseInt(grpid[0], 16); + let grpno = parseInt(grpid[0], 16); return this.makePackets('connect', grpno); } dbgHexstr(data) { let output = ''; - data.map((item) => { + data.map(item => { let number = item.toString(16); if (number.length < 2) { number = `0${number}`; @@ -163,34 +155,48 @@ class PingpongG1 extends BaseModule { this.send_cmd = handler.read('COMMAND'); if (this.send_cmd) { - if (this.send_cmd.id == -1) { - this.cmd_seq = 0; - //console.log('P:handle RD: CLEAR'); - } else if (this.send_cmd.id != this.cmd_seq) { + if (this.send_cmd.id > this.cmd_seq) { this.cmd_seq = this.send_cmd.id; - this.sendBuffer.push(Buffer.from(this.send_cmd.data)); + const sendBuffer = Buffer.from(this.send_cmd.data); + this.sp.write(sendBuffer); //console.log('D:send PACKET: %s ', this.dbgHexstr(sendBuffer)); + } else if (this.send_cmd.id == -1) { + this.cmd_seq = 0; + //console.log('P:handle RD: CLEAR'); } } } // 하드웨어 기기에 전달할 데이터 requestLocalData() { - const self = this; - if (!this.isDraing && this.sendBuffer.length > 0) { - this.isDraing = true; - const msg = this.sendBuffer.shift(); - //console.log('P:requestLocalData() : ', msg, this.sendBuffer.length); - this.sp.write(msg, () => { - if (self.sp) { - self.sp.drain(() => { - self.isDraing = false; - }); - } - }); - } + /* + var isSendData = false; + var sendBuffer; + + if (this.send_cmd && this.send_cmd.id > this.cmd_seq) { + isSendData = true; + //console.log('P:request LD: ', this.send_cmd); + this.cmd_seq = this.send_cmd.id; + sendBuffer = Buffer.from(this.send_cmd.data); + } + + if (isSendData) { + console.log('P:request LD: '); + return sendBuffer; + } + */ return null; + + /* + const header = new Buffer([0xff, 0xff, 0xff]); + const position = new Buffer([0xff]); + const data = new Buffer([0x00, 0xc8, 0xb8, 0x00, 0x0b]); + const interval = new Buffer([10]); + const tail = new Buffer([0x01]); + + return Buffer.concat([header, position, data, interval, tail]); + */ } // 하드웨어에서 온 데이터 처리 @@ -248,14 +254,14 @@ class PingpongG1 extends BaseModule { requestRemoteData(handler) { //console.log('P:request RD: '); const self = this; - Object.keys(this.readValue).forEach((key) => { + Object.keys(this.readValue).forEach(key => { if (self.readValue[key] !== undefined) { handler.write(key, self.readValue[key]); } }); //XXX: entryjs의 monitorTemplate 사용하려면 트리상단에 PORT 정보 보내야함 - Object.keys(this._sensorData).forEach((key) => { + Object.keys(this._sensorData).forEach(key => { if (self._sensorData[key] !== undefined) { //console.log(" --handler.write (%s) = %j ", key, self._sensorData[key]); handler.write(key, self._sensorData[key]); @@ -271,7 +277,7 @@ class PingpongG1 extends BaseModule { }, 500); setTimeout(() => { - this.sp.write(this.makePackets('getSensorData'), (err) => { + this.sp.write(this.makePackets('getSensorData'), err => { console.log('done.........'); }); }, 1000); @@ -288,7 +294,7 @@ class PingpongG1 extends BaseModule { // getSensor disable //this.sp.write( Buffer.from('ffffffff00c8b8000b0001', 'hex') ); - this.sp.write(this.makePackets('disconnect'), (err) => { + this.sp.write(this.makePackets('disconnect'), err => { if (this.sp.isOpen) { console.log('Disconnect'); connect.close(); diff --git a/app/modules/pingpong_g1.json b/app/modules/pingpong_g1.json index 297bd22c4..29b29d2c2 100644 --- a/app/modules/pingpong_g1.json +++ b/app/modules/pingpong_g1.json @@ -28,7 +28,7 @@ "hardware": { "type": "bluetooth", "control": "slave", - "duration": 50, + "duration": 10000, "vendor": "Microsoft", "lostTimer": 5000, "firmwarecheck": false, diff --git a/app/modules/pingpong_g2.json b/app/modules/pingpong_g2.json index cd0e0b2fc..3a2c7fe9f 100644 --- a/app/modules/pingpong_g2.json +++ b/app/modules/pingpong_g2.json @@ -28,7 +28,7 @@ "hardware": { "type": "bluetooth", "control": "slave", - "duration": 50, + "duration": 10000, "lostTimer": 5000, "vendor": "Microsoft", "baudRate": 115200 diff --git a/app/modules/pingpong_g3.json b/app/modules/pingpong_g3.json index 1f4859fc7..7bf016ec8 100644 --- a/app/modules/pingpong_g3.json +++ b/app/modules/pingpong_g3.json @@ -28,7 +28,7 @@ "hardware": { "type": "bluetooth", "control": "slave", - "duration": 50, + "duration": 10000, "lostTimer": 5000, "vendor": "Microsoft", "baudRate": 115200 diff --git a/app/modules/pingpong_g4.json b/app/modules/pingpong_g4.json index 7061542be..56f60f822 100644 --- a/app/modules/pingpong_g4.json +++ b/app/modules/pingpong_g4.json @@ -28,7 +28,7 @@ "hardware": { "type": "bluetooth", "control": "slave", - "duration": 50, + "duration": 10000, "lostTimer": 5000, "vendor": "Microsoft", "baudRate": 115200