this is using the mbed os version 5-13-1

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Sat Mar 16 13:05:52 2019 +0000
Revision:
78:07bb86e3ce14
Parent:
75:08eff6258e1b
Child:
79:a2187bbfa407
Main Manager class constructors and configuration structures implemented.

Who changed what in which revision?

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