bowen liu
/
mbed-os-example-blinky
ex
Fork of mbed-os-example-mbed5-blinky by
DuerOS-Light-SDK-v1.1.0/demo/factory_test.cpp@50:9ecaa144d1f3, 2017-07-18 (annotated)
- Committer:
- tmboy
- Date:
- Tue Jul 18 09:08:52 2017 +0000
- Revision:
- 50:9ecaa144d1f3
- Parent:
- 47:9e361da97763
add .json
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TMBOY | 47:9e361da97763 | 1 | #if defined(TARGET_UNO_91H) |
TMBOY | 47:9e361da97763 | 2 | #include "mbed.h" |
TMBOY | 47:9e361da97763 | 3 | #include "rtos.h" |
TMBOY | 47:9e361da97763 | 4 | #include "console.h" |
TMBOY | 47:9e361da97763 | 5 | #include "WiFiStackInterface.h" |
TMBOY | 47:9e361da97763 | 6 | #include "rda_wdt_api.h" |
TMBOY | 47:9e361da97763 | 7 | #include "rda_ccfg_api.h" |
TMBOY | 47:9e361da97763 | 8 | #include "cmsis_os.h" |
TMBOY | 47:9e361da97763 | 9 | #include "rda_wdt_api.h" |
TMBOY | 47:9e361da97763 | 10 | #include "Rda58xx.h" |
TMBOY | 47:9e361da97763 | 11 | |
TMBOY | 47:9e361da97763 | 12 | static char* version = "**********RDA Software Version sta_V2.0_124**********"; |
TMBOY | 47:9e361da97763 | 13 | static int op_mode = 0;//initial ~ 0 factory test ~ 1 function ~ 2 |
TMBOY | 47:9e361da97763 | 14 | static char conn_flag = 0; |
TMBOY | 47:9e361da97763 | 15 | static WiFiStackInterface wifi; |
TMBOY | 47:9e361da97763 | 16 | extern unsigned char rda_mac_addr[6]; |
TMBOY | 47:9e361da97763 | 17 | extern rda58xx _rda58xx; |
TMBOY | 47:9e361da97763 | 18 | |
TMBOY | 47:9e361da97763 | 19 | int do_conn_state(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 20 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 21 | return 0; |
TMBOY | 47:9e361da97763 | 22 | } |
TMBOY | 47:9e361da97763 | 23 | |
TMBOY | 47:9e361da97763 | 24 | if (argc < 1) { |
TMBOY | 47:9e361da97763 | 25 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 26 | return -1; |
TMBOY | 47:9e361da97763 | 27 | } |
TMBOY | 47:9e361da97763 | 28 | |
TMBOY | 47:9e361da97763 | 29 | #if 1 |
TMBOY | 47:9e361da97763 | 30 | const char* ssid; |
TMBOY | 47:9e361da97763 | 31 | ssid = wifi.get_ssid(); |
TMBOY | 47:9e361da97763 | 32 | |
TMBOY | 47:9e361da97763 | 33 | if (ssid[0]) { |
TMBOY | 47:9e361da97763 | 34 | printf("CONNECTED! ssid:%s RSSI:%d db ip:%s\r\n", wifi.get_ssid(), wifi.get_rssi(), |
TMBOY | 47:9e361da97763 | 35 | wifi.get_ip_address()); |
TMBOY | 47:9e361da97763 | 36 | } else { |
TMBOY | 47:9e361da97763 | 37 | printf("NOT CONNECTED!\r\n"); |
TMBOY | 47:9e361da97763 | 38 | } |
TMBOY | 47:9e361da97763 | 39 | |
TMBOY | 47:9e361da97763 | 40 | #else |
TMBOY | 47:9e361da97763 | 41 | |
TMBOY | 47:9e361da97763 | 42 | if (wifi.bss.SSID[0]) { |
TMBOY | 47:9e361da97763 | 43 | printf("CONNECTED! ssid:%s RSSI:%d db\r\n", wifi.bss.SSID, wifi.bss.SSID); |
TMBOY | 47:9e361da97763 | 44 | } else { |
TMBOY | 47:9e361da97763 | 45 | printf("NOT CONNECTED!\r\n"); |
TMBOY | 47:9e361da97763 | 46 | } |
TMBOY | 47:9e361da97763 | 47 | |
TMBOY | 47:9e361da97763 | 48 | #endif |
TMBOY | 47:9e361da97763 | 49 | return 0; |
TMBOY | 47:9e361da97763 | 50 | } |
TMBOY | 47:9e361da97763 | 51 | |
TMBOY | 47:9e361da97763 | 52 | int do_get_mac(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 53 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 54 | return 0; |
TMBOY | 47:9e361da97763 | 55 | } |
TMBOY | 47:9e361da97763 | 56 | |
TMBOY | 47:9e361da97763 | 57 | if (argc < 1) { |
TMBOY | 47:9e361da97763 | 58 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 59 | return -1; |
TMBOY | 47:9e361da97763 | 60 | } |
TMBOY | 47:9e361da97763 | 61 | |
TMBOY | 47:9e361da97763 | 62 | char mac[6]; |
TMBOY | 47:9e361da97763 | 63 | mbed_mac_address(mac); |
TMBOY | 47:9e361da97763 | 64 | printf("MAC address: %02x:%02x:%02x:%02x:%02x:%02x\r\n", |
TMBOY | 47:9e361da97763 | 65 | mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
TMBOY | 47:9e361da97763 | 66 | |
TMBOY | 47:9e361da97763 | 67 | return 0; |
TMBOY | 47:9e361da97763 | 68 | } |
TMBOY | 47:9e361da97763 | 69 | |
TMBOY | 47:9e361da97763 | 70 | int do_set_mac(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 71 | char* mdata, mac[6], i; |
TMBOY | 47:9e361da97763 | 72 | |
TMBOY | 47:9e361da97763 | 73 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 74 | return 0; |
TMBOY | 47:9e361da97763 | 75 | } |
TMBOY | 47:9e361da97763 | 76 | |
TMBOY | 47:9e361da97763 | 77 | if (argc < 2) { |
TMBOY | 47:9e361da97763 | 78 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 79 | return -1; |
TMBOY | 47:9e361da97763 | 80 | } |
TMBOY | 47:9e361da97763 | 81 | |
TMBOY | 47:9e361da97763 | 82 | if (strlen(argv[1]) != 12) { |
TMBOY | 47:9e361da97763 | 83 | printf("Error MAC address len\r\n"); |
TMBOY | 47:9e361da97763 | 84 | return -2; |
TMBOY | 47:9e361da97763 | 85 | } |
TMBOY | 47:9e361da97763 | 86 | |
TMBOY | 47:9e361da97763 | 87 | mdata = argv[1]; |
TMBOY | 47:9e361da97763 | 88 | |
TMBOY | 47:9e361da97763 | 89 | for (i = 0; i < 12; i++) { |
TMBOY | 47:9e361da97763 | 90 | if (mdata[i] >= 0x41 && mdata[i] <= 0x46) { // switch 'A' to 'a' |
TMBOY | 47:9e361da97763 | 91 | mdata[i] += 0x20; |
TMBOY | 47:9e361da97763 | 92 | } |
TMBOY | 47:9e361da97763 | 93 | |
TMBOY | 47:9e361da97763 | 94 | if (mdata[i] >= 0x61 && mdata[i] <= 0x66) { //switch "ab" to 0xab |
TMBOY | 47:9e361da97763 | 95 | mac[i] = mdata[i] - 0x57; |
TMBOY | 47:9e361da97763 | 96 | } |
TMBOY | 47:9e361da97763 | 97 | |
TMBOY | 47:9e361da97763 | 98 | if (mdata[i] >= 0x30 && mdata[i] <= 0x39) { |
TMBOY | 47:9e361da97763 | 99 | mac[i] = mdata[i] - 0x30; |
TMBOY | 47:9e361da97763 | 100 | } |
TMBOY | 47:9e361da97763 | 101 | |
TMBOY | 47:9e361da97763 | 102 | if (i % 2 == 1) { |
TMBOY | 47:9e361da97763 | 103 | mac[i / 2] = mac[i - 1] << 4 | mac[i]; |
TMBOY | 47:9e361da97763 | 104 | } |
TMBOY | 47:9e361da97763 | 105 | } |
TMBOY | 47:9e361da97763 | 106 | |
TMBOY | 47:9e361da97763 | 107 | if (!mac_is_valid(mac)) { |
TMBOY | 47:9e361da97763 | 108 | printf("MAC is ZERO\r\n"); |
TMBOY | 47:9e361da97763 | 109 | return 0; |
TMBOY | 47:9e361da97763 | 110 | } |
TMBOY | 47:9e361da97763 | 111 | |
TMBOY | 47:9e361da97763 | 112 | memcpy(rda_mac_addr, mac, 6); |
TMBOY | 47:9e361da97763 | 113 | rda5981_flash_write_mac_addr(rda_mac_addr); |
TMBOY | 47:9e361da97763 | 114 | return 0; |
TMBOY | 47:9e361da97763 | 115 | } |
TMBOY | 47:9e361da97763 | 116 | |
TMBOY | 47:9e361da97763 | 117 | int do_get_ver(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 118 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 119 | return 0; |
TMBOY | 47:9e361da97763 | 120 | } |
TMBOY | 47:9e361da97763 | 121 | |
TMBOY | 47:9e361da97763 | 122 | if (argc < 1) { |
TMBOY | 47:9e361da97763 | 123 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 124 | return -1; |
TMBOY | 47:9e361da97763 | 125 | } |
TMBOY | 47:9e361da97763 | 126 | |
TMBOY | 47:9e361da97763 | 127 | printf("Software Version: %s\r\n", version); |
TMBOY | 47:9e361da97763 | 128 | return 0; |
TMBOY | 47:9e361da97763 | 129 | } |
TMBOY | 47:9e361da97763 | 130 | |
TMBOY | 47:9e361da97763 | 131 | int do_get_ver_5856(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 132 | char ver[32] = {0}; |
TMBOY | 47:9e361da97763 | 133 | rda58xx_at_status ret; |
TMBOY | 47:9e361da97763 | 134 | |
TMBOY | 47:9e361da97763 | 135 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 136 | return 0; |
TMBOY | 47:9e361da97763 | 137 | } |
TMBOY | 47:9e361da97763 | 138 | |
TMBOY | 47:9e361da97763 | 139 | if (argc < 1) { |
TMBOY | 47:9e361da97763 | 140 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 141 | return -1; |
TMBOY | 47:9e361da97763 | 142 | } |
TMBOY | 47:9e361da97763 | 143 | |
TMBOY | 47:9e361da97763 | 144 | printf("do_get_ver_5856\r\n"); |
TMBOY | 47:9e361da97763 | 145 | |
TMBOY | 47:9e361da97763 | 146 | while (!_rda58xx.isPowerOn()) { |
TMBOY | 47:9e361da97763 | 147 | Thread::wait(100); |
TMBOY | 47:9e361da97763 | 148 | } |
TMBOY | 47:9e361da97763 | 149 | |
TMBOY | 47:9e361da97763 | 150 | ret = _rda58xx.getChipVersion(ver); |
TMBOY | 47:9e361da97763 | 151 | |
TMBOY | 47:9e361da97763 | 152 | if (VACK == ret) { |
TMBOY | 47:9e361da97763 | 153 | printf("5856 Software Version: %s\r\n", ver); |
TMBOY | 47:9e361da97763 | 154 | return 0; |
TMBOY | 47:9e361da97763 | 155 | } else { |
TMBOY | 47:9e361da97763 | 156 | printf("5856 Software Version: Fail!\r\n"); |
TMBOY | 47:9e361da97763 | 157 | return -1; |
TMBOY | 47:9e361da97763 | 158 | } |
TMBOY | 47:9e361da97763 | 159 | } |
TMBOY | 47:9e361da97763 | 160 | |
TMBOY | 47:9e361da97763 | 161 | int do_factory_test_5856(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 162 | rda58xx_at_status ret; |
TMBOY | 47:9e361da97763 | 163 | |
TMBOY | 47:9e361da97763 | 164 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 165 | return 0; |
TMBOY | 47:9e361da97763 | 166 | } |
TMBOY | 47:9e361da97763 | 167 | |
TMBOY | 47:9e361da97763 | 168 | if (argc < 1) { |
TMBOY | 47:9e361da97763 | 169 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 170 | return -1; |
TMBOY | 47:9e361da97763 | 171 | } |
TMBOY | 47:9e361da97763 | 172 | |
TMBOY | 47:9e361da97763 | 173 | printf("do_factory_test_5856\r\n"); |
TMBOY | 47:9e361da97763 | 174 | ret = _rda58xx.factoryTest(FT_ENABLE); |
TMBOY | 47:9e361da97763 | 175 | |
TMBOY | 47:9e361da97763 | 176 | if (VACK == ret) { |
TMBOY | 47:9e361da97763 | 177 | printf("5856 Factory Test: Succeed\r\n"); |
TMBOY | 47:9e361da97763 | 178 | return 0; |
TMBOY | 47:9e361da97763 | 179 | } else { |
TMBOY | 47:9e361da97763 | 180 | printf("5856 Factory Test: Fail\r\n"); |
TMBOY | 47:9e361da97763 | 181 | return -1; |
TMBOY | 47:9e361da97763 | 182 | } |
TMBOY | 47:9e361da97763 | 183 | } |
TMBOY | 47:9e361da97763 | 184 | |
TMBOY | 47:9e361da97763 | 185 | |
TMBOY | 47:9e361da97763 | 186 | int do_write_usedata(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 187 | |
TMBOY | 47:9e361da97763 | 188 | int len, ret, tmp_len = 0; |
TMBOY | 47:9e361da97763 | 189 | unsigned char* buf; |
TMBOY | 47:9e361da97763 | 190 | |
TMBOY | 47:9e361da97763 | 191 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 192 | return 0; |
TMBOY | 47:9e361da97763 | 193 | } |
TMBOY | 47:9e361da97763 | 194 | |
TMBOY | 47:9e361da97763 | 195 | if (argc < 2) { |
TMBOY | 47:9e361da97763 | 196 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 197 | return -1; |
TMBOY | 47:9e361da97763 | 198 | } |
TMBOY | 47:9e361da97763 | 199 | |
TMBOY | 47:9e361da97763 | 200 | len = atoi(argv[1]); |
TMBOY | 47:9e361da97763 | 201 | buf = (unsigned char*)malloc(len); |
TMBOY | 47:9e361da97763 | 202 | memset(buf, 0, len); |
TMBOY | 47:9e361da97763 | 203 | |
TMBOY | 47:9e361da97763 | 204 | do { |
TMBOY | 47:9e361da97763 | 205 | unsigned int size; |
TMBOY | 47:9e361da97763 | 206 | size = console_fifo_get(buf + tmp_len, len - tmp_len); |
TMBOY | 47:9e361da97763 | 207 | tmp_len += size; |
TMBOY | 47:9e361da97763 | 208 | } while (tmp_len < len); |
TMBOY | 47:9e361da97763 | 209 | |
TMBOY | 47:9e361da97763 | 210 | ret = rda5981_flash_write_3rdparter_data(buf, len); |
TMBOY | 47:9e361da97763 | 211 | |
TMBOY | 47:9e361da97763 | 212 | if (ret < 0) { |
TMBOY | 47:9e361da97763 | 213 | printf("write flash error, error %d\r\n", ret); |
TMBOY | 47:9e361da97763 | 214 | } else { |
TMBOY | 47:9e361da97763 | 215 | printf("Data write complete\r\n"); |
TMBOY | 47:9e361da97763 | 216 | } |
TMBOY | 47:9e361da97763 | 217 | |
TMBOY | 47:9e361da97763 | 218 | free(buf); |
TMBOY | 47:9e361da97763 | 219 | return 0; |
TMBOY | 47:9e361da97763 | 220 | } |
TMBOY | 47:9e361da97763 | 221 | |
TMBOY | 47:9e361da97763 | 222 | int do_read_usedata(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 223 | |
TMBOY | 47:9e361da97763 | 224 | int len = 0, ret = -1; |
TMBOY | 47:9e361da97763 | 225 | unsigned char* buf; |
TMBOY | 47:9e361da97763 | 226 | |
TMBOY | 47:9e361da97763 | 227 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 228 | return 0; |
TMBOY | 47:9e361da97763 | 229 | } |
TMBOY | 47:9e361da97763 | 230 | |
TMBOY | 47:9e361da97763 | 231 | if (argc != 1) { |
TMBOY | 47:9e361da97763 | 232 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 233 | return -1; |
TMBOY | 47:9e361da97763 | 234 | } |
TMBOY | 47:9e361da97763 | 235 | |
TMBOY | 47:9e361da97763 | 236 | len = rda5981_flash_read_3rdparter_data_length(); |
TMBOY | 47:9e361da97763 | 237 | |
TMBOY | 47:9e361da97763 | 238 | if (len < 0) { |
TMBOY | 47:9e361da97763 | 239 | printf("No user data in flah\r\n"); |
TMBOY | 47:9e361da97763 | 240 | return -1; |
TMBOY | 47:9e361da97763 | 241 | } |
TMBOY | 47:9e361da97763 | 242 | |
TMBOY | 47:9e361da97763 | 243 | buf = (unsigned char*)malloc(len + 1); |
TMBOY | 47:9e361da97763 | 244 | memset(buf, 0, len + 1); |
TMBOY | 47:9e361da97763 | 245 | |
TMBOY | 47:9e361da97763 | 246 | ret = rda5981_flash_read_3rdparter_data(buf, len); |
TMBOY | 47:9e361da97763 | 247 | |
TMBOY | 47:9e361da97763 | 248 | if (ret < 0) { |
TMBOY | 47:9e361da97763 | 249 | printf("read flash error, error %d\r\n", ret); |
TMBOY | 47:9e361da97763 | 250 | } else { |
TMBOY | 47:9e361da97763 | 251 | printf("Data read complete, len:%d\r\n", ret); |
TMBOY | 47:9e361da97763 | 252 | } |
TMBOY | 47:9e361da97763 | 253 | |
TMBOY | 47:9e361da97763 | 254 | buf[len] = 0; |
TMBOY | 47:9e361da97763 | 255 | console_puts((char*)buf); |
TMBOY | 47:9e361da97763 | 256 | printf("\n"); |
TMBOY | 47:9e361da97763 | 257 | free(buf); |
TMBOY | 47:9e361da97763 | 258 | return 0; |
TMBOY | 47:9e361da97763 | 259 | } |
TMBOY | 47:9e361da97763 | 260 | |
TMBOY | 47:9e361da97763 | 261 | int do_reset(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 262 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 263 | return 0; |
TMBOY | 47:9e361da97763 | 264 | } |
TMBOY | 47:9e361da97763 | 265 | |
TMBOY | 47:9e361da97763 | 266 | if (argc < 1) { |
TMBOY | 47:9e361da97763 | 267 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 268 | return -1; |
TMBOY | 47:9e361da97763 | 269 | } |
TMBOY | 47:9e361da97763 | 270 | |
TMBOY | 47:9e361da97763 | 271 | printf("SOFTWARE RESET!!!!\r\n"); |
TMBOY | 47:9e361da97763 | 272 | rda_wdt_softreset(); |
TMBOY | 47:9e361da97763 | 273 | return 0; |
TMBOY | 47:9e361da97763 | 274 | |
TMBOY | 47:9e361da97763 | 275 | } |
TMBOY | 47:9e361da97763 | 276 | |
TMBOY | 47:9e361da97763 | 277 | int do_conn(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 278 | char* ssid_t, *pw_t; |
TMBOY | 47:9e361da97763 | 279 | const char* ip_addr; |
TMBOY | 47:9e361da97763 | 280 | char ssid[20]; |
TMBOY | 47:9e361da97763 | 281 | char pw[20]; |
TMBOY | 47:9e361da97763 | 282 | |
TMBOY | 47:9e361da97763 | 283 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 284 | return 0; |
TMBOY | 47:9e361da97763 | 285 | } |
TMBOY | 47:9e361da97763 | 286 | |
TMBOY | 47:9e361da97763 | 287 | if (conn_flag == 1) { |
TMBOY | 47:9e361da97763 | 288 | printf("error! Has been connected!"); |
TMBOY | 47:9e361da97763 | 289 | return -1; |
TMBOY | 47:9e361da97763 | 290 | } |
TMBOY | 47:9e361da97763 | 291 | |
TMBOY | 47:9e361da97763 | 292 | printf("OK, start connect\r\n"); |
TMBOY | 47:9e361da97763 | 293 | |
TMBOY | 47:9e361da97763 | 294 | if (argc < 1) { |
TMBOY | 47:9e361da97763 | 295 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 296 | return -1; |
TMBOY | 47:9e361da97763 | 297 | } |
TMBOY | 47:9e361da97763 | 298 | |
TMBOY | 47:9e361da97763 | 299 | memset(ssid, 0, sizeof(ssid)); |
TMBOY | 47:9e361da97763 | 300 | memset(pw, 0, sizeof(pw)); |
TMBOY | 47:9e361da97763 | 301 | |
TMBOY | 47:9e361da97763 | 302 | if (argc > 1) { |
TMBOY | 47:9e361da97763 | 303 | memcpy(ssid, argv[1], strlen(argv[1])); |
TMBOY | 47:9e361da97763 | 304 | } |
TMBOY | 47:9e361da97763 | 305 | |
TMBOY | 47:9e361da97763 | 306 | if (argc > 2) { |
TMBOY | 47:9e361da97763 | 307 | memcpy(pw, argv[2], strlen(argv[2])); |
TMBOY | 47:9e361da97763 | 308 | } |
TMBOY | 47:9e361da97763 | 309 | |
TMBOY | 47:9e361da97763 | 310 | if (strlen(ssid) != 0) { |
TMBOY | 47:9e361da97763 | 311 | ssid_t = ssid; |
TMBOY | 47:9e361da97763 | 312 | } else { |
TMBOY | 47:9e361da97763 | 313 | ssid_t = NULL; |
TMBOY | 47:9e361da97763 | 314 | } |
TMBOY | 47:9e361da97763 | 315 | |
TMBOY | 47:9e361da97763 | 316 | if (strlen(pw) != 0) { |
TMBOY | 47:9e361da97763 | 317 | pw_t = pw; |
TMBOY | 47:9e361da97763 | 318 | } else { |
TMBOY | 47:9e361da97763 | 319 | pw_t = NULL; |
TMBOY | 47:9e361da97763 | 320 | } |
TMBOY | 47:9e361da97763 | 321 | |
TMBOY | 47:9e361da97763 | 322 | printf("ssid %s pw %s\r\n", ssid_t, pw_t); |
TMBOY | 47:9e361da97763 | 323 | |
TMBOY | 47:9e361da97763 | 324 | wifi.connect(ssid_t, pw_t, NSAPI_SECURITY_NONE); |
TMBOY | 47:9e361da97763 | 325 | |
TMBOY | 47:9e361da97763 | 326 | while (!wifi.get_ip_address()); |
TMBOY | 47:9e361da97763 | 327 | |
TMBOY | 47:9e361da97763 | 328 | ip_addr = wifi.get_ip_address(); |
TMBOY | 47:9e361da97763 | 329 | |
TMBOY | 47:9e361da97763 | 330 | if (ip_addr) { |
TMBOY | 47:9e361da97763 | 331 | printf("Client IP Address is %s\r\n", ip_addr); |
TMBOY | 47:9e361da97763 | 332 | } else { |
TMBOY | 47:9e361da97763 | 333 | printf("No Client IP Address\r\n"); |
TMBOY | 47:9e361da97763 | 334 | } |
TMBOY | 47:9e361da97763 | 335 | |
TMBOY | 47:9e361da97763 | 336 | conn_flag = 1; |
TMBOY | 47:9e361da97763 | 337 | //rda5981_flash_write_smartconfig_data(); |
TMBOY | 47:9e361da97763 | 338 | return 0; |
TMBOY | 47:9e361da97763 | 339 | } |
TMBOY | 47:9e361da97763 | 340 | |
TMBOY | 47:9e361da97763 | 341 | int do_disconn(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 342 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 343 | return 0; |
TMBOY | 47:9e361da97763 | 344 | } |
TMBOY | 47:9e361da97763 | 345 | |
TMBOY | 47:9e361da97763 | 346 | if (argc < 1) { |
TMBOY | 47:9e361da97763 | 347 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 348 | return -1; |
TMBOY | 47:9e361da97763 | 349 | } |
TMBOY | 47:9e361da97763 | 350 | |
TMBOY | 47:9e361da97763 | 351 | if (conn_flag == 0) { |
TMBOY | 47:9e361da97763 | 352 | printf("Not connectted!\r\n"); |
TMBOY | 47:9e361da97763 | 353 | return 0; |
TMBOY | 47:9e361da97763 | 354 | } |
TMBOY | 47:9e361da97763 | 355 | |
TMBOY | 47:9e361da97763 | 356 | wifi.disconnect(); |
TMBOY | 47:9e361da97763 | 357 | |
TMBOY | 47:9e361da97763 | 358 | while (wifi.get_ip_address() != NULL) { |
TMBOY | 47:9e361da97763 | 359 | Thread::wait(20); |
TMBOY | 47:9e361da97763 | 360 | } |
TMBOY | 47:9e361da97763 | 361 | |
TMBOY | 47:9e361da97763 | 362 | conn_flag = 0; |
TMBOY | 47:9e361da97763 | 363 | //printf("OK, Disconnect successful\r\n"); |
TMBOY | 47:9e361da97763 | 364 | return 0; |
TMBOY | 47:9e361da97763 | 365 | } |
TMBOY | 47:9e361da97763 | 366 | |
TMBOY | 47:9e361da97763 | 367 | int do_set_baud(cmd_tbl_t* cmd, int argc, char* argv[]) { |
TMBOY | 47:9e361da97763 | 368 | unsigned int baudrate; |
TMBOY | 47:9e361da97763 | 369 | |
TMBOY | 47:9e361da97763 | 370 | if (op_mode != 1) { |
TMBOY | 47:9e361da97763 | 371 | return 0; |
TMBOY | 47:9e361da97763 | 372 | } |
TMBOY | 47:9e361da97763 | 373 | |
TMBOY | 47:9e361da97763 | 374 | if (argc < 2) { |
TMBOY | 47:9e361da97763 | 375 | show_cmd_usage(cmd); |
TMBOY | 47:9e361da97763 | 376 | return -1; |
TMBOY | 47:9e361da97763 | 377 | } |
TMBOY | 47:9e361da97763 | 378 | |
TMBOY | 47:9e361da97763 | 379 | printf("OK, do set baud\r\n"); |
TMBOY | 47:9e361da97763 | 380 | baudrate = atoi(argv[1]); |
TMBOY | 47:9e361da97763 | 381 | console_set_baudrate(baudrate); |
TMBOY | 47:9e361da97763 | 382 | |
TMBOY | 47:9e361da97763 | 383 | return 0; |
TMBOY | 47:9e361da97763 | 384 | } |
TMBOY | 47:9e361da97763 | 385 | |
TMBOY | 47:9e361da97763 | 386 | void add_cmd() { |
TMBOY | 47:9e361da97763 | 387 | int i; |
TMBOY | 47:9e361da97763 | 388 | cmd_tbl_t cmd_list[] = { |
TMBOY | 47:9e361da97763 | 389 | { |
TMBOY | 47:9e361da97763 | 390 | "reset", 1, do_reset, |
TMBOY | 47:9e361da97763 | 391 | "reset - Software Reset\n" |
TMBOY | 47:9e361da97763 | 392 | }, |
TMBOY | 47:9e361da97763 | 393 | { |
TMBOY | 47:9e361da97763 | 394 | "conn", 3, do_conn, |
TMBOY | 47:9e361da97763 | 395 | "conn - start connect\n" |
TMBOY | 47:9e361da97763 | 396 | }, |
TMBOY | 47:9e361da97763 | 397 | { |
TMBOY | 47:9e361da97763 | 398 | "setbaud", 2, do_set_baud, |
TMBOY | 47:9e361da97763 | 399 | "setbaud - set serial baudrate\n" |
TMBOY | 47:9e361da97763 | 400 | }, |
TMBOY | 47:9e361da97763 | 401 | { |
TMBOY | 47:9e361da97763 | 402 | "connstate", 1, do_conn_state, |
TMBOY | 47:9e361da97763 | 403 | "connstate - get conn state\n" |
TMBOY | 47:9e361da97763 | 404 | }, |
TMBOY | 47:9e361da97763 | 405 | { |
TMBOY | 47:9e361da97763 | 406 | "setmac", 2, do_set_mac, |
TMBOY | 47:9e361da97763 | 407 | "setmac - set mac address\n" |
TMBOY | 47:9e361da97763 | 408 | }, |
TMBOY | 47:9e361da97763 | 409 | { |
TMBOY | 47:9e361da97763 | 410 | "getmac", 1, do_get_mac, |
TMBOY | 47:9e361da97763 | 411 | "getmac - get mac address\n" |
TMBOY | 47:9e361da97763 | 412 | }, |
TMBOY | 47:9e361da97763 | 413 | { |
TMBOY | 47:9e361da97763 | 414 | "getver", 1, do_get_ver, |
TMBOY | 47:9e361da97763 | 415 | "getver - get version\n" |
TMBOY | 47:9e361da97763 | 416 | }, |
TMBOY | 47:9e361da97763 | 417 | { |
TMBOY | 47:9e361da97763 | 418 | "getver5856", 1, do_get_ver_5856, |
TMBOY | 47:9e361da97763 | 419 | "getver5856 - get 5856 version\n" |
TMBOY | 47:9e361da97763 | 420 | }, |
TMBOY | 47:9e361da97763 | 421 | { |
TMBOY | 47:9e361da97763 | 422 | "ftest5856", 1, do_factory_test_5856, |
TMBOY | 47:9e361da97763 | 423 | "ftest5856 - 5856 factory test\n" |
TMBOY | 47:9e361da97763 | 424 | }, |
TMBOY | 47:9e361da97763 | 425 | { |
TMBOY | 47:9e361da97763 | 426 | "disconn", 1, do_disconn, |
TMBOY | 47:9e361da97763 | 427 | "disconn - start disconnect\n" |
TMBOY | 47:9e361da97763 | 428 | }, |
TMBOY | 47:9e361da97763 | 429 | { |
TMBOY | 47:9e361da97763 | 430 | "wuserdata", 2, do_write_usedata, |
TMBOY | 47:9e361da97763 | 431 | "wusedate - write user data\n" |
TMBOY | 47:9e361da97763 | 432 | }, |
TMBOY | 47:9e361da97763 | 433 | { |
TMBOY | 47:9e361da97763 | 434 | "ruserdata", 1, do_read_usedata, |
TMBOY | 47:9e361da97763 | 435 | "ruserdate - read user data\n" |
TMBOY | 47:9e361da97763 | 436 | }, |
TMBOY | 47:9e361da97763 | 437 | }; |
TMBOY | 47:9e361da97763 | 438 | i = sizeof(cmd_list) / sizeof(cmd_tbl_t); |
TMBOY | 47:9e361da97763 | 439 | |
TMBOY | 47:9e361da97763 | 440 | while (i--) { |
TMBOY | 47:9e361da97763 | 441 | if (0 != console_cmd_add(&cmd_list[i])) { |
TMBOY | 47:9e361da97763 | 442 | printf("Add cmd failed\r\n"); |
TMBOY | 47:9e361da97763 | 443 | } |
TMBOY | 47:9e361da97763 | 444 | } |
TMBOY | 47:9e361da97763 | 445 | } |
TMBOY | 47:9e361da97763 | 446 | |
TMBOY | 47:9e361da97763 | 447 | int factory_test() { |
TMBOY | 47:9e361da97763 | 448 | unsigned int flag = (*((volatile unsigned int*)(0x40001024UL))); |
TMBOY | 47:9e361da97763 | 449 | |
TMBOY | 47:9e361da97763 | 450 | //printf("flag = %x\r\n", flag); |
TMBOY | 47:9e361da97763 | 451 | if ((flag & (0x01UL << 29)) == 0) { |
TMBOY | 47:9e361da97763 | 452 | return 0; |
TMBOY | 47:9e361da97763 | 453 | } |
TMBOY | 47:9e361da97763 | 454 | |
TMBOY | 47:9e361da97763 | 455 | op_mode = 1; |
TMBOY | 47:9e361da97763 | 456 | console_init(); |
TMBOY | 47:9e361da97763 | 457 | add_cmd(); |
TMBOY | 47:9e361da97763 | 458 | |
TMBOY | 47:9e361da97763 | 459 | while (1); |
TMBOY | 47:9e361da97763 | 460 | |
TMBOY | 47:9e361da97763 | 461 | //return 0; |
TMBOY | 47:9e361da97763 | 462 | } |
TMBOY | 47:9e361da97763 | 463 | #endif |