Skip to content

Commit

Permalink
Revert "Revert "Merge pull request #485 from o2lee/develop-hw""
Browse files Browse the repository at this point in the history
This reverts commit d08da24.
  • Loading branch information
wodnjs6512 committed Aug 24, 2021
1 parent 6652fd2 commit d997d25
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 70 deletions.
71 changes: 56 additions & 15 deletions app/modules/pingpong_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ 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;
Expand All @@ -28,15 +31,41 @@ 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;
Expand Down Expand Up @@ -69,12 +98,12 @@ class PingpongBase extends BaseModule {
// 연결 후 초기에 송신할 데이터가 필요한 경우 사용합니다.
requestInitialData(sp, payload) {
//console.log('P:requestInitialData: ');
let grpid = payload.match(/[0-7]{1,2}$/g);
const grpid = payload.match(/[0-7]{1,2}$/g);
if (grpid == null) {
console.warn('Wrong group id inputted', payload);
return null;
}
let grpno = parseInt(grpid[0], 16);
const grpno = parseInt(grpid[0], 16);
return this.makePackets('setMultirole', grpno);
}

Expand All @@ -100,7 +129,7 @@ class PingpongBase extends BaseModule {
this.checkBuffer = Buffer.from(data);
}

let payload = this.checkBuffer;
const payload = this.checkBuffer;

if (payload.length >= 9) {
const packetSize = payload.readInt16BE(7);
Expand Down Expand Up @@ -129,24 +158,36 @@ class PingpongBase extends BaseModule {

// 엔트리에서 받은 데이터에 대한 처리
handleRemoteData(handler) {
//console.log('P:handle RemoteData: ', handler);

this.send_cmd = handler.read('COMMAND');
if (this.send_cmd) {
if (this.send_cmd.id > this.cmd_seq) {
this.cmd_seq = this.send_cmd.id;
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) {
//console.log('P:handleRemoteData: ', this.send_cmd);
if (this.send_cmd.id == -1) {
this.cmd_seq = 0;
//console.log('P:handle RD: CLEAR');
//console.log('P:handleRemoteData RD: CLEAR');
} else 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);
}
}
}

// 하드웨어 기기에 전달할 데이터
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;
}

Expand Down
96 changes: 45 additions & 51 deletions app/modules/pingpong_g1.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ 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;
Expand Down Expand Up @@ -41,27 +44,32 @@ 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,
]);
}
Expand Down Expand Up @@ -114,18 +122,18 @@ class PingpongG1 extends BaseModule {
// 연결 후 초기에 송신할 데이터가 필요한 경우 사용합니다.
requestInitialData(sp, payload) {
//console.log('P:requestInitialData: ');
let grpid = payload.match(/[0-7]{1,2}$/g);
const grpid = payload.match(/[0-7]{1,2}$/g);
if (grpid == null) {
console.warn('Wrong group id inputted', payload);
return null;
}
let grpno = parseInt(grpid[0], 16);
const 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}`;
Expand Down Expand Up @@ -155,48 +163,34 @@ class PingpongG1 extends BaseModule {

this.send_cmd = handler.read('COMMAND');
if (this.send_cmd) {
if (this.send_cmd.id > this.cmd_seq) {
this.cmd_seq = this.send_cmd.id;
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) {
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) {
this.cmd_seq = this.send_cmd.id;
this.sendBuffer.push(Buffer.from(this.send_cmd.data));
//console.log('D:send PACKET: %s ', this.dbgHexstr(sendBuffer));
}
}
}

// 하드웨어 기기에 전달할 데이터
requestLocalData() {
/*
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;
}
*/
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;

/*
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]);
*/
}

// 하드웨어에서 온 데이터 처리
Expand Down Expand Up @@ -254,14 +248,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]);
Expand All @@ -277,7 +271,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);
Expand All @@ -294,7 +288,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();
Expand Down
2 changes: 1 addition & 1 deletion app/modules/pingpong_g1.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"hardware": {
"type": "bluetooth",
"control": "slave",
"duration": 10000,
"duration": 50,
"vendor": "Microsoft",
"lostTimer": 5000,
"firmwarecheck": false,
Expand Down
2 changes: 1 addition & 1 deletion app/modules/pingpong_g2.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"hardware": {
"type": "bluetooth",
"control": "slave",
"duration": 10000,
"duration": 50,
"lostTimer": 5000,
"vendor": "Microsoft",
"baudRate": 115200
Expand Down
2 changes: 1 addition & 1 deletion app/modules/pingpong_g3.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"hardware": {
"type": "bluetooth",
"control": "slave",
"duration": 10000,
"duration": 50,
"lostTimer": 5000,
"vendor": "Microsoft",
"baudRate": 115200
Expand Down
2 changes: 1 addition & 1 deletion app/modules/pingpong_g4.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"hardware": {
"type": "bluetooth",
"control": "slave",
"duration": 10000,
"duration": 50,
"lostTimer": 5000,
"vendor": "Microsoft",
"baudRate": 115200
Expand Down

0 comments on commit d997d25

Please sign in to comment.