920MHz帯無線通信モジュールIM920のライブラリ

Dependents:   Hybrid_OB2021_MAIN Hybrid_OB2021_GROUND pressure_control_system pressure_control_receiver ... more

Committer:
Sigma884
Date:
Sun Jun 24 17:47:20 2018 +0000
Revision:
1:5c181b7606f4
Parent:
0:8e1682c378ec
????????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gaku0606 0:8e1682c378ec 1 #ifndef _IM920_H_
Gaku0606 0:8e1682c378ec 2 #define _IM920_H_
Gaku0606 0:8e1682c378ec 3 #include "mbed.h"
Gaku0606 0:8e1682c378ec 4
Gaku0606 0:8e1682c378ec 5 #define IM920_BUFF_SIZE 160
Gaku0606 0:8e1682c378ec 6
Gaku0606 0:8e1682c378ec 7 const int FUNC_NUMBER = 256;
Gaku0606 0:8e1682c378ec 8
Gaku0606 0:8e1682c378ec 9
Gaku0606 0:8e1682c378ec 10 typedef enum im920_buff_classify{
Gaku0606 0:8e1682c378ec 11 BUFF_A = 0,
Gaku0606 0:8e1682c378ec 12 BUFF_B = 1
Gaku0606 0:8e1682c378ec 13 }IM920_Buff_Classify;
Gaku0606 0:8e1682c378ec 14
Gaku0606 0:8e1682c378ec 15 //解析方法に関する変数
Gaku0606 0:8e1682c378ec 16 const int WAIT_TIME_US = 1000;
Gaku0606 0:8e1682c378ec 17 typedef enum{
Gaku0606 0:8e1682c378ec 18 DATA_STRING = 0, //データの文字列
Gaku0606 0:8e1682c378ec 19 RESPONSE_STRING = 1, //OKかNGのレスポンスの文字列
Gaku0606 0:8e1682c378ec 20 NORMAL_STRING = 2,
Gaku0606 0:8e1682c378ec 21 OTHER_STRING = 3,
Gaku0606 0:8e1682c378ec 22 RECEIVE_ID = 4,
Gaku0606 0:8e1682c378ec 23 INTERACTIVE_STRING = 5
Gaku0606 0:8e1682c378ec 24 }IM920_Analyze_Selector;
Gaku0606 0:8e1682c378ec 25
Gaku0606 0:8e1682c378ec 26
Gaku0606 0:8e1682c378ec 27
Gaku0606 0:8e1682c378ec 28 static IM920_Buff_Classify AB = BUFF_A;
Gaku0606 0:8e1682c378ec 29
Gaku0606 0:8e1682c378ec 30 class IM920{
Gaku0606 0:8e1682c378ec 31 public:
Gaku0606 0:8e1682c378ec 32 IM920(Serial &serial, Serial &pc, int baudrate = 19200);
Gaku0606 0:8e1682c378ec 33 private:
Gaku0606 0:8e1682c378ec 34 Serial *ser;
Gaku0606 0:8e1682c378ec 35 Serial *_pc;
Gaku0606 0:8e1682c378ec 36
Gaku0606 0:8e1682c378ec 37 //バッファ関連の変数
Gaku0606 0:8e1682c378ec 38 char buff_A[IM920_BUFF_SIZE];
Gaku0606 0:8e1682c378ec 39 char buff_B[IM920_BUFF_SIZE];
Gaku0606 0:8e1682c378ec 40 char* readBuffAddr;
Gaku0606 0:8e1682c378ec 41 char* writeBuffAddr;
Gaku0606 0:8e1682c378ec 42
Gaku0606 0:8e1682c378ec 43
Gaku0606 0:8e1682c378ec 44 char im920_dataLength;
Gaku0606 0:8e1682c378ec 45 char im920_sendBuff[129];
Gaku0606 0:8e1682c378ec 46
Gaku0606 0:8e1682c378ec 47 int nodeNumber;
Gaku0606 0:8e1682c378ec 48 //インタラクティブモードから復帰できるかを示すフラグ
Gaku0606 0:8e1682c378ec 49 //1ならインタラクティブモード、0なら通常モード
Gaku0606 0:8e1682c378ec 50 int interactiveFlag;
Gaku0606 0:8e1682c378ec 51
Gaku0606 0:8e1682c378ec 52 IM920_Analyze_Selector AS;
Gaku0606 0:8e1682c378ec 53
Gaku0606 0:8e1682c378ec 54 public:
Gaku0606 0:8e1682c378ec 55
Gaku0606 0:8e1682c378ec 56 union IM920_CAST{
Gaku0606 0:8e1682c378ec 57 double d;
Gaku0606 0:8e1682c378ec 58 float f;
Gaku0606 0:8e1682c378ec 59 long l;
Gaku0606 0:8e1682c378ec 60 int i;
Gaku0606 0:8e1682c378ec 61 short s;
Gaku0606 0:8e1682c378ec 62 char c;
Gaku0606 0:8e1682c378ec 63 char u[8];
Gaku0606 0:8e1682c378ec 64 };
Gaku0606 0:8e1682c378ec 65 union IM920_CAST im920_cast;
Gaku0606 0:8e1682c378ec 66
Gaku0606 0:8e1682c378ec 67 char data[64];
Gaku0606 0:8e1682c378ec 68 int sendDataSize;
Gaku0606 0:8e1682c378ec 69 void (*p_callFunc[256])(void);
Gaku0606 0:8e1682c378ec 70 char node;
Gaku0606 0:8e1682c378ec 71 char RSSI;//受信強度
Gaku0606 0:8e1682c378ec 72 int rID;//受信した送信機ID
Gaku0606 0:8e1682c378ec 73 int ID; //自分の固有ID
Gaku0606 0:8e1682c378ec 74
Gaku0606 0:8e1682c378ec 75 /**
Gaku0606 0:8e1682c378ec 76 @note 無線機の設定を変更するわけではない
Gaku0606 0:8e1682c378ec 77 @bref IM920XSとの通信ボーレート変更
Gaku0606 0:8e1682c378ec 78 @param baudrate 1200,2400,4800,9600,19200,38400,57600 or 115200
Gaku0606 0:8e1682c378ec 79 */
Gaku0606 0:8e1682c378ec 80 void baud(int baudrate){
Gaku0606 0:8e1682c378ec 81 ser->baud(baudrate);
Gaku0606 0:8e1682c378ec 82 }
Gaku0606 0:8e1682c378ec 83
Gaku0606 0:8e1682c378ec 84 /**
Gaku0606 0:8e1682c378ec 85 @bref インタラクティブモードへ移行する,@で復帰
Gaku0606 0:8e1682c378ec 86 */
Gaku0606 0:8e1682c378ec 87 void interactiveMode();
Gaku0606 0:8e1682c378ec 88
Gaku0606 0:8e1682c378ec 89 /**
Gaku0606 0:8e1682c378ec 90 @bref 16進数文字列データから数値データを取得します
Gaku0606 0:8e1682c378ec 91 */
Gaku0606 0:8e1682c378ec 92 void data_analyze();
Gaku0606 0:8e1682c378ec 93
Gaku0606 0:8e1682c378ec 94 /**
Gaku0606 0:8e1682c378ec 95 @bref データ処理関数を設定
Gaku0606 0:8e1682c378ec 96 @param *funcAddr 関数ポインタ、void型引数無し関数のみ設定可
Gaku0606 0:8e1682c378ec 97 @param header 関数を選択する0~255のヘッダー
Gaku0606 0:8e1682c378ec 98 */
Gaku0606 0:8e1682c378ec 99 void attach(void (*funcAddr)(void), unsigned header);
Gaku0606 0:8e1682c378ec 100
Gaku0606 0:8e1682c378ec 101 /**
Gaku0606 0:8e1682c378ec 102 @bref パラメータ不揮発メモリ書き込み許可モードへ移行
Gaku0606 0:8e1682c378ec 103 */
Gaku0606 0:8e1682c378ec 104 bool enableWrite();
Gaku0606 0:8e1682c378ec 105
Gaku0606 0:8e1682c378ec 106 /**
Gaku0606 0:8e1682c378ec 107 @bref パラメータ不揮発メモリ書き込み不許可モードへ移行
Gaku0606 0:8e1682c378ec 108 */
Gaku0606 0:8e1682c378ec 109 bool disableWrite();
Gaku0606 0:8e1682c378ec 110
Gaku0606 0:8e1682c378ec 111 /**
Gaku0606 0:8e1682c378ec 112 @bref 固有IDを読み出す
Gaku0606 0:8e1682c378ec 113 */
Gaku0606 0:8e1682c378ec 114 int readID();
Gaku0606 0:8e1682c378ec 115
Gaku0606 0:8e1682c378ec 116 /**
Gaku0606 0:8e1682c378ec 117 @bref ノード番号をセットする
Gaku0606 0:8e1682c378ec 118 */
Gaku0606 0:8e1682c378ec 119 bool setNodeNumber(char nodeNum);
Gaku0606 0:8e1682c378ec 120
Gaku0606 0:8e1682c378ec 121 /**
Gaku0606 0:8e1682c378ec 122 @bref ノード番号を読み出す
Gaku0606 0:8e1682c378ec 123 */
Gaku0606 0:8e1682c378ec 124 int readNodeNumber();
Gaku0606 0:8e1682c378ec 125
Gaku0606 0:8e1682c378ec 126 /**
Gaku0606 0:8e1682c378ec 127 @bref 受信する無線機IDを一つ登録する
Gaku0606 0:8e1682c378ec 128 */
Gaku0606 0:8e1682c378ec 129 bool setReceiveID(int ID);
Gaku0606 0:8e1682c378ec 130
Gaku0606 0:8e1682c378ec 131 /**
Gaku0606 0:8e1682c378ec 132 @bref 登録されている受信IDを表示する
Gaku0606 0:8e1682c378ec 133 */
Gaku0606 0:8e1682c378ec 134 void readReceiveID();
Gaku0606 0:8e1682c378ec 135
Gaku0606 0:8e1682c378ec 136 /**
Gaku0606 0:8e1682c378ec 137 @bref 登録されている受信IDを全消去する
Gaku0606 0:8e1682c378ec 138 */
Gaku0606 0:8e1682c378ec 139 bool eraseReceiveID();
Gaku0606 0:8e1682c378ec 140
Gaku0606 0:8e1682c378ec 141 /**
Gaku0606 0:8e1682c378ec 142 @bref 使用する周波数chを設定する
Gaku0606 0:8e1682c378ec 143 */
Gaku0606 0:8e1682c378ec 144 bool setChannel(char ch);
Gaku0606 0:8e1682c378ec 145
Gaku0606 0:8e1682c378ec 146 /**
Gaku0606 0:8e1682c378ec 147 @bref 使用する周波数chを読み出す
Gaku0606 0:8e1682c378ec 148 */
Gaku0606 0:8e1682c378ec 149 char readChannel();
Gaku0606 0:8e1682c378ec 150
Gaku0606 0:8e1682c378ec 151 /**
Gaku0606 0:8e1682c378ec 152 @bref アスキーコードの文字列で送受信ができるようにする
Gaku0606 0:8e1682c378ec 153 */
Gaku0606 0:8e1682c378ec 154 bool enableCharacterIO();
Gaku0606 0:8e1682c378ec 155
Gaku0606 0:8e1682c378ec 156 /**
Gaku0606 0:8e1682c378ec 157 @bref バイナリ送受信モードへ移行
Gaku0606 0:8e1682c378ec 158 */
Gaku0606 0:8e1682c378ec 159 bool disableCharacterIO();
Gaku0606 0:8e1682c378ec 160
Gaku0606 0:8e1682c378ec 161 /**
Gaku0606 0:8e1682c378ec 162 @bref 送信バッファにdouble型を一つ入れる
Gaku0606 0:8e1682c378ec 163 */
Gaku0606 0:8e1682c378ec 164 void write(double val);
Gaku0606 0:8e1682c378ec 165
Gaku0606 0:8e1682c378ec 166 /**
Gaku0606 0:8e1682c378ec 167 @bref 送信バッファにlong型を一つ入れる
Gaku0606 0:8e1682c378ec 168 */
Gaku0606 0:8e1682c378ec 169 void write(long val);
Gaku0606 0:8e1682c378ec 170
Gaku0606 0:8e1682c378ec 171 /**
Gaku0606 0:8e1682c378ec 172 @bref 送信バッファにfloat型を一つ入れる
Gaku0606 0:8e1682c378ec 173 */
Gaku0606 0:8e1682c378ec 174 void write(float val);
Gaku0606 0:8e1682c378ec 175 /**
Gaku0606 0:8e1682c378ec 176 @bref 送信バッファにint型を一つ入れる
Gaku0606 0:8e1682c378ec 177 */
Gaku0606 0:8e1682c378ec 178 void write(int val);
Gaku0606 0:8e1682c378ec 179
Gaku0606 0:8e1682c378ec 180 /**
Gaku0606 0:8e1682c378ec 181 @bref 送信バッファにshort型を一つ入れる
Gaku0606 0:8e1682c378ec 182 */
Gaku0606 0:8e1682c378ec 183 void write(short val);
Gaku0606 0:8e1682c378ec 184
Gaku0606 0:8e1682c378ec 185 /**
Gaku0606 0:8e1682c378ec 186 @bref 送信バッファにchar型を一つ入れる
Gaku0606 0:8e1682c378ec 187 */
Gaku0606 0:8e1682c378ec 188 void write(char val);
Gaku0606 0:8e1682c378ec 189
Gaku0606 0:8e1682c378ec 190 /**
Gaku0606 0:8e1682c378ec 191 @bref 送信バッファにfloat型を複数入れる
Gaku0606 0:8e1682c378ec 192 */
Gaku0606 0:8e1682c378ec 193 // void write(float *array, int count);
Gaku0606 0:8e1682c378ec 194
Gaku0606 0:8e1682c378ec 195 template <typename T> void write(T *array, int count){
Gaku0606 0:8e1682c378ec 196 for(int i = 0;i < count; i++){
Gaku0606 0:8e1682c378ec 197 write(array[i]);
Gaku0606 0:8e1682c378ec 198 }
Gaku0606 0:8e1682c378ec 199 }
Gaku0606 0:8e1682c378ec 200 /**
Gaku0606 0:8e1682c378ec 201 @bref 送信バッファを送信する
Gaku0606 0:8e1682c378ec 202 */
Gaku0606 0:8e1682c378ec 203 void send();
Gaku0606 0:8e1682c378ec 204
Gaku0606 0:8e1682c378ec 205 /**
Gaku0606 0:8e1682c378ec 206 @bref 送信バッファにヘッダーを付ける、writeする前に使う
Gaku0606 0:8e1682c378ec 207 */
Gaku0606 0:8e1682c378ec 208 void header(char headerNumber){
Gaku0606 0:8e1682c378ec 209 write(headerNumber);
Gaku0606 0:8e1682c378ec 210 }
Gaku0606 0:8e1682c378ec 211
Gaku0606 0:8e1682c378ec 212 /**
Gaku0606 0:8e1682c378ec 213 @bref デバッグ用、受信バッファを表示
Gaku0606 0:8e1682c378ec 214 */
Gaku0606 0:8e1682c378ec 215 void im920_debug();
Gaku0606 0:8e1682c378ec 216
Gaku0606 0:8e1682c378ec 217 /**
Gaku0606 0:8e1682c378ec 218 @bref インタラクティブモードでコマンドを表示する
Gaku0606 0:8e1682c378ec 219 */
Gaku0606 0:8e1682c378ec 220 void printFormat();
Gaku0606 0:8e1682c378ec 221
Gaku0606 0:8e1682c378ec 222 /**
Gaku0606 0:8e1682c378ec 223 @bref データ配列をshort型に変換する
Gaku0606 0:8e1682c378ec 224 @param array データのchar型配列、データの始まるアドレスを入れる
Gaku0606 0:8e1682c378ec 225 */
Gaku0606 0:8e1682c378ec 226 short toShort(char *array);
Gaku0606 0:8e1682c378ec 227 short toShort(int i){
Gaku0606 0:8e1682c378ec 228 return toShort(&data[i]);
Gaku0606 0:8e1682c378ec 229 }
Gaku0606 0:8e1682c378ec 230
Gaku0606 0:8e1682c378ec 231 /**
Gaku0606 0:8e1682c378ec 232 @bref データ配列をint型に変換する
Gaku0606 0:8e1682c378ec 233 @param array データのchar型配列、データの始まるアドレスを入れる
Gaku0606 0:8e1682c378ec 234 */
Gaku0606 0:8e1682c378ec 235 int toInt(char *array);
Gaku0606 0:8e1682c378ec 236 int toInt(int i){
Gaku0606 0:8e1682c378ec 237 return toInt(&data[i]);
Gaku0606 0:8e1682c378ec 238 }
Gaku0606 0:8e1682c378ec 239 /**
Gaku0606 0:8e1682c378ec 240 @bref データ配列をfloat型に変換する
Gaku0606 0:8e1682c378ec 241 @param array データのchar型配列、データの始まるアドレスを入れる
Gaku0606 0:8e1682c378ec 242 */
Gaku0606 0:8e1682c378ec 243 float toFloat(char *array);
Gaku0606 0:8e1682c378ec 244 float toFloat(int i){
Gaku0606 0:8e1682c378ec 245 return toFloat(&data[i]);
Gaku0606 0:8e1682c378ec 246 }
Gaku0606 0:8e1682c378ec 247 /**
Gaku0606 0:8e1682c378ec 248 @bref データ配列をlong型に変換する
Gaku0606 0:8e1682c378ec 249 @param array データのchar型配列、データの始まるアドレスを入れる
Gaku0606 0:8e1682c378ec 250 */
Gaku0606 0:8e1682c378ec 251 long toLong(char *array);
Gaku0606 0:8e1682c378ec 252 long toLong(int i){
Gaku0606 0:8e1682c378ec 253 return toLong(&data[i]);
Gaku0606 0:8e1682c378ec 254 }
Gaku0606 0:8e1682c378ec 255
Gaku0606 0:8e1682c378ec 256 /**
Gaku0606 0:8e1682c378ec 257 @bref データ配列をdouble型に変換する
Gaku0606 0:8e1682c378ec 258 @param array データのchar型配列、データの始まるアドレスを入れる
Gaku0606 0:8e1682c378ec 259 */
Gaku0606 0:8e1682c378ec 260 double toDouble(char *array);
Gaku0606 0:8e1682c378ec 261 double toDouble(int i){
Gaku0606 0:8e1682c378ec 262 return toDouble(&data[i]);
Gaku0606 0:8e1682c378ec 263 }
Gaku0606 0:8e1682c378ec 264 /**
Gaku0606 0:8e1682c378ec 265 @bref チェックサムを計算する
Gaku0606 0:8e1682c378ec 266 @param count データの個数、何byteか
Gaku0606 0:8e1682c378ec 267 */
Gaku0606 0:8e1682c378ec 268 char im920CheckSum(int count);
Gaku0606 0:8e1682c378ec 269
Gaku0606 0:8e1682c378ec 270 /**
Gaku0606 0:8e1682c378ec 271 @bref 受信データのチェックサムの計算結果を入れる
Gaku0606 0:8e1682c378ec 272 */
Gaku0606 0:8e1682c378ec 273 char receiveCheckSum;
Gaku0606 0:8e1682c378ec 274
Gaku0606 0:8e1682c378ec 275 private:
Gaku0606 0:8e1682c378ec 276
Gaku0606 0:8e1682c378ec 277 /**
Gaku0606 0:8e1682c378ec 278 @bref 1文字受信するごとに呼ばれ、受信バッファに入れる
Gaku0606 0:8e1682c378ec 279 */
Gaku0606 0:8e1682c378ec 280 void im920Handler();
Gaku0606 0:8e1682c378ec 281
Gaku0606 0:8e1682c378ec 282 char checkSum;
Gaku0606 0:8e1682c378ec 283
Gaku0606 0:8e1682c378ec 284 /**
Gaku0606 0:8e1682c378ec 285 @bref 何もしない関数
Gaku0606 0:8e1682c378ec 286 */
Gaku0606 0:8e1682c378ec 287 static void dummyFunc(void);
Gaku0606 0:8e1682c378ec 288
Gaku0606 0:8e1682c378ec 289 /**
Gaku0606 0:8e1682c378ec 290 @bref 16進数文字を数値に変換する関数
Gaku0606 0:8e1682c378ec 291 */
Gaku0606 0:8e1682c378ec 292 int asciiToNumber(char c);
Gaku0606 0:8e1682c378ec 293 };
Gaku0606 0:8e1682c378ec 294
Gaku0606 0:8e1682c378ec 295 inline void IM920::write(double val){
Gaku0606 0:8e1682c378ec 296 if(sendDataSize <= 56){
Gaku0606 0:8e1682c378ec 297 im920_cast.d = val;
Gaku0606 0:8e1682c378ec 298 sprintf(im920_sendBuff, "%s%02X%02X%02X%02X%02X%02X%02X%02X", im920_sendBuff, im920_cast.u[0], im920_cast.u[1], im920_cast.u[2]
Gaku0606 0:8e1682c378ec 299 , im920_cast.u[3], im920_cast.u[4], im920_cast.u[5], im920_cast.u[6], im920_cast.u[7]);
Gaku0606 0:8e1682c378ec 300 sendDataSize += 8;
Gaku0606 0:8e1682c378ec 301 checkSum = checkSum ^ im920_cast.u[7] ^ im920_cast.u[6] ^ im920_cast.u[5] ^ im920_cast.u[4] ^ im920_cast.u[3] ^ im920_cast.u[2] ^ im920_cast.u[1] ^ im920_cast.u[0];
Gaku0606 0:8e1682c378ec 302 }
Gaku0606 0:8e1682c378ec 303 }
Gaku0606 0:8e1682c378ec 304
Gaku0606 0:8e1682c378ec 305 inline void IM920::write(long val){
Gaku0606 0:8e1682c378ec 306 if(sendDataSize <= 56){
Gaku0606 0:8e1682c378ec 307 im920_cast.l = val;
Gaku0606 0:8e1682c378ec 308 sprintf(im920_sendBuff, "%s%02X%02X%02X%02X%02X%02X%02X%02X", im920_sendBuff, im920_cast.u[0], im920_cast.u[1], im920_cast.u[2]
Gaku0606 0:8e1682c378ec 309 , im920_cast.u[3], im920_cast.u[4], im920_cast.u[5], im920_cast.u[6], im920_cast.u[7]);
Gaku0606 0:8e1682c378ec 310 sendDataSize += 8;
Gaku0606 0:8e1682c378ec 311 checkSum = checkSum ^ im920_cast.u[7] ^ im920_cast.u[6] ^ im920_cast.u[5] ^ im920_cast.u[4] ^ im920_cast.u[3] ^ im920_cast.u[2] ^ im920_cast.u[1] ^ im920_cast.u[0];
Gaku0606 0:8e1682c378ec 312 }
Gaku0606 0:8e1682c378ec 313 }
Gaku0606 0:8e1682c378ec 314
Gaku0606 0:8e1682c378ec 315 inline void IM920::write(float val){
Gaku0606 0:8e1682c378ec 316 if(sendDataSize <= 60){
Gaku0606 0:8e1682c378ec 317 im920_cast.f = val;
Gaku0606 0:8e1682c378ec 318 sprintf(im920_sendBuff, "%s%02X%02X%02X%02X", im920_sendBuff, im920_cast.u[0],im920_cast.u[1],im920_cast.u[2],im920_cast.u[3]);
Gaku0606 0:8e1682c378ec 319 sendDataSize += 4;
Gaku0606 0:8e1682c378ec 320 checkSum = checkSum ^ im920_cast.u[3] ^ im920_cast.u[2] ^ im920_cast.u[1] ^ im920_cast.u[0];
Gaku0606 0:8e1682c378ec 321 }
Gaku0606 0:8e1682c378ec 322 }
Gaku0606 0:8e1682c378ec 323 inline void IM920::write(int val){
Gaku0606 0:8e1682c378ec 324 if(sendDataSize <= 60){
Gaku0606 0:8e1682c378ec 325 im920_cast.i = val;
Gaku0606 0:8e1682c378ec 326 sprintf(im920_sendBuff, "%s%08X", im920_sendBuff, (uint32_t)val);
Gaku0606 0:8e1682c378ec 327 sendDataSize += 4;
Gaku0606 0:8e1682c378ec 328 checkSum = checkSum ^ im920_cast.u[3] ^ im920_cast.u[2] ^ im920_cast.u[1] ^ im920_cast.u[0];
Gaku0606 0:8e1682c378ec 329 }
Gaku0606 0:8e1682c378ec 330 }
Gaku0606 0:8e1682c378ec 331 inline void IM920::write(short val){
Gaku0606 0:8e1682c378ec 332 if(sendDataSize <= 62){
Gaku0606 0:8e1682c378ec 333 im920_cast.s = val;
Gaku0606 0:8e1682c378ec 334 sprintf(im920_sendBuff, "%s%04X", im920_sendBuff, (uint16_t)val);
Gaku0606 0:8e1682c378ec 335 sendDataSize += 2;
Gaku0606 0:8e1682c378ec 336 checkSum = checkSum ^ im920_cast.u[1] ^ im920_cast.u[0];
Gaku0606 0:8e1682c378ec 337 }
Gaku0606 0:8e1682c378ec 338 }
Gaku0606 0:8e1682c378ec 339 inline void IM920::write(char val){
Gaku0606 0:8e1682c378ec 340 if(sendDataSize < 64){
Gaku0606 0:8e1682c378ec 341 im920_cast.c = val;
Gaku0606 0:8e1682c378ec 342 sprintf(im920_sendBuff, "%s%02X", im920_sendBuff, (uint8_t)val);
Gaku0606 0:8e1682c378ec 343 sendDataSize += 1;
Gaku0606 0:8e1682c378ec 344 checkSum = im920_cast.u[0] ^ '0';
Gaku0606 0:8e1682c378ec 345 }
Gaku0606 0:8e1682c378ec 346 }
Gaku0606 0:8e1682c378ec 347 /*
Gaku0606 0:8e1682c378ec 348 inline void IM920::write(float *array, int count){
Gaku0606 0:8e1682c378ec 349 if(sendDataSize < (64 - (4*count))){
Gaku0606 0:8e1682c378ec 350 for(int i = 0; i < count; i++){
Gaku0606 0:8e1682c378ec 351 write((float)array[i]);
Gaku0606 0:8e1682c378ec 352 }
Gaku0606 0:8e1682c378ec 353 }
Gaku0606 0:8e1682c378ec 354 }*/
Gaku0606 0:8e1682c378ec 355
Gaku0606 0:8e1682c378ec 356 inline void IM920::send(){
Gaku0606 0:8e1682c378ec 357 if(sendDataSize > 0){
Gaku0606 0:8e1682c378ec 358 AS = RESPONSE_STRING;
Gaku0606 0:8e1682c378ec 359 //write(checkSum);
Gaku0606 0:8e1682c378ec 360 //sprintf(im920_sendBuff, "%s%02X", im920_sendBuff, checkSum);
Gaku0606 0:8e1682c378ec 361 im920_sendBuff[128] = '\0';//もしバッファがあふれて文字列になっていなかったら
Gaku0606 0:8e1682c378ec 362 ser->printf("TXDA %s\r\n", im920_sendBuff);
Gaku0606 0:8e1682c378ec 363 //printf("send -> TXDA %s\r\n", im920_sendBuff);
Gaku0606 0:8e1682c378ec 364 sendDataSize = 0;//初期化
Gaku0606 0:8e1682c378ec 365 memset(im920_sendBuff, '\0', 129);
Gaku0606 0:8e1682c378ec 366 AS = DATA_STRING;
Gaku0606 0:8e1682c378ec 367 }
Gaku0606 0:8e1682c378ec 368 }
Gaku0606 0:8e1682c378ec 369
Gaku0606 0:8e1682c378ec 370 #endif