Okundu Omeni
/
wifi-https-ble-sm-uart-atcmd-5-13-1
this is using the mbed os version 5-13-1
source/ATCmdManager.cpp@75:08eff6258e1b, 2019-03-14 (annotated)
- Committer:
- ocomeni
- Date:
- Thu Mar 14 21:34:06 2019 +0000
- Revision:
- 75:08eff6258e1b
- Parent:
- 74:f26e846adfe9
- Child:
- 78:07bb86e3ce14
Ble Security example now working!
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ocomeni | 74:f26e846adfe9 | 1 | #include "ATCmdManager.h" |
ocomeni | 74:f26e846adfe9 | 2 | #include "common_config.h" |
ocomeni | 74:f26e846adfe9 | 3 | |
ocomeni | 74:f26e846adfe9 | 4 | ATCmdManager::ATCmdManager(PinName tx, PinName rx, bool debug) |
ocomeni | 74:f26e846adfe9 | 5 | : |
ocomeni | 74:f26e846adfe9 | 6 | _serial(tx, rx, DEFAULT_BAUD_RATE), |
ocomeni | 74:f26e846adfe9 | 7 | _parser(&_serial) |
ocomeni | 74:f26e846adfe9 | 8 | |
ocomeni | 74:f26e846adfe9 | 9 | { |
ocomeni | 74:f26e846adfe9 | 10 | // constructor |
ocomeni | 74:f26e846adfe9 | 11 | _serial.set_baud(DEFAULT_BAUD_RATE); |
ocomeni | 74:f26e846adfe9 | 12 | _parser.debug_on(debug); |
ocomeni | 74:f26e846adfe9 | 13 | _parser.set_delimiter("\r\n"); |
ocomeni | 75:08eff6258e1b | 14 | _parser.send("+STARTUP"); |
ocomeni | 75:08eff6258e1b | 15 | _parser.oob("ATE0", callback(this, &ATCmdManager::_oob_echo_off)); |
ocomeni | 75:08eff6258e1b | 16 | _parser.oob("ATE1", callback(this, &ATCmdManager::_oob_echo_on)); |
ocomeni | 75:08eff6258e1b | 17 | _parser.oob("AT+UMRS", callback(this, &ATCmdManager::_oob_uart_setup)); |
ocomeni | 75:08eff6258e1b | 18 | |
ocomeni | 75:08eff6258e1b | 19 | _parser.oob("ATO", callback(this, &ATCmdManager::_oob_data_mode)); |
ocomeni | 75:08eff6258e1b | 20 | _parser.oob("AT+UMLA", callback(this, &ATCmdManager::_oob_get_mac_addr)); |
ocomeni | 75:08eff6258e1b | 21 | _parser.oob("AT+UBTLE?", callback(this, &ATCmdManager::_oob_get_ble_role)); |
ocomeni | 75:08eff6258e1b | 22 | _parser.oob("AT+UBTLE=2", callback(this, &ATCmdManager::_oob_ena_ble_peri)); |
ocomeni | 75:08eff6258e1b | 23 | _parser.oob("AT+CPWROFF", callback(this, &ATCmdManager::_oob_reboot)); |
ocomeni | 75:08eff6258e1b | 24 | _parser.oob("AT+CGMR", callback(this, &ATCmdManager::_oob_get_fw_ver)); |
ocomeni | 75:08eff6258e1b | 25 | |
ocomeni | 75:08eff6258e1b | 26 | |
ocomeni | 75:08eff6258e1b | 27 | //_parser.oob("ATE0", callback(this, &ATCmdManager::_oob_startup_hdlr)); |
ocomeni | 74:f26e846adfe9 | 28 | printf("\n --- ATCmdManager constructor completed ---\n"); |
ocomeni | 75:08eff6258e1b | 29 | |
ocomeni | 75:08eff6258e1b | 30 | //AT+UMRS=230400,2,8,1,1,1 |
ocomeni | 74:f26e846adfe9 | 31 | // AT+UBTLE |
ocomeni | 74:f26e846adfe9 | 32 | } |
ocomeni | 74:f26e846adfe9 | 33 | |
ocomeni | 74:f26e846adfe9 | 34 | |
ocomeni | 74:f26e846adfe9 | 35 | void ATCmdManager::runMain(){ |
ocomeni | 74:f26e846adfe9 | 36 | while(true){ |
ocomeni | 74:f26e846adfe9 | 37 | _process_oob(UBLOX_ODIN_W2_RECV_TIMEOUT, true); |
ocomeni | 74:f26e846adfe9 | 38 | wait_ms(MAIN_LOOP_WAIT_TIME_MS); // allow BTLE to be |
ocomeni | 74:f26e846adfe9 | 39 | } |
ocomeni | 74:f26e846adfe9 | 40 | |
ocomeni | 74:f26e846adfe9 | 41 | } |
ocomeni | 74:f26e846adfe9 | 42 | |
ocomeni | 74:f26e846adfe9 | 43 | |
ocomeni | 74:f26e846adfe9 | 44 | // OOB processing |
ocomeni | 74:f26e846adfe9 | 45 | void ATCmdManager::_process_oob(uint32_t timeout, bool all){ |
ocomeni | 74:f26e846adfe9 | 46 | set_timeout(timeout); |
ocomeni | 74:f26e846adfe9 | 47 | // Poll for inbound packets |
ocomeni | 74:f26e846adfe9 | 48 | while (_parser.process_oob() && all) { |
ocomeni | 74:f26e846adfe9 | 49 | } |
ocomeni | 74:f26e846adfe9 | 50 | set_timeout(); |
ocomeni | 74:f26e846adfe9 | 51 | } |
ocomeni | 74:f26e846adfe9 | 52 | |
ocomeni | 74:f26e846adfe9 | 53 | |
ocomeni | 74:f26e846adfe9 | 54 | // OOB message handlers |
ocomeni | 74:f26e846adfe9 | 55 | void ATCmdManager::_oob_startup_hdlr(){ |
ocomeni | 74:f26e846adfe9 | 56 | } |
ocomeni | 74:f26e846adfe9 | 57 | |
ocomeni | 74:f26e846adfe9 | 58 | |
ocomeni | 74:f26e846adfe9 | 59 | void ATCmdManager::_oob_bleRole_hdlr(){ |
ocomeni | 74:f26e846adfe9 | 60 | } |
ocomeni | 74:f26e846adfe9 | 61 | |
ocomeni | 74:f26e846adfe9 | 62 | |
ocomeni | 74:f26e846adfe9 | 63 | void ATCmdManager::_oob_wifiMode_err(){ |
ocomeni | 74:f26e846adfe9 | 64 | } |
ocomeni | 74:f26e846adfe9 | 65 | |
ocomeni | 74:f26e846adfe9 | 66 | |
ocomeni | 74:f26e846adfe9 | 67 | void ATCmdManager::_oob_conn_already(){ |
ocomeni | 74:f26e846adfe9 | 68 | } |
ocomeni | 74:f26e846adfe9 | 69 | |
ocomeni | 74:f26e846adfe9 | 70 | |
ocomeni | 74:f26e846adfe9 | 71 | void ATCmdManager::_oob_err(){ |
ocomeni | 74:f26e846adfe9 | 72 | } |
ocomeni | 74:f26e846adfe9 | 73 | |
ocomeni | 75:08eff6258e1b | 74 | void ATCmdManager::_oob_uart_setup(){ |
ocomeni | 75:08eff6258e1b | 75 | int uOpts[NUM_UART_OPTIONS]; |
ocomeni | 75:08eff6258e1b | 76 | //if(_parser.recv("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5])) { |
ocomeni | 75:08eff6258e1b | 77 | if(_parser.scanf("=%d,%d,%d,%d,%d,%d", &uOpts[0], &uOpts[1], &uOpts[2], &uOpts[3], &uOpts[4], &uOpts[5]) >0) { |
ocomeni | 75:08eff6258e1b | 78 | printf("\nATCmdParser: Uart Options=%d,%d,%d,%d,%d,%d\n", uOpts[0], uOpts[1], uOpts[2], uOpts[3], uOpts[4], uOpts[5]); |
ocomeni | 75:08eff6258e1b | 79 | } else { |
ocomeni | 75:08eff6258e1b | 80 | printf("\nATCmdParser: Retrieving Uart Options failed"); |
ocomeni | 75:08eff6258e1b | 81 | } |
ocomeni | 75:08eff6258e1b | 82 | } |
ocomeni | 75:08eff6258e1b | 83 | |
ocomeni | 74:f26e846adfe9 | 84 | void ATCmdManager::set_timeout(uint32_t timeout_ms) |
ocomeni | 74:f26e846adfe9 | 85 | { |
ocomeni | 74:f26e846adfe9 | 86 | _parser.set_timeout(timeout_ms); |
ocomeni | 74:f26e846adfe9 | 87 | } |
ocomeni | 74:f26e846adfe9 | 88 | |
ocomeni | 75:08eff6258e1b | 89 | |
ocomeni | 75:08eff6258e1b | 90 | void ATCmdManager::_oob_echo_off() |
ocomeni | 75:08eff6258e1b | 91 | { |
ocomeni | 75:08eff6258e1b | 92 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 93 | printf("\n Received ATEO OOB command!!\n"); |
ocomeni | 75:08eff6258e1b | 94 | printf("\n turning echo OFF!!\n"); |
ocomeni | 75:08eff6258e1b | 95 | _parser.debug_on(false); |
ocomeni | 75:08eff6258e1b | 96 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 97 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 98 | } |
ocomeni | 75:08eff6258e1b | 99 | |
ocomeni | 75:08eff6258e1b | 100 | |
ocomeni | 75:08eff6258e1b | 101 | void ATCmdManager::_oob_echo_on() |
ocomeni | 75:08eff6258e1b | 102 | { |
ocomeni | 75:08eff6258e1b | 103 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 104 | printf("\n Received ATE1 OOB command!!\n"); |
ocomeni | 75:08eff6258e1b | 105 | printf("\n turning echo ON!!\n"); |
ocomeni | 75:08eff6258e1b | 106 | _parser.debug_on(true); |
ocomeni | 75:08eff6258e1b | 107 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 108 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 109 | } |
ocomeni | 75:08eff6258e1b | 110 | |
ocomeni | 75:08eff6258e1b | 111 | |
ocomeni | 75:08eff6258e1b | 112 | void ATCmdManager::_oob_data_mode(){ |
ocomeni | 75:08eff6258e1b | 113 | int dataMode; |
ocomeni | 75:08eff6258e1b | 114 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 115 | printf("\n Received EDM mode command!!\n"); |
ocomeni | 75:08eff6258e1b | 116 | if(_parser.scanf("%d", &dataMode) >0) { |
ocomeni | 75:08eff6258e1b | 117 | printf("\nATCmdParser: Data mode=%d\n", dataMode); |
ocomeni | 75:08eff6258e1b | 118 | switch(dataMode) |
ocomeni | 75:08eff6258e1b | 119 | { |
ocomeni | 75:08eff6258e1b | 120 | case 0: |
ocomeni | 75:08eff6258e1b | 121 | printf("\nATCmdParser: Command Mode request received"); |
ocomeni | 75:08eff6258e1b | 122 | break; |
ocomeni | 75:08eff6258e1b | 123 | case 1: |
ocomeni | 75:08eff6258e1b | 124 | printf("\nATCmdParser: Data Mode request received"); |
ocomeni | 75:08eff6258e1b | 125 | break; |
ocomeni | 75:08eff6258e1b | 126 | case 2: |
ocomeni | 75:08eff6258e1b | 127 | printf("\nATCmdParser: Extended data Mode request received"); |
ocomeni | 75:08eff6258e1b | 128 | break; |
ocomeni | 75:08eff6258e1b | 129 | default: |
ocomeni | 75:08eff6258e1b | 130 | printf("\nATCmdParser: ERROR - UNKNOWN DATA MODE RECEIVED!!! \n"); |
ocomeni | 75:08eff6258e1b | 131 | break; |
ocomeni | 75:08eff6258e1b | 132 | } |
ocomeni | 75:08eff6258e1b | 133 | } else { |
ocomeni | 75:08eff6258e1b | 134 | printf("\nATCmdParser: Retrieving Uart Options failed"); |
ocomeni | 75:08eff6258e1b | 135 | } |
ocomeni | 75:08eff6258e1b | 136 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 137 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 138 | } |
ocomeni | 75:08eff6258e1b | 139 | |
ocomeni | 75:08eff6258e1b | 140 | void ATCmdManager::_oob_get_mac_addr(){ |
ocomeni | 75:08eff6258e1b | 141 | int bleOrWifi; |
ocomeni | 75:08eff6258e1b | 142 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 143 | if(_parser.scanf("=%d", &bleOrWifi) >0) { |
ocomeni | 75:08eff6258e1b | 144 | switch(bleOrWifi) |
ocomeni | 75:08eff6258e1b | 145 | { |
ocomeni | 75:08eff6258e1b | 146 | case 1: |
ocomeni | 75:08eff6258e1b | 147 | printf("\nATCmdParser: BLE MAC Address request received"); |
ocomeni | 75:08eff6258e1b | 148 | break; |
ocomeni | 75:08eff6258e1b | 149 | case 2: |
ocomeni | 75:08eff6258e1b | 150 | printf("\nATCmdParser: WiFi MAC Address request received"); |
ocomeni | 75:08eff6258e1b | 151 | break; |
ocomeni | 75:08eff6258e1b | 152 | default: |
ocomeni | 75:08eff6258e1b | 153 | printf("\nATCmdParser: ERROR - UNKNOWN MAC ADDRESS REQUEST RECEIVED!!! \n"); |
ocomeni | 75:08eff6258e1b | 154 | break; |
ocomeni | 75:08eff6258e1b | 155 | } |
ocomeni | 75:08eff6258e1b | 156 | } else { |
ocomeni | 75:08eff6258e1b | 157 | printf("\nATCmdParser: Retrieving Uart Options failed"); |
ocomeni | 75:08eff6258e1b | 158 | } |
ocomeni | 75:08eff6258e1b | 159 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 160 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 161 | } |
ocomeni | 75:08eff6258e1b | 162 | |
ocomeni | 75:08eff6258e1b | 163 | void ATCmdManager::_oob_get_ble_role(){ |
ocomeni | 75:08eff6258e1b | 164 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 165 | printf("\n Received get BLE role command!!\n"); |
ocomeni | 75:08eff6258e1b | 166 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 167 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 168 | } |
ocomeni | 75:08eff6258e1b | 169 | |
ocomeni | 75:08eff6258e1b | 170 | void ATCmdManager::_oob_ena_ble_peri(){ |
ocomeni | 75:08eff6258e1b | 171 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 172 | printf("\n Received enable BLE Peripheral command!!\n"); |
ocomeni | 75:08eff6258e1b | 173 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 174 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 175 | } |
ocomeni | 75:08eff6258e1b | 176 | |
ocomeni | 75:08eff6258e1b | 177 | void ATCmdManager::_oob_reboot(){ |
ocomeni | 75:08eff6258e1b | 178 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 179 | printf("\n Received reboot command!!\n"); |
ocomeni | 75:08eff6258e1b | 180 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 181 | _parser.send("System Resetting....\n"); |
ocomeni | 75:08eff6258e1b | 182 | system_reset(); |
ocomeni | 75:08eff6258e1b | 183 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 184 | } |
ocomeni | 75:08eff6258e1b | 185 | |
ocomeni | 75:08eff6258e1b | 186 | void ATCmdManager::_oob_get_fw_ver(){ |
ocomeni | 75:08eff6258e1b | 187 | _smutex.lock(); |
ocomeni | 75:08eff6258e1b | 188 | printf("\n Received Firmware Version command!!\n"); |
ocomeni | 75:08eff6258e1b | 189 | _parser.send("OK\n"); |
ocomeni | 75:08eff6258e1b | 190 | _smutex.unlock(); |
ocomeni | 75:08eff6258e1b | 191 | } |
ocomeni | 75:08eff6258e1b | 192 |