Skip to content

Commit be45d4d

Browse files
authored
Merge pull request #796 from JH-Kim88/develop-hw
[Develop hw] uart serial 통신 모델을 bluetooth ssp 모델로 변경 작업 완료.
2 parents f79e660 + 1e574bd commit be45d4d

File tree

3 files changed

+76
-9
lines changed

3 files changed

+76
-9
lines changed

app/modules/avatarbot.js

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ function Module() {
5858
Osci: 27000000,
5959
Freq: 50
6060
}
61+
6162
this.Board_Servo = {
6263
Pulse_Min: 150,
6364
Pulse_Max: 600,
6465
us_Min: 400,
65-
us_Max: 2100
66+
us_Max: 2100,
67+
angle: 90
6668
}
69+
6770
this.Board_LED_Strip = {
6871
En:0,
6972
sample: 0,
@@ -133,7 +136,9 @@ Module.prototype.init = function(handler, config) {
133136
this.remoteDataSet[index+6] = (this.Board_Servo.us_Min>>8)&0xff;
134137

135138
this.remoteDataSet[index+7] = (this.Board_Servo.us_Max)&0xff;
136-
this.remoteDataSet[index+8] = (this.Board_Servo.us_Max>>8)&0xff;
139+
this.remoteDataSet[index+8] = (this.Board_Servo.us_Max>>8)&0xff;
140+
141+
this.remoteDataSet[index+9] = (this.Board_Servo.angle)&0xff;
137142
}
138143

139144
// led
@@ -203,10 +208,14 @@ slave 모드인 경우 duration 속성 간격으로 지속적으로 기기에
203208
Module.prototype.requestLocalData = function() {
204209
var queryString = [];
205210
var data = this.remoteDataSet; // Module 객체의 dataset table read. max length 200
211+
var checksum = 0;
206212
for (var index = 0; index < this.avatarBotDataSet; index++) {
207213
var query = (data[index])&0xff;
208214
queryString.push(query); // 1byte
215+
checksum += query;
209216
}
217+
checksum = (checksum)&0xff;
218+
queryString.push(checksum); // 1byte
210219
/*
211220
for(var i=0; i<(data.length/10); i++)
212221
{
@@ -222,13 +231,20 @@ Module.prototype.requestLocalData = function() {
222231
};
223232

224233
// 하드웨어에서 온 데이터 처리
234+
/*
225235
Module.prototype.handleLocalData = function(data) {
226236
var self = this;
227237
for (var i = 0; i < data.length; i++) {
228238
self.dataSet[self.dataSet_index+i] = data[i];
229239
}
230-
231-
240+
console.log('data length ', data.length);
241+
for(var j=0; j<21; j++)
242+
{
243+
let i = j*10;
244+
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],
245+
self.dataSet[i+6], self.dataSet[i+7], self.dataSet[i+8], self.dataSet[i+9]);
246+
}
247+
232248
if(self.dataSet[0] === 0x99 && self.dataSet[1] === 0x01 && self.dataSet[2] === 0x01 && self.dataSet[3] === self.avatarBotDataSet)
233249
{
234250
self.dataSet_index = self.dataSet_index + data.length;
@@ -250,6 +266,57 @@ Module.prototype.handleLocalData = function(data) {
250266
251267
252268
};
269+
*/
270+
Module.prototype.handleLocalData = function(data) {
271+
var self = this;
272+
// data.length => 211
273+
var checksum = 0;
274+
var getChecksum = 0;
275+
for (var i = 0; i < data.length; i++) {
276+
if(self.dataSet.length > i)
277+
{
278+
self.dataSet[self.dataSet_index+i] = data[i];
279+
checksum += data[i];
280+
}else{
281+
// last buffer
282+
getChecksum = data[i];
283+
}
284+
}
285+
286+
checksum = (checksum)&0xff;
287+
288+
/*
289+
console.log('data length ', data.length, ', checksum = ', checksum, ', getChecksum = ', getChecksum);
290+
for(var j=0; j<21; j++)
291+
{
292+
let i = j*10;
293+
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],
294+
self.dataSet[i+6], self.dataSet[i+7], self.dataSet[i+8], self.dataSet[i+9]);
295+
}
296+
*/
297+
298+
if(self.dataSet[0] === 0x99 && self.dataSet[1] === 0x01 && self.dataSet[2] === 0x01 && self.dataSet[3] === self.avatarBotDataSet && getChecksum == checksum)
299+
{
300+
self.dataSet_index = self.dataSet_index + (data.length-1);
301+
}else{
302+
self.dataSet_index = 0;
303+
return;
304+
}
305+
306+
if(self.dataSet_index == self.avatarBotDataSet){
307+
self.originParsing(self.dataSet);
308+
self.dataSet_index = 0;
309+
self.dataSet[0] = 0; // clear
310+
self.dataSet[1] = 0; // clear
311+
self.dataSet[2] = 0; // clear
312+
self.dataSet[3] = 0; // clear
313+
//
314+
// console.log('[jhkim] handleLocalData - dataSet_index[11] = ', self.dataSet[11]);
315+
}
316+
317+
318+
};
319+
253320

254321
/* Original Parsing FF 55 ~ */
255322
Module.prototype.originParsing = function(data) {

app/modules/avatarbot.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"en": "AvatarBot",
55
"ko": "AvatarBot"
66
},
7+
"category": "board",
78
"platform": ["win32", "darwin"],
89
"icon" : "avatarbot.png",
910
"module": "avatarbot.js",
@@ -13,18 +14,17 @@
1314
"translate": "Arduino compatible driver"
1415
},
1516
"reconnect" : true,
16-
"firmware": "http://avatarmecha.ddns.net:5050/sharing/iCuhzvxcu",
1717
"select_com_port":true,
1818
"entry": {
1919
"protocol": "json"
2020
},
2121
"hardware": {
22-
"type": "serial",
22+
"type": "bluetooth",
2323
"control": "slave",
24-
"duration": 500,
24+
"duration": 300,
2525
"vendor": ["Arduino", "wch.cn", "FTDI"],
26-
"baudRate": 460800,
27-
"lostTimer": 1000,
26+
"baudRate": 1000000,
27+
"lostTimer": 2000,
2828
"firmwarecheck": false
2929
}
3030
}

app/modules/avatarbot.png

23.8 KB
Loading

0 commit comments

Comments
 (0)