修订版 | 8211b8653caec9a334b528ebd718fe71a1e4f87b (tree) |
---|---|
时间 | 2014-07-04 01:45:46 |
作者 | nyatla <nyatla@4719...> |
Commiter | nyatla |
mbedJSのMCUに関数を追加
git-svn-id: http://svn.osdn.jp/svnroot/mimic/trunk@381 47198e57-cb75-475f-84c4-a814cd6f29e0
@@ -538,7 +538,7 @@ var MiMicJS={}; | ||
538 | 538 | rx+='})'; |
539 | 539 | rxst=0; |
540 | 540 | { |
541 | -// log(rx);//Debug | |
541 | + log(rx);//Debug | |
542 | 542 | //JSONがたぶん確定 |
543 | 543 | var j=eval(rx); |
544 | 544 | for(var i2=q.length-1;i2>=0;i2--){ |
@@ -600,14 +600,14 @@ var MiMicJS={}; | ||
600 | 600 | * @param {string} i_params |
601 | 601 | * カンマ区切りのJSONスタイルの文字列です。この文字列は[....]に埋め込まれます。エスケープ文字列は使用できません。 |
602 | 602 | * @param {function(json)}i_callback |
603 | - * Resultを受け取るコールベック関数です。jsonにはResult JSONをパースしたオブジェクトが入ります。 | |
603 | + * Resultを受け取るコールバック関数です。jsonにはResult JSONをパースしたオブジェクトが入ります。 | |
604 | 604 | * @return {int} |
605 | 605 | * メソッドIDを返します。 |
606 | 606 | */ |
607 | 607 | sendMethod:function callJsonRpc(i_method,i_params,i_callback) |
608 | 608 | { |
609 | 609 | var v="{\"jsonrpc\":\"2.0\",\"method\":\""+i_method+"\",\"params\":["+i_params+"],\"id\":"+this._method_id+"}"; |
610 | -// log(v);//Debug | |
610 | + log(v);//Debug | |
611 | 611 | this._ws.send(v); |
612 | 612 | this._q.push([this._method_id,i_callback]);//キューに記録 |
613 | 613 | this._method_id=(this._method_id+1)&0x0fffffff;//IDインクリメント |
@@ -27,6 +27,15 @@ var MI=MiMicJS; | ||
27 | 27 | * 何らかの異常で通信を継続できないエラーが発生し、コネクションを維持できない時に発生します。 |
28 | 28 | * このイベントが発生するとコネクションは閉じられれます。 |
29 | 29 | * </li> |
30 | + * <li>{function(v)} onDisposeObject | |
31 | + * disposeObject関数が完了したときに呼び出されます。 | |
32 | + * vは削除に成功したかの真偽値です。 | |
33 | + * </li> | |
34 | + * <li>{function(v)} onGetInfo | |
35 | + * onGetInfo関数が完了したときに呼び出されます。 | |
36 | + * vは戻り値を格納した複合連想配列です。 | |
37 | + * {version,platform,mcu:{name,eth},memory:{free}} | |
38 | + * </li> | |
30 | 39 | * </ul> |
31 | 40 | * <p> |
32 | 41 | * Generatorを指定した場合、コールバック関数の戻り値はyiledの戻り値として取得できます。 |
@@ -94,6 +103,7 @@ var CLASS=function Mcu(i_url,i_handler) | ||
94 | 103 | } |
95 | 104 | CLASS.prototype= |
96 | 105 | { |
106 | + RPC_NS:"mbedJS:Mcu", | |
97 | 107 | _lc:null, |
98 | 108 | _rpc:null, |
99 | 109 | _gen:null, |
@@ -167,7 +177,58 @@ CLASS.prototype= | ||
167 | 177 | /** @private */ |
168 | 178 | addItem:function(o){ |
169 | 179 | this._items.push(o); |
170 | - } | |
180 | + }, | |
181 | + /** | |
182 | + * Mcuの情報を返します。 | |
183 | + * @name mbedJS.Mcu#rpc | |
184 | + * @function | |
185 | + * @return {HashMap} | |
186 | + * 情報を格納した連想配列です。 | |
187 | + */ | |
188 | + getInfo:function(){ | |
189 | + try{ | |
190 | + var _t=this; | |
191 | + if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
192 | + _t._lc=CLASS.getInfo; | |
193 | + return _t.rpc(_t.RPC_NS+":getInfo","", | |
194 | + function (j) | |
195 | + { | |
196 | + var r=j.result; | |
197 | + var v={version:r[0],platform:r[1],mcu:{name:r[3],eth:r[2]},memory:{free:r[4]}}; | |
198 | + if(_t._event.onGetInfo){_t._event.onGetInfo(v);} | |
199 | + if(_t._gen){_t._gen.next(v);} | |
200 | + _t._lc=null; | |
201 | + } | |
202 | + ); | |
203 | + }catch(e){ | |
204 | + throw new MI.MiMicException(e); | |
205 | + } | |
206 | + }, | |
207 | + /** | |
208 | + * 指定idのオブジェクトをMCUのメモリから削除します。 | |
209 | + * @name mbedJS.Mcu#disposeObject | |
210 | + * @function | |
211 | + * @return {boolean} | |
212 | + * 結果を返します。 | |
213 | + */ | |
214 | + disposeObject:function(i_oid){ | |
215 | + try{ | |
216 | + var _t=this; | |
217 | + if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);} | |
218 | + _t._lc=CLASS.disposeObject; | |
219 | + return _t.rpc(_t.RPC_NS+":disposeObject",i_oid, | |
220 | + function (j) | |
221 | + { | |
222 | + var v=j.result[0]?true:false; | |
223 | + if(_t._event.onDisposeObject){_t._event.onDisposeObject(v);} | |
224 | + if(_t._gen){_t._gen.next(v);} | |
225 | + _t._lc=null; | |
226 | + } | |
227 | + ); | |
228 | + }catch(e){ | |
229 | + throw new MI.MiMicException(e); | |
230 | + } | |
231 | + } | |
171 | 232 | } |
172 | 233 | NS.Mcu=CLASS; |
173 | 234 | }()); |
\ No newline at end of file |
@@ -5,7 +5,7 @@ | ||
5 | 5 | <script type="text/javascript" src="mbedJS/MiMicCore.js"></script> |
6 | 6 | <script type="text/javascript" src="mbedJS/mbed.types.js"></script> |
7 | 7 | <script type="text/javascript" src="mbedJS/mbed.Mcu.js"></script> |
8 | -<script type="text/javascript" src="mbedJS/mbed.DigitalOut.js"></script> | |
8 | +<script type="text/javascript" src="mbedJS/mbed.DigitalIn.js"></script> | |
9 | 9 | <script type="text/javascript"> |
10 | 10 | |
11 | 11 |
@@ -28,6 +28,17 @@ function async() | ||
28 | 28 | { |
29 | 29 | onNew:function(){ |
30 | 30 | log("[PASS]onNew"); |
31 | + mcu.getInfo(); | |
32 | + }, | |
33 | + onGetInfo:function(v){ | |
34 | + log("[PASS]onGetInfo:"+v.version+","+v.platform+","+v.mcu.name+","+v.mcu.eth+","+v.memory.free); | |
35 | + var pin=new mbedJS.DigitalIn(mcu,mbedJS.PinName.P0_22,{ | |
36 | + onNew:function(){ | |
37 | + mcu.disposeObject(pin._oid); | |
38 | + }}); | |
39 | + }, | |
40 | + onDisposeObject:function(v){ | |
41 | + log("[PASS]onDisposeObject:"+v); | |
31 | 42 | mcu.close(); |
32 | 43 | }, |
33 | 44 | onClose:function(){ |
@@ -104,7 +104,52 @@ function async() | ||
104 | 104 | } |
105 | 105 | }); |
106 | 106 | } |
107 | +function sync() | |
108 | +{ | |
109 | + log(); | |
110 | + var g=function*(){ | |
111 | + try{ | |
112 | + var v; | |
113 | + var mcu=new mbedJS.Mcu("192.168.128.39",g); | |
114 | + yield mcu.waitForNew(); | |
115 | + var mem=new mbedJS.Memory(mcu,g); | |
116 | + yield mem.waitForNew(); | |
117 | + yield mem.write(0x20080000,1); | |
118 | + log("[PASS]onWrite:"); | |
119 | + v=yield mem.read(0x20080000,1); | |
120 | + log("[PASS]onRead:"+v); | |
121 | + v=yield mem.read(0x20080001,1); | |
122 | + log("[PASS]onRead:"+v); | |
123 | + v=yield mem.read(0x20080000,8); | |
124 | + log("[PASS]onRead:"+v); | |
125 | + yield mem.write(0x20080001,[2]); | |
126 | + log("[PASS]onWrite:"); | |
127 | + yield mem.write(0x20080004,[10,20,30]); | |
128 | + log("[PASS]onWrite:"); | |
129 | + yield mem.write32(0x20080000,0xff); | |
130 | + log("[PASS]onWrite32:"); | |
131 | + v=yield mem.read32(0x20080000); | |
132 | + log("[PASS]onRead32:"+v); | |
133 | + v=yield mem.read32(0x20080004,4); | |
134 | + log("[PASS]onRead32:"+v); | |
135 | + v=yield mem.read32(0x20080000,16); | |
136 | + log("[PASS]onRead32:"+v); | |
137 | + yield mem.write32(0x20080004,[2]); | |
138 | + log("[PASS]onWrite32:"); | |
139 | + yield mem.write32(0x20080004,[10,20,30]); | |
140 | + log("[PASS]onWrite32:"); | |
141 | + mcu.close(); | |
107 | 142 | |
143 | + }catch(e){ | |
144 | + mcu.shutdown(); | |
145 | + alert(e); | |
146 | + throw e; | |
147 | + } | |
148 | + }(); | |
149 | + g.next(); | |
150 | + return; | |
151 | + | |
152 | +} | |
108 | 153 | |
109 | 154 | </script> |
110 | 155 | </head> |