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.
ATCmdManager.h
00001 #ifndef __ATCMD_MANAGER_H__ 00002 #define __ATCMD_MANAGER_H__ 00003 #include <events/mbed_events.h> 00004 #include <mbed.h> 00005 #include <vector> 00006 #include "ATCmdParser.h" 00007 #include "BleManager.h" 00008 #include "WiFiManager.h" 00009 #include "common_config.h" 00010 00011 #define NUM_UART_OPTIONS 6 00012 #ifndef UBLOX_ODIN_W2_MISC_TIMEOUT 00013 #define UBLOX_ODIN_W2_MISC_TIMEOUT 2000 00014 #endif 00015 00016 #define OK_RESP "\r\nOK\r\n" 00017 #define ERROR_RESP "\r\nERROR\r\n" 00018 #define WIFI_BUSY_RESP "\r\nWIFI BUSY\r\n" 00019 #define UART_TIMEOUT_ERROR "\r\nUART TIMEOUT ERROR\r\n" 00020 #define MEMORY_ALLOCATION_ERROR "\r\nMEMORY ALLOCATION ERROR\r\n" 00021 #define BOX_UBLOX_DEMO_TESTING 00022 //extern void print_memory_info(); 00023 //extern void blinkLEDs(); 00024 class ATCmdManager { 00025 public: 00026 ATCmdManager(PinName tx, PinName rx, uart_config_t *uart_config, 00027 events::EventQueue &event_queue, WiFiManager *wifi, 00028 MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool, 00029 Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue, 00030 MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool, 00031 Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue, 00032 MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool, 00033 Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue, 00034 MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool, 00035 Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue, 00036 MemoryPool<at_ble_msg_t, PQDSZ_BLE> *aT2BleDatamPool, 00037 Queue<at_ble_msg_t, PQDSZ_BLE> *aT2BleDataQueue, 00038 MemoryPool<ble_at_msg_t, PQDSZ_BLE> *ble2ATDatamPool, 00039 Queue<ble_at_msg_t, PQDSZ_BLE> *ble2ATDataQueue, 00040 startup_config_t *startup_config, bool debug = false); 00041 public: 00042 void runMain(); 00043 00044 00045 00046 private: 00047 // UART settings 00048 UARTSerial _serial; 00049 uart_config_t *uart_config; 00050 Mutex _smutex; // Protect serial port access 00051 Mutex _rmutex; // Reset protection 00052 // define event queue 00053 events::EventQueue &_event_queue; 00054 // AT Command Parser 00055 SMDevicePeripheral *blePeripheral; 00056 WiFiManager *wiFiManager; 00057 at_cmd_resp_t at_resp; 00058 at_data_mode_t dataMode; 00059 uint32_t lastHttpRespTime; 00060 uint8_t lastCloudMsgType; 00061 /* Queue and memory pool for AT to Wifi commands */ 00062 MemoryPool<wifi_cmd_message_t, 16> *_aT2WiFimPool; 00063 Queue<wifi_cmd_message_t, 16> *_aT2WiFiCmdQueue; 00064 00065 /* Queue and memory pool for WiFi to AT commands */ 00066 MemoryPool<at_resp_message_t, 16> *_wiFi2ATmPool; 00067 Queue<at_resp_message_t, 16> *_wiFi2ATCmdQueue; 00068 00069 /* Queue and memory pool for AT to WiFi data */ 00070 MemoryPool<wifi_data_msg_t, PQDSZ> *_aT2WiFiDatamPool; 00071 Queue<wifi_data_msg_t, PQDSZ> *_aT2WiFiDataQueue; 00072 00073 00074 /* Queue and memory pool for WiFi to AT data */ 00075 MemoryPool<at_data_msg_t, PQDSZ> *_wiFi2ATDatamPool; 00076 Queue<at_data_msg_t, PQDSZ> *_wiFi2ATDataQueue; 00077 00078 /* Queue and memory pool for AT to BLE data */ 00079 MemoryPool<at_ble_msg_t, PQDSZ_BLE> *_aT2BleDatamPool; 00080 Queue<at_ble_msg_t, PQDSZ_BLE> *_aT2BleDataQueue; 00081 00082 00083 /* Queue and memory pool for BLE to AT data */ 00084 MemoryPool<ble_at_msg_t, PQDSZ_BLE> *_ble2ATDatamPool; 00085 Queue<ble_at_msg_t, PQDSZ_BLE> *_ble2ATDataQueue; 00086 ATCmdParser _parser; 00087 00088 00089 //pointer to wifi response data - should be deleted after processing 00090 at_data_msg_t *resp_data; 00091 //pointer to ble response data - should be deleted after processing 00092 ble_at_msg_t *ble_resp_data; 00093 edm_header_t edm_hdr; 00094 uint8_t *rx_buf_ptr; 00095 startup_config_t *startup_config; 00096 int debug_flags_map; 00097 at_cmd_resp_t wifiStateControl; 00098 #ifdef BOX_UBLOX_DEMO_TESTING 00099 bool check_for_at_cmd; 00100 #endif 00101 00102 // OOB processing 00103 void _process_oob(uint32_t timeout, bool all); 00104 // OOB message handlers 00105 void _oob_startup_hdlr(); 00106 void _oob_ok_hdlr(); 00107 void _oob_bleRole_hdlr(); 00108 void _oob_enable_wifi(); 00109 void _oob_wifiMode_err(); 00110 void _oob_conn_already(); 00111 void _oob_err(); 00112 void _oob_echo_off(); 00113 void _oob_uart_setup(); 00114 void _oob_echo_on(); 00115 void _oob_debug_logs_on(); 00116 void _oob_debug_logs_off(); 00117 void _oob_set_debug_flag(); 00118 void _oob_data_mode(); 00119 void _oob_get_mac_addr(); 00120 void _oob_get_ble_role(); 00121 void _oob_ena_ble_peri(); 00122 void _oob_get_ble_name(); 00123 void _oob_reboot(); 00124 void _oob_get_fw_ver(); 00125 void _oob_saveSettings_hdlr(); 00126 void _oob_scanWiFiNetworks(); 00127 void _oob_WiFiStationConfigAction(); 00128 void _oob_disconnectWiFiNetwork(); 00129 void _oob_setupInternetConnection(); 00130 void _oob_factoryReset(); 00131 void _oob_deleteConfiguration(); 00132 void _oob_setWiFiSSID(); 00133 void _oob_setWiFiPWD(); 00134 void _oob_setWiFiSecurity(); 00135 void _oob_sendHttpMessage(); 00136 void _oob_getNetworkStatus(); 00137 void _oob_WiFiNetworkStatus(); 00138 wifi_config_t init_wifi_config(); 00139 const char * sec2str(nsapi_security_t sec); 00140 bool queueWiFiCommand(wifi_cmd_t cmd); 00141 bool dequeueATresponse(); 00142 bool queueWiFiDataRequest(wifi_data_msg_t cmd); 00143 bool dequeueWiFidataResponse(); 00144 void processResponses(); 00145 bool setNextResponse(at_cmd_resp_t resp); 00146 int ReadBytes(uint8_t *buf, int maxBytes); 00147 int readStringBytes(uint8_t *buf, int maxBytes); 00148 bool validate(edm_header_t edm_header); 00149 bool createHttpRequest(); 00150 http_method str2HttpMethod(const char * methodStr); 00151 void return_response(bool download=false); 00152 void printBufferInHex(const uint8_t *buf, int pLen); 00153 void outputEDMdata(const uint8_t *buf, int pLen, 00154 edm_msg_id_t identifier, edm_msg_type_t type, 00155 channel_id_t channel_id); 00156 00157 void sendAtConfirmation(const char *buf); 00158 void sendAtConfirmationFreeMpool(const char *buf); 00159 void sendConnectIndicationFreeMpool(const char *buf); 00160 void sendAtEvent(const char *buf); 00161 void sendConnectEvent(const uint8_t *buf, int len); 00162 int readAtCommandString(char *strbuf, size_t bufLen); 00163 void updateWiFiMgrStatus(); 00164 void sendBleDataEvent(const char *buf, int len); 00165 void sendBleAtEvent(const char *buf, int len); 00166 void sendBleConnectEvent(const char *buf, int len); 00167 void sendBleDisconnectEvent(); 00168 bool dequeueBleDataResponse(); 00169 bool queueBleDataRequest(at_ble_msg_t data_req); 00170 void filterHttpResponse(); 00171 int readEDMmodeBytes(uint8_t *rx_buf_ptr, int pLen); 00172 00173 /** 00174 * Allows timeout to be changed between commands 00175 * 00176 * @param timeout_ms timeout of the connection 00177 */ 00178 void set_timeout(uint32_t timeout_ms = UBLOX_ODIN_W2_MISC_TIMEOUT); 00179 }; 00180 #endif // __ATCMD_MANAGER_H__
Generated on Wed Jul 13 2022 05:40:26 by
1.7.2