IM920のライブラリ

Committer:
Gaku0606
Date:
Thu Aug 10 19:34:50 2017 +0000
Revision:
0:ccdeb3bea793
Child:
1:11ae0d702ecc
??

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gaku0606 0:ccdeb3bea793 1 #include "IM920.h"
Gaku0606 0:ccdeb3bea793 2 #include "mbed.h"
Gaku0606 0:ccdeb3bea793 3
Gaku0606 0:ccdeb3bea793 4 short IM920::toShort(char *array){
Gaku0606 0:ccdeb3bea793 5 im920_cast.s = ((uint16_t)array[0] << 8) | (uint16_t)array[1];
Gaku0606 0:ccdeb3bea793 6 return im920_cast.s;
Gaku0606 0:ccdeb3bea793 7 }
Gaku0606 0:ccdeb3bea793 8 int IM920::toInt(char *array){
Gaku0606 0:ccdeb3bea793 9 im920_cast.i = ((uint32_t)array[0] << 24) | ((uint32_t)array[1] << 16) | ((uint32_t)array[2] << 8) | (uint32_t)array[3];
Gaku0606 0:ccdeb3bea793 10 return im920_cast.i;
Gaku0606 0:ccdeb3bea793 11 }
Gaku0606 0:ccdeb3bea793 12 float IM920::toFloat(char *array){
Gaku0606 0:ccdeb3bea793 13 im920_cast.u[0] = array[0];
Gaku0606 0:ccdeb3bea793 14 im920_cast.u[1] = array[1];
Gaku0606 0:ccdeb3bea793 15 im920_cast.u[2] = array[2];
Gaku0606 0:ccdeb3bea793 16 im920_cast.u[3] = array[3];
Gaku0606 0:ccdeb3bea793 17
Gaku0606 0:ccdeb3bea793 18 return im920_cast.f;
Gaku0606 0:ccdeb3bea793 19 }
Gaku0606 0:ccdeb3bea793 20 long IM920::toLong(char *array){
Gaku0606 0:ccdeb3bea793 21 for(int i = 0; i < 8; i++){
Gaku0606 0:ccdeb3bea793 22 im920_cast.u[i] = array[i];
Gaku0606 0:ccdeb3bea793 23 }
Gaku0606 0:ccdeb3bea793 24 return im920_cast.l;
Gaku0606 0:ccdeb3bea793 25 }
Gaku0606 0:ccdeb3bea793 26 double IM920::toDouble(char *array){
Gaku0606 0:ccdeb3bea793 27 for(int i = 0; i< 8; i++){
Gaku0606 0:ccdeb3bea793 28 im920_cast.u[i] = array[i];
Gaku0606 0:ccdeb3bea793 29 }
Gaku0606 0:ccdeb3bea793 30 return im920_cast.d;
Gaku0606 0:ccdeb3bea793 31 }
Gaku0606 0:ccdeb3bea793 32
Gaku0606 0:ccdeb3bea793 33 void IM920::dummyFunc(){
Gaku0606 0:ccdeb3bea793 34 printf("NO FUNCTION\r\n");
Gaku0606 0:ccdeb3bea793 35 };
Gaku0606 0:ccdeb3bea793 36
Gaku0606 0:ccdeb3bea793 37 char IM920::im920CheckSum(int count){
Gaku0606 0:ccdeb3bea793 38 char ans = 0;
Gaku0606 0:ccdeb3bea793 39 for(int i = 0; i < count; i++){
Gaku0606 0:ccdeb3bea793 40 ans = ans ^ data[i];
Gaku0606 0:ccdeb3bea793 41 }
Gaku0606 0:ccdeb3bea793 42 return ans;
Gaku0606 0:ccdeb3bea793 43 }
Gaku0606 0:ccdeb3bea793 44
Gaku0606 0:ccdeb3bea793 45 IM920::IM920(Serial &serial, Serial &pc, int baudrate){
Gaku0606 0:ccdeb3bea793 46
Gaku0606 0:ccdeb3bea793 47 ser = &serial;//参照渡し
Gaku0606 0:ccdeb3bea793 48 _pc = &pc;
Gaku0606 0:ccdeb3bea793 49
Gaku0606 0:ccdeb3bea793 50 ser->baud(baudrate);
Gaku0606 0:ccdeb3bea793 51
Gaku0606 0:ccdeb3bea793 52 memset(buff_A, '\0', IM920_BUFF_SIZE);
Gaku0606 0:ccdeb3bea793 53 memset(buff_B, '\0', IM920_BUFF_SIZE);
Gaku0606 0:ccdeb3bea793 54 readBuffAddr = buff_B;
Gaku0606 0:ccdeb3bea793 55 writeBuffAddr = buff_A;
Gaku0606 0:ccdeb3bea793 56 sendDataSize = 0;
Gaku0606 0:ccdeb3bea793 57 interactiveFlag = 0;
Gaku0606 0:ccdeb3bea793 58 for(int i = 0;i < 256; i++){
Gaku0606 0:ccdeb3bea793 59 p_callFunc[i] = &this->dummyFunc;
Gaku0606 0:ccdeb3bea793 60 }
Gaku0606 0:ccdeb3bea793 61 memset(data, 0, 64);
Gaku0606 0:ccdeb3bea793 62 im920_dataLength = 0;
Gaku0606 0:ccdeb3bea793 63 memset(im920_sendBuff, '\0', 129);
Gaku0606 0:ccdeb3bea793 64 sendDataSize = 0;
Gaku0606 0:ccdeb3bea793 65 nodeNumber = 0;
Gaku0606 0:ccdeb3bea793 66 AS = DATA_STRING;
Gaku0606 0:ccdeb3bea793 67 checkSum = 0;
Gaku0606 0:ccdeb3bea793 68 for(int i = 0; i < 8; i++){
Gaku0606 0:ccdeb3bea793 69 im920_cast.u[i] = 0;
Gaku0606 0:ccdeb3bea793 70 }
Gaku0606 0:ccdeb3bea793 71 node = 0;
Gaku0606 0:ccdeb3bea793 72 RSSI = 0;
Gaku0606 0:ccdeb3bea793 73 rID = 0;
Gaku0606 0:ccdeb3bea793 74 ID = 0;
Gaku0606 0:ccdeb3bea793 75
Gaku0606 0:ccdeb3bea793 76 receiveCheckSum = 0;
Gaku0606 0:ccdeb3bea793 77 ser->attach(this, &IM920::im920Handler, Serial::RxIrq);
Gaku0606 0:ccdeb3bea793 78 }
Gaku0606 0:ccdeb3bea793 79
Gaku0606 0:ccdeb3bea793 80
Gaku0606 0:ccdeb3bea793 81
Gaku0606 0:ccdeb3bea793 82
Gaku0606 0:ccdeb3bea793 83
Gaku0606 0:ccdeb3bea793 84
Gaku0606 0:ccdeb3bea793 85 void IM920::im920_debug(){
Gaku0606 0:ccdeb3bea793 86 printf("%s\r\n", readBuffAddr);
Gaku0606 0:ccdeb3bea793 87 return;
Gaku0606 0:ccdeb3bea793 88 }
Gaku0606 0:ccdeb3bea793 89
Gaku0606 0:ccdeb3bea793 90
Gaku0606 0:ccdeb3bea793 91
Gaku0606 0:ccdeb3bea793 92 int IM920::asciiToNumber(char c){
Gaku0606 0:ccdeb3bea793 93 //printf("%c ", c);
Gaku0606 0:ccdeb3bea793 94 if((int)c >= 65){//A ~ F
Gaku0606 0:ccdeb3bea793 95 return ((int)c - 55);
Gaku0606 0:ccdeb3bea793 96 }
Gaku0606 0:ccdeb3bea793 97 else{//0 ~ 9
Gaku0606 0:ccdeb3bea793 98 return ((int)c - 48);
Gaku0606 0:ccdeb3bea793 99 }
Gaku0606 0:ccdeb3bea793 100 }
Gaku0606 0:ccdeb3bea793 101
Gaku0606 0:ccdeb3bea793 102 void IM920::data_analyze(){
Gaku0606 0:ccdeb3bea793 103 //00,0001,78:01,02,03,04,...,FF\0
Gaku0606 0:ccdeb3bea793 104 //| | | | +- <CR><LF>文字列終了
Gaku0606 0:ccdeb3bea793 105 //| | | +-------------------- 16進数をascii文字にしたもの、最大64区切り(64Byte)
Gaku0606 0:ccdeb3bea793 106 //| | +----------------------- 受信強度、RSSI値
Gaku0606 0:ccdeb3bea793 107 //| +---------------------------- 送信モジュールの固有ID
Gaku0606 0:ccdeb3bea793 108 //+------------------------------- ノード番号
Gaku0606 0:ccdeb3bea793 109 char tempStr[160];
Gaku0606 0:ccdeb3bea793 110 strcpy(tempStr, readBuffAddr);
Gaku0606 0:ccdeb3bea793 111 char *tok = strtok(tempStr, ",");//ノード番号
Gaku0606 0:ccdeb3bea793 112 node = ((asciiToNumber(tok[0]) << 4)) | asciiToNumber(tok[1]);
Gaku0606 0:ccdeb3bea793 113 tok = strtok(NULL, ",");//送信機のID
Gaku0606 0:ccdeb3bea793 114 rID = 0;
Gaku0606 0:ccdeb3bea793 115 rID = (asciiToNumber(tok[0]) << 12) | (asciiToNumber(tok[1]) << 8) | (asciiToNumber(tok[2]) << 4) | asciiToNumber(tok[3]);
Gaku0606 0:ccdeb3bea793 116 tok = strtok(NULL, ":");//受信強度
Gaku0606 0:ccdeb3bea793 117 RSSI = (char)((asciiToNumber(tok[0]) << 4) | (asciiToNumber(tok[1])));
Gaku0606 0:ccdeb3bea793 118 im920_dataLength = 64;
Gaku0606 0:ccdeb3bea793 119 memset(data, 0, 64);
Gaku0606 0:ccdeb3bea793 120 receiveCheckSum = 0;
Gaku0606 0:ccdeb3bea793 121 if(tok != NULL){
Gaku0606 0:ccdeb3bea793 122 for(int i = 0; i < 64; i++){
Gaku0606 0:ccdeb3bea793 123 if(tok[0] == '\0'){
Gaku0606 0:ccdeb3bea793 124 im920_dataLength = i - 1;
Gaku0606 0:ccdeb3bea793 125 break;
Gaku0606 0:ccdeb3bea793 126 }
Gaku0606 0:ccdeb3bea793 127 tok = strtok(NULL, ",");
Gaku0606 0:ccdeb3bea793 128 data[i] = (asciiToNumber(tok[0]) << 4) | asciiToNumber(tok[1]);
Gaku0606 0:ccdeb3bea793 129 receiveCheckSum = receiveCheckSum ^ tok[0] ^ tok[1];
Gaku0606 0:ccdeb3bea793 130 }
Gaku0606 0:ccdeb3bea793 131 }
Gaku0606 0:ccdeb3bea793 132 else{
Gaku0606 0:ccdeb3bea793 133 im920_dataLength = 0;
Gaku0606 0:ccdeb3bea793 134 }
Gaku0606 0:ccdeb3bea793 135 return;
Gaku0606 0:ccdeb3bea793 136 }
Gaku0606 0:ccdeb3bea793 137
Gaku0606 0:ccdeb3bea793 138 void IM920::im920Handler(){
Gaku0606 0:ccdeb3bea793 139 static int current = 0;
Gaku0606 0:ccdeb3bea793 140 static char c = 0;
Gaku0606 0:ccdeb3bea793 141 c = ser->getc();
Gaku0606 0:ccdeb3bea793 142 if(AS == RESPONSE_STRING || AS == INTERACTIVE_STRING){
Gaku0606 0:ccdeb3bea793 143 printf("%c", c);//描画、後で1行描画だと次の行がすぐ来た時にハングアップしてしまう
Gaku0606 0:ccdeb3bea793 144 }
Gaku0606 0:ccdeb3bea793 145
Gaku0606 0:ccdeb3bea793 146 if(c == '\r'){//文字列終了
Gaku0606 0:ccdeb3bea793 147 writeBuffAddr[current] = '\0';
Gaku0606 0:ccdeb3bea793 148 if(AB == BUFF_A){//現在バッファAに書き込み中
Gaku0606 0:ccdeb3bea793 149 readBuffAddr = buff_A;
Gaku0606 0:ccdeb3bea793 150 writeBuffAddr = buff_B;
Gaku0606 0:ccdeb3bea793 151 AB = BUFF_B;
Gaku0606 0:ccdeb3bea793 152 }
Gaku0606 0:ccdeb3bea793 153 else{//現在バッファBに書き込み中
Gaku0606 0:ccdeb3bea793 154 readBuffAddr = buff_B;
Gaku0606 0:ccdeb3bea793 155 writeBuffAddr = buff_A;
Gaku0606 0:ccdeb3bea793 156 AB = BUFF_A;
Gaku0606 0:ccdeb3bea793 157 }
Gaku0606 0:ccdeb3bea793 158
Gaku0606 0:ccdeb3bea793 159 //im920_debug();
Gaku0606 0:ccdeb3bea793 160 //----------------------
Gaku0606 0:ccdeb3bea793 161 // 文字列の解析
Gaku0606 0:ccdeb3bea793 162 //----------------------
Gaku0606 0:ccdeb3bea793 163 if(AS == DATA_STRING){//データの形式によって分岐
Gaku0606 0:ccdeb3bea793 164 if(current > 9){
Gaku0606 0:ccdeb3bea793 165 //データの取り出し、配列化
Gaku0606 0:ccdeb3bea793 166 data_analyze();
Gaku0606 0:ccdeb3bea793 167 for(int i = 0;i < 64;i++){
Gaku0606 0:ccdeb3bea793 168 printf("%d ",data[i]);
Gaku0606 0:ccdeb3bea793 169 }
Gaku0606 0:ccdeb3bea793 170 printf("\r\n");
Gaku0606 0:ccdeb3bea793 171 //printf("header: %0X\r\n",(uint8_t)data[0]);
Gaku0606 0:ccdeb3bea793 172 //header0xFF();
Gaku0606 0:ccdeb3bea793 173 // 関数の呼び出し
Gaku0606 0:ccdeb3bea793 174 (*p_callFunc[(uint8_t)data[0]])();
Gaku0606 0:ccdeb3bea793 175 }
Gaku0606 0:ccdeb3bea793 176 }
Gaku0606 0:ccdeb3bea793 177 //初期化
Gaku0606 0:ccdeb3bea793 178 current = 0;
Gaku0606 0:ccdeb3bea793 179 //memset(writeBuffAddr, '\0', IM920_BUFF_SIZE);
Gaku0606 0:ccdeb3bea793 180 return;
Gaku0606 0:ccdeb3bea793 181 }
Gaku0606 0:ccdeb3bea793 182 else if(c !='\n'){
Gaku0606 0:ccdeb3bea793 183 //文字列生成
Gaku0606 0:ccdeb3bea793 184 writeBuffAddr[current] = c;
Gaku0606 0:ccdeb3bea793 185 current++;
Gaku0606 0:ccdeb3bea793 186 if(current >= IM920_BUFF_SIZE){//初期化
Gaku0606 0:ccdeb3bea793 187 current = 0;
Gaku0606 0:ccdeb3bea793 188 memset(writeBuffAddr, '\0', IM920_BUFF_SIZE);
Gaku0606 0:ccdeb3bea793 189 }
Gaku0606 0:ccdeb3bea793 190 return;
Gaku0606 0:ccdeb3bea793 191 }
Gaku0606 0:ccdeb3bea793 192 }
Gaku0606 0:ccdeb3bea793 193
Gaku0606 0:ccdeb3bea793 194 void IM920::attach(void (*funcAddr)(void), unsigned header){
Gaku0606 0:ccdeb3bea793 195 p_callFunc[header] = funcAddr;
Gaku0606 0:ccdeb3bea793 196 return;
Gaku0606 0:ccdeb3bea793 197 }
Gaku0606 0:ccdeb3bea793 198
Gaku0606 0:ccdeb3bea793 199 /**
Gaku0606 0:ccdeb3bea793 200 @bref パラメータ不揮発メモリ書き込み許可モードへ移行
Gaku0606 0:ccdeb3bea793 201 */
Gaku0606 0:ccdeb3bea793 202 bool IM920::enableWrite(){
Gaku0606 0:ccdeb3bea793 203 AS = RESPONSE_STRING;//レスポンス受信モードへ移行
Gaku0606 0:ccdeb3bea793 204 ser->printf("ENWR\r\n");
Gaku0606 0:ccdeb3bea793 205 wait_us(WAIT_TIME_US);//待つ
Gaku0606 0:ccdeb3bea793 206 AS = DATA_STRING; //データ受信モードへ以降
Gaku0606 0:ccdeb3bea793 207 if(strncmp(readBuffAddr, "OK", 2) == 0){
Gaku0606 0:ccdeb3bea793 208 return true;
Gaku0606 0:ccdeb3bea793 209 }
Gaku0606 0:ccdeb3bea793 210 else{
Gaku0606 0:ccdeb3bea793 211 return false;
Gaku0606 0:ccdeb3bea793 212 }
Gaku0606 0:ccdeb3bea793 213 }
Gaku0606 0:ccdeb3bea793 214
Gaku0606 0:ccdeb3bea793 215 bool IM920::disableWrite(){
Gaku0606 0:ccdeb3bea793 216 AS = RESPONSE_STRING;//レスポンス受信モードへ移行
Gaku0606 0:ccdeb3bea793 217 ser->printf("DSWR\r\n");
Gaku0606 0:ccdeb3bea793 218 wait_us(WAIT_TIME_US);
Gaku0606 0:ccdeb3bea793 219 AS = DATA_STRING;
Gaku0606 0:ccdeb3bea793 220 if(strncmp(readBuffAddr, "OK", 2) == 0){
Gaku0606 0:ccdeb3bea793 221 return true;
Gaku0606 0:ccdeb3bea793 222 }
Gaku0606 0:ccdeb3bea793 223 else{
Gaku0606 0:ccdeb3bea793 224 return false;
Gaku0606 0:ccdeb3bea793 225 }
Gaku0606 0:ccdeb3bea793 226 }
Gaku0606 0:ccdeb3bea793 227
Gaku0606 0:ccdeb3bea793 228 /**
Gaku0606 0:ccdeb3bea793 229 @bref 固有IDを読み出す
Gaku0606 0:ccdeb3bea793 230 */
Gaku0606 0:ccdeb3bea793 231 int IM920::readID(){
Gaku0606 0:ccdeb3bea793 232 AS = NORMAL_STRING;
Gaku0606 0:ccdeb3bea793 233 ser->printf("RDID\r\n");
Gaku0606 0:ccdeb3bea793 234 wait_us(WAIT_TIME_US);
Gaku0606 0:ccdeb3bea793 235 AS = DATA_STRING;
Gaku0606 0:ccdeb3bea793 236 int val = 0;
Gaku0606 0:ccdeb3bea793 237
Gaku0606 0:ccdeb3bea793 238 //pc.printf("%c:%c:%c:%c\r\n",readBuffAddr[0],readBuffAddr[1],readBuffAddr[2],readBuffAddr[3]);
Gaku0606 0:ccdeb3bea793 239 val = asciiToNumber(readBuffAddr[0]) << 24;
Gaku0606 0:ccdeb3bea793 240 val |= asciiToNumber(readBuffAddr[1]) << 16;
Gaku0606 0:ccdeb3bea793 241 val |= asciiToNumber(readBuffAddr[2]) << 8;
Gaku0606 0:ccdeb3bea793 242 val |= asciiToNumber(readBuffAddr[3]);
Gaku0606 0:ccdeb3bea793 243 ID = val;
Gaku0606 0:ccdeb3bea793 244 return val;
Gaku0606 0:ccdeb3bea793 245 }
Gaku0606 0:ccdeb3bea793 246
Gaku0606 0:ccdeb3bea793 247 bool IM920::setReceiveID(int ID){
Gaku0606 0:ccdeb3bea793 248 AS = RESPONSE_STRING;
Gaku0606 0:ccdeb3bea793 249 printf("SRID %4X\r\n", ID);
Gaku0606 0:ccdeb3bea793 250 ser->printf("SRID %4X\r\n", ID);
Gaku0606 0:ccdeb3bea793 251 wait_us(WAIT_TIME_US);
Gaku0606 0:ccdeb3bea793 252 if(strncmp(readBuffAddr, "OK", 2) == 0){
Gaku0606 0:ccdeb3bea793 253 return true;
Gaku0606 0:ccdeb3bea793 254 }
Gaku0606 0:ccdeb3bea793 255 else{
Gaku0606 0:ccdeb3bea793 256 return false;
Gaku0606 0:ccdeb3bea793 257 }
Gaku0606 0:ccdeb3bea793 258 }
Gaku0606 0:ccdeb3bea793 259
Gaku0606 0:ccdeb3bea793 260 bool IM920::setChannel(char ch){
Gaku0606 0:ccdeb3bea793 261 AS = RESPONSE_STRING;
Gaku0606 0:ccdeb3bea793 262 printf("STCH %2d\r\n", ch);
Gaku0606 0:ccdeb3bea793 263 ser->printf("STCH %4d\r\n", ch);
Gaku0606 0:ccdeb3bea793 264 wait_us(WAIT_TIME_US);
Gaku0606 0:ccdeb3bea793 265 AS = DATA_STRING;
Gaku0606 0:ccdeb3bea793 266 if(strncmp(readBuffAddr, "OK", 2) == 0){
Gaku0606 0:ccdeb3bea793 267 return true;
Gaku0606 0:ccdeb3bea793 268 }
Gaku0606 0:ccdeb3bea793 269 else return false;
Gaku0606 0:ccdeb3bea793 270 }
Gaku0606 0:ccdeb3bea793 271
Gaku0606 0:ccdeb3bea793 272 char IM920::readChannel(){
Gaku0606 0:ccdeb3bea793 273 AS = RESPONSE_STRING;
Gaku0606 0:ccdeb3bea793 274 printf("RDCH\r\n");
Gaku0606 0:ccdeb3bea793 275 ser->printf("RDCH\r\n");
Gaku0606 0:ccdeb3bea793 276 wait_us(WAIT_TIME_US);
Gaku0606 0:ccdeb3bea793 277 AS = DATA_STRING;
Gaku0606 0:ccdeb3bea793 278 if(strncmp(readBuffAddr, "OK", 2 ) == 0){
Gaku0606 0:ccdeb3bea793 279 return true;
Gaku0606 0:ccdeb3bea793 280 }
Gaku0606 0:ccdeb3bea793 281 else{
Gaku0606 0:ccdeb3bea793 282 return false;
Gaku0606 0:ccdeb3bea793 283 }
Gaku0606 0:ccdeb3bea793 284 }
Gaku0606 0:ccdeb3bea793 285
Gaku0606 0:ccdeb3bea793 286 bool IM920::enableCharacterIO(){
Gaku0606 0:ccdeb3bea793 287 AS = RESPONSE_STRING;
Gaku0606 0:ccdeb3bea793 288 printf("ECIO\r\n");
Gaku0606 0:ccdeb3bea793 289 ser->printf("ECIO\r\n");
Gaku0606 0:ccdeb3bea793 290 wait_us(WAIT_TIME_US);
Gaku0606 0:ccdeb3bea793 291 AS = DATA_STRING;
Gaku0606 0:ccdeb3bea793 292 if(strncmp(readBuffAddr, "OK", 2) == 0){
Gaku0606 0:ccdeb3bea793 293 return true;
Gaku0606 0:ccdeb3bea793 294 }
Gaku0606 0:ccdeb3bea793 295 else{
Gaku0606 0:ccdeb3bea793 296 return false;
Gaku0606 0:ccdeb3bea793 297 }
Gaku0606 0:ccdeb3bea793 298 }
Gaku0606 0:ccdeb3bea793 299
Gaku0606 0:ccdeb3bea793 300 bool IM920::disableCharacterIO(){
Gaku0606 0:ccdeb3bea793 301 AS = RESPONSE_STRING;
Gaku0606 0:ccdeb3bea793 302 printf("DCIO\r\n");
Gaku0606 0:ccdeb3bea793 303 ser->printf("DCIO\r\n");
Gaku0606 0:ccdeb3bea793 304 wait_us(WAIT_TIME_US);
Gaku0606 0:ccdeb3bea793 305 AS = DATA_STRING;
Gaku0606 0:ccdeb3bea793 306 if(strncmp(readBuffAddr, "OK", 2) == 0){
Gaku0606 0:ccdeb3bea793 307 return true;
Gaku0606 0:ccdeb3bea793 308 }
Gaku0606 0:ccdeb3bea793 309 else{
Gaku0606 0:ccdeb3bea793 310 return false;
Gaku0606 0:ccdeb3bea793 311 }
Gaku0606 0:ccdeb3bea793 312 }
Gaku0606 0:ccdeb3bea793 313 void IM920::printFormat(){
Gaku0606 0:ccdeb3bea793 314 _pc->printf("-----------------------\r\n");
Gaku0606 0:ccdeb3bea793 315 _pc->printf(" ENWR : EEPROMへの書き込みを許可\r\n");
Gaku0606 0:ccdeb3bea793 316 _pc->printf(" DSWR : EEPROMへの書き込みを禁止\r\n");
Gaku0606 0:ccdeb3bea793 317 _pc->printf(" RDID : 固有IDを読み出す\r\n");
Gaku0606 0:ccdeb3bea793 318 _pc->printf(" STNN パラメータ : ノード番号を設定,00~FF\r\n");
Gaku0606 0:ccdeb3bea793 319 _pc->printf(" RDNN : ノード番号を読み出す\r\n");
Gaku0606 0:ccdeb3bea793 320 _pc->printf(" SRID XXXX : 受信ID設定,0000~FFFF\r\n");
Gaku0606 0:ccdeb3bea793 321 _pc->printf(" RRID : 受信IDを読み出す\r\n");
Gaku0606 0:ccdeb3bea793 322 _pc->printf(" ERID : 設定された受信IDの全消去\r\n");
Gaku0606 0:ccdeb3bea793 323 _pc->printf(" STCH XX : チャンネル設定,01~15\r\n");
Gaku0606 0:ccdeb3bea793 324 _pc->printf(" RDCH : チャンネル読み出し\r\n");
Gaku0606 0:ccdeb3bea793 325 _pc->printf(" ECIO : キャラクタ入出力設定\r\n");
Gaku0606 0:ccdeb3bea793 326 _pc->printf(" DCIO : キャラクタ入出力設定解除\r\n");
Gaku0606 0:ccdeb3bea793 327 _pc->printf(" TXDT data : 8バイトデータ送信,dataは16進数をASCII文字で入力\r\n");
Gaku0606 0:ccdeb3bea793 328 _pc->printf(" TXDA data : 1~64バイトデータ送信,dataは16進数をASCII文字で入力\r\n");
Gaku0606 0:ccdeb3bea793 329 _pc->printf(" RDRS : RSSI値読み出し\r\n");
Gaku0606 0:ccdeb3bea793 330 _pc->printf(" STPO 送信出力 : 1~3で入力, 1:0.1mW, 2:1mW, 3:10mW\r\n");
Gaku0606 0:ccdeb3bea793 331 _pc->printf(" RDPO : 送信出力読み出し\r\n");
Gaku0606 0:ccdeb3bea793 332 _pc->printf(" STRT 速度値 : 無線通信速度設定, 1:高速(50kbps), 2:長距離(1.25kbps)\r\n");
Gaku0606 0:ccdeb3bea793 333 _pc->printf(" RDRT : 無線通信速度を読み出す\r\n");
Gaku0606 0:ccdeb3bea793 334 _pc->printf(" RDVR : 製品バージョンの読み出し\r\n");
Gaku0606 0:ccdeb3bea793 335 _pc->printf(" ERPT : 簡易中継ON\r\n");
Gaku0606 0:ccdeb3bea793 336 _pc->printf(" DRPT : 簡易中継OFF\r\n");
Gaku0606 0:ccdeb3bea793 337 _pc->printf(" RPRM : パラメータ一括読み出し\r\n");
Gaku0606 0:ccdeb3bea793 338 _pc->printf(" SRST : ソフトウェアリセット\r\n");
Gaku0606 0:ccdeb3bea793 339 _pc->printf(" PCLR : パラメータクリア\r\n");
Gaku0606 0:ccdeb3bea793 340 _pc->printf("-----------------------\r\n");
Gaku0606 0:ccdeb3bea793 341 }
Gaku0606 0:ccdeb3bea793 342 void IM920::interactiveMode(){
Gaku0606 0:ccdeb3bea793 343 AS = INTERACTIVE_STRING;
Gaku0606 0:ccdeb3bea793 344 //interactiveFlag = 1;
Gaku0606 0:ccdeb3bea793 345 int current = 0;
Gaku0606 0:ccdeb3bea793 346 static char buf[IM920_BUFF_SIZE] = {'\0'};
Gaku0606 0:ccdeb3bea793 347 memset(buf, '\0', IM920_BUFF_SIZE);
Gaku0606 0:ccdeb3bea793 348 _pc->printf("Start Interactive mode!!\r\n");
Gaku0606 0:ccdeb3bea793 349 printFormat();
Gaku0606 0:ccdeb3bea793 350 while(1){
Gaku0606 0:ccdeb3bea793 351 if(_pc->readable()){
Gaku0606 0:ccdeb3bea793 352 char ccc = _pc->getc();
Gaku0606 0:ccdeb3bea793 353
Gaku0606 0:ccdeb3bea793 354 if(ccc == '@'){
Gaku0606 0:ccdeb3bea793 355 _pc->printf("Interactive mode finish!!\r\n");
Gaku0606 0:ccdeb3bea793 356 break;
Gaku0606 0:ccdeb3bea793 357 }
Gaku0606 0:ccdeb3bea793 358 if(ccc == '\r'){
Gaku0606 0:ccdeb3bea793 359 _pc->printf("\r\n");
Gaku0606 0:ccdeb3bea793 360 buf[current] = '\0';
Gaku0606 0:ccdeb3bea793 361
Gaku0606 0:ccdeb3bea793 362 ser->printf("%s\r\n", buf);
Gaku0606 0:ccdeb3bea793 363 current = 0;
Gaku0606 0:ccdeb3bea793 364 memset(buf, '\0', IM920_BUFF_SIZE);
Gaku0606 0:ccdeb3bea793 365 wait(1.0);
Gaku0606 0:ccdeb3bea793 366 printFormat();
Gaku0606 0:ccdeb3bea793 367 while(_pc->readable()){ _pc->getc();}
Gaku0606 0:ccdeb3bea793 368 }
Gaku0606 0:ccdeb3bea793 369 else if(ccc != '\n'){
Gaku0606 0:ccdeb3bea793 370 _pc->printf("%c", ccc);
Gaku0606 0:ccdeb3bea793 371 buf[current] = ccc;
Gaku0606 0:ccdeb3bea793 372 current++;
Gaku0606 0:ccdeb3bea793 373 if(current >= 160){
Gaku0606 0:ccdeb3bea793 374 current = 0;
Gaku0606 0:ccdeb3bea793 375 memset(buf, '\0', IM920_BUFF_SIZE);
Gaku0606 0:ccdeb3bea793 376 }
Gaku0606 0:ccdeb3bea793 377 }
Gaku0606 0:ccdeb3bea793 378 }
Gaku0606 0:ccdeb3bea793 379 }
Gaku0606 0:ccdeb3bea793 380 AS = DATA_STRING;
Gaku0606 0:ccdeb3bea793 381 return;
Gaku0606 0:ccdeb3bea793 382 }