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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Fri Jul 19 16:49:26 2019 +0000
Branch:
PassingRegression
Revision:
129:590bdc2dcf5b
Parent:
127:a21788227ca6
Implementation of Access token acquisition; 1. make request with credentials - DONE; 2. get response - DONE; 3. extract Id and refresh tokens from response - DONE; 4. integrate with code - DONE; Testing ongoing

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 118:8df0e9c2ee3f 9 #include "common_config.h"
ocomeni 74:f26e846adfe9 10
ocomeni 75:08eff6258e1b 11 #define NUM_UART_OPTIONS 6
ocomeni 74:f26e846adfe9 12 #ifndef UBLOX_ODIN_W2_MISC_TIMEOUT
ocomeni 74:f26e846adfe9 13 #define UBLOX_ODIN_W2_MISC_TIMEOUT 2000
ocomeni 74:f26e846adfe9 14 #endif
ocomeni 74:f26e846adfe9 15
ocomeni 95:290859010c8c 16 #define OK_RESP "\r\nOK\r\n"
ocomeni 95:290859010c8c 17 #define ERROR_RESP "\r\nERROR\r\n"
ocomeni 104:11e9605093c9 18 #define WIFI_BUSY_RESP "\r\nWIFI BUSY\r\n"
ocomeni 119:8d939a902333 19 #define UART_TIMEOUT_ERROR "\r\nUART TIMEOUT ERROR\r\n"
ocomeni 126:9bc33f8b57d5 20 #define MEMORY_ALLOCATION_ERROR "\r\nMEMORY ALLOCATION ERROR\r\n"
ocomeni 103:7b566b522427 21 #define BOX_UBLOX_DEMO_TESTING
ocomeni 114:b11bb96c09f3 22 //extern void print_memory_info();
ocomeni 114:b11bb96c09f3 23 //extern void blinkLEDs();
ocomeni 74:f26e846adfe9 24 class ATCmdManager {
ocomeni 74:f26e846adfe9 25 public:
ocomeni 117:8fd05113efc1 26 ATCmdManager(PinName tx, PinName rx, uart_config_t *uart_config,
ocomeni 79:a2187bbfa407 27 events::EventQueue &event_queue, WiFiManager *wifi,
ocomeni 79:a2187bbfa407 28 MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool,
ocomeni 79:a2187bbfa407 29 Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue,
ocomeni 81:637a87eb8170 30 MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool,
ocomeni 81:637a87eb8170 31 Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue,
ocomeni 87:99b37d26ff2a 32 MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool,
ocomeni 87:99b37d26ff2a 33 Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue,
ocomeni 87:99b37d26ff2a 34 MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool,
ocomeni 87:99b37d26ff2a 35 Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue,
ocomeni 118:8df0e9c2ee3f 36 MemoryPool<at_ble_msg_t, PQDSZ_BLE> *aT2BleDatamPool,
ocomeni 118:8df0e9c2ee3f 37 Queue<at_ble_msg_t, PQDSZ_BLE> *aT2BleDataQueue,
ocomeni 118:8df0e9c2ee3f 38 MemoryPool<ble_at_msg_t, PQDSZ_BLE> *ble2ATDatamPool,
ocomeni 118:8df0e9c2ee3f 39 Queue<ble_at_msg_t, PQDSZ_BLE> *ble2ATDataQueue,
ocomeni 121:ac4f59839e4f 40 startup_config_t *startup_config, bool debug = false);
ocomeni 74:f26e846adfe9 41 public:
ocomeni 74:f26e846adfe9 42 void runMain();
ocomeni 74:f26e846adfe9 43
ocomeni 74:f26e846adfe9 44
ocomeni 74:f26e846adfe9 45
ocomeni 74:f26e846adfe9 46 private:
ocomeni 74:f26e846adfe9 47 // UART settings
ocomeni 119:8d939a902333 48 UARTSerial _serial;
ocomeni 117:8fd05113efc1 49 uart_config_t *uart_config;
ocomeni 74:f26e846adfe9 50 Mutex _smutex; // Protect serial port access
ocomeni 74:f26e846adfe9 51 Mutex _rmutex; // Reset protection
ocomeni 79:a2187bbfa407 52 // define event queue
ocomeni 79:a2187bbfa407 53 events::EventQueue &_event_queue;
ocomeni 74:f26e846adfe9 54 // AT Command Parser
ocomeni 78:07bb86e3ce14 55 SMDevicePeripheral *blePeripheral;
ocomeni 79:a2187bbfa407 56 WiFiManager *wiFiManager;
ocomeni 81:637a87eb8170 57 at_cmd_resp_t at_resp;
ocomeni 81:637a87eb8170 58 at_data_mode_t dataMode;
ocomeni 118:8df0e9c2ee3f 59 uint32_t lastHttpRespTime;
ocomeni 118:8df0e9c2ee3f 60 uint8_t lastCloudMsgType;
ocomeni 80:e8f0e92e3ac9 61 /* Queue and memory pool for AT to Wifi commands */
ocomeni 79:a2187bbfa407 62 MemoryPool<wifi_cmd_message_t, 16> *_aT2WiFimPool;
ocomeni 79:a2187bbfa407 63 Queue<wifi_cmd_message_t, 16> *_aT2WiFiCmdQueue;
ocomeni 80:e8f0e92e3ac9 64
ocomeni 80:e8f0e92e3ac9 65 /* Queue and memory pool for WiFi to AT commands */
ocomeni 81:637a87eb8170 66 MemoryPool<at_resp_message_t, 16> *_wiFi2ATmPool;
ocomeni 81:637a87eb8170 67 Queue<at_resp_message_t, 16> *_wiFi2ATCmdQueue;
ocomeni 80:e8f0e92e3ac9 68
ocomeni 80:e8f0e92e3ac9 69 /* Queue and memory pool for AT to WiFi data */
ocomeni 87:99b37d26ff2a 70 MemoryPool<wifi_data_msg_t, PQDSZ> *_aT2WiFiDatamPool;
ocomeni 87:99b37d26ff2a 71 Queue<wifi_data_msg_t, PQDSZ> *_aT2WiFiDataQueue;
ocomeni 80:e8f0e92e3ac9 72
ocomeni 80:e8f0e92e3ac9 73
ocomeni 80:e8f0e92e3ac9 74 /* Queue and memory pool for WiFi to AT data */
ocomeni 87:99b37d26ff2a 75 MemoryPool<at_data_msg_t, PQDSZ> *_wiFi2ATDatamPool;
ocomeni 87:99b37d26ff2a 76 Queue<at_data_msg_t, PQDSZ> *_wiFi2ATDataQueue;
ocomeni 118:8df0e9c2ee3f 77
ocomeni 118:8df0e9c2ee3f 78 /* Queue and memory pool for AT to BLE data */
ocomeni 118:8df0e9c2ee3f 79 MemoryPool<at_ble_msg_t, PQDSZ_BLE> *_aT2BleDatamPool;
ocomeni 118:8df0e9c2ee3f 80 Queue<at_ble_msg_t, PQDSZ_BLE> *_aT2BleDataQueue;
ocomeni 118:8df0e9c2ee3f 81
ocomeni 118:8df0e9c2ee3f 82
ocomeni 118:8df0e9c2ee3f 83 /* Queue and memory pool for BLE to AT data */
ocomeni 118:8df0e9c2ee3f 84 MemoryPool<ble_at_msg_t, PQDSZ_BLE> *_ble2ATDatamPool;
ocomeni 118:8df0e9c2ee3f 85 Queue<ble_at_msg_t, PQDSZ_BLE> *_ble2ATDataQueue;
ocomeni 119:8d939a902333 86 ATCmdParser _parser;
ocomeni 118:8df0e9c2ee3f 87
ocomeni 81:637a87eb8170 88
ocomeni 119:8d939a902333 89 //pointer to wifi response data - should be deleted after processing
ocomeni 81:637a87eb8170 90 at_data_msg_t *resp_data;
ocomeni 119:8d939a902333 91 //pointer to ble response data - should be deleted after processing
ocomeni 119:8d939a902333 92 ble_at_msg_t *ble_resp_data;
ocomeni 83:9c271a50a70b 93 edm_header_t edm_hdr;
ocomeni 83:9c271a50a70b 94 uint8_t *rx_buf_ptr;
ocomeni 121:ac4f59839e4f 95 startup_config_t *startup_config;
ocomeni 127:a21788227ca6 96 int debug_flags_map;
ocomeni 104:11e9605093c9 97 at_cmd_resp_t wifiStateControl;
ocomeni 103:7b566b522427 98 #ifdef BOX_UBLOX_DEMO_TESTING
ocomeni 103:7b566b522427 99 bool check_for_at_cmd;
ocomeni 103:7b566b522427 100 #endif
ocomeni 80:e8f0e92e3ac9 101
ocomeni 74:f26e846adfe9 102 // OOB processing
ocomeni 74:f26e846adfe9 103 void _process_oob(uint32_t timeout, bool all);
ocomeni 74:f26e846adfe9 104 // OOB message handlers
ocomeni 74:f26e846adfe9 105 void _oob_startup_hdlr();
ocomeni 81:637a87eb8170 106 void _oob_ok_hdlr();
ocomeni 74:f26e846adfe9 107 void _oob_bleRole_hdlr();
ocomeni 114:b11bb96c09f3 108 void _oob_enable_wifi();
ocomeni 74:f26e846adfe9 109 void _oob_wifiMode_err();
ocomeni 74:f26e846adfe9 110 void _oob_conn_already();
ocomeni 74:f26e846adfe9 111 void _oob_err();
ocomeni 75:08eff6258e1b 112 void _oob_echo_off();
ocomeni 75:08eff6258e1b 113 void _oob_uart_setup();
ocomeni 75:08eff6258e1b 114 void _oob_echo_on();
ocomeni 118:8df0e9c2ee3f 115 void _oob_debug_logs_on();
ocomeni 118:8df0e9c2ee3f 116 void _oob_debug_logs_off();
ocomeni 127:a21788227ca6 117 void _oob_set_debug_flag();
ocomeni 75:08eff6258e1b 118 void _oob_data_mode();
ocomeni 75:08eff6258e1b 119 void _oob_get_mac_addr();
ocomeni 75:08eff6258e1b 120 void _oob_get_ble_role();
ocomeni 75:08eff6258e1b 121 void _oob_ena_ble_peri();
ocomeni 123:a49e9ffbaca6 122 void _oob_get_ble_name();
ocomeni 75:08eff6258e1b 123 void _oob_reboot();
ocomeni 75:08eff6258e1b 124 void _oob_get_fw_ver();
ocomeni 121:ac4f59839e4f 125 void _oob_saveSettings_hdlr();
ocomeni 79:a2187bbfa407 126 void _oob_scanWiFiNetworks();
ocomeni 98:65c2333a38b6 127 void _oob_WiFiStationConfigAction();
ocomeni 79:a2187bbfa407 128 void _oob_disconnectWiFiNetwork();
ocomeni 81:637a87eb8170 129 void _oob_setupInternetConnection();
ocomeni 121:ac4f59839e4f 130 void _oob_factoryReset();
ocomeni 121:ac4f59839e4f 131 void _oob_deleteConfiguration();
ocomeni 82:10072c1794d3 132 void _oob_setWiFiSSID();
ocomeni 82:10072c1794d3 133 void _oob_setWiFiPWD();
ocomeni 82:10072c1794d3 134 void _oob_setWiFiSecurity();
ocomeni 83:9c271a50a70b 135 void _oob_sendHttpMessage();
ocomeni 95:290859010c8c 136 void _oob_getNetworkStatus();
ocomeni 95:290859010c8c 137 void _oob_WiFiNetworkStatus();
ocomeni 82:10072c1794d3 138 wifi_config_t init_wifi_config();
ocomeni 79:a2187bbfa407 139 const char * sec2str(nsapi_security_t sec);
ocomeni 87:99b37d26ff2a 140 bool queueWiFiCommand(wifi_cmd_t cmd);
ocomeni 87:99b37d26ff2a 141 bool dequeueATresponse();
ocomeni 87:99b37d26ff2a 142 bool queueWiFiDataRequest(wifi_data_msg_t cmd);
ocomeni 87:99b37d26ff2a 143 bool dequeueWiFidataResponse();
ocomeni 87:99b37d26ff2a 144 void processResponses();
ocomeni 87:99b37d26ff2a 145 bool setNextResponse(at_cmd_resp_t resp);
ocomeni 87:99b37d26ff2a 146 int ReadBytes(uint8_t *buf, int maxBytes);
ocomeni 87:99b37d26ff2a 147 int readStringBytes(uint8_t *buf, int maxBytes);
ocomeni 87:99b37d26ff2a 148 bool validate(edm_header_t edm_header);
ocomeni 87:99b37d26ff2a 149 bool createHttpRequest();
ocomeni 84:7c7add00f4bf 150 http_method str2HttpMethod(const char * methodStr);
ocomeni 89:45f6db09a76d 151 void return_response(bool download=false);
ocomeni 104:11e9605093c9 152 void printBufferInHex(const uint8_t *buf, int pLen);
ocomeni 90:ed0267eca7b5 153 void outputEDMdata(const uint8_t *buf, int pLen,
ocomeni 91:d6b6319ad681 154 edm_msg_id_t identifier, edm_msg_type_t type,
ocomeni 91:d6b6319ad681 155 channel_id_t channel_id);
ocomeni 74:f26e846adfe9 156
ocomeni 93:06e755a80187 157 void sendAtConfirmation(const char *buf);
ocomeni 96:f5ed273881af 158 void sendAtConfirmationFreeMpool(const char *buf);
ocomeni 104:11e9605093c9 159 void sendConnectIndicationFreeMpool(const char *buf);
ocomeni 93:06e755a80187 160 void sendAtEvent(const char *buf);
ocomeni 99:05398b3184f8 161 void sendConnectEvent(const uint8_t *buf, int len);
ocomeni 103:7b566b522427 162 int readAtCommandString(char *strbuf, size_t bufLen);
ocomeni 104:11e9605093c9 163 void updateWiFiMgrStatus();
ocomeni 118:8df0e9c2ee3f 164 void sendBleDataEvent(const char *buf, int len);
ocomeni 119:8d939a902333 165 void sendBleAtEvent(const char *buf, int len);
ocomeni 119:8d939a902333 166 void sendBleConnectEvent(const char *buf, int len);
ocomeni 120:779b74689747 167 void sendBleDisconnectEvent();
ocomeni 120:779b74689747 168 bool dequeueBleDataResponse();
ocomeni 120:779b74689747 169 bool queueBleDataRequest(at_ble_msg_t data_req);
ocomeni 122:62166886db5f 170 void filterHttpResponse();
ocomeni 126:9bc33f8b57d5 171 int readEDMmodeBytes(uint8_t *rx_buf_ptr, int pLen);
ocomeni 93:06e755a80187 172
ocomeni 74:f26e846adfe9 173 /**
ocomeni 74:f26e846adfe9 174 * Allows timeout to be changed between commands
ocomeni 74:f26e846adfe9 175 *
ocomeni 74:f26e846adfe9 176 * @param timeout_ms timeout of the connection
ocomeni 74:f26e846adfe9 177 */
ocomeni 74:f26e846adfe9 178 void set_timeout(uint32_t timeout_ms = UBLOX_ODIN_W2_MISC_TIMEOUT);
ocomeni 74:f26e846adfe9 179 };
ocomeni 74:f26e846adfe9 180 #endif // __ATCMD_MANAGER_H__