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

Dependencies:   mbed-http

Committer:
ocomeni
Date:
Sun Apr 14 14:38:51 2019 +0000
Revision:
93:06e755a80187
Parent:
92:ec9550034276
Child:
95:290859010c8c
fixed bug with wifi configuration API (was adding an extra character causing wifi connection to fail because of incorrect credentials)

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 84:7c7add00f4bf 10 #define MAIN_LOOP_WAIT_TIME_MS 100 // milliseconds
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 92:ec9550034276 16 #define OK_RESP "OK\n\r"
ocomeni 84:7c7add00f4bf 17 extern void print_memory_info();
ocomeni 74:f26e846adfe9 18 class ATCmdManager {
ocomeni 74:f26e846adfe9 19 public:
ocomeni 78:07bb86e3ce14 20 ATCmdManager(PinName tx, PinName rx, SMDevicePeripheral *blePeripheral,
ocomeni 79:a2187bbfa407 21 events::EventQueue &event_queue, WiFiManager *wifi,
ocomeni 79:a2187bbfa407 22 MemoryPool<wifi_cmd_message_t, 16> *aT2WiFimPool,
ocomeni 79:a2187bbfa407 23 Queue<wifi_cmd_message_t, 16> *aT2WiFiCmdQueue,
ocomeni 81:637a87eb8170 24 MemoryPool<at_resp_message_t, 16> *wiFi2ATmPool,
ocomeni 81:637a87eb8170 25 Queue<at_resp_message_t, 16> *wiFi2ATCmdQueue,
ocomeni 87:99b37d26ff2a 26 MemoryPool<wifi_data_msg_t, PQDSZ> *aT2WiFiDatamPool,
ocomeni 87:99b37d26ff2a 27 Queue<wifi_data_msg_t, PQDSZ> *aT2WiFiDataQueue,
ocomeni 87:99b37d26ff2a 28 MemoryPool<at_data_msg_t, PQDSZ> *wiFi2ATDatamPool,
ocomeni 87:99b37d26ff2a 29 Queue<at_data_msg_t, PQDSZ> *wiFi2ATDataQueue,
ocomeni 79:a2187bbfa407 30 bool debug = false);
ocomeni 74:f26e846adfe9 31 public:
ocomeni 74:f26e846adfe9 32 void runMain();
ocomeni 74:f26e846adfe9 33
ocomeni 74:f26e846adfe9 34
ocomeni 74:f26e846adfe9 35
ocomeni 74:f26e846adfe9 36 private:
ocomeni 74:f26e846adfe9 37 // UART settings
ocomeni 74:f26e846adfe9 38 UARTSerial _serial;
ocomeni 74:f26e846adfe9 39 Mutex _smutex; // Protect serial port access
ocomeni 74:f26e846adfe9 40 Mutex _rmutex; // Reset protection
ocomeni 79:a2187bbfa407 41 // define event queue
ocomeni 79:a2187bbfa407 42 events::EventQueue &_event_queue;
ocomeni 74:f26e846adfe9 43 // AT Command Parser
ocomeni 74:f26e846adfe9 44 ATCmdParser _parser;
ocomeni 78:07bb86e3ce14 45 SMDevicePeripheral *blePeripheral;
ocomeni 79:a2187bbfa407 46 WiFiManager *wiFiManager;
ocomeni 81:637a87eb8170 47 at_cmd_resp_t at_resp;
ocomeni 81:637a87eb8170 48 at_data_mode_t dataMode;
ocomeni 80:e8f0e92e3ac9 49 /* Queue and memory pool for AT to Wifi commands */
ocomeni 79:a2187bbfa407 50 MemoryPool<wifi_cmd_message_t, 16> *_aT2WiFimPool;
ocomeni 79:a2187bbfa407 51 Queue<wifi_cmd_message_t, 16> *_aT2WiFiCmdQueue;
ocomeni 80:e8f0e92e3ac9 52
ocomeni 80:e8f0e92e3ac9 53 /* Queue and memory pool for WiFi to AT commands */
ocomeni 81:637a87eb8170 54 MemoryPool<at_resp_message_t, 16> *_wiFi2ATmPool;
ocomeni 81:637a87eb8170 55 Queue<at_resp_message_t, 16> *_wiFi2ATCmdQueue;
ocomeni 80:e8f0e92e3ac9 56
ocomeni 80:e8f0e92e3ac9 57 /* Queue and memory pool for AT to WiFi data */
ocomeni 87:99b37d26ff2a 58 MemoryPool<wifi_data_msg_t, PQDSZ> *_aT2WiFiDatamPool;
ocomeni 87:99b37d26ff2a 59 Queue<wifi_data_msg_t, PQDSZ> *_aT2WiFiDataQueue;
ocomeni 80:e8f0e92e3ac9 60
ocomeni 80:e8f0e92e3ac9 61
ocomeni 80:e8f0e92e3ac9 62 /* Queue and memory pool for WiFi to AT data */
ocomeni 87:99b37d26ff2a 63 MemoryPool<at_data_msg_t, PQDSZ> *_wiFi2ATDatamPool;
ocomeni 87:99b37d26ff2a 64 Queue<at_data_msg_t, PQDSZ> *_wiFi2ATDataQueue;
ocomeni 81:637a87eb8170 65
ocomeni 81:637a87eb8170 66 //pointer to response data - should be deleted after processing
ocomeni 81:637a87eb8170 67 at_data_msg_t *resp_data;
ocomeni 83:9c271a50a70b 68 edm_header_t edm_hdr;
ocomeni 83:9c271a50a70b 69 uint8_t *rx_buf_ptr;
ocomeni 80:e8f0e92e3ac9 70
ocomeni 74:f26e846adfe9 71 // OOB processing
ocomeni 74:f26e846adfe9 72 void _process_oob(uint32_t timeout, bool all);
ocomeni 74:f26e846adfe9 73 // OOB message handlers
ocomeni 74:f26e846adfe9 74 void _oob_startup_hdlr();
ocomeni 81:637a87eb8170 75 void _oob_ok_hdlr();
ocomeni 74:f26e846adfe9 76 void _oob_bleRole_hdlr();
ocomeni 74:f26e846adfe9 77 void _oob_wifiMode_err();
ocomeni 74:f26e846adfe9 78 void _oob_conn_already();
ocomeni 74:f26e846adfe9 79 void _oob_err();
ocomeni 75:08eff6258e1b 80 void _oob_echo_off();
ocomeni 75:08eff6258e1b 81 void _oob_uart_setup();
ocomeni 75:08eff6258e1b 82 void _oob_echo_on();
ocomeni 75:08eff6258e1b 83 void _oob_data_mode();
ocomeni 75:08eff6258e1b 84 void _oob_get_mac_addr();
ocomeni 75:08eff6258e1b 85 void _oob_get_ble_role();
ocomeni 75:08eff6258e1b 86 void _oob_ena_ble_peri();
ocomeni 75:08eff6258e1b 87 void _oob_reboot();
ocomeni 75:08eff6258e1b 88 void _oob_get_fw_ver();
ocomeni 79:a2187bbfa407 89 void _oob_scanWiFiNetworks();
ocomeni 79:a2187bbfa407 90 void _oob_connect2WiFiNetwork();
ocomeni 79:a2187bbfa407 91 void _oob_disconnectWiFiNetwork();
ocomeni 81:637a87eb8170 92 void _oob_setupInternetConnection();
ocomeni 82:10072c1794d3 93 void _oob_setWiFiSSID();
ocomeni 82:10072c1794d3 94 void _oob_setWiFiPWD();
ocomeni 82:10072c1794d3 95 void _oob_setWiFiSecurity();
ocomeni 83:9c271a50a70b 96 void _oob_sendHttpMessage();
ocomeni 82:10072c1794d3 97 wifi_config_t init_wifi_config();
ocomeni 79:a2187bbfa407 98 const char * sec2str(nsapi_security_t sec);
ocomeni 87:99b37d26ff2a 99 bool queueWiFiCommand(wifi_cmd_t cmd);
ocomeni 87:99b37d26ff2a 100 bool dequeueATresponse();
ocomeni 87:99b37d26ff2a 101 bool queueWiFiDataRequest(wifi_data_msg_t cmd);
ocomeni 87:99b37d26ff2a 102 bool dequeueWiFidataResponse();
ocomeni 87:99b37d26ff2a 103 void processResponses();
ocomeni 87:99b37d26ff2a 104 bool setNextResponse(at_cmd_resp_t resp);
ocomeni 87:99b37d26ff2a 105 int ReadBytes(uint8_t *buf, int maxBytes);
ocomeni 87:99b37d26ff2a 106 int readStringBytes(uint8_t *buf, int maxBytes);
ocomeni 87:99b37d26ff2a 107 bool validate(edm_header_t edm_header);
ocomeni 87:99b37d26ff2a 108 bool createHttpRequest();
ocomeni 84:7c7add00f4bf 109 http_method str2HttpMethod(const char * methodStr);
ocomeni 89:45f6db09a76d 110 void return_response(bool download=false);
ocomeni 89:45f6db09a76d 111 void printBufferInHex(uint8_t *buf, int pLen);
ocomeni 90:ed0267eca7b5 112 void outputEDMdata(const uint8_t *buf, int pLen,
ocomeni 91:d6b6319ad681 113 edm_msg_id_t identifier, edm_msg_type_t type,
ocomeni 91:d6b6319ad681 114 channel_id_t channel_id);
ocomeni 74:f26e846adfe9 115
ocomeni 93:06e755a80187 116 void sendAtConfirmation(const char *buf);
ocomeni 93:06e755a80187 117 void sendAtEvent(const char *buf);
ocomeni 93:06e755a80187 118
ocomeni 74:f26e846adfe9 119 /**
ocomeni 74:f26e846adfe9 120 * Allows timeout to be changed between commands
ocomeni 74:f26e846adfe9 121 *
ocomeni 74:f26e846adfe9 122 * @param timeout_ms timeout of the connection
ocomeni 74:f26e846adfe9 123 */
ocomeni 74:f26e846adfe9 124 void set_timeout(uint32_t timeout_ms = UBLOX_ODIN_W2_MISC_TIMEOUT);
ocomeni 74:f26e846adfe9 125 };
ocomeni 74:f26e846adfe9 126 #endif // __ATCMD_MANAGER_H__