this is using the mbed os version 5-13-1
source/common_types.h@93:06e755a80187, 2019-04-14 (annotated)
- 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?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ocomeni | 78:07bb86e3ce14 | 1 | #ifndef __COMMON_TYPES_H__ |
| ocomeni | 78:07bb86e3ce14 | 2 | #define __COMMON_TYPES_H__ |
| ocomeni | 78:07bb86e3ce14 | 3 | #include <mbed.h> |
| ocomeni | 81:637a87eb8170 | 4 | #include <string> |
| ocomeni | 79:a2187bbfa407 | 5 | #include "ble/BLE.h" |
| ocomeni | 79:a2187bbfa407 | 6 | #include "SecurityManager.h" |
| ocomeni | 84:7c7add00f4bf | 7 | #include "http_request.h" |
| ocomeni | 80:e8f0e92e3ac9 | 8 | #include "common_config.h" |
| ocomeni | 78:07bb86e3ce14 | 9 | #define BLE_MAX_DEVICE_NAME_LEN 10 |
| ocomeni | 78:07bb86e3ce14 | 10 | #define MAX_SSID_LEN 32 |
| ocomeni | 78:07bb86e3ce14 | 11 | #define MAX_PASSKEY_LEN 32 |
| ocomeni | 84:7c7add00f4bf | 12 | #define EDM_START_BYTE 0xAA |
| ocomeni | 84:7c7add00f4bf | 13 | #define EDM_STOP_BYTE 0x55 |
| ocomeni | 90:ed0267eca7b5 | 14 | #define EDM_HDR_LEN 6 |
| ocomeni | 84:7c7add00f4bf | 15 | #define MAX_EDM_PAYLOAD_LEN (4096-1) |
| ocomeni | 84:7c7add00f4bf | 16 | #define MIN_EDM_PAYLOAD_LEN (2) |
| ocomeni | 84:7c7add00f4bf | 17 | #define MAX_HTTP_HEADER_LINES |
| ocomeni | 84:7c7add00f4bf | 18 | #define MAX_URL_LEN 100 |
| ocomeni | 78:07bb86e3ce14 | 19 | |
| ocomeni | 78:07bb86e3ce14 | 20 | /** ble configuration structure |
| ocomeni | 78:07bb86e3ce14 | 21 | */ |
| ocomeni | 92:ec9550034276 | 22 | typedef struct { |
| ocomeni | 79:a2187bbfa407 | 23 | char deviceName[BLE_MAX_DEVICE_NAME_LEN]; /* BLE Device Name */ |
| ocomeni | 79:a2187bbfa407 | 24 | uint16_t advInterval; /* advertising interval in msecs */ |
| ocomeni | 79:a2187bbfa407 | 25 | uint16_t advTimeout; /* advertising timeout in secs */ |
| ocomeni | 79:a2187bbfa407 | 26 | //Passkey_t pairingKey; /* pairing Key */ |
| ocomeni | 79:a2187bbfa407 | 27 | uint8_t pairingKey[6]; /* pairing Key */ |
| ocomeni | 78:07bb86e3ce14 | 28 | } ble_config_t; |
| ocomeni | 78:07bb86e3ce14 | 29 | |
| ocomeni | 78:07bb86e3ce14 | 30 | /** ble configuration structure |
| ocomeni | 78:07bb86e3ce14 | 31 | */ |
| ocomeni | 92:ec9550034276 | 32 | typedef struct { |
| ocomeni | 78:07bb86e3ce14 | 33 | char ssid[MAX_SSID_LEN]; /* WiFi SSID */ |
| ocomeni | 78:07bb86e3ce14 | 34 | char pass[MAX_PASSKEY_LEN]; /* WiFi Passkey */ |
| ocomeni | 78:07bb86e3ce14 | 35 | nsapi_security_t security; /* WiFi security */ |
| ocomeni | 78:07bb86e3ce14 | 36 | } wifi_config_t; |
| ocomeni | 78:07bb86e3ce14 | 37 | |
| ocomeni | 78:07bb86e3ce14 | 38 | /** ble configuration structure |
| ocomeni | 78:07bb86e3ce14 | 39 | */ |
| ocomeni | 92:ec9550034276 | 40 | typedef struct { |
| ocomeni | 78:07bb86e3ce14 | 41 | wifi_config_t wifi_config; /* wifi configuration */ |
| ocomeni | 78:07bb86e3ce14 | 42 | ble_config_t ble_config; /* ble configuration */ |
| ocomeni | 78:07bb86e3ce14 | 43 | } app_config_t; |
| ocomeni | 78:07bb86e3ce14 | 44 | |
| ocomeni | 78:07bb86e3ce14 | 45 | |
| ocomeni | 92:ec9550034276 | 46 | typedef enum |
| ocomeni | 79:a2187bbfa407 | 47 | { |
| ocomeni | 79:a2187bbfa407 | 48 | WIFI_CMD_NONE, |
| ocomeni | 81:637a87eb8170 | 49 | WIFI_CMD_CONFIG, |
| ocomeni | 81:637a87eb8170 | 50 | WIFI_CMD_INTERNET_CONFIG, |
| ocomeni | 79:a2187bbfa407 | 51 | WIFI_CMD_SCAN, |
| ocomeni | 81:637a87eb8170 | 52 | WIFI_CMD_DETAILED_SCAN, |
| ocomeni | 79:a2187bbfa407 | 53 | WIFI_CMD_CONNECT, |
| ocomeni | 79:a2187bbfa407 | 54 | WIFI_CMD_DISCONNECT, |
| ocomeni | 79:a2187bbfa407 | 55 | WIFI_CMD_SEND_HTTPS_REQ, |
| ocomeni | 79:a2187bbfa407 | 56 | WIFI_CMD_SEND_HTTP_REQ |
| ocomeni | 79:a2187bbfa407 | 57 | }wifi_cmd_t; |
| ocomeni | 79:a2187bbfa407 | 58 | |
| ocomeni | 92:ec9550034276 | 59 | typedef enum |
| ocomeni | 81:637a87eb8170 | 60 | { |
| ocomeni | 81:637a87eb8170 | 61 | AT_RESP_NONE, |
| ocomeni | 81:637a87eb8170 | 62 | AT_SCAN_RESP, |
| ocomeni | 81:637a87eb8170 | 63 | AT_DETAILED_SCAN_RESP, |
| ocomeni | 81:637a87eb8170 | 64 | AT_CONNECT_RESP, |
| ocomeni | 81:637a87eb8170 | 65 | AT_DISCONNECT_RESP, |
| ocomeni | 81:637a87eb8170 | 66 | WIFI_RECONNECT_INFO, |
| ocomeni | 81:637a87eb8170 | 67 | WIFI_DISCONNECT_INFO, |
| ocomeni | 81:637a87eb8170 | 68 | AT_CONFIG_RESP, |
| ocomeni | 81:637a87eb8170 | 69 | AT_INTERNET_CONFIG_RESP, |
| ocomeni | 81:637a87eb8170 | 70 | AT_HTTPS_RESP, |
| ocomeni | 89:45f6db09a76d | 71 | AT_HTTPS_RESP_DOWNLOAD, |
| ocomeni | 89:45f6db09a76d | 72 | AT_HTTP_RESP, |
| ocomeni | 93:06e755a80187 | 73 | AT_HTTP_RESP_DOWNLOAD, |
| ocomeni | 93:06e755a80187 | 74 | AT_COMMAND_FAILED |
| ocomeni | 81:637a87eb8170 | 75 | }at_cmd_resp_t; |
| ocomeni | 81:637a87eb8170 | 76 | |
| ocomeni | 90:ed0267eca7b5 | 77 | typedef enum edm_msg_id |
| ocomeni | 90:ed0267eca7b5 | 78 | { |
| ocomeni | 90:ed0267eca7b5 | 79 | CONNECT_MSG_ID = 0x0010, |
| ocomeni | 90:ed0267eca7b5 | 80 | DISCONNECT_MSG_ID = 0x0020, |
| ocomeni | 90:ed0267eca7b5 | 81 | DATA_MSG_ID = 0x0030, |
| ocomeni | 90:ed0267eca7b5 | 82 | AT_MSG_ID = 0x0040 |
| ocomeni | 90:ed0267eca7b5 | 83 | }edm_msg_id_t; |
| ocomeni | 90:ed0267eca7b5 | 84 | |
| ocomeni | 90:ed0267eca7b5 | 85 | |
| ocomeni | 90:ed0267eca7b5 | 86 | typedef enum edm_msg_type |
| ocomeni | 90:ed0267eca7b5 | 87 | { |
| ocomeni | 90:ed0267eca7b5 | 88 | EVENT_MSG_TYPE = 0x01, |
| ocomeni | 90:ed0267eca7b5 | 89 | INDICATION_MSG_TYPE = 0x02, |
| ocomeni | 90:ed0267eca7b5 | 90 | RESPONSE_MSG_TYPE = 0x03, |
| ocomeni | 90:ed0267eca7b5 | 91 | REQUEST_MSG_TYPE = 0x04, |
| ocomeni | 90:ed0267eca7b5 | 92 | CONFIRMATION_MSG_TYPE = 0x05, |
| ocomeni | 90:ed0267eca7b5 | 93 | COMMAND_MSG_TYPE = 0x06 |
| ocomeni | 90:ed0267eca7b5 | 94 | }edm_msg_type_t; |
| ocomeni | 90:ed0267eca7b5 | 95 | |
| ocomeni | 90:ed0267eca7b5 | 96 | typedef enum channel_id |
| ocomeni | 90:ed0267eca7b5 | 97 | { |
| ocomeni | 90:ed0267eca7b5 | 98 | WIFI_CHANNEL = 0x00, |
| ocomeni | 93:06e755a80187 | 99 | BLE_CHANNEL = 0x01, |
| ocomeni | 93:06e755a80187 | 100 | NO_CHANNEL = 0xFF |
| ocomeni | 90:ed0267eca7b5 | 101 | }channel_id_t; |
| ocomeni | 90:ed0267eca7b5 | 102 | |
| ocomeni | 90:ed0267eca7b5 | 103 | |
| ocomeni | 81:637a87eb8170 | 104 | |
| ocomeni | 81:637a87eb8170 | 105 | typedef enum at_data_mode |
| ocomeni | 81:637a87eb8170 | 106 | { |
| ocomeni | 81:637a87eb8170 | 107 | AT_CMD_DATA_MODE, |
| ocomeni | 81:637a87eb8170 | 108 | AT_STD_DATA_MODE, |
| ocomeni | 81:637a87eb8170 | 109 | AT_EXT_DATA_MODE |
| ocomeni | 81:637a87eb8170 | 110 | }at_data_mode_t; |
| ocomeni | 81:637a87eb8170 | 111 | |
| ocomeni | 83:9c271a50a70b | 112 | typedef enum edm_payload_id |
| ocomeni | 83:9c271a50a70b | 113 | { |
| ocomeni | 83:9c271a50a70b | 114 | CONNECT_EVENT = 0x0011, |
| ocomeni | 83:9c271a50a70b | 115 | DISCONNECT_EVENT = 0x0021, |
| ocomeni | 83:9c271a50a70b | 116 | DATA_EVENT = 0x0031, |
| ocomeni | 83:9c271a50a70b | 117 | DATA_COMMAND = 0x0036, |
| ocomeni | 83:9c271a50a70b | 118 | AT_REQUEST = 0x0044, |
| ocomeni | 83:9c271a50a70b | 119 | AT_CONFIRMATION = 0x0045, |
| ocomeni | 83:9c271a50a70b | 120 | AT_EVENT = 0x0041 |
| ocomeni | 83:9c271a50a70b | 121 | }edm_payload_id_t; |
| ocomeni | 83:9c271a50a70b | 122 | |
| ocomeni | 81:637a87eb8170 | 123 | typedef enum conn_scheme |
| ocomeni | 81:637a87eb8170 | 124 | { |
| ocomeni | 81:637a87eb8170 | 125 | INVALID_SCHEME, |
| ocomeni | 81:637a87eb8170 | 126 | ALWAYS_CONNECTED, |
| ocomeni | 81:637a87eb8170 | 127 | EXTERNAL_CONNECT |
| ocomeni | 81:637a87eb8170 | 128 | }conn_scheme_t; |
| ocomeni | 81:637a87eb8170 | 129 | |
| ocomeni | 79:a2187bbfa407 | 130 | |
| ocomeni | 79:a2187bbfa407 | 131 | typedef struct { |
| ocomeni | 79:a2187bbfa407 | 132 | wifi_cmd_t wifi_cmd; /* wifi command */ |
| ocomeni | 93:06e755a80187 | 133 | uint8_t padding[4-sizeof(wifi_cmd_t)]; /* padding */ |
| ocomeni | 79:a2187bbfa407 | 134 | } wifi_cmd_message_t; |
| ocomeni | 79:a2187bbfa407 | 135 | |
| ocomeni | 80:e8f0e92e3ac9 | 136 | typedef struct { |
| ocomeni | 81:637a87eb8170 | 137 | at_cmd_resp_t at_resp; /* AT response */ |
| ocomeni | 81:637a87eb8170 | 138 | } at_resp_message_t; |
| ocomeni | 81:637a87eb8170 | 139 | |
| ocomeni | 81:637a87eb8170 | 140 | typedef struct { |
| ocomeni | 80:e8f0e92e3ac9 | 141 | wifi_cmd_t wifi_cmd; /* wifi data command */ |
| ocomeni | 93:06e755a80187 | 142 | uint8_t padding[4-sizeof(wifi_cmd_t)]; /* padding */ |
| ocomeni | 81:637a87eb8170 | 143 | int dataLen; /* size of data in buffer */ |
| ocomeni | 81:637a87eb8170 | 144 | uint8_t buffer[TX_BUFFER_LEN]; /* buffer length */ |
| ocomeni | 80:e8f0e92e3ac9 | 145 | } wifi_data_msg_t; |
| ocomeni | 80:e8f0e92e3ac9 | 146 | |
| ocomeni | 81:637a87eb8170 | 147 | typedef struct { |
| ocomeni | 81:637a87eb8170 | 148 | at_cmd_resp_t at_resp; /* AT response */ |
| ocomeni | 81:637a87eb8170 | 149 | int dataLen; /* size of data in buffer */ |
| ocomeni | 81:637a87eb8170 | 150 | uint8_t buffer[TX_BUFFER_LEN]; /* buffer length */ |
| ocomeni | 81:637a87eb8170 | 151 | } at_data_msg_t; |
| ocomeni | 81:637a87eb8170 | 152 | |
| ocomeni | 81:637a87eb8170 | 153 | typedef struct { |
| ocomeni | 84:7c7add00f4bf | 154 | http_method method; /* POST/GET etc... */ |
| ocomeni | 90:ed0267eca7b5 | 155 | char * request_URI; /* request URI/path */ |
| ocomeni | 90:ed0267eca7b5 | 156 | char * http_version; /* http verstion HTTP/1.1 */ |
| ocomeni | 90:ed0267eca7b5 | 157 | char * hostName; /* host name */ |
| ocomeni | 90:ed0267eca7b5 | 158 | char * AcceptVal; /* types accepted */ |
| ocomeni | 90:ed0267eca7b5 | 159 | char * contentType; /* content type */ |
| ocomeni | 90:ed0267eca7b5 | 160 | char * contentLen; /* content length */ |
| ocomeni | 90:ed0267eca7b5 | 161 | uint8_t * body; /* body */ |
| ocomeni | 90:ed0267eca7b5 | 162 | uint8_t buffer[TX_BUFFER_LEN - 8*sizeof(char *) |
| ocomeni | 90:ed0267eca7b5 | 163 | - sizeof(http_method)]; // buffer |
| ocomeni | 84:7c7add00f4bf | 164 | } http_request_t; |
| ocomeni | 81:637a87eb8170 | 165 | |
| ocomeni | 81:637a87eb8170 | 166 | typedef struct { |
| ocomeni | 83:9c271a50a70b | 167 | uint8_t startByte; /* start Byte 0xAA */ |
| ocomeni | 83:9c271a50a70b | 168 | uint16_t payloadLen; /* payload Length */ |
| ocomeni | 83:9c271a50a70b | 169 | uint16_t payloadID; /* payload identifier */ |
| ocomeni | 90:ed0267eca7b5 | 170 | channel_id_t channel_id; /* channel_id_t*/ |
| ocomeni | 83:9c271a50a70b | 171 | } edm_header_t; |
| ocomeni | 83:9c271a50a70b | 172 | |
| ocomeni | 83:9c271a50a70b | 173 | typedef struct { |
| ocomeni | 81:637a87eb8170 | 174 | string contentType; /* content type */ |
| ocomeni | 81:637a87eb8170 | 175 | int bodyLen; /* body length */ |
| ocomeni | 81:637a87eb8170 | 176 | uint8_t body[900]; /* body */ |
| ocomeni | 81:637a87eb8170 | 177 | } http_response_t; |
| ocomeni | 81:637a87eb8170 | 178 | |
| ocomeni | 81:637a87eb8170 | 179 | typedef struct { |
| ocomeni | 81:637a87eb8170 | 180 | uint8_t peer_id ; /* peer id */ |
| ocomeni | 81:637a87eb8170 | 181 | conn_scheme_t connectionScheme; /* connection scheme */ |
| ocomeni | 90:ed0267eca7b5 | 182 | char url[MAX_URL_LEN]; /* url string */ |
| ocomeni | 81:637a87eb8170 | 183 | } internet_config_t; |
| ocomeni | 81:637a87eb8170 | 184 | |
| ocomeni | 78:07bb86e3ce14 | 185 | #endif // __COMMON_TYPES_H__ |