8 * mbedJSを搭載したmbedに接続したインスタンスを生成します。
\r
9 * @param {string} i_url
\r
10 * 接続先のMiMicRPCサービスのアドレスを指定します。
\r
11 * @param {HashMap|Generator} i_handler
\r
12 * 非同期イベントハンドラの連想配列、又はGeneratorです。
\r
14 * 非同期イベントハンドラの場合、関数はイベントハンドラで結果を通知します。
\r
16 * <li>{function()} onNew -
\r
17 * インスタンスが使用可能になった時に呼び出されます。
\r
19 * <li>{function()} onClose -
\r
20 * Close関数のコールバック関数です。
\r
22 * <li>{function()} onError -
\r
23 * 何らかの異常で通信を継続できないエラーが発生し、コネクションを維持できない時に発生します。
\r
24 * このイベントが発生するとコネクションは閉じられれます。
\r
28 * Generatorを指定した場合、コールバック関数の戻り値はyiledの戻り値として取得できます。
\r
30 * @return {mbedJS.Mcu}
\r
33 var CLASS=function Mcu(i_url,i_handler)
\r
37 _t._has_error=false;
\r
38 if(MI.isGenerator(i_handler)){_t._gen=i_handler;}
\r
39 else if(i_handler){_t._event=i_handler}
\r
41 _t._rpc=new MI.Rpc({
\r
42 onOpen:function _Mcu_onOpen(){
\r
43 if(_t._event.onNew){_t._event.onNew();}
\r
44 if(_t._gen){_t._gen.next(_t);}
\r
47 onClose:function _Mcu_onClose(){
\r
48 if(_t._lc==CLASS.close){
\r
49 if(_t._event.onClose){_t._event.onClose();}
\r
51 if(_t._event.onError){_t._event.onError();}
\r
58 onError:function _Mcu_onError()
\r
61 if(_t._event.onError){_t._event.onError();}
\r
62 if(_t._gen && _t._lc){
\r
63 _t._gen.throw(new MI.MiMicException());
\r
65 //@todo MCUにぶら下がってる全てのyieldに対してもExceptionの発生要請?
\r
69 this._rpc.open(i_url);
\r
79 * @name mbedJS.Mcu#hasError
\r
82 * Generatorモードの場合に、定期実行してインスタンスの状態をチェックできます。
\r
83 * falseの場合、下位のオブジェクトでyieldロックが発生している場合があります。
\r
85 * true - インスタンスはエラー状態で停止中です。使用できません。
\r
86 * false - インスタンスは動作中です。使用可能です。
\r
88 hasError:function(){
\r
89 return _t._has_error;
\r
92 * @name mbedJS.Mcu#waitForNew
\r
94 * Generatorモードのときに使用する関数です。
\r
95 * Generatorモードの時は、yieldと併用してnew Mcu()の完了を待ちます。
\r
97 waitForNew:function MCU_waitForNew(){
\r
98 if(this._lc!=CLASS){throw new MI.MiMicException(MI.Error.NG_ILLEGAL_CALL);}
\r
99 this._lc=CLASS.waitForNew;
\r
102 * @name mbedJS.Mcu#close
\r
104 * RPCを切断します。関数の完了時にonCloseイベントが発生します。
\r
105 * Generatorモードの時は、yieldと併用して完了を待機できます。
\r
107 close:function MCU_close(){
\r
108 if(this._gen && this._lc){throw new MI.MiMicException(MI.Error.NG_YIELD_NOT_COMPLETED);}
\r
109 this._lc=CLASS.close;
\r
113 * @name mbedJS.Mcu#shutdown
\r
115 * コールバック関数を全てキャンセルして、Mcuとの接続をシャットダウンします。
\r
117 shutdown:function MCU_shutdown(){
\r
118 this._rpc.shutdown();
\r
121 * @name mbedJS.Mcu#rpc
\r
124 * @param {string} m
\r
126 * @param {string} p
\r
127 * パラメータ部の文字列です。JSONオブジェクトの配列を記述します。
\r
128 * 配列の要素はプリミティブ型である必要があります。
\r
129 * @param {function(json)} c
\r
130 * RPCが完了したときに呼び出すコールバック関数です。
\r
132 * <li>json - 戻り値をJSON文字列としてパースしたObjectです。</li>
\r
137 rpc:function Mcu_rpc(m,p,c){
\r
138 if(this._has_error){
\r
139 throw new MI.MiMicException();
\r
141 return this._rpc.sendMethod(m,p,c);
\r
143 addItem:function(o){
\r
144 this._items.push(o);
\r