Dependencies:   mbed-http

Committer:
ocomeni
Date:
Sat May 18 15:44:48 2019 +0000
Branch:
PassingRegression
Revision:
114:b11bb96c09f3
Parent:
108:3c8fb2c6e7bf
Child:
117:8fd05113efc1
main program refactored:; 1. only atcmd manager started by default; 2. added state in main to allow ATCMD to trigger enabling BLE and WiFi; 3. added main.h to expose trigger functions to ATCMD; 4. added triggers to ATCMD; ; Testing not yet done.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ocomeni 74:f26e846adfe9 1 #ifndef __ATCMD_MANAGER_H__
ocomeni 74:f26e846adfe9 2 #define __ATCMD_MANAGER_H__
ocomeni 79:a2187bbfa407 3 #include <events/mbed_events.h>
ocomeni 74:f26e846adfe9 4 #include <mbed.h>
ocomeni 83:9c271a50a70b 5 #include <vector>
ocomeni 74:f26e846adfe9 6 #include "ATCmdParser.h"
ocomeni 78:07bb86e3ce14 7 #include "BleManager.h"
ocomeni 78:07bb86e3ce14 8 #include "WiFiManager.h"
ocomeni 74:f26e846adfe9 9
ocomeni 75:08eff6258e1b 10 #define NUM_UART_OPTIONS 6
ocomeni 74:f26e846adfe9 11 #ifndef UBLOX_ODIN_W2_MISC_TIMEOUT
ocomeni 74:f26e846adfe9 12 #define UBLOX_ODIN_W2_MISC_TIMEOUT 2000
ocomeni 74:f26e846adfe9 13 #endif
ocomeni 74:f26e846adfe9 14
ocomeni 95:290859010c8c 15 #define OK_RESP "\r\nOK\r\n"
ocomeni 95:290859010c8c 16 #define ERROR_RESP "\r\nERROR\r\n"
ocomeni 104:11e9605093c9 17 #define WIFI_BUSY_RESP "\r\nWIFI BUSY\r\n"
ocomeni 103:7b566b522427 18 #define BOX_UBLOX_DEMO_TESTING
ocomeni 114:b11bb96c09f3 19 //extern void print_memory_info();
ocomeni 114:b11bb96c09f3 20 //extern void blinkLEDs();
ocomeni 74:f26e846adfe9 21 class ATCmdManager {
ocomeni 74:f26e846adfe9 22 public:
ocomeni 78:07bb86e3ce14 23 ATCmdManager(PinName tx, PinName rx, SMDevicePeripheral *blePeripheral,
ocomeni 79:a2187bbfa407 24 events::EventQueue &event_queue, WiFiManager *wifi,
ocomeni 79:a2187bbfa407 25 MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool,
ocomeni 79:a2187bbfa407 26 Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue,
ocomeni 81:637a87eb8170 27 MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool,
ocomeni 81:637a87eb8170 28 Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue,
ocomeni 87:99b37d26ff2a 29 MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool,
ocomeni 87:99b37d26ff2a 30 Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue,
ocomeni 87:99b37d26ff2a 31 MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool,
ocomeni 87:99b37d26ff2a 32 Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue,
ocomeni 79:a2187bbfa407 33 bool debug = false);
ocomeni 74:f26e846adfe9 34 public:
ocomeni 74:f26e846adfe9 35 void runMain();
ocomeni 74:f26e846adfe9 36
ocomeni 74:f26e846adfe9 37
ocomeni 74:f26e846adfe9 38
ocomeni 74:f26e846adfe9 39 private:
ocomeni 74:f26e846adfe9 40 // UART settings
ocomeni 74:f26e846adfe9 41 UARTSerial _serial;
ocomeni 74:f26e846adfe9 42 Mutex _smutex; // Protect serial port access
ocomeni 74:f26e846adfe9 43 Mutex _rmutex; // Reset protection
ocomeni 79:a2187bbfa407 44 // define event queue
ocomeni 79:a2187bbfa407 45 events::EventQueue &_event_queue;
ocomeni 74:f26e846adfe9 46 // AT Command Parser
ocomeni 74:f26e846adfe9 47 ATCmdParser _parser;
ocomeni 78:07bb86e3ce14 48 SMDevicePeripheral *blePeripheral;
ocomeni 79:a2187bbfa407 49 WiFiManager *wiFiManager;
ocomeni 81:637a87eb8170 50 at_cmd_resp_t at_resp;
ocomeni 81:637a87eb8170 51 at_data_mode_t dataMode;
ocomeni 80:e8f0e92e3ac9 52 /* Queue and memory pool for AT to Wifi commands */
ocomeni 79:a2187bbfa407 53 MemoryPool<wifi_cmd_message_t, 16> *_aT2WiFimPool;
ocomeni 79:a2187bbfa407 54 Queue<wifi_cmd_message_t, 16> *_aT2WiFiCmdQueue;
ocomeni 80:e8f0e92e3ac9 55
ocomeni 80:e8f0e92e3ac9 56 /* Queue and memory pool for WiFi to AT commands */
ocomeni 81:637a87eb8170 57 MemoryPool<at_resp_message_t, 16> *_wiFi2ATmPool;
ocomeni 81:637a87eb8170 58 Queue<at_resp_message_t, 16> *_wiFi2ATCmdQueue;
ocomeni 80:e8f0e92e3ac9 59
ocomeni 80:e8f0e92e3ac9 60 /* Queue and memory pool for AT to WiFi data */
ocomeni 87:99b37d26ff2a 61 MemoryPool<wifi_data_msg_t, PQDSZ> *_aT2WiFiDatamPool;
ocomeni 87:99b37d26ff2a 62 Queue<wifi_data_msg_t, PQDSZ> *_aT2WiFiDataQueue;
ocomeni 80:e8f0e92e3ac9 63
ocomeni 80:e8f0e92e3ac9 64
ocomeni 80:e8f0e92e3ac9 65 /* Queue and memory pool for WiFi to AT data */
ocomeni 87:99b37d26ff2a 66 MemoryPool<at_data_msg_t, PQDSZ> *_wiFi2ATDatamPool;
ocomeni 87:99b37d26ff2a 67 Queue<at_data_msg_t, PQDSZ> *_wiFi2ATDataQueue;
ocomeni 81:637a87eb8170 68
ocomeni 81:637a87eb8170 69 //pointer to response data - should be deleted after processing
ocomeni 81:637a87eb8170 70 at_data_msg_t *resp_data;
ocomeni 83:9c271a50a70b 71 edm_header_t edm_hdr;
ocomeni 83:9c271a50a70b 72 uint8_t *rx_buf_ptr;
ocomeni 98:65c2333a38b6 73 int debug_flag;
ocomeni 104:11e9605093c9 74 at_cmd_resp_t wifiStateControl;
ocomeni 103:7b566b522427 75 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 103:7b566b522427 76 bool check_for_at_cmd;
ocomeni 103:7b566b522427 77 #endif
ocomeni 80:e8f0e92e3ac9 78
ocomeni 74:f26e846adfe9 79 // OOB processing
ocomeni 74:f26e846adfe9 80 void _process_oob(uint32_t timeout, bool all);
ocomeni 74:f26e846adfe9 81 // OOB message handlers
ocomeni 74:f26e846adfe9 82 void _oob_startup_hdlr();
ocomeni 81:637a87eb8170 83 void _oob_ok_hdlr();
ocomeni 74:f26e846adfe9 84 void _oob_bleRole_hdlr();
ocomeni 114:b11bb96c09f3 85 void _oob_enable_wifi();
ocomeni 74:f26e846adfe9 86 void _oob_wifiMode_err();
ocomeni 74:f26e846adfe9 87 void _oob_conn_already();
ocomeni 74:f26e846adfe9 88 void _oob_err();
ocomeni 75:08eff6258e1b 89 void _oob_echo_off();
ocomeni 75:08eff6258e1b 90 void _oob_uart_setup();
ocomeni 75:08eff6258e1b 91 void _oob_echo_on();
ocomeni 75:08eff6258e1b 92 void _oob_data_mode();
ocomeni 75:08eff6258e1b 93 void _oob_get_mac_addr();
ocomeni 75:08eff6258e1b 94 void _oob_get_ble_role();
ocomeni 75:08eff6258e1b 95 void _oob_ena_ble_peri();
ocomeni 75:08eff6258e1b 96 void _oob_reboot();
ocomeni 75:08eff6258e1b 97 void _oob_get_fw_ver();
ocomeni 79:a2187bbfa407 98 void _oob_scanWiFiNetworks();
ocomeni 98:65c2333a38b6 99 void _oob_WiFiStationConfigAction();
ocomeni 79:a2187bbfa407 100 void _oob_disconnectWiFiNetwork();
ocomeni 81:637a87eb8170 101 void _oob_setupInternetConnection();
ocomeni 82:10072c1794d3 102 void _oob_setWiFiSSID();
ocomeni 82:10072c1794d3 103 void _oob_setWiFiPWD();
ocomeni 82:10072c1794d3 104 void _oob_setWiFiSecurity();
ocomeni 83:9c271a50a70b 105 void _oob_sendHttpMessage();
ocomeni 95:290859010c8c 106 void _oob_getNetworkStatus();
ocomeni 95:290859010c8c 107 void _oob_WiFiNetworkStatus();
ocomeni 82:10072c1794d3 108 wifi_config_t init_wifi_config();
ocomeni 79:a2187bbfa407 109 const char * sec2str(nsapi_security_t sec);
ocomeni 87:99b37d26ff2a 110 bool queueWiFiCommand(wifi_cmd_t cmd);
ocomeni 87:99b37d26ff2a 111 bool dequeueATresponse();
ocomeni 87:99b37d26ff2a 112 bool queueWiFiDataRequest(wifi_data_msg_t cmd);
ocomeni 87:99b37d26ff2a 113 bool dequeueWiFidataResponse();
ocomeni 87:99b37d26ff2a 114 void processResponses();
ocomeni 87:99b37d26ff2a 115 bool setNextResponse(at_cmd_resp_t resp);
ocomeni 87:99b37d26ff2a 116 int ReadBytes(uint8_t *buf, int maxBytes);
ocomeni 87:99b37d26ff2a 117 int readStringBytes(uint8_t *buf, int maxBytes);
ocomeni 87:99b37d26ff2a 118 bool validate(edm_header_t edm_header);
ocomeni 87:99b37d26ff2a 119 bool createHttpRequest();
ocomeni 84:7c7add00f4bf 120 http_method str2HttpMethod(const char * methodStr);
ocomeni 89:45f6db09a76d 121 void return_response(bool download=false);
ocomeni 104:11e9605093c9 122 void printBufferInHex(const uint8_t *buf, int pLen);
ocomeni 90:ed0267eca7b5 123 void outputEDMdata(const uint8_t *buf, int pLen,
ocomeni 91:d6b6319ad681 124 edm_msg_id_t identifier, edm_msg_type_t type,
ocomeni 91:d6b6319ad681 125 channel_id_t channel_id);
ocomeni 74:f26e846adfe9 126
ocomeni 93:06e755a80187 127 void sendAtConfirmation(const char *buf);
ocomeni 96:f5ed273881af 128 void sendAtConfirmationFreeMpool(const char *buf);
ocomeni 104:11e9605093c9 129 void sendConnectIndicationFreeMpool(const char *buf);
ocomeni 93:06e755a80187 130 void sendAtEvent(const char *buf);
ocomeni 99:05398b3184f8 131 void sendConnectEvent(const uint8_t *buf, int len);
ocomeni 103:7b566b522427 132 int readAtCommandString(char *strbuf, size_t bufLen);
ocomeni 104:11e9605093c9 133 void updateWiFiMgrStatus();
ocomeni 93:06e755a80187 134
ocomeni 74:f26e846adfe9 135 /**
ocomeni 74:f26e846adfe9 136 * Allows timeout to be changed between commands
ocomeni 74:f26e846adfe9 137 *
ocomeni 74:f26e846adfe9 138 * @param timeout_ms timeout of the connection
ocomeni 74:f26e846adfe9 139 */
ocomeni 74:f26e846adfe9 140 void set_timeout(uint32_t timeout_ms = UBLOX_ODIN_W2_MISC_TIMEOUT);
ocomeni 74:f26e846adfe9 141 };
ocomeni 74:f26e846adfe9 142 #endif // __ATCMD_MANAGER_H__