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