Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-os-example-mbed5-blinky by
factory_test.cpp
00001 #if defined(TARGET_UNO_91H) 00002 #include "mbed.h" 00003 #include "rtos.h" 00004 #include "console.h" 00005 #include "WiFiStackInterface.h" 00006 #include "rda_wdt_api.h" 00007 #include "rda_ccfg_api.h" 00008 #include "cmsis_os.h" 00009 #include "rda_wdt_api.h" 00010 #include "Rda58xx.h" 00011 00012 static char* version = "**********RDA Software Version sta_V2.0_124**********"; 00013 static int op_mode = 0;//initial ~ 0 factory test ~ 1 function ~ 2 00014 static char conn_flag = 0; 00015 static WiFiStackInterface wifi; 00016 extern unsigned char rda_mac_addr[6]; 00017 extern rda58xx _rda58xx; 00018 00019 int do_conn_state(cmd_tbl_t* cmd, int argc, char* argv[]) { 00020 if (op_mode != 1) { 00021 return 0; 00022 } 00023 00024 if (argc < 1) { 00025 show_cmd_usage(cmd); 00026 return -1; 00027 } 00028 00029 #if 1 00030 const char* ssid; 00031 ssid = wifi.get_ssid(); 00032 00033 if (ssid[0]) { 00034 printf("CONNECTED! ssid:%s RSSI:%d db ip:%s\r\n", wifi.get_ssid(), wifi.get_rssi(), 00035 wifi.get_ip_address()); 00036 } else { 00037 printf("NOT CONNECTED!\r\n"); 00038 } 00039 00040 #else 00041 00042 if (wifi.bss.SSID[0]) { 00043 printf("CONNECTED! ssid:%s RSSI:%d db\r\n", wifi.bss.SSID, wifi.bss.SSID); 00044 } else { 00045 printf("NOT CONNECTED!\r\n"); 00046 } 00047 00048 #endif 00049 return 0; 00050 } 00051 00052 int do_get_mac(cmd_tbl_t* cmd, int argc, char* argv[]) { 00053 if (op_mode != 1) { 00054 return 0; 00055 } 00056 00057 if (argc < 1) { 00058 show_cmd_usage(cmd); 00059 return -1; 00060 } 00061 00062 char mac[6]; 00063 mbed_mac_address(mac); 00064 printf("MAC address: %02x:%02x:%02x:%02x:%02x:%02x\r\n", 00065 mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 00066 00067 return 0; 00068 } 00069 00070 int do_set_mac(cmd_tbl_t* cmd, int argc, char* argv[]) { 00071 char* mdata, mac[6], i; 00072 00073 if (op_mode != 1) { 00074 return 0; 00075 } 00076 00077 if (argc < 2) { 00078 show_cmd_usage(cmd); 00079 return -1; 00080 } 00081 00082 if (strlen(argv[1]) != 12) { 00083 printf("Error MAC address len\r\n"); 00084 return -2; 00085 } 00086 00087 mdata = argv[1]; 00088 00089 for (i = 0; i < 12; i++) { 00090 if (mdata[i] >= 0x41 && mdata[i] <= 0x46) { // switch 'A' to 'a' 00091 mdata[i] += 0x20; 00092 } 00093 00094 if (mdata[i] >= 0x61 && mdata[i] <= 0x66) { //switch "ab" to 0xab 00095 mac[i] = mdata[i] - 0x57; 00096 } 00097 00098 if (mdata[i] >= 0x30 && mdata[i] <= 0x39) { 00099 mac[i] = mdata[i] - 0x30; 00100 } 00101 00102 if (i % 2 == 1) { 00103 mac[i / 2] = mac[i - 1] << 4 | mac[i]; 00104 } 00105 } 00106 00107 if (!mac_is_valid(mac)) { 00108 printf("MAC is ZERO\r\n"); 00109 return 0; 00110 } 00111 00112 memcpy(rda_mac_addr, mac, 6); 00113 rda5981_flash_write_mac_addr(rda_mac_addr); 00114 return 0; 00115 } 00116 00117 int do_get_ver(cmd_tbl_t* cmd, int argc, char* argv[]) { 00118 if (op_mode != 1) { 00119 return 0; 00120 } 00121 00122 if (argc < 1) { 00123 show_cmd_usage(cmd); 00124 return -1; 00125 } 00126 00127 printf("Software Version: %s\r\n", version); 00128 return 0; 00129 } 00130 00131 int do_get_ver_5856(cmd_tbl_t* cmd, int argc, char* argv[]) { 00132 char ver[32] = {0}; 00133 rda58xx_at_status ret; 00134 00135 if (op_mode != 1) { 00136 return 0; 00137 } 00138 00139 if (argc < 1) { 00140 show_cmd_usage(cmd); 00141 return -1; 00142 } 00143 00144 printf("do_get_ver_5856\r\n"); 00145 00146 while (!_rda58xx.isPowerOn()) { 00147 Thread::wait(100); 00148 } 00149 00150 ret = _rda58xx.getChipVersion(ver); 00151 00152 if (VACK == ret) { 00153 printf("5856 Software Version: %s\r\n", ver); 00154 return 0; 00155 } else { 00156 printf("5856 Software Version: Fail!\r\n"); 00157 return -1; 00158 } 00159 } 00160 00161 int do_factory_test_5856(cmd_tbl_t* cmd, int argc, char* argv[]) { 00162 rda58xx_at_status ret; 00163 00164 if (op_mode != 1) { 00165 return 0; 00166 } 00167 00168 if (argc < 1) { 00169 show_cmd_usage(cmd); 00170 return -1; 00171 } 00172 00173 printf("do_factory_test_5856\r\n"); 00174 ret = _rda58xx.factoryTest(FT_ENABLE); 00175 00176 if (VACK == ret) { 00177 printf("5856 Factory Test: Succeed\r\n"); 00178 return 0; 00179 } else { 00180 printf("5856 Factory Test: Fail\r\n"); 00181 return -1; 00182 } 00183 } 00184 00185 00186 int do_write_usedata(cmd_tbl_t* cmd, int argc, char* argv[]) { 00187 00188 int len, ret, tmp_len = 0; 00189 unsigned char* buf; 00190 00191 if (op_mode != 1) { 00192 return 0; 00193 } 00194 00195 if (argc < 2) { 00196 show_cmd_usage(cmd); 00197 return -1; 00198 } 00199 00200 len = atoi(argv[1]); 00201 buf = (unsigned char*)malloc(len); 00202 memset(buf, 0, len); 00203 00204 do { 00205 unsigned int size; 00206 size = console_fifo_get(buf + tmp_len, len - tmp_len); 00207 tmp_len += size; 00208 } while (tmp_len < len); 00209 00210 ret = rda5981_flash_write_3rdparter_data(buf, len); 00211 00212 if (ret < 0) { 00213 printf("write flash error, error %d\r\n", ret); 00214 } else { 00215 printf("Data write complete\r\n"); 00216 } 00217 00218 free(buf); 00219 return 0; 00220 } 00221 00222 int do_read_usedata(cmd_tbl_t* cmd, int argc, char* argv[]) { 00223 00224 int len = 0, ret = -1; 00225 unsigned char* buf; 00226 00227 if (op_mode != 1) { 00228 return 0; 00229 } 00230 00231 if (argc != 1) { 00232 show_cmd_usage(cmd); 00233 return -1; 00234 } 00235 00236 len = rda5981_flash_read_3rdparter_data_length(); 00237 00238 if (len < 0) { 00239 printf("No user data in flah\r\n"); 00240 return -1; 00241 } 00242 00243 buf = (unsigned char*)malloc(len + 1); 00244 memset(buf, 0, len + 1); 00245 00246 ret = rda5981_flash_read_3rdparter_data(buf, len); 00247 00248 if (ret < 0) { 00249 printf("read flash error, error %d\r\n", ret); 00250 } else { 00251 printf("Data read complete, len:%d\r\n", ret); 00252 } 00253 00254 buf[len] = 0; 00255 console_puts((char*)buf); 00256 printf("\n"); 00257 free(buf); 00258 return 0; 00259 } 00260 00261 int do_reset(cmd_tbl_t* cmd, int argc, char* argv[]) { 00262 if (op_mode != 1) { 00263 return 0; 00264 } 00265 00266 if (argc < 1) { 00267 show_cmd_usage(cmd); 00268 return -1; 00269 } 00270 00271 printf("SOFTWARE RESET!!!!\r\n"); 00272 rda_wdt_softreset(); 00273 return 0; 00274 00275 } 00276 00277 int do_conn(cmd_tbl_t* cmd, int argc, char* argv[]) { 00278 char* ssid_t, *pw_t; 00279 const char* ip_addr; 00280 char ssid[20]; 00281 char pw[20]; 00282 00283 if (op_mode != 1) { 00284 return 0; 00285 } 00286 00287 if (conn_flag == 1) { 00288 printf("error! Has been connected!"); 00289 return -1; 00290 } 00291 00292 printf("OK, start connect\r\n"); 00293 00294 if (argc < 1) { 00295 show_cmd_usage(cmd); 00296 return -1; 00297 } 00298 00299 memset(ssid, 0, sizeof(ssid)); 00300 memset(pw, 0, sizeof(pw)); 00301 00302 if (argc > 1) { 00303 memcpy(ssid, argv[1], strlen(argv[1])); 00304 } 00305 00306 if (argc > 2) { 00307 memcpy(pw, argv[2], strlen(argv[2])); 00308 } 00309 00310 if (strlen(ssid) != 0) { 00311 ssid_t = ssid; 00312 } else { 00313 ssid_t = NULL; 00314 } 00315 00316 if (strlen(pw) != 0) { 00317 pw_t = pw; 00318 } else { 00319 pw_t = NULL; 00320 } 00321 00322 printf("ssid %s pw %s\r\n", ssid_t, pw_t); 00323 00324 wifi.connect(ssid_t, pw_t, NSAPI_SECURITY_NONE); 00325 00326 while (!wifi.get_ip_address()); 00327 00328 ip_addr = wifi.get_ip_address(); 00329 00330 if (ip_addr) { 00331 printf("Client IP Address is %s\r\n", ip_addr); 00332 } else { 00333 printf("No Client IP Address\r\n"); 00334 } 00335 00336 conn_flag = 1; 00337 //rda5981_flash_write_smartconfig_data(); 00338 return 0; 00339 } 00340 00341 int do_disconn(cmd_tbl_t* cmd, int argc, char* argv[]) { 00342 if (op_mode != 1) { 00343 return 0; 00344 } 00345 00346 if (argc < 1) { 00347 show_cmd_usage(cmd); 00348 return -1; 00349 } 00350 00351 if (conn_flag == 0) { 00352 printf("Not connectted!\r\n"); 00353 return 0; 00354 } 00355 00356 wifi.disconnect(); 00357 00358 while (wifi.get_ip_address() != NULL) { 00359 Thread::wait(20); 00360 } 00361 00362 conn_flag = 0; 00363 //printf("OK, Disconnect successful\r\n"); 00364 return 0; 00365 } 00366 00367 int do_set_baud(cmd_tbl_t* cmd, int argc, char* argv[]) { 00368 unsigned int baudrate; 00369 00370 if (op_mode != 1) { 00371 return 0; 00372 } 00373 00374 if (argc < 2) { 00375 show_cmd_usage(cmd); 00376 return -1; 00377 } 00378 00379 printf("OK, do set baud\r\n"); 00380 baudrate = atoi(argv[1]); 00381 console_set_baudrate(baudrate); 00382 00383 return 0; 00384 } 00385 00386 void add_cmd() { 00387 int i; 00388 cmd_tbl_t cmd_list[] = { 00389 { 00390 "reset", 1, do_reset, 00391 "reset - Software Reset\n" 00392 }, 00393 { 00394 "conn", 3, do_conn, 00395 "conn - start connect\n" 00396 }, 00397 { 00398 "setbaud", 2, do_set_baud, 00399 "setbaud - set serial baudrate\n" 00400 }, 00401 { 00402 "connstate", 1, do_conn_state, 00403 "connstate - get conn state\n" 00404 }, 00405 { 00406 "setmac", 2, do_set_mac, 00407 "setmac - set mac address\n" 00408 }, 00409 { 00410 "getmac", 1, do_get_mac, 00411 "getmac - get mac address\n" 00412 }, 00413 { 00414 "getver", 1, do_get_ver, 00415 "getver - get version\n" 00416 }, 00417 { 00418 "getver5856", 1, do_get_ver_5856, 00419 "getver5856 - get 5856 version\n" 00420 }, 00421 { 00422 "ftest5856", 1, do_factory_test_5856, 00423 "ftest5856 - 5856 factory test\n" 00424 }, 00425 { 00426 "disconn", 1, do_disconn, 00427 "disconn - start disconnect\n" 00428 }, 00429 { 00430 "wuserdata", 2, do_write_usedata, 00431 "wusedate - write user data\n" 00432 }, 00433 { 00434 "ruserdata", 1, do_read_usedata, 00435 "ruserdate - read user data\n" 00436 }, 00437 }; 00438 i = sizeof(cmd_list) / sizeof(cmd_tbl_t); 00439 00440 while (i--) { 00441 if (0 != console_cmd_add(&cmd_list[i])) { 00442 printf("Add cmd failed\r\n"); 00443 } 00444 } 00445 } 00446 00447 int factory_test() { 00448 unsigned int flag = (*((volatile unsigned int*)(0x40001024UL))); 00449 00450 //printf("flag = %x\r\n", flag); 00451 if ((flag & (0x01UL << 29)) == 0) { 00452 return 0; 00453 } 00454 00455 op_mode = 1; 00456 console_init(); 00457 add_cmd(); 00458 00459 while (1); 00460 00461 //return 0; 00462 } 00463 #endif
Generated on Tue Jul 12 2022 16:28:53 by
1.7.2
