IM920のライブラリ
IM920.cpp@1:11ae0d702ecc, 2018-02-22 (annotated)
- Committer:
- Gaku0606
- Date:
- Thu Feb 22 08:52:51 2018 +0000
- Revision:
- 1:11ae0d702ecc
- Parent:
- 0:ccdeb3bea793
???
Who changed what in which revision?
User | Revision | Line number | New 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 | 1:11ae0d702ecc | 109 | char tempStr[IM920_BUFF_SIZE]; |
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 | 1:11ae0d702ecc | 147 | printf("\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 148 | writeBuffAddr[current] = '\0'; |
Gaku0606 | 0:ccdeb3bea793 | 149 | if(AB == BUFF_A){//現在バッファAに書き込み中 |
Gaku0606 | 0:ccdeb3bea793 | 150 | readBuffAddr = buff_A; |
Gaku0606 | 0:ccdeb3bea793 | 151 | writeBuffAddr = buff_B; |
Gaku0606 | 0:ccdeb3bea793 | 152 | AB = BUFF_B; |
Gaku0606 | 0:ccdeb3bea793 | 153 | } |
Gaku0606 | 0:ccdeb3bea793 | 154 | else{//現在バッファBに書き込み中 |
Gaku0606 | 0:ccdeb3bea793 | 155 | readBuffAddr = buff_B; |
Gaku0606 | 0:ccdeb3bea793 | 156 | writeBuffAddr = buff_A; |
Gaku0606 | 0:ccdeb3bea793 | 157 | AB = BUFF_A; |
Gaku0606 | 0:ccdeb3bea793 | 158 | } |
Gaku0606 | 0:ccdeb3bea793 | 159 | |
Gaku0606 | 0:ccdeb3bea793 | 160 | //im920_debug(); |
Gaku0606 | 0:ccdeb3bea793 | 161 | //---------------------- |
Gaku0606 | 0:ccdeb3bea793 | 162 | // 文字列の解析 |
Gaku0606 | 0:ccdeb3bea793 | 163 | //---------------------- |
Gaku0606 | 0:ccdeb3bea793 | 164 | if(AS == DATA_STRING){//データの形式によって分岐 |
Gaku0606 | 0:ccdeb3bea793 | 165 | if(current > 9){ |
Gaku0606 | 0:ccdeb3bea793 | 166 | //データの取り出し、配列化 |
Gaku0606 | 0:ccdeb3bea793 | 167 | data_analyze(); |
Gaku0606 | 1:11ae0d702ecc | 168 | /*for(int i = 0;i < 64;i++){ |
Gaku0606 | 0:ccdeb3bea793 | 169 | printf("%d ",data[i]); |
Gaku0606 | 0:ccdeb3bea793 | 170 | } |
Gaku0606 | 0:ccdeb3bea793 | 171 | printf("\r\n"); |
Gaku0606 | 1:11ae0d702ecc | 172 | printf("header: %0X\r\n",(uint8_t)data[0]);*/ |
Gaku0606 | 0:ccdeb3bea793 | 173 | //header0xFF(); |
Gaku0606 | 0:ccdeb3bea793 | 174 | // 関数の呼び出し |
Gaku0606 | 0:ccdeb3bea793 | 175 | (*p_callFunc[(uint8_t)data[0]])(); |
Gaku0606 | 0:ccdeb3bea793 | 176 | } |
Gaku0606 | 0:ccdeb3bea793 | 177 | } |
Gaku0606 | 0:ccdeb3bea793 | 178 | //初期化 |
Gaku0606 | 0:ccdeb3bea793 | 179 | current = 0; |
Gaku0606 | 0:ccdeb3bea793 | 180 | //memset(writeBuffAddr, '\0', IM920_BUFF_SIZE); |
Gaku0606 | 0:ccdeb3bea793 | 181 | return; |
Gaku0606 | 0:ccdeb3bea793 | 182 | } |
Gaku0606 | 0:ccdeb3bea793 | 183 | else if(c !='\n'){ |
Gaku0606 | 0:ccdeb3bea793 | 184 | //文字列生成 |
Gaku0606 | 0:ccdeb3bea793 | 185 | writeBuffAddr[current] = c; |
Gaku0606 | 0:ccdeb3bea793 | 186 | current++; |
Gaku0606 | 0:ccdeb3bea793 | 187 | if(current >= IM920_BUFF_SIZE){//初期化 |
Gaku0606 | 0:ccdeb3bea793 | 188 | current = 0; |
Gaku0606 | 0:ccdeb3bea793 | 189 | memset(writeBuffAddr, '\0', IM920_BUFF_SIZE); |
Gaku0606 | 0:ccdeb3bea793 | 190 | } |
Gaku0606 | 0:ccdeb3bea793 | 191 | return; |
Gaku0606 | 0:ccdeb3bea793 | 192 | } |
Gaku0606 | 0:ccdeb3bea793 | 193 | } |
Gaku0606 | 0:ccdeb3bea793 | 194 | |
Gaku0606 | 0:ccdeb3bea793 | 195 | void IM920::attach(void (*funcAddr)(void), unsigned header){ |
Gaku0606 | 0:ccdeb3bea793 | 196 | p_callFunc[header] = funcAddr; |
Gaku0606 | 0:ccdeb3bea793 | 197 | return; |
Gaku0606 | 0:ccdeb3bea793 | 198 | } |
Gaku0606 | 0:ccdeb3bea793 | 199 | |
Gaku0606 | 0:ccdeb3bea793 | 200 | /** |
Gaku0606 | 0:ccdeb3bea793 | 201 | @bref パラメータ不揮発メモリ書き込み許可モードへ移行 |
Gaku0606 | 0:ccdeb3bea793 | 202 | */ |
Gaku0606 | 0:ccdeb3bea793 | 203 | bool IM920::enableWrite(){ |
Gaku0606 | 0:ccdeb3bea793 | 204 | AS = RESPONSE_STRING;//レスポンス受信モードへ移行 |
Gaku0606 | 0:ccdeb3bea793 | 205 | ser->printf("ENWR\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 206 | wait_us(WAIT_TIME_US);//待つ |
Gaku0606 | 0:ccdeb3bea793 | 207 | AS = DATA_STRING; //データ受信モードへ以降 |
Gaku0606 | 0:ccdeb3bea793 | 208 | if(strncmp(readBuffAddr, "OK", 2) == 0){ |
Gaku0606 | 0:ccdeb3bea793 | 209 | return true; |
Gaku0606 | 0:ccdeb3bea793 | 210 | } |
Gaku0606 | 0:ccdeb3bea793 | 211 | else{ |
Gaku0606 | 0:ccdeb3bea793 | 212 | return false; |
Gaku0606 | 0:ccdeb3bea793 | 213 | } |
Gaku0606 | 0:ccdeb3bea793 | 214 | } |
Gaku0606 | 0:ccdeb3bea793 | 215 | |
Gaku0606 | 0:ccdeb3bea793 | 216 | bool IM920::disableWrite(){ |
Gaku0606 | 0:ccdeb3bea793 | 217 | AS = RESPONSE_STRING;//レスポンス受信モードへ移行 |
Gaku0606 | 0:ccdeb3bea793 | 218 | ser->printf("DSWR\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 219 | wait_us(WAIT_TIME_US); |
Gaku0606 | 0:ccdeb3bea793 | 220 | AS = DATA_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 221 | if(strncmp(readBuffAddr, "OK", 2) == 0){ |
Gaku0606 | 0:ccdeb3bea793 | 222 | return true; |
Gaku0606 | 0:ccdeb3bea793 | 223 | } |
Gaku0606 | 0:ccdeb3bea793 | 224 | else{ |
Gaku0606 | 0:ccdeb3bea793 | 225 | return false; |
Gaku0606 | 0:ccdeb3bea793 | 226 | } |
Gaku0606 | 0:ccdeb3bea793 | 227 | } |
Gaku0606 | 0:ccdeb3bea793 | 228 | |
Gaku0606 | 0:ccdeb3bea793 | 229 | /** |
Gaku0606 | 0:ccdeb3bea793 | 230 | @bref 固有IDを読み出す |
Gaku0606 | 0:ccdeb3bea793 | 231 | */ |
Gaku0606 | 0:ccdeb3bea793 | 232 | int IM920::readID(){ |
Gaku0606 | 0:ccdeb3bea793 | 233 | AS = NORMAL_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 234 | ser->printf("RDID\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 235 | wait_us(WAIT_TIME_US); |
Gaku0606 | 0:ccdeb3bea793 | 236 | AS = DATA_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 237 | int val = 0; |
Gaku0606 | 0:ccdeb3bea793 | 238 | |
Gaku0606 | 0:ccdeb3bea793 | 239 | //pc.printf("%c:%c:%c:%c\r\n",readBuffAddr[0],readBuffAddr[1],readBuffAddr[2],readBuffAddr[3]); |
Gaku0606 | 0:ccdeb3bea793 | 240 | val = asciiToNumber(readBuffAddr[0]) << 24; |
Gaku0606 | 0:ccdeb3bea793 | 241 | val |= asciiToNumber(readBuffAddr[1]) << 16; |
Gaku0606 | 0:ccdeb3bea793 | 242 | val |= asciiToNumber(readBuffAddr[2]) << 8; |
Gaku0606 | 0:ccdeb3bea793 | 243 | val |= asciiToNumber(readBuffAddr[3]); |
Gaku0606 | 0:ccdeb3bea793 | 244 | ID = val; |
Gaku0606 | 0:ccdeb3bea793 | 245 | return val; |
Gaku0606 | 0:ccdeb3bea793 | 246 | } |
Gaku0606 | 0:ccdeb3bea793 | 247 | |
Gaku0606 | 0:ccdeb3bea793 | 248 | bool IM920::setReceiveID(int ID){ |
Gaku0606 | 0:ccdeb3bea793 | 249 | AS = RESPONSE_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 250 | printf("SRID %4X\r\n", ID); |
Gaku0606 | 0:ccdeb3bea793 | 251 | ser->printf("SRID %4X\r\n", ID); |
Gaku0606 | 0:ccdeb3bea793 | 252 | wait_us(WAIT_TIME_US); |
Gaku0606 | 0:ccdeb3bea793 | 253 | if(strncmp(readBuffAddr, "OK", 2) == 0){ |
Gaku0606 | 0:ccdeb3bea793 | 254 | return true; |
Gaku0606 | 0:ccdeb3bea793 | 255 | } |
Gaku0606 | 0:ccdeb3bea793 | 256 | else{ |
Gaku0606 | 0:ccdeb3bea793 | 257 | return false; |
Gaku0606 | 0:ccdeb3bea793 | 258 | } |
Gaku0606 | 0:ccdeb3bea793 | 259 | } |
Gaku0606 | 0:ccdeb3bea793 | 260 | |
Gaku0606 | 0:ccdeb3bea793 | 261 | bool IM920::setChannel(char ch){ |
Gaku0606 | 0:ccdeb3bea793 | 262 | AS = RESPONSE_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 263 | printf("STCH %2d\r\n", ch); |
Gaku0606 | 0:ccdeb3bea793 | 264 | ser->printf("STCH %4d\r\n", ch); |
Gaku0606 | 0:ccdeb3bea793 | 265 | wait_us(WAIT_TIME_US); |
Gaku0606 | 0:ccdeb3bea793 | 266 | AS = DATA_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 267 | if(strncmp(readBuffAddr, "OK", 2) == 0){ |
Gaku0606 | 0:ccdeb3bea793 | 268 | return true; |
Gaku0606 | 0:ccdeb3bea793 | 269 | } |
Gaku0606 | 0:ccdeb3bea793 | 270 | else return false; |
Gaku0606 | 0:ccdeb3bea793 | 271 | } |
Gaku0606 | 0:ccdeb3bea793 | 272 | |
Gaku0606 | 0:ccdeb3bea793 | 273 | char IM920::readChannel(){ |
Gaku0606 | 0:ccdeb3bea793 | 274 | AS = RESPONSE_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 275 | printf("RDCH\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 276 | ser->printf("RDCH\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 277 | wait_us(WAIT_TIME_US); |
Gaku0606 | 0:ccdeb3bea793 | 278 | AS = DATA_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 279 | if(strncmp(readBuffAddr, "OK", 2 ) == 0){ |
Gaku0606 | 0:ccdeb3bea793 | 280 | return true; |
Gaku0606 | 0:ccdeb3bea793 | 281 | } |
Gaku0606 | 0:ccdeb3bea793 | 282 | else{ |
Gaku0606 | 0:ccdeb3bea793 | 283 | return false; |
Gaku0606 | 0:ccdeb3bea793 | 284 | } |
Gaku0606 | 0:ccdeb3bea793 | 285 | } |
Gaku0606 | 0:ccdeb3bea793 | 286 | |
Gaku0606 | 0:ccdeb3bea793 | 287 | bool IM920::enableCharacterIO(){ |
Gaku0606 | 0:ccdeb3bea793 | 288 | AS = RESPONSE_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 289 | printf("ECIO\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 290 | ser->printf("ECIO\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 291 | wait_us(WAIT_TIME_US); |
Gaku0606 | 0:ccdeb3bea793 | 292 | AS = DATA_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 293 | if(strncmp(readBuffAddr, "OK", 2) == 0){ |
Gaku0606 | 0:ccdeb3bea793 | 294 | return true; |
Gaku0606 | 0:ccdeb3bea793 | 295 | } |
Gaku0606 | 0:ccdeb3bea793 | 296 | else{ |
Gaku0606 | 0:ccdeb3bea793 | 297 | return false; |
Gaku0606 | 0:ccdeb3bea793 | 298 | } |
Gaku0606 | 0:ccdeb3bea793 | 299 | } |
Gaku0606 | 0:ccdeb3bea793 | 300 | |
Gaku0606 | 0:ccdeb3bea793 | 301 | bool IM920::disableCharacterIO(){ |
Gaku0606 | 0:ccdeb3bea793 | 302 | AS = RESPONSE_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 303 | printf("DCIO\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 304 | ser->printf("DCIO\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 305 | wait_us(WAIT_TIME_US); |
Gaku0606 | 0:ccdeb3bea793 | 306 | AS = DATA_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 307 | if(strncmp(readBuffAddr, "OK", 2) == 0){ |
Gaku0606 | 0:ccdeb3bea793 | 308 | return true; |
Gaku0606 | 0:ccdeb3bea793 | 309 | } |
Gaku0606 | 0:ccdeb3bea793 | 310 | else{ |
Gaku0606 | 0:ccdeb3bea793 | 311 | return false; |
Gaku0606 | 0:ccdeb3bea793 | 312 | } |
Gaku0606 | 0:ccdeb3bea793 | 313 | } |
Gaku0606 | 0:ccdeb3bea793 | 314 | void IM920::printFormat(){ |
Gaku0606 | 0:ccdeb3bea793 | 315 | _pc->printf("-----------------------\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 316 | _pc->printf(" ENWR : EEPROMへの書き込みを許可\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 317 | _pc->printf(" DSWR : EEPROMへの書き込みを禁止\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 318 | _pc->printf(" RDID : 固有IDを読み出す\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 319 | _pc->printf(" STNN パラメータ : ノード番号を設定,00~FF\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 320 | _pc->printf(" RDNN : ノード番号を読み出す\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 321 | _pc->printf(" SRID XXXX : 受信ID設定,0000~FFFF\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 322 | _pc->printf(" RRID : 受信IDを読み出す\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 323 | _pc->printf(" ERID : 設定された受信IDの全消去\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 324 | _pc->printf(" STCH XX : チャンネル設定,01~15\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 325 | _pc->printf(" RDCH : チャンネル読み出し\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 326 | _pc->printf(" ECIO : キャラクタ入出力設定\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 327 | _pc->printf(" DCIO : キャラクタ入出力設定解除\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 328 | _pc->printf(" TXDT data : 8バイトデータ送信,dataは16進数をASCII文字で入力\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 329 | _pc->printf(" TXDA data : 1~64バイトデータ送信,dataは16進数をASCII文字で入力\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 330 | _pc->printf(" RDRS : RSSI値読み出し\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 331 | _pc->printf(" STPO 送信出力 : 1~3で入力, 1:0.1mW, 2:1mW, 3:10mW\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 332 | _pc->printf(" RDPO : 送信出力読み出し\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 333 | _pc->printf(" STRT 速度値 : 無線通信速度設定, 1:高速(50kbps), 2:長距離(1.25kbps)\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 334 | _pc->printf(" RDRT : 無線通信速度を読み出す\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 335 | _pc->printf(" RDVR : 製品バージョンの読み出し\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 336 | _pc->printf(" ERPT : 簡易中継ON\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 337 | _pc->printf(" DRPT : 簡易中継OFF\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 338 | _pc->printf(" RPRM : パラメータ一括読み出し\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 339 | _pc->printf(" SRST : ソフトウェアリセット\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 340 | _pc->printf(" PCLR : パラメータクリア\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 341 | _pc->printf("-----------------------\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 342 | } |
Gaku0606 | 0:ccdeb3bea793 | 343 | void IM920::interactiveMode(){ |
Gaku0606 | 0:ccdeb3bea793 | 344 | AS = INTERACTIVE_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 345 | //interactiveFlag = 1; |
Gaku0606 | 0:ccdeb3bea793 | 346 | int current = 0; |
Gaku0606 | 0:ccdeb3bea793 | 347 | static char buf[IM920_BUFF_SIZE] = {'\0'}; |
Gaku0606 | 0:ccdeb3bea793 | 348 | memset(buf, '\0', IM920_BUFF_SIZE); |
Gaku0606 | 0:ccdeb3bea793 | 349 | _pc->printf("Start Interactive mode!!\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 350 | printFormat(); |
Gaku0606 | 0:ccdeb3bea793 | 351 | while(1){ |
Gaku0606 | 0:ccdeb3bea793 | 352 | if(_pc->readable()){ |
Gaku0606 | 0:ccdeb3bea793 | 353 | char ccc = _pc->getc(); |
Gaku0606 | 0:ccdeb3bea793 | 354 | |
Gaku0606 | 0:ccdeb3bea793 | 355 | if(ccc == '@'){ |
Gaku0606 | 0:ccdeb3bea793 | 356 | _pc->printf("Interactive mode finish!!\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 357 | break; |
Gaku0606 | 0:ccdeb3bea793 | 358 | } |
Gaku0606 | 0:ccdeb3bea793 | 359 | if(ccc == '\r'){ |
Gaku0606 | 0:ccdeb3bea793 | 360 | _pc->printf("\r\n"); |
Gaku0606 | 0:ccdeb3bea793 | 361 | buf[current] = '\0'; |
Gaku0606 | 0:ccdeb3bea793 | 362 | |
Gaku0606 | 0:ccdeb3bea793 | 363 | ser->printf("%s\r\n", buf); |
Gaku0606 | 0:ccdeb3bea793 | 364 | current = 0; |
Gaku0606 | 0:ccdeb3bea793 | 365 | memset(buf, '\0', IM920_BUFF_SIZE); |
Gaku0606 | 0:ccdeb3bea793 | 366 | wait(1.0); |
Gaku0606 | 0:ccdeb3bea793 | 367 | printFormat(); |
Gaku0606 | 0:ccdeb3bea793 | 368 | while(_pc->readable()){ _pc->getc();} |
Gaku0606 | 0:ccdeb3bea793 | 369 | } |
Gaku0606 | 0:ccdeb3bea793 | 370 | else if(ccc != '\n'){ |
Gaku0606 | 0:ccdeb3bea793 | 371 | _pc->printf("%c", ccc); |
Gaku0606 | 0:ccdeb3bea793 | 372 | buf[current] = ccc; |
Gaku0606 | 0:ccdeb3bea793 | 373 | current++; |
Gaku0606 | 0:ccdeb3bea793 | 374 | if(current >= 160){ |
Gaku0606 | 0:ccdeb3bea793 | 375 | current = 0; |
Gaku0606 | 0:ccdeb3bea793 | 376 | memset(buf, '\0', IM920_BUFF_SIZE); |
Gaku0606 | 0:ccdeb3bea793 | 377 | } |
Gaku0606 | 0:ccdeb3bea793 | 378 | } |
Gaku0606 | 0:ccdeb3bea793 | 379 | } |
Gaku0606 | 0:ccdeb3bea793 | 380 | } |
Gaku0606 | 0:ccdeb3bea793 | 381 | AS = DATA_STRING; |
Gaku0606 | 0:ccdeb3bea793 | 382 | return; |
Gaku0606 | 0:ccdeb3bea793 | 383 | } |