From 8ea18d44aa59003857273c7f145e0cfb74f916c9 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Wed, 12 Jun 2024 16:21:02 +0900 Subject: [PATCH 01/17] etboard_test --- app/modules/avmboard.js | 578 ++++++++++++++++++++++++++++++++++++++ app/modules/avmboard.json | 30 ++ app/modules/avmboard.png | Bin 0 -> 4549 bytes 3 files changed, 608 insertions(+) create mode 100644 app/modules/avmboard.js create mode 100644 app/modules/avmboard.json create mode 100644 app/modules/avmboard.png diff --git a/app/modules/avmboard.js b/app/modules/avmboard.js new file mode 100644 index 000000000..83a1ce85f --- /dev/null +++ b/app/modules/avmboard.js @@ -0,0 +1,578 @@ +function Module() { + this.sp = null; + this.sensorTypes = { + ALIVE: 0, + DIGITAL: 1, + ANALOG: 2, + PWM: 3, + SERVO_PIN: 4, + TONE: 5, + PULSEIN: 6, + ULTRASONIC: 7, + TIMER: 8, + OLED: 241, + COM: 242, + NEOPIXEL: 243, + ULTRASONIC_COUNTER: 244 + } + + this.actionTypes = { + GET: 1, + SET: 2, + RESET: 3 + }; + + this.sensorValueSize = { + FLOAT: 2, + SHORT: 3 + } + + this.digitalPortTimeList = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; + //this.digitalPortTimeList = [0, 0, 0, 0, 0, 0, 0, 0]; + + this.sensorData = { + ULTRASONIC: 0, + DIGITAL: { + '0': 0, + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + '6': 0, + '7': 0, + '8': 0, + '9': 0, + '10': 0, + '11': 0, + '12': 0, + '13': 0 + }, + ANALOG: { + '0': 0, + '1': 0, + '2': 0, + '3': 0, + '4': 0, + '5': 0, + '6': 0, + '7': 0, + }, + PULSEIN: { + }, + TIMER: 0, + } + + this.defaultOutput = { + } + + this.recentCheckData = { + + } + + this.sendBuffers = []; + + this.lastTime = 0; + this.lastSendTime = 0; + this.isDraing = false; + this.isStartUltrasonic = false; +} + +var sensorIdx = 0; + +Module.prototype.init = function(handler, config) { +}; + +Module.prototype.setSerialPort = function (sp) { + var self = this; + this.sp = sp; +}; + +// Module.prototype.lostController = function () {}; + +Module.prototype.requestInitialData = function() { + return this.makeSensorReadBuffer(this.sensorTypes.ANALOG, 0); +}; + +Module.prototype.checkInitialData = function(data, config) { + this.isDraing = false; //갑자기 전송이 중단됐을때 전송상태 초기화 + this.isStartUltrasonic = false; //초음파 센서 전역 변수 + return true; + // 이후에 체크 로직 개선되면 처리 + // var datas = this.getDataByBuffer(data); + // var isValidData = datas.some(function (data) { + // return (data.length > 4 && data[0] === 255 && data[1] === 85); + // }); + // return isValidData; +}; + +Module.prototype.afterConnect = function(that, cb) { + that.connected = true; + if(cb) { + cb('connected'); + } +}; + +Module.prototype.validateLocalData = function(data) { + return true; +}; + +Module.prototype.requestRemoteData = function(handler) { + var self = this; + if(!self.sensorData) { + return; + } + Object.keys(this.sensorData).forEach(function (key) { + if(self.sensorData[key] != undefined) { + handler.write(key, self.sensorData[key]); + if (key == "DIGITAL") + { + var dObj = self.sensorData["DIGITAL"]; + //console.log("send : sensorData = " + dObj[6]); + } + + } + }) +}; + +Module.prototype.handleRemoteData = function(handler) { + var self = this; + var getDatas = handler.read('GET'); + var setDatas = handler.read('SET') || this.defaultOutput; + var time = handler.read('TIME'); + var buffer = new Buffer([]); + + if(getDatas) { + var keys = Object.keys(getDatas); + keys.forEach(function(key) { + var isSend = false; + var dataObj = getDatas[key]; + if(typeof dataObj.port === 'string' || typeof dataObj.port === 'number') { + var time = self.digitalPortTimeList[dataObj.port]; + if(dataObj.time > time) { + isSend = true; + self.digitalPortTimeList[dataObj.port] = dataObj.time; + } + } else if(Array.isArray(dataObj.port)){ + isSend = dataObj.port.every(function(port) { + var time = self.digitalPortTimeList[port]; + return dataObj.time > time; + }); + + if(isSend) { + dataObj.port.forEach(function(port) { + self.digitalPortTimeList[port] = dataObj.time; + }); + } + } + + if(isSend) { + if(!self.isRecentData(dataObj.port, key, dataObj.data)) { + self.recentCheckData[dataObj.port] = { + type: key, + data: dataObj.data + } + buffer = Buffer.concat([buffer, self.makeSensorReadBuffer(key, dataObj.port, dataObj.data)]); + //console.log(dataObj.port); + } + } + }); + } + + if(setDatas) { + var setKeys = Object.keys(setDatas); + setKeys.forEach(function (port) { + var data = setDatas[port]; + if(data) { + if(self.digitalPortTimeList[port] < data.time) { + self.digitalPortTimeList[port] = data.time; + + if(!self.isRecentData(port, data.type, data.data)) { + self.recentCheckData[port] = { + type: data.type, + data: data.data + } + buffer = Buffer.concat([buffer, self.makeOutputBuffer(data.type, port, data.data)]); + } + } + } + }); + } + + if(buffer.length) { + this.sendBuffers.push(buffer); + } +}; + +Module.prototype.isRecentData = function(port, type, data) { + var isRecent = false; + + if(type == this.sensorTypes.ULTRASONIC_COUNTER) { + isRecent = false; + return isRecent; + } + + if(type == this.sensorTypes.ULTRASONIC && !this.isStartUltrasonic) + { + isRecent = false; + this.isStartUltrasonic = true; + return isRecent; + } + if(type == this.sensorTypes.COM) + { + isRecent = false; + return isRecent; + } + + if(port in this.recentCheckData) { + if(type != this.sensorTypes.TONE && this.recentCheckData[port].type === type && this.recentCheckData[port].data === data) { + isRecent = true; + } + } + + return isRecent; +} + +Module.prototype.requestLocalData = function() { + var self = this; + + //console.log(this.sendBuffers.length); + //console.log(this.isDraing); + + if(!this.isDraing && this.sendBuffers.length > 0) { + this.isDraing = true; + this.sp.write(this.sendBuffers.shift(), function () { + if(self.sp) { + self.sp.drain(function () { + self.isDraing = false; + }); + } + }); + } + + return null; +}; + +/* +ff 55 idx size data a +*/ +Module.prototype.handleLocalData = function(data) { + var self = this; + var datas = this.getDataByBuffer(data); + + datas.forEach(function (data) { + if(data.length <= 4) {// || data[0] === 255 && data[1] === 86 ) { + return; + } + + if(data[0] === 255 && data[1] === 85) { + self.originParsing(data); + } else if (data[0] === 255 && data[1] === 86) { + self.kParsing(data); + } else { + return; + } + + }); + + +}; + + +/* Original Parsing FF 55 ~ */ +Module.prototype.originParsing = function(data) { + var self = this; + var readData = data.subarray(2, data.length); + var value; + switch(readData[0]) { + case self.sensorValueSize.FLOAT: { + value = new Buffer(readData.subarray(1, 5)).readFloatLE(); + value = Math.round(value * 100) / 100; + break; + } + case self.sensorValueSize.SHORT: { + value = new Buffer(readData.subarray(1, 3)).readInt16LE(); + break; + } + default: { + value = 0; + break; + } + } + + var type = readData[readData.length - 1]; + var port = readData[readData.length - 2]; + + switch(type) { + case self.sensorTypes.DIGITAL: { + self.sensorData.DIGITAL[port] = value; + break; + } + case self.sensorTypes.ANALOG: { + self.sensorData.ANALOG[port] = value; + break; + } + case self.sensorTypes.PULSEIN: { + self.sensorData.PULSEIN[port] = value; + break; + } + case self.sensorTypes.ULTRASONIC: { + self.sensorData.ULTRASONIC = value; + break; + } + case self.sensorTypes.TIMER: { + self.sensorData.TIMER = value; + break; + } + case self.sensorTypes.NEOPIXEL: { + self.sensorData.NEOPIXEL = value; + break; + } + default: { + break; + } + } +}; + +/* K-Board Parsing FF 56 ~ */ +Module.prototype.kParsing = function(data) { + var self = this; + var readData = data.subarray(2, data.length); + var value; + + for(var i = 0; i<8; i++) { + if(bit_test(readData[0], i)) + { + self.sensorData.DIGITAL[i + 2] = 1; + } else { + self.sensorData.DIGITAL[i + 2] = 0; + } + } + + var index = 0; + for(var i = 1; i<19; i = i + 2){ + value = new Buffer(readData.subarray(i, i+2)).readInt16LE(); + value = Math.round(value * 100) / 100; + + if( value > 1023 || value < 0) + value = 0; + + if(index != 8) + { + if(index == 0) + { + if((1023 - (value * 1.72)) > 0) + self.sensorData.ANALOG[index] = parseInt(Math.abs(1023 - (value * 1.72))); + else + self.sensorData.ANALOG[index] = 0; + } + else + self.sensorData.ANALOG[index] = value; + //console.log("self.sensorData.ANALOG" + index + " = " + self.sensorData.ANALOG[index]); + } else { + self.sensorData.ULTRASONIC = value; + //console.log("self.sensorData.ULTRASONIC" + index + " = " + self.sensorData.ULTRASONIC); + } + + //console.log("value=" + value); + + index = index + 1; + } + + + + +}; + +function bit_test(num, bit){ + return ((num>>bit) % 2 != 0) +} + +/* +ff 55 len idx action device port slot data a +0 1 2 3 4 5 6 7 8 +*/ + +Module.prototype.makeSensorReadBuffer = function(device, port, data) { + + var buffer; + var dummy = new Buffer([10]); + + if(device == this.sensorTypes.ULTRASONIC) { + buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port[0], port[1], 10]); + + /* + } else if(device == this.sensorTypes.ULTRASONIC_COUNTER) { + buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port[0], port[1], 10]); + */ + } else if(!data) { + buffer = new Buffer([255, 85, 5, sensorIdx, this.actionTypes.GET, device, port, 10]); + } else { + value = new Buffer(2); + value.writeInt16LE(data); + buffer = new Buffer([255, 85, 7, sensorIdx, this.actionTypes.GET, device, port, 10]); + buffer = Buffer.concat([buffer, value, dummy]); + } + sensorIdx++; + if(sensorIdx > 254) { + sensorIdx = 0; + } + //console.log(buffer); + return buffer; +}; + +//0xff 0x55 0x6 0x0 0x1 0xa 0x9 0x0 0x0 0xa +Module.prototype.makeOutputBuffer = function(device, port, data) { + var buffer; + var value = new Buffer(2); + var dummy = new Buffer([10]); + + + switch(device) { + + case this.sensorTypes.SERVO_PIN: + case this.sensorTypes.DIGITAL: + case this.sensorTypes.PWM: { + value.writeInt16LE(data); + buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.SET, device, port]); + buffer = Buffer.concat([buffer, value, dummy]); + break; + } + case this.sensorTypes.TONE: { + var time = new Buffer(2); + if($.isPlainObject(data)) { + value.writeInt16LE(data.value); + time.writeInt16LE(data.duration); + } else { + value.writeInt16LE(0); + time.writeInt16LE(0); + } + buffer = new Buffer([255, 85, 8, sensorIdx, this.actionTypes.SET, device, port]); + buffer = Buffer.concat([buffer, value, time, dummy]); + break; + } + case this.sensorTypes.OLED: { + var arr = []; + var i; + data = data.toString(); + + for(i=0; i)vy0P-uL_P&7AMdyv&?A^Uawg13h&bN_I*jA|e`14HcsspYSgz$Zo9cy4Jq| zVt*rbC87_*;LRIC`b1Gzk%*}7In{;Zts4&T)v)v@BBEmW7sTJ^BQA)D=&dwW6itHd zcHaVmO;kVj>HAnh0F|T^Iy?Y|7!V5%=;*K3MQi8??joKx>>EMm`HTv{IEFrsvvauT0UY1C5BfE3)0P%0&nMIab zZ(*efQGVz@3`t~ec)^zh$QQ^m@BbNo#o5Tg ztwdDDFNAMsK3}2-+rX6&0q_iI(_%yBIlUkClq0CCOS#XGLJY6FS~nx&YrRhj%30u6 zE2WLf-oWhSEb+m=yv&MZU=g<_*^c;eE3h?vZA%?q#=HkkC!^KlA_vUF8h$SEZuB7k zOi1_l+WUUsS?fr+xkLtU9flVAms(pOeCZ@t$|@@2pR+{Jq{!QQCKhAq zArLddu5xG0rtv1btzB&&YkfR#=X8RRq2GSdp0f4i zcU|sh9)}*}^2(j;%ig{vzb)%}W&=-rUY@Ob^188)hez(g*IXT}(X-68M16%s)ISx_ zg;P?kK_Lrt2X?mQ^L$ss{?6W^d};v}OTF;A)uN6sT0tRk_57*yi_Gw-;-kK3GaSbe z*8A=YzL5_4s`*;Rk8W%A89yk*fm@!3iog9Z_sL}bLfd{ArwY%yJX|Nm!v;@w-3-p+zZdMohcFw+Q5cqqG4dSj8 z67%1LTsi9=e5&%L$AZmovTgbaWtu^U3ns{JTuRnVo&|*<`jvL?8_OW3_*z@b7)R+i zw|BFoZl;hx0~P0oQ_nIoZJk4%An&E%1`RKz%4l#aGbc{cU2^&%a_v~$*hwPvrqJS`0w+C8vKG+ACF5TFQpq)%5=D_JXs_`ooOoULZ9=y-|9)ylz5+pMs(r- zZBx(FM|FANQgEX7UBDx2gN^qqzva zrhC*6!=gRHs>&%Zfh@Dnkj~42fs^)Nw+2890LE*tfec9XCKt8d*bgc@Pi8P1mb!h% z!_X1xprd^rcn{m;Bv?mh1ePqa-_Ib$dM2 zC<;NK(f({~+1jIT_(H}{p3-Gu3lAc)1;%W;e=bc7#2L5NN$j&n%~#N)DEsFiIN0|O2vfmb&0@G!NsRBc{a8NHxy>^+DlN+u zLO^7PEy6LB;8B{yI*%F0a(afn-QP$u)ECi~_@;`e z7(t8-|~*7`1nEN zlZT~zH`0f@l_ZvTfZwl)VL`)t&c8p?>TsiRDA+YrmeD8P- zEu4&t5G7v0&k{QhCRWo6JafM~)A+{df$e}!rVa2J_8)CeYwioSFT5xQJ*=14xjcUR zB4adejf_=M7$`3J78m5%u$-XVx@@p8;3fw1GJ}ym=Ni)wSsWKq6N7;zZIlXs?a5P~ z)3PYoT?tBsegtU^e(geIzUW>b=ow6C77A3$>C(!J?Xhgktg?>gV1zqG>7ATRNW4+m zIa*+=iHRSXLvg@lbFf=FTO|z#rOL(hmYUyqigLHW(n7UH1nj*OpUwY*n##4^o6KWl z9SDX2H33LE_ARz}we&_7X8ZUawMWX_!cruerjx-2`Yqmba970hUIi*@#0>s+PavG+ zu}_+LNu+`Ddex+WvhelKQ>VLvg2s4doY&}W!-pJVN`vWZdosyTiURwsYKNwYD>vi- zvuvry2E)4LV1^wDUqDT}xd&WOqEZo6MBM;htQlPSrs5R?U9cjWtH;+#e*V7ZnW-mZ zH7YdmgsRE@OJw5#2cc&AcbD@>TX|dkb%gDs^Aa(RN4qiI{I%4CnI8l%M%Ow?2kC5-GTw^|%^tjH%V8S|B^3KO?2!A>LIxbw8iZo;XcrqXK zG(<+5uU~Lq?Xn-20gB7z|E`K>hBGWSh__L(rZkpzcKFtjPF0OK3SQpR0q1=D)s42T zc>RM;2u?Eo4EN!2lWj}T?f|Nbr0Ge_d@T|hw3`WiB2UA%-$5kGi*s1}4t4Bp1nlIr zc+J+c)(8EWeppDXR%zZw;!g4^)3j)^_sB|>*(D4cQ!FcDb0o^-C^+r3LMW{D7_eWO zzdj`yEO#AywV%mi30wT+^O%-}yK>B;J`fx`1V2vgrbCWW_s9ft$L!8DO?72K?#4cr ze^xRf*l7kh?HgV~9p?A+Yz8Re(IhYCQ{zH*;DPR499F00avKoc$PI+lt4OPm#TBYd z#50Od=d$ZMrhV(e)57Oz(UQ%9I3Qu@7xJq{$M09D>82+>dG&H>^dMd|E<}I_Cd7b$ zM+635GwN&Zk*UIk25i1-*M2}YD{Pxxi8oTB^Gz3!V5xwAZk1XM7es?qmsMjEgxbG& z>>TUoaH1pC8GHZ0s4l}7{EGekfA`rxbf-j|UHY$UXFywr;;KgWe%_{w<}GR-QgcX@ zs`mqa&c0dq^{#xs*3R>#((?3mcMB7rh}$jkRJk?sbjEgUPto~L_$JbuWtMcOT#ktS|T2nH%*TSQ;XNDo(BSrP~R)@_(Lc*44av3>; zdM*>+H-iw7sNLC~&xwxZwQ0_UIVq5pf^^;8bkfU%c*J^@qC8w7c_ql;_(5<1-XTBN zmV6l<@i>#b!8LRoL1Zd;d5%BIr7HD+G+bP@i8BctmiO_ycce904H4$sYY!Us9lnMa z6^hD%xNgoo8ve_(I~E_69tOmObweC$rhAis9%$I_lI?*95jFR$`lj#}s~bULts~$EmY>8;r#)va zm;wMGPMIOiI^aSoE*sp{)_y(Ntf41P;0gG2%XX~m2AzfBA$Il?wr{B*l zzIMdn67)Z38eKOT%LIARj*W?C0wt}|vv<0-N=kZ(#XDfM_pc9`<6o^WU&Jxsy>UO1 z%#y3sW~k) zu@R-7(-u`)(toY*8@*axE@q8LnZwbs?a6Zsn_8-mW?4nikEaBC2R4Su1VR0Xd`U*_ z!63V0+I{lXefA1!;`ezbRswoZv{GMmuHc<=80g+nV7Bix9X8Sl7Vvz(jH2eA!6v(0 zEczZ37dD6~Am#ZabqCjHDao(?)>LX0T0%fM(T zsZt<8ofR(7rRb2tRZ;5>uK4HSlqK@g32Re+^2v?rMy$aOTZ0lIvx9Kg?K7q$W2@@A zj$aPM;3Ra}NejO&xSW6xYjb-%)^wT+R6UjrSzUOjQdXX=gvE%muNP)vFv=z-q+ET* zMw|S0opx#T2J;#*2#O|{5%XHgy3GLybT33(<}Eqr?XT+~la?Bcxe~SYrzI=ZxbNUy z8T|WR^mLS|O-ldlsiIJ2MMeUM%WQhb+_n?lxg4@&mNKv(27p29!72h(cHv)q+gq$Y z@lzTm-ESjHJ`0<6Dcq(3)G6LQlZf@BG2i5B#1_`Fqjvc3F28FXfdIJvSIPbl987e@ ZEhg(1Djk1|^yc+Kq^YW>@ Date: Thu, 13 Jun 2024 10:10:53 +0900 Subject: [PATCH 02/17] et-board -> arduino[esp32] --- app/modules/avmboard.js | 606 +++++--------------------------------- app/modules/avmboard.json | 4 +- 2 files changed, 70 insertions(+), 540 deletions(-) diff --git a/app/modules/avmboard.js b/app/modules/avmboard.js index 83a1ce85f..6a46330e8 100644 --- a/app/modules/avmboard.js +++ b/app/modules/avmboard.js @@ -1,578 +1,108 @@ function Module() { - this.sp = null; - this.sensorTypes = { - ALIVE: 0, - DIGITAL: 1, - ANALOG: 2, - PWM: 3, - SERVO_PIN: 4, - TONE: 5, - PULSEIN: 6, - ULTRASONIC: 7, - TIMER: 8, - OLED: 241, - COM: 242, - NEOPIXEL: 243, - ULTRASONIC_COUNTER: 244 - } - - this.actionTypes = { - GET: 1, - SET: 2, - RESET: 3 - }; - - this.sensorValueSize = { - FLOAT: 2, - SHORT: 3 - } - - this.digitalPortTimeList = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]; - //this.digitalPortTimeList = [0, 0, 0, 0, 0, 0, 0, 0]; - - this.sensorData = { - ULTRASONIC: 0, - DIGITAL: { - '0': 0, - '1': 0, - '2': 0, - '3': 0, - '4': 0, - '5': 0, - '6': 0, - '7': 0, - '8': 0, - '9': 0, - '10': 0, - '11': 0, - '12': 0, - '13': 0 - }, - ANALOG: { - '0': 0, - '1': 0, - '2': 0, - '3': 0, - '4': 0, - '5': 0, - '6': 0, - '7': 0, - }, - PULSEIN: { - }, - TIMER: 0, - } - - this.defaultOutput = { - } + this.digitalValue = new Array(14); + this.analogValue = new Array(6); - this.recentCheckData = { - - } - - this.sendBuffers = []; - - this.lastTime = 0; - this.lastSendTime = 0; - this.isDraing = false; - this.isStartUltrasonic = false; + this.remoteDigitalValue = new Array(14); + this.readablePorts = null; + this.remainValue = null; } -var sensorIdx = 0; - -Module.prototype.init = function(handler, config) { -}; - -Module.prototype.setSerialPort = function (sp) { - var self = this; - this.sp = sp; -}; - -// Module.prototype.lostController = function () {}; +Module.prototype.init = function(handler, config) {}; Module.prototype.requestInitialData = function() { - return this.makeSensorReadBuffer(this.sensorTypes.ANALOG, 0); + return null; }; Module.prototype.checkInitialData = function(data, config) { - this.isDraing = false; //갑자기 전송이 중단됐을때 전송상태 초기화 - this.isStartUltrasonic = false; //초음파 센서 전역 변수 return true; - // 이후에 체크 로직 개선되면 처리 - // var datas = this.getDataByBuffer(data); - // var isValidData = datas.some(function (data) { - // return (data.length > 4 && data[0] === 255 && data[1] === 85); - // }); - // return isValidData; -}; - -Module.prototype.afterConnect = function(that, cb) { - that.connected = true; - if(cb) { - cb('connected'); - } }; Module.prototype.validateLocalData = function(data) { return true; }; -Module.prototype.requestRemoteData = function(handler) { - var self = this; - if(!self.sensorData) { - return; - } - Object.keys(this.sensorData).forEach(function (key) { - if(self.sensorData[key] != undefined) { - handler.write(key, self.sensorData[key]); - if (key == "DIGITAL") - { - var dObj = self.sensorData["DIGITAL"]; - //console.log("send : sensorData = " + dObj[6]); - } - - } - }) -}; - Module.prototype.handleRemoteData = function(handler) { - var self = this; - var getDatas = handler.read('GET'); - var setDatas = handler.read('SET') || this.defaultOutput; - var time = handler.read('TIME'); - var buffer = new Buffer([]); - - if(getDatas) { - var keys = Object.keys(getDatas); - keys.forEach(function(key) { - var isSend = false; - var dataObj = getDatas[key]; - if(typeof dataObj.port === 'string' || typeof dataObj.port === 'number') { - var time = self.digitalPortTimeList[dataObj.port]; - if(dataObj.time > time) { - isSend = true; - self.digitalPortTimeList[dataObj.port] = dataObj.time; - } - } else if(Array.isArray(dataObj.port)){ - isSend = dataObj.port.every(function(port) { - var time = self.digitalPortTimeList[port]; - return dataObj.time > time; - }); - - if(isSend) { - dataObj.port.forEach(function(port) { - self.digitalPortTimeList[port] = dataObj.time; - }); - } - } - - if(isSend) { - if(!self.isRecentData(dataObj.port, key, dataObj.data)) { - self.recentCheckData[dataObj.port] = { - type: key, - data: dataObj.data - } - buffer = Buffer.concat([buffer, self.makeSensorReadBuffer(key, dataObj.port, dataObj.data)]); - //console.log(dataObj.port); - } - } - }); - } - - if(setDatas) { - var setKeys = Object.keys(setDatas); - setKeys.forEach(function (port) { - var data = setDatas[port]; - if(data) { - if(self.digitalPortTimeList[port] < data.time) { - self.digitalPortTimeList[port] = data.time; - - if(!self.isRecentData(port, data.type, data.data)) { - self.recentCheckData[port] = { - type: data.type, - data: data.data - } - buffer = Buffer.concat([buffer, self.makeOutputBuffer(data.type, port, data.data)]); - } - } - } - }); - } - - if(buffer.length) { - this.sendBuffers.push(buffer); + this.readablePorts = handler.read('readablePorts'); + var digitalValue = this.remoteDigitalValue; + for (var port = 0; port < 14; port++) { + digitalValue[port] = handler.read(port); } }; -Module.prototype.isRecentData = function(port, type, data) { - var isRecent = false; - - if(type == this.sensorTypes.ULTRASONIC_COUNTER) { - isRecent = false; - return isRecent; - } - - if(type == this.sensorTypes.ULTRASONIC && !this.isStartUltrasonic) - { - isRecent = false; - this.isStartUltrasonic = true; - return isRecent; - } - if(type == this.sensorTypes.COM) - { - isRecent = false; - return isRecent; - } - - if(port in this.recentCheckData) { - if(type != this.sensorTypes.TONE && this.recentCheckData[port].type === type && this.recentCheckData[port].data === data) { - isRecent = true; - } - } - - return isRecent; -} - Module.prototype.requestLocalData = function() { - var self = this; - - //console.log(this.sendBuffers.length); - //console.log(this.isDraing); - - if(!this.isDraing && this.sendBuffers.length > 0) { - this.isDraing = true; - this.sp.write(this.sendBuffers.shift(), function () { - if(self.sp) { - self.sp.drain(function () { - self.isDraing = false; - }); - } - }); - } - - return null; -}; - -/* -ff 55 idx size data a -*/ -Module.prototype.handleLocalData = function(data) { - var self = this; - var datas = this.getDataByBuffer(data); - - datas.forEach(function (data) { - if(data.length <= 4) {// || data[0] === 255 && data[1] === 86 ) { - return; - } - - if(data[0] === 255 && data[1] === 85) { - self.originParsing(data); - } else if (data[0] === 255 && data[1] === 86) { - self.kParsing(data); - } else { - return; - } + var queryString = []; - }); - - -}; - - -/* Original Parsing FF 55 ~ */ -Module.prototype.originParsing = function(data) { - var self = this; - var readData = data.subarray(2, data.length); - var value; - switch(readData[0]) { - case self.sensorValueSize.FLOAT: { - value = new Buffer(readData.subarray(1, 5)).readFloatLE(); - value = Math.round(value * 100) / 100; - break; - } - case self.sensorValueSize.SHORT: { - value = new Buffer(readData.subarray(1, 3)).readInt16LE(); - break; - } - default: { - value = 0; - break; + var readablePorts = this.readablePorts; + if (readablePorts) { + for (var i in readablePorts) { + var query = (5 << 5) + (readablePorts[i] << 1); + queryString.push(query); } } - - var type = readData[readData.length - 1]; - var port = readData[readData.length - 2]; - - switch(type) { - case self.sensorTypes.DIGITAL: { - self.sensorData.DIGITAL[port] = value; - break; + var readablePortsValues = + (readablePorts && Object.values(readablePorts)) || []; + var digitalValue = this.remoteDigitalValue; + for (var port = 0; port < 14; port++) { + if (readablePortsValues.indexOf(port) > -1) { + continue; } - case self.sensorTypes.ANALOG: { - self.sensorData.ANALOG[port] = value; - break; - } - case self.sensorTypes.PULSEIN: { - self.sensorData.PULSEIN[port] = value; - break; - } - case self.sensorTypes.ULTRASONIC: { - self.sensorData.ULTRASONIC = value; - break; - } - case self.sensorTypes.TIMER: { - self.sensorData.TIMER = value; - break; - } - case self.sensorTypes.NEOPIXEL: { - self.sensorData.NEOPIXEL = value; - break; - } - default: { - break; + var value = digitalValue[port]; + if (value === 255 || value === 0) { + var query = (7 << 5) + (port << 1) + (value == 255 ? 1 : 0); + queryString.push(query); + } else if (value > 0 && value < 255) { + var query = (6 << 5) + (port << 1) + (value >> 7); + queryString.push(query); + query = value & 127; + queryString.push(query); } } + return queryString; }; -/* K-Board Parsing FF 56 ~ */ -Module.prototype.kParsing = function(data) { - var self = this; - var readData = data.subarray(2, data.length); - var value; - - for(var i = 0; i<8; i++) { - if(bit_test(readData[0], i)) - { - self.sensorData.DIGITAL[i + 2] = 1; - } else { - self.sensorData.DIGITAL[i + 2] = 0; - } - } - - var index = 0; - for(var i = 1; i<19; i = i + 2){ - value = new Buffer(readData.subarray(i, i+2)).readInt16LE(); - value = Math.round(value * 100) / 100; - - if( value > 1023 || value < 0) - value = 0; - - if(index != 8) - { - if(index == 0) - { - if((1023 - (value * 1.72)) > 0) - self.sensorData.ANALOG[index] = parseInt(Math.abs(1023 - (value * 1.72))); - else - self.sensorData.ANALOG[index] = 0; - } - else - self.sensorData.ANALOG[index] = value; - //console.log("self.sensorData.ANALOG" + index + " = " + self.sensorData.ANALOG[index]); - } else { - self.sensorData.ULTRASONIC = value; - //console.log("self.sensorData.ULTRASONIC" + index + " = " + self.sensorData.ULTRASONIC); - } - - //console.log("value=" + value); - - index = index + 1; - } - - - - -}; - -function bit_test(num, bit){ - return ((num>>bit) % 2 != 0) -} - -/* -ff 55 len idx action device port slot data a -0 1 2 3 4 5 6 7 8 -*/ - -Module.prototype.makeSensorReadBuffer = function(device, port, data) { - - var buffer; - var dummy = new Buffer([10]); - - if(device == this.sensorTypes.ULTRASONIC) { - buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port[0], port[1], 10]); - - /* - } else if(device == this.sensorTypes.ULTRASONIC_COUNTER) { - buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.GET, device, port[0], port[1], 10]); - */ - } else if(!data) { - buffer = new Buffer([255, 85, 5, sensorIdx, this.actionTypes.GET, device, port, 10]); - } else { - value = new Buffer(2); - value.writeInt16LE(data); - buffer = new Buffer([255, 85, 7, sensorIdx, this.actionTypes.GET, device, port, 10]); - buffer = Buffer.concat([buffer, value, dummy]); - } - sensorIdx++; - if(sensorIdx > 254) { - sensorIdx = 0; - } - //console.log(buffer); - return buffer; -}; - -//0xff 0x55 0x6 0x0 0x1 0xa 0x9 0x0 0x0 0xa -Module.prototype.makeOutputBuffer = function(device, port, data) { - var buffer; - var value = new Buffer(2); - var dummy = new Buffer([10]); - - - switch(device) { - - case this.sensorTypes.SERVO_PIN: - case this.sensorTypes.DIGITAL: - case this.sensorTypes.PWM: { - value.writeInt16LE(data); - buffer = new Buffer([255, 85, 6, sensorIdx, this.actionTypes.SET, device, port]); - buffer = Buffer.concat([buffer, value, dummy]); - break; - } - case this.sensorTypes.TONE: { - var time = new Buffer(2); - if($.isPlainObject(data)) { - value.writeInt16LE(data.value); - time.writeInt16LE(data.duration); +Module.prototype.handleLocalData = function(data) { + // data: Native Buffer + var pointer = 0; + for (var i = 0; i < 32; i++) { + var chunk; + if (!this.remainValue) { + chunk = data[i]; + } else { + chunk = this.remainValue; + i--; + } + if (chunk >> 7) { + if ((chunk >> 6) & 1) { + var nextChunk = data[i + 1]; + if (!nextChunk && nextChunk !== 0) { + this.remainValue = chunk; + } else { + this.remainValue = null; + + var port = (chunk >> 3) & 7; + this.analogValue[port] = + ((chunk & 7) << 7) + (nextChunk & 127); + } + i++; } else { - value.writeInt16LE(0); - time.writeInt16LE(0); + var port = (chunk >> 2) & 15; + this.digitalValue[port] = chunk & 1; } - buffer = new Buffer([255, 85, 8, sensorIdx, this.actionTypes.SET, device, port]); - buffer = Buffer.concat([buffer, value, time, dummy]); - break; - } - case this.sensorTypes.OLED: { - var arr = []; - var i; - data = data.toString(); - - for(i=0; i Date: Mon, 24 Jun 2024 11:39:30 +0900 Subject: [PATCH 03/17] avmboard -> avatarbot --- app/modules/{avmboard.js => avatarbot.js} | 0 app/modules/{avmboard.json => avatarbot.json} | 8 ++++---- app/modules/{avmboard.png => avatarbot.png} | Bin 3 files changed, 4 insertions(+), 4 deletions(-) rename app/modules/{avmboard.js => avatarbot.js} (100%) rename app/modules/{avmboard.json => avatarbot.json} (85%) rename app/modules/{avmboard.png => avatarbot.png} (100%) diff --git a/app/modules/avmboard.js b/app/modules/avatarbot.js similarity index 100% rename from app/modules/avmboard.js rename to app/modules/avatarbot.js diff --git a/app/modules/avmboard.json b/app/modules/avatarbot.json similarity index 85% rename from app/modules/avmboard.json rename to app/modules/avatarbot.json index 103a8e728..5800ed6b1 100644 --- a/app/modules/avmboard.json +++ b/app/modules/avatarbot.json @@ -1,12 +1,12 @@ { "id": "990101", "name": { - "en": "AVM-Board", - "ko": "AVM-Board" + "en": "AvatarBot", + "ko": "AvatarBot" }, "platform": ["win32", "darwin"], - "icon" : "avmboard.png", - "module": "avmboard.js", + "icon" : "avatarbot.png", + "module": "avatarbot.js", "driver": { "win32-ia32": "CH34x_Install_Windows_v3_4/CH34x_Install_Windows_v3_4.EXE", "win32-x64": "CH34x_Install_Windows_v3_4/CH34x_Install_Windows_v3_4.EXE", diff --git a/app/modules/avmboard.png b/app/modules/avatarbot.png similarity index 100% rename from app/modules/avmboard.png rename to app/modules/avatarbot.png From 27e82f0c9eabe2f151dcc6fc989c21b86e71f252 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Thu, 27 Jun 2024 11:01:33 +0900 Subject: [PATCH 04/17] avatarbot command test --- app/modules/avatarbot.js | 224 +++++++++++++++++++++++++++++++++++-- app/modules/avatarbot.json | 5 +- 2 files changed, 217 insertions(+), 12 deletions(-) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index 6a46330e8..3b50abc48 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -1,65 +1,220 @@ +// 클래스 내부에서 사용될 필드 function Module() { + /* this.digitalValue = new Array(14); this.analogValue = new Array(6); this.remoteDigitalValue = new Array(14); this.readablePorts = null; this.remainValue = null; + */ + // + this.dataSet_index = null; + this.dataSet = new Array(200).fill(0); + this.remoteDataSet = new Array(200).fill(0); + this.BoardFunType = { + Info: 0, + Button:10, + GPIO_LED_PWM: 20, + ADC: 30, + DAC: 40, + IR_Remote: 50, + Buzzer: 60, + PCA9568: 70, + Servo_M0: 80, + Servo_M1: 90, + Servo_M2: 100, + Servo_M3: 110, + Servo_M4: 120, + Servo_M5: 130, + Servo_M6: 140, + Servo_M7: 150, + DC_M: 160, + MPU6050: 170, + LED_Strip: 180, + ULTRA_SONIC: 190 + } + this.Board_PWM = { + Resolution: 13, + Freq: 5000 + } + this.Board_ADC = { + Resolution: 12, + Attenuation_0db: 0, + Attenuation_2_5db: 1, + Attenuation_6db: 2, + Attenuation_11db: 3 // default db value. + } + this.Board_PCA9568 = { + Osci: 27000000, + Freq: 50 + } + this.Board_Servo = { + Pulse_Min: 150, + Pulse_Max: 600, + us_Min: 500, + us_Max: 2400 + } } -Module.prototype.init = function(handler, config) {}; +/* +최초에 커넥션이 이루어진 후의 초기 설정. +handler 는 워크스페이스와 통신하 데이터를 json 화 하는 오브젝트입니다. (datahandler/json 참고) +config 은 module.json 오브젝트입니다. +*/ + +Module.prototype.init = function(handler, config) { + console.log('[jhkim] Module initialized with handler:', handler, 'and config:', config); + var index = this.BoardFunType.Info; + this.remoteDataSet[index+0] = 0x99; + this.remoteDataSet[index+1] = 0x01; + this.remoteDataSet[index+2] = 0x01; + this.remoteDataSet[index+3] = 200; + + // pwm + index = this.BoardFunType.GPIO_LED_PWM; + this.remoteDataSet[index+2] = (this.Board_PWM.Freq)&0xff; + this.remoteDataSet[index+3] = (this.Board_PWM.Freq>>8)&0xff; + this.remoteDataSet[index+4] = (this.Board_PWM.Freq>>16)&0xff; + this.remoteDataSet[index+5] = (this.Board_PWM.Resolution)&0xff; + + // adc + index = this.BoardFunType.ADC; + this.remoteDataSet[index+4] = (this.Board_ADC.Attenuation_11db)&0xff; + this.remoteDataSet[index+5] = (this.Board_ADC.Resolution)&0xff; + + // pca9568 + index = this.BoardFunType.PCA9568; + this.remoteDataSet[index+1] = (this.Board_PCA9568.Freq)&0xff; + this.remoteDataSet[index+2] = (this.Board_PCA9568.Freq>>8)&0xff; + this.remoteDataSet[index+3] = (this.Board_PCA9568.Freq>>16)&0xff; + this.remoteDataSet[index+4] = (this.Board_PCA9568.Freq>>24)&0xff; + + this.remoteDataSet[index+5] = (this.Board_PCA9568.Osci)&0xff; + this.remoteDataSet[index+6] = (this.Board_PCA9568.Osci>>8)&0xff; + this.remoteDataSet[index+7] = (this.Board_PCA9568.Osci>>16)&0xff; + this.remoteDataSet[index+8] = (this.Board_PCA9568.Osci>>24)&0xff; + + // servo moter + for(var i=0; i<8; i++) + { + index = this.BoardFunType.Servo_M0 + (i*10); + this.remoteDataSet[index+1] = (this.Board_Servo.Pulse_Min)&0xff; + this.remoteDataSet[index+2] = (this.Board_Servo.Pulse_Min>>8)&0xff; + + this.remoteDataSet[index+3] = (this.Board_Servo.Pulse_Max)&0xff; + this.remoteDataSet[index+4] = (this.Board_Servo.Pulse_Max>>8)&0xff; + + this.remoteDataSet[index+5] = (this.Board_Servo.us_Min)&0xff; + 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; + } + + // init... + this.dataSet_index = 0; + this.dataSet = this.remoteDataSet.slice(); // copy data. +}; +//---------------------------------------------------------------------- +/* +연결 후 초기에 송신할 데이터가 필요한 경우 사용합니다. +requestInitialData 를 사용한 경우 checkInitialData 가 필수입니다. +이 두 함수가 정의되어있어야 로직이 동작합니다. 필요없으면 작성하지 않아도 됩니다. +*/ Module.prototype.requestInitialData = function() { + // console.log('[jhkim] Module requestInitialData'); return null; }; +// 연결 후 초기에 수신받아서 정상연결인지를 확인해야하는 경우 사용합니다. Module.prototype.checkInitialData = function(data, config) { + // console.log('[jhkim] Module checkInitialData'); return true; }; - +//---------------------------------------------------------------------- +// 주기적으로 하드웨어에서 받은 데이터의 검증이 필요한 경우 사용합니다. Module.prototype.validateLocalData = function(data) { + // console.log('[jhkim] Module validateLocalData'); return true; }; +// 엔트리에서 받은 데이터에 대한 처리 +/* Module.prototype.handleRemoteData = function(handler) { + console.log('[jhkim] Handling remote data...'); this.readablePorts = handler.read('readablePorts'); var digitalValue = this.remoteDigitalValue; for (var port = 0; port < 14; port++) { digitalValue[port] = handler.read(port); } + // console.log('[jhkim] Remote digital values updated:', digitalValue); +}; +*/ +Module.prototype.handleRemoteData = function(handler) { + var data = this.remoteDataSet; + for (var index = 0; index < 200; index++) { + data[index] = handler.read(index); // remoteDataset shallow copy + } }; +/* +하드웨어 기기에 전달할 데이터를 반환합니다. +slave 모드인 경우 duration 속성 간격으로 지속적으로 기기에 요청을 보냅니다. +*/ +/* Module.prototype.requestLocalData = function() { var queryString = []; - var readablePorts = this.readablePorts; + var readablePorts = this.readablePorts; // Module 객체의 readablePorts 필드를 가져옴 if (readablePorts) { + // readablePorts가 존재할 경우 for (var i in readablePorts) { + // readablePorts의 각 항목에 대해 반복 var query = (5 << 5) + (readablePorts[i] << 1); - queryString.push(query); + queryString.push(query); // 쿼리 스트링 배열에 추가 } } var readablePortsValues = (readablePorts && Object.values(readablePorts)) || []; - var digitalValue = this.remoteDigitalValue; + // readablePorts의 값들을 배열 형태로 가져옴, 없으면 빈 배열 + var digitalValue = this.remoteDigitalValue; // Module 객체의 remoteDigitalValue 필드를 가져옴 for (var port = 0; port < 14; port++) { if (readablePortsValues.indexOf(port) > -1) { continue; } var value = digitalValue[port]; if (value === 255 || value === 0) { + // digital out + // (0b111<<5) + [0~14]<<1 + [1 or 0] = 0b11100000 + 0b11110 + 0b1 var query = (7 << 5) + (port << 1) + (value == 255 ? 1 : 0); - queryString.push(query); + queryString.push(query); // 1byte } else if (value > 0 && value < 255) { + // ADC write + // (0b110<<5) + [0~14]<<1 + [0] = 0b11100000 + 0b11110 + 0bx var query = (6 << 5) + (port << 1) + (value >> 7); - queryString.push(query); + queryString.push(query); // 1byte + // 0b0xxx_xxxx query = value & 127; - queryString.push(query); + queryString.push(query); // 1byte } } return queryString; }; +*/ +Module.prototype.requestLocalData = function() { + var queryString = []; + var data = this.remoteDataSet; // Module 객체의 dataset table read. max length 200 + for (var index = 0; index < 200; index++) { + var query = (data[index])&0xff; + queryString.push(query); // 1byte + } + return queryString; +}; +// 하드웨어에서 온 데이터 처리 +/* Module.prototype.handleLocalData = function(data) { // data: Native Buffer var pointer = 0; @@ -73,6 +228,7 @@ Module.prototype.handleLocalData = function(data) { } if (chunk >> 7) { if ((chunk >> 6) & 1) { + // 0b11xx_xxxx => adc value var nextChunk = data[i + 1]; if (!nextChunk && nextChunk !== 0) { this.remainValue = chunk; @@ -81,17 +237,58 @@ Module.prototype.handleLocalData = function(data) { var port = (chunk >> 3) & 7; this.analogValue[port] = - ((chunk & 7) << 7) + (nextChunk & 127); + ((chunk & 7) << 7) + (nextChunk & 127); // 3bit + 7bit = 10bit adc } i++; } else { + // 0b10xx_xxxx => digital value var port = (chunk >> 2) & 15; this.digitalValue[port] = chunk & 1; } } } }; +*/ +Module.prototype.handleLocalData = function(data) { + var self = this; + for (var i = 0; i < data.length; i++) { + self.dataSet[self.dataSet_index+i] = data[i]; + } + + if(self.dataSet[0] === 0x99 && self.dataSet[1] === 0x01 && self.dataSet[2] === 0x01 && self.dataSet[3] === 200) { + self.dataSet_index = self.dataSet_index + data.length; + }else{ + self.dataSet_index = 0; + return; + } + console.log('[jhkim] handleLocalData - DataSet length = ', data.length); + console.log('[jhkim] handleLocalData - dataSet_index = ', self.dataSet_index); + if(self.dataSet_index == 200){ + 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 + } +}; + +/* Original Parsing FF 55 ~ */ +Module.prototype.originParsing = function(data) { + console.log('[jhkim] originParsing - DataSet length = ', data.length); + for(var i=0; i<20; i++) + { + var index = i*10; + console.log('[jhkim] originParsing - DataSet[', i, ']: ', + data[index+0], ' | ', data[index+1], ' | ', data[index+2], ' | ', + data[index+3], ' | ', data[index+4], ' | ', data[index+5], ' | ', + data[index+6], ' | ', data[index+7], ' | ', data[index+8], ' | ', + data[index+9]); + } +}; +// 엔트리로 전달할 데이터 +/* Module.prototype.requestRemoteData = function(handler) { for (var i = 0; i < this.analogValue.length; i++) { var value = this.analogValue[i]; @@ -102,7 +299,14 @@ Module.prototype.requestRemoteData = function(handler) { handler.write(i, value); } }; - +*/ +Module.prototype.requestRemoteData = function(handler) { + for (var i = 0; i < 200; i++) { + var value = this.dataSet[i]; + handler.write(i, value); + } +}; +// Module.prototype.reset = function() {}; module.exports = new Module(); diff --git a/app/modules/avatarbot.json b/app/modules/avatarbot.json index 5800ed6b1..ee2da0d14 100644 --- a/app/modules/avatarbot.json +++ b/app/modules/avatarbot.json @@ -13,15 +13,16 @@ "translate": "Arduino compatible driver" }, "reconnect" : true, + "firmware": "AvatarBot", "firmwareBaudRate": 115200, - "firmware": "http://et.ketri.re.kr/purchase/", + "select_com_port":true, "entry": { "protocol": "json" }, "hardware": { "type": "serial", "control": "slave", - "duration": 32, + "duration": 200, "vendor": ["Arduino", "wch.cn", "FTDI"], "baudRate": 115200, "lostTimer": 1000, From 9dc63bcba4bc569aa9df511724087e249e57bd99 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Fri, 28 Jun 2024 14:37:55 +0900 Subject: [PATCH 05/17] avatarbot gpu backup --- app/modules/avatarbot.js | 84 +++++++++++++++++++++++--------------- app/modules/avatarbot.json | 6 +-- 2 files changed, 53 insertions(+), 37 deletions(-) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index 3b50abc48..5bcf32230 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -9,30 +9,35 @@ function Module() { this.remainValue = null; */ // + this.sendBuffers = []; + this.avatarBotDataSet = 230; this.dataSet_index = null; - this.dataSet = new Array(200).fill(0); - this.remoteDataSet = new Array(200).fill(0); + this.dataSet = new Array(230).fill(0); + this.remoteDataSet = new Array(230).fill(0); this.BoardFunType = { Info: 0, Button:10, - GPIO_LED_PWM: 20, - ADC: 30, - DAC: 40, - IR_Remote: 50, - Buzzer: 60, - PCA9568: 70, - Servo_M0: 80, - Servo_M1: 90, - Servo_M2: 100, - Servo_M3: 110, - Servo_M4: 120, - Servo_M5: 130, - Servo_M6: 140, - Servo_M7: 150, - DC_M: 160, - MPU6050: 170, - LED_Strip: 180, - ULTRA_SONIC: 190 + GPIO_LED_PWM0: 20, + GPIO_LED_PWM1: 30, + GPIO_LED_PWM2: 40, + GPIO_LED_PWM3: 50, + ADC: 60, + DAC: 70, + IR_Remote: 80, + Buzzer: 90, + PCA9568: 100, + Servo_M0: 110, + Servo_M1: 120, + Servo_M2: 130, + Servo_M3: 140, + Servo_M4: 150, + Servo_M5: 160, + Servo_M6: 170, + Servo_M7: 180, + DC_M: 190, + MPU6050: 200, + LED_Strip: 210, + ULTRA_SONIC: 220 } this.Board_PWM = { Resolution: 13, @@ -69,15 +74,17 @@ Module.prototype.init = function(handler, config) { this.remoteDataSet[index+0] = 0x99; this.remoteDataSet[index+1] = 0x01; this.remoteDataSet[index+2] = 0x01; - this.remoteDataSet[index+3] = 200; - - // pwm - index = this.BoardFunType.GPIO_LED_PWM; - this.remoteDataSet[index+2] = (this.Board_PWM.Freq)&0xff; - this.remoteDataSet[index+3] = (this.Board_PWM.Freq>>8)&0xff; - this.remoteDataSet[index+4] = (this.Board_PWM.Freq>>16)&0xff; - this.remoteDataSet[index+5] = (this.Board_PWM.Resolution)&0xff; + this.remoteDataSet[index+3] = this.avatarBotDataSet; + // pwm. 2~5 pad + for(var i=0; i<4; i++) + { + index = this.BoardFunType.GPIO_LED_PWM0 + (i*10); + this.remoteDataSet[index+2] = (this.Board_PWM.Freq)&0xff; + this.remoteDataSet[index+3] = (this.Board_PWM.Freq>>8)&0xff; + this.remoteDataSet[index+4] = (this.Board_PWM.Freq>>16)&0xff; + this.remoteDataSet[index+5] = (this.Board_PWM.Resolution)&0xff; + } // adc index = this.BoardFunType.ADC; this.remoteDataSet[index+4] = (this.Board_ADC.Attenuation_11db)&0xff; @@ -125,6 +132,7 @@ requestInitialData 를 사용한 경우 checkInitialData 가 필수입니다. */ Module.prototype.requestInitialData = function() { // console.log('[jhkim] Module requestInitialData'); + // return this.makeSensorReadBuffer(this.sensorTypes.ANALOG, 0); return null; }; @@ -153,8 +161,9 @@ Module.prototype.handleRemoteData = function(handler) { }; */ Module.prototype.handleRemoteData = function(handler) { + // console.log('[jhkim] handleRemoteData(read entry)'); var data = this.remoteDataSet; - for (var index = 0; index < 200; index++) { + for (var index = 0; index < this.avatarBotDataSet; index++) { data[index] = handler.read(index); // remoteDataset shallow copy } }; @@ -206,7 +215,7 @@ Module.prototype.requestLocalData = function() { Module.prototype.requestLocalData = function() { var queryString = []; var data = this.remoteDataSet; // Module 객체의 dataset table read. max length 200 - for (var index = 0; index < 200; index++) { + for (var index = 0; index < this.avatarBotDataSet; index++) { var query = (data[index])&0xff; queryString.push(query); // 1byte } @@ -255,15 +264,19 @@ Module.prototype.handleLocalData = function(data) { self.dataSet[self.dataSet_index+i] = data[i]; } - if(self.dataSet[0] === 0x99 && self.dataSet[1] === 0x01 && self.dataSet[2] === 0x01 && self.dataSet[3] === 200) { + 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; }else{ self.dataSet_index = 0; return; } + + /* console.log('[jhkim] handleLocalData - DataSet length = ', data.length); console.log('[jhkim] handleLocalData - dataSet_index = ', self.dataSet_index); - if(self.dataSet_index == 200){ + */ + + if(self.dataSet_index == self.avatarBotDataSet){ self.originParsing(self.dataSet); self.dataSet_index = 0; self.dataSet[0] = 0; // clear @@ -275,8 +288,9 @@ Module.prototype.handleLocalData = function(data) { /* Original Parsing FF 55 ~ */ Module.prototype.originParsing = function(data) { + /* console.log('[jhkim] originParsing - DataSet length = ', data.length); - for(var i=0; i<20; i++) + for(var i=0; i<(data.length/10); i++) { var index = i*10; console.log('[jhkim] originParsing - DataSet[', i, ']: ', @@ -285,6 +299,7 @@ Module.prototype.originParsing = function(data) { data[index+6], ' | ', data[index+7], ' | ', data[index+8], ' | ', data[index+9]); } + */ }; // 엔트리로 전달할 데이터 @@ -301,7 +316,8 @@ Module.prototype.requestRemoteData = function(handler) { }; */ Module.prototype.requestRemoteData = function(handler) { - for (var i = 0; i < 200; i++) { + // console.log('[jhkim] requestRemoteData(to entry)'); + for (var i = 0; i < this.avatarBotDataSet; i++) { var value = this.dataSet[i]; handler.write(i, value); } diff --git a/app/modules/avatarbot.json b/app/modules/avatarbot.json index ee2da0d14..dc6789bad 100644 --- a/app/modules/avatarbot.json +++ b/app/modules/avatarbot.json @@ -14,7 +14,7 @@ }, "reconnect" : true, "firmware": "AvatarBot", - "firmwareBaudRate": 115200, + "firmwareBaudRate": 460800, "select_com_port":true, "entry": { "protocol": "json" @@ -22,9 +22,9 @@ "hardware": { "type": "serial", "control": "slave", - "duration": 200, + "duration": 2000, "vendor": ["Arduino", "wch.cn", "FTDI"], - "baudRate": 115200, + "baudRate": 460800, "lostTimer": 1000, "firmwarecheck": false } From 150179e6af683b2551f85ecec5235571659f5916 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Tue, 2 Jul 2024 10:05:30 +0900 Subject: [PATCH 06/17] =?UTF-8?q?hw=20=ED=86=B5=EC=8B=A0=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/avatarbot.js | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index 5bcf32230..fd04da769 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -161,11 +161,25 @@ Module.prototype.handleRemoteData = function(handler) { }; */ Module.prototype.handleRemoteData = function(handler) { - // console.log('[jhkim] handleRemoteData(read entry)'); + // console.log('[jhkim] handleRemoteData(read entry)', this.dataSet[23]); + const cmd = handler.read('CMD'); var data = this.remoteDataSet; for (var index = 0; index < this.avatarBotDataSet; index++) { - data[index] = handler.read(index); // remoteDataset shallow copy + // data[index] = handler.read(index); // remoteDataset shallow copy + data[index] = cmd[index]; } + // console.log('[jhkim] handleRemoteData(read entry)', this.remoteDataSet[23]); + /* + for(var i=0; i<(data.length/10); i++) + { + var index = i*10; + console.log('[jhkim] originParsing - DataSet[', i, ']: ', + data[index+0], ' | ', data[index+1], ' | ', data[index+2], ' | ', + data[index+3], ' | ', data[index+4], ' | ', data[index+5], ' | ', + data[index+6], ' | ', data[index+7], ' | ', data[index+8], ' | ', + data[index+9]); + } + */ }; /* @@ -316,11 +330,25 @@ Module.prototype.requestRemoteData = function(handler) { }; */ Module.prototype.requestRemoteData = function(handler) { - // console.log('[jhkim] requestRemoteData(to entry)'); + // console.log('[jhkim] requestRemoteData(to entry) : ', this.dataSet[23]); + /* for (var i = 0; i < this.avatarBotDataSet; i++) { var value = this.dataSet[i]; handler.write(i, value); } + */ + handler.write('CMD', this.dataSet); + /* + for(var i=0; i<(this.dataSet.length/10); i++) + { + var index = i*10; + console.log('[jhkim] requestRemoteData - DataSet[', i, ']: ', + this.dataSet[index+0], ' | ', this.dataSet[index+1], ' | ', this.dataSet[index+2], ' | ', + this.dataSet[index+3], ' | ', this.dataSet[index+4], ' | ', this.dataSet[index+5], ' | ', + this.dataSet[index+6], ' | ', this.dataSet[index+7], ' | ', this.dataSet[index+8], ' | ', + this.dataSet[index+9]); + } + */ }; // Module.prototype.reset = function() {}; From 8b3dc6b30f823dba3fda933aba21110f06c3f2fb Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Tue, 2 Jul 2024 16:33:50 +0900 Subject: [PATCH 07/17] button test ok --- app/modules/avatarbot.js | 54 ++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index fd04da769..1b221d01a 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -12,6 +12,8 @@ function Module() { this.sendBuffers = []; this.avatarBotDataSet = 230; this.dataSet_index = null; + // + this.dataSetHW = new Array(230).fill(0); this.dataSet = new Array(230).fill(0); this.remoteDataSet = new Array(230).fill(0); this.BoardFunType = { @@ -161,13 +163,15 @@ Module.prototype.handleRemoteData = function(handler) { }; */ Module.prototype.handleRemoteData = function(handler) { - // console.log('[jhkim] handleRemoteData(read entry)', this.dataSet[23]); + console.log('[jhkim] handleRemoteData(read entry)', this.remoteDataSet[11]); const cmd = handler.read('CMD'); var data = this.remoteDataSet; + console.log('[jhkim] handleRemoteData(read entry) data = ', data[11], ', cmd = ', cmd[11] ); for (var index = 0; index < this.avatarBotDataSet; index++) { // data[index] = handler.read(index); // remoteDataset shallow copy data[index] = cmd[index]; } + console.log('[jhkim] handleRemoteData(read entry) data = ', data[11], ', cmd = ', cmd[11], ', de = ', this.remoteDataSet[11]); // console.log('[jhkim] handleRemoteData(read entry)', this.remoteDataSet[23]); /* for(var i=0; i<(data.length/10); i++) @@ -233,6 +237,7 @@ Module.prototype.requestLocalData = function() { var query = (data[index])&0xff; queryString.push(query); // 1byte } + return queryString; }; @@ -274,22 +279,47 @@ Module.prototype.handleLocalData = function(data) { */ Module.prototype.handleLocalData = function(data) { var self = this; + /* + if(data[0] === 0x99 && data[1] === 0x01 && data[2] === 0x01 && data[3] === self.avatarBotDataSet) + { + self.dataSet_index = 1; + } + + if(self.dataSet_index == 0) + { + return; + } + + for (var i = 0; i < data.length; i++) { + self.dataSet[self.dataSet_index+i] = data[i]; + } + self.dataSet_index = self.dataSet_index + data.length; + + 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]); + } + */ + for (var i = 0; i < data.length; i++) { self.dataSet[self.dataSet_index+i] = data[i]; } - if(self.dataSet[0] === 0x99 && self.dataSet[1] === 0x01 && self.dataSet[2] === 0x01 && self.dataSet[3] === self.avatarBotDataSet) { + + 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; }else{ self.dataSet_index = 0; return; } - /* - console.log('[jhkim] handleLocalData - DataSet length = ', data.length); - console.log('[jhkim] handleLocalData - dataSet_index = ', self.dataSet_index); - */ - if(self.dataSet_index == self.avatarBotDataSet){ self.originParsing(self.dataSet); self.dataSet_index = 0; @@ -297,12 +327,16 @@ Module.prototype.handleLocalData = function(data) { 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) { - /* + console.log('[jhkim] originParsing - DataSet length = ', data.length); for(var i=0; i<(data.length/10); i++) { @@ -313,7 +347,7 @@ Module.prototype.originParsing = function(data) { data[index+6], ' | ', data[index+7], ' | ', data[index+8], ' | ', data[index+9]); } - */ + }; // 엔트리로 전달할 데이터 @@ -330,7 +364,7 @@ Module.prototype.requestRemoteData = function(handler) { }; */ Module.prototype.requestRemoteData = function(handler) { - // console.log('[jhkim] requestRemoteData(to entry) : ', this.dataSet[23]); + // console.log('[jhkim] requestRemoteData(to entry) : ', this.dataSet[11]); /* for (var i = 0; i < this.avatarBotDataSet; i++) { var value = this.dataSet[i]; From 66a65e8cfc1866237d7249144b261887f8777d5d Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Tue, 2 Jul 2024 16:51:59 +0900 Subject: [PATCH 08/17] =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20=EC=98=88=EC=A0=9C?= =?UTF-8?q?=20=EC=86=8C=EC=8A=A4=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/avatarbot.js | 147 +-------------------------------------- 1 file changed, 1 insertion(+), 146 deletions(-) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index 1b221d01a..3a8e919b2 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -1,13 +1,5 @@ // 클래스 내부에서 사용될 필드 function Module() { - /* - this.digitalValue = new Array(14); - this.analogValue = new Array(6); - - this.remoteDigitalValue = new Array(14); - this.readablePorts = null; - this.remainValue = null; - */ // this.sendBuffers = []; this.avatarBotDataSet = 230; @@ -151,17 +143,6 @@ Module.prototype.validateLocalData = function(data) { }; // 엔트리에서 받은 데이터에 대한 처리 -/* -Module.prototype.handleRemoteData = function(handler) { - console.log('[jhkim] Handling remote data...'); - this.readablePorts = handler.read('readablePorts'); - var digitalValue = this.remoteDigitalValue; - for (var port = 0; port < 14; port++) { - digitalValue[port] = handler.read(port); - } - // console.log('[jhkim] Remote digital values updated:', digitalValue); -}; -*/ Module.prototype.handleRemoteData = function(handler) { console.log('[jhkim] handleRemoteData(read entry)', this.remoteDataSet[11]); const cmd = handler.read('CMD'); @@ -173,63 +154,12 @@ Module.prototype.handleRemoteData = function(handler) { } console.log('[jhkim] handleRemoteData(read entry) data = ', data[11], ', cmd = ', cmd[11], ', de = ', this.remoteDataSet[11]); // console.log('[jhkim] handleRemoteData(read entry)', this.remoteDataSet[23]); - /* - for(var i=0; i<(data.length/10); i++) - { - var index = i*10; - console.log('[jhkim] originParsing - DataSet[', i, ']: ', - data[index+0], ' | ', data[index+1], ' | ', data[index+2], ' | ', - data[index+3], ' | ', data[index+4], ' | ', data[index+5], ' | ', - data[index+6], ' | ', data[index+7], ' | ', data[index+8], ' | ', - data[index+9]); - } - */ }; /* 하드웨어 기기에 전달할 데이터를 반환합니다. slave 모드인 경우 duration 속성 간격으로 지속적으로 기기에 요청을 보냅니다. */ -/* -Module.prototype.requestLocalData = function() { - var queryString = []; - - var readablePorts = this.readablePorts; // Module 객체의 readablePorts 필드를 가져옴 - if (readablePorts) { - // readablePorts가 존재할 경우 - for (var i in readablePorts) { - // readablePorts의 각 항목에 대해 반복 - var query = (5 << 5) + (readablePorts[i] << 1); - queryString.push(query); // 쿼리 스트링 배열에 추가 - } - } - var readablePortsValues = - (readablePorts && Object.values(readablePorts)) || []; - // readablePorts의 값들을 배열 형태로 가져옴, 없으면 빈 배열 - var digitalValue = this.remoteDigitalValue; // Module 객체의 remoteDigitalValue 필드를 가져옴 - for (var port = 0; port < 14; port++) { - if (readablePortsValues.indexOf(port) > -1) { - continue; - } - var value = digitalValue[port]; - if (value === 255 || value === 0) { - // digital out - // (0b111<<5) + [0~14]<<1 + [1 or 0] = 0b11100000 + 0b11110 + 0b1 - var query = (7 << 5) + (port << 1) + (value == 255 ? 1 : 0); - queryString.push(query); // 1byte - } else if (value > 0 && value < 255) { - // ADC write - // (0b110<<5) + [0~14]<<1 + [0] = 0b11100000 + 0b11110 + 0bx - var query = (6 << 5) + (port << 1) + (value >> 7); - queryString.push(query); // 1byte - // 0b0xxx_xxxx - query = value & 127; - queryString.push(query); // 1byte - } - } - return queryString; -}; -*/ Module.prototype.requestLocalData = function() { var queryString = []; var data = this.remoteDataSet; // Module 객체의 dataset table read. max length 200 @@ -242,71 +172,8 @@ Module.prototype.requestLocalData = function() { }; // 하드웨어에서 온 데이터 처리 -/* -Module.prototype.handleLocalData = function(data) { - // data: Native Buffer - var pointer = 0; - for (var i = 0; i < 32; i++) { - var chunk; - if (!this.remainValue) { - chunk = data[i]; - } else { - chunk = this.remainValue; - i--; - } - if (chunk >> 7) { - if ((chunk >> 6) & 1) { - // 0b11xx_xxxx => adc value - var nextChunk = data[i + 1]; - if (!nextChunk && nextChunk !== 0) { - this.remainValue = chunk; - } else { - this.remainValue = null; - - var port = (chunk >> 3) & 7; - this.analogValue[port] = - ((chunk & 7) << 7) + (nextChunk & 127); // 3bit + 7bit = 10bit adc - } - i++; - } else { - // 0b10xx_xxxx => digital value - var port = (chunk >> 2) & 15; - this.digitalValue[port] = chunk & 1; - } - } - } -}; -*/ Module.prototype.handleLocalData = function(data) { - var self = this; - /* - if(data[0] === 0x99 && data[1] === 0x01 && data[2] === 0x01 && data[3] === self.avatarBotDataSet) - { - self.dataSet_index = 1; - } - - if(self.dataSet_index == 0) - { - return; - } - - for (var i = 0; i < data.length; i++) { - self.dataSet[self.dataSet_index+i] = data[i]; - } - self.dataSet_index = self.dataSet_index + data.length; - - 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]); - } - */ - + var self = this; for (var i = 0; i < data.length; i++) { self.dataSet[self.dataSet_index+i] = data[i]; } @@ -351,18 +218,6 @@ Module.prototype.originParsing = function(data) { }; // 엔트리로 전달할 데이터 -/* -Module.prototype.requestRemoteData = function(handler) { - for (var i = 0; i < this.analogValue.length; i++) { - var value = this.analogValue[i]; - handler.write('a' + i, value); - } - for (var i = 0; i < this.digitalValue.length; i++) { - var value = this.digitalValue[i]; - handler.write(i, value); - } -}; -*/ Module.prototype.requestRemoteData = function(handler) { // console.log('[jhkim] requestRemoteData(to entry) : ', this.dataSet[11]); /* From f37b44133b0f119507692d6df26faebbf167a0a4 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Tue, 2 Jul 2024 18:49:36 +0900 Subject: [PATCH 09/17] =?UTF-8?q?=ED=86=B5=EC=8B=A0=20=ED=94=84=EB=A1=9C?= =?UTF-8?q?=ED=86=A0=EC=BD=9C=20=EC=A0=95=EB=A6=AC=20test=20ok?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/avatarbot.js | 87 +++++++++++++++++++++++----------------- 1 file changed, 51 insertions(+), 36 deletions(-) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index 3a8e919b2..885efe5d2 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -2,36 +2,34 @@ function Module() { // this.sendBuffers = []; - this.avatarBotDataSet = 230; + this.avatarBotDataSet = 210; this.dataSet_index = null; // - this.dataSetHW = new Array(230).fill(0); - this.dataSet = new Array(230).fill(0); - this.remoteDataSet = new Array(230).fill(0); + this.dataSetHW = new Array(210).fill(0); + this.dataSet = new Array(210).fill(0); + this.remoteDataSet = new Array(210).fill(0); this.BoardFunType = { Info: 0, Button:10, - GPIO_LED_PWM0: 20, - GPIO_LED_PWM1: 30, - GPIO_LED_PWM2: 40, - GPIO_LED_PWM3: 50, - ADC: 60, - DAC: 70, - IR_Remote: 80, - Buzzer: 90, - PCA9568: 100, - Servo_M0: 110, - Servo_M1: 120, - Servo_M2: 130, - Servo_M3: 140, - Servo_M4: 150, - Servo_M5: 160, - Servo_M6: 170, - Servo_M7: 180, - DC_M: 190, - MPU6050: 200, - LED_Strip: 210, - ULTRA_SONIC: 220 + GPIO_PWM_SET: 20, + GPIO_PWM: 30, + ADC: 40, + IR_Remote: 50, + Buzzer: 60, + PCA9568: 70, + Servo_M0: 80, + Servo_M1: 90, + Servo_M2: 100, + Servo_M3: 110, + Servo_M4: 120, + Servo_M5: 130, + Servo_M6: 140, + Servo_M7: 150, + DC_M: 160, + MPU6050_1: 170, + MPU6050_2: 180, + LED_Strip: 190, + ULTRA_SONIC: 200 } this.Board_PWM = { Resolution: 13, @@ -70,15 +68,13 @@ Module.prototype.init = function(handler, config) { this.remoteDataSet[index+2] = 0x01; this.remoteDataSet[index+3] = this.avatarBotDataSet; - // pwm. 2~5 pad - for(var i=0; i<4; i++) - { - index = this.BoardFunType.GPIO_LED_PWM0 + (i*10); - this.remoteDataSet[index+2] = (this.Board_PWM.Freq)&0xff; - this.remoteDataSet[index+3] = (this.Board_PWM.Freq>>8)&0xff; - this.remoteDataSet[index+4] = (this.Board_PWM.Freq>>16)&0xff; - this.remoteDataSet[index+5] = (this.Board_PWM.Resolution)&0xff; - } + // pwm pad + index = this.BoardFunType.GPIO_PWM_SET; + this.remoteDataSet[index+1] = (this.Board_PWM.Freq)&0xff; + this.remoteDataSet[index+2] = (this.Board_PWM.Freq>>8)&0xff; + this.remoteDataSet[index+3] = (this.Board_PWM.Freq>>16)&0xff; + this.remoteDataSet[index+4] = (this.Board_PWM.Resolution)&0xff; + // adc index = this.BoardFunType.ADC; this.remoteDataSet[index+4] = (this.Board_ADC.Attenuation_11db)&0xff; @@ -154,6 +150,16 @@ Module.prototype.handleRemoteData = function(handler) { } console.log('[jhkim] handleRemoteData(read entry) data = ', data[11], ', cmd = ', cmd[11], ', de = ', this.remoteDataSet[11]); // console.log('[jhkim] handleRemoteData(read entry)', this.remoteDataSet[23]); + // console.log('[jhkim] originParsing - DataSet length = ', data.length); + for(var i=0; i<(data.length/10); i++) + { + var index = i*10; + console.log('[jhkim] handleRemoteData - DataSet[', i, ']: ', + data[index+0], ' | ', data[index+1], ' | ', data[index+2], ' | ', + data[index+3], ' | ', data[index+4], ' | ', data[index+5], ' | ', + data[index+6], ' | ', data[index+7], ' | ', data[index+8], ' | ', + data[index+9]); + } }; /* @@ -168,6 +174,15 @@ Module.prototype.requestLocalData = function() { queryString.push(query); // 1byte } + for(var i=0; i<(data.length/10); i++) + { + var index = i*10; + console.log('[jhkim] requestLocalData - DataSet[', i, ']: ', + data[index+0], ' | ', data[index+1], ' | ', data[index+2], ' | ', + data[index+3], ' | ', data[index+4], ' | ', data[index+5], ' | ', + data[index+6], ' | ', data[index+7], ' | ', data[index+8], ' | ', + data[index+9]); + } return queryString; }; @@ -203,7 +218,7 @@ Module.prototype.handleLocalData = function(data) { /* Original Parsing FF 55 ~ */ Module.prototype.originParsing = function(data) { - + /* console.log('[jhkim] originParsing - DataSet length = ', data.length); for(var i=0; i<(data.length/10); i++) { @@ -214,7 +229,7 @@ Module.prototype.originParsing = function(data) { data[index+6], ' | ', data[index+7], ' | ', data[index+8], ' | ', data[index+9]); } - + */ }; // 엔트리로 전달할 데이터 From aa2656d38168a8f684b90922740c4ac995a49417 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Wed, 3 Jul 2024 14:35:35 +0900 Subject: [PATCH 10/17] adc test --- app/modules/avatarbot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index 885efe5d2..ef1d5209b 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -210,7 +210,7 @@ Module.prototype.handleLocalData = function(data) { self.dataSet[2] = 0; // clear self.dataSet[3] = 0; // clear // - console.log('[jhkim] handleLocalData - dataSet_index[11] = ', self.dataSet[11]); + // console.log('[jhkim] handleLocalData - dataSet_index[11] = ', self.dataSet[11]); } From 989383b2737e5af8ffaa7d850b2aaa33cdd822e4 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Fri, 5 Jul 2024 13:57:37 +0900 Subject: [PATCH 11/17] all module test. --- app/modules/avatarbot.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index ef1d5209b..80658468b 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -49,8 +49,8 @@ function Module() { this.Board_Servo = { Pulse_Min: 150, Pulse_Max: 600, - us_Min: 500, - us_Max: 2400 + us_Min: 400, + us_Max: 2100 } } From a2044519cc7eb66313dda098714d73ea1717e806 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Wed, 11 Sep 2024 12:25:38 +0900 Subject: [PATCH 12/17] backup --- app/modules/avatarbot.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index 80658468b..c0e2bf5c4 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -52,6 +52,17 @@ function Module() { us_Min: 400, us_Max: 2100 } + this.Board_LED_Strip = { + En:0, + sample: 0, + led_num: 64, + color_order: 0, + r: 0, + g: 0, + b: 0, + brightness:63, + set_en: 0, + } } /* @@ -109,6 +120,11 @@ Module.prototype.init = function(handler, config) { this.remoteDataSet[index+8] = (this.Board_Servo.us_Max>>8)&0xff; } + // led + index = this.BoardFunType.LED_Strip; + this.remoteDataSet[index+2] = (this.Board_LED_Strip.led_num)&0xff; + this.remoteDataSet[index+7] = (this.Board_LED_Strip.brightness)&0xff; + // init... this.dataSet_index = 0; this.dataSet = this.remoteDataSet.slice(); // copy data. @@ -151,6 +167,7 @@ Module.prototype.handleRemoteData = function(handler) { console.log('[jhkim] handleRemoteData(read entry) data = ', data[11], ', cmd = ', cmd[11], ', de = ', this.remoteDataSet[11]); // console.log('[jhkim] handleRemoteData(read entry)', this.remoteDataSet[23]); // console.log('[jhkim] originParsing - DataSet length = ', data.length); + /* for(var i=0; i<(data.length/10); i++) { var index = i*10; @@ -160,6 +177,7 @@ Module.prototype.handleRemoteData = function(handler) { data[index+6], ' | ', data[index+7], ' | ', data[index+8], ' | ', data[index+9]); } + */ }; /* @@ -173,7 +191,7 @@ Module.prototype.requestLocalData = function() { var query = (data[index])&0xff; queryString.push(query); // 1byte } - + /* for(var i=0; i<(data.length/10); i++) { var index = i*10; @@ -183,6 +201,7 @@ Module.prototype.requestLocalData = function() { data[index+6], ' | ', data[index+7], ' | ', data[index+8], ' | ', data[index+9]); } + */ return queryString; }; From 8619b66c7030159c73c42c5a9accf630c21b968a Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Thu, 12 Sep 2024 15:56:54 +0900 Subject: [PATCH 13/17] irreceiver --- app/modules/avatarbot.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index c0e2bf5c4..d52532171 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -42,6 +42,16 @@ function Module() { Attenuation_6db: 2, Attenuation_11db: 3 // default db value. } + + this.Board_IR_Remote = { + Flag: 0, + Value: 0xff, + Repeat: 0, + Address: 0, + Command: 0, + Raw_data: 0 + } + this.Board_PCA9568 = { Osci: 27000000, Freq: 50 @@ -91,6 +101,10 @@ Module.prototype.init = function(handler, config) { this.remoteDataSet[index+4] = (this.Board_ADC.Attenuation_11db)&0xff; this.remoteDataSet[index+5] = (this.Board_ADC.Resolution)&0xff; + // ir receiver + index = this.BoardFunType.IR_Remote; + this.remoteDataSet[index+1] = (this.Board_IR_Remote.Value)&0xff; + // pca9568 index = this.BoardFunType.PCA9568; this.remoteDataSet[index+1] = (this.Board_PCA9568.Freq)&0xff; From a2b32a51f9e235b90d0ae9d1e41ec5e8f75caa07 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Thu, 12 Sep 2024 18:21:08 +0900 Subject: [PATCH 14/17] oled ifx --- app/modules/avatarbot.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index d52532171..58285ed6a 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -11,6 +11,7 @@ function Module() { this.BoardFunType = { Info: 0, Button:10, + OLED:12, // OLED : 12(EN),13(Sample) GPIO_PWM_SET: 20, GPIO_PWM: 30, ADC: 40, From b7f4b958ff55b24057402d678058fd1ce6785c53 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Fri, 13 Sep 2024 17:27:54 +0900 Subject: [PATCH 15/17] buzzer timer fix --- app/modules/avatarbot.js | 9 +++++---- app/modules/avatarbot.json | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/modules/avatarbot.js b/app/modules/avatarbot.js index 58285ed6a..daca5a875 100644 --- a/app/modules/avatarbot.js +++ b/app/modules/avatarbot.js @@ -10,6 +10,7 @@ function Module() { this.remoteDataSet = new Array(210).fill(0); this.BoardFunType = { Info: 0, + Info_isConnect: 5, Button:10, OLED:12, // OLED : 12(EN),13(Sample) GPIO_PWM_SET: 20, @@ -89,7 +90,7 @@ Module.prototype.init = function(handler, config) { this.remoteDataSet[index+1] = 0x01; this.remoteDataSet[index+2] = 0x01; this.remoteDataSet[index+3] = this.avatarBotDataSet; - + // pwm pad index = this.BoardFunType.GPIO_PWM_SET; this.remoteDataSet[index+1] = (this.Board_PWM.Freq)&0xff; @@ -171,15 +172,15 @@ Module.prototype.validateLocalData = function(data) { // 엔트리에서 받은 데이터에 대한 처리 Module.prototype.handleRemoteData = function(handler) { - console.log('[jhkim] handleRemoteData(read entry)', this.remoteDataSet[11]); + // console.log('[jhkim] handleRemoteData(read entry)', this.remoteDataSet[11]); const cmd = handler.read('CMD'); var data = this.remoteDataSet; - console.log('[jhkim] handleRemoteData(read entry) data = ', data[11], ', cmd = ', cmd[11] ); + // console.log('[jhkim] handleRemoteData(read entry) data = ', data[11], ', cmd = ', cmd[11] ); for (var index = 0; index < this.avatarBotDataSet; index++) { // data[index] = handler.read(index); // remoteDataset shallow copy data[index] = cmd[index]; } - console.log('[jhkim] handleRemoteData(read entry) data = ', data[11], ', cmd = ', cmd[11], ', de = ', this.remoteDataSet[11]); + // console.log('[jhkim] handleRemoteData(read entry) data = ', data[11], ', cmd = ', cmd[11], ', de = ', this.remoteDataSet[11]); // console.log('[jhkim] handleRemoteData(read entry)', this.remoteDataSet[23]); // console.log('[jhkim] originParsing - DataSet length = ', data.length); /* diff --git a/app/modules/avatarbot.json b/app/modules/avatarbot.json index dc6789bad..2ddf220e3 100644 --- a/app/modules/avatarbot.json +++ b/app/modules/avatarbot.json @@ -22,7 +22,7 @@ "hardware": { "type": "serial", "control": "slave", - "duration": 2000, + "duration": 500, "vendor": ["Arduino", "wch.cn", "FTDI"], "baudRate": 460800, "lostTimer": 1000, From 0aa0a63066df9705214617a25603cd434437f0a5 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Thu, 19 Sep 2024 14:47:06 +0900 Subject: [PATCH 16/17] avatarbot firmware v1.0 upload --- app/modules/avatarbot.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/modules/avatarbot.json b/app/modules/avatarbot.json index 2ddf220e3..7432145da 100644 --- a/app/modules/avatarbot.json +++ b/app/modules/avatarbot.json @@ -13,8 +13,7 @@ "translate": "Arduino compatible driver" }, "reconnect" : true, - "firmware": "AvatarBot", - "firmwareBaudRate": 460800, + "firmware": "http://avatarmecha.ddns.net:5050/sharing/iCuhzvxcu", "select_com_port":true, "entry": { "protocol": "json" From 280fa4554e9262df6ca32d32fc274529a19cd462 Mon Sep 17 00:00:00 2001 From: JinHo Kim Date: Thu, 26 Sep 2024 15:14:05 +0900 Subject: [PATCH 17/17] =?UTF-8?q?entry=20id=20=EB=B0=9C=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/modules/avatarbot.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/modules/avatarbot.json b/app/modules/avatarbot.json index 7432145da..9e55ad445 100644 --- a/app/modules/avatarbot.json +++ b/app/modules/avatarbot.json @@ -1,5 +1,5 @@ { - "id": "990101", + "id": "640101", "name": { "en": "AvatarBot", "ko": "AvatarBot"