this is using the mbed os version 5-13-1
source/common_types.h@116:2296cf274661, 2019-05-19 (annotated)
- Committer:
- ocomeni
- Date:
- Sun May 19 13:09:27 2019 +0000
- Branch:
- PassingRegression
- Revision:
- 116:2296cf274661
- Parent:
- 114:b11bb96c09f3
- Child:
- 117:8fd05113efc1
refactoring main, atcmd, BLE and WiFi. added data structures into main and replaced values with references in main. tested and works.
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 | 100:80ef4bc31b7a | 19 | #define MAX_IPv4_LEN 16 |
| ocomeni | 116:2296cf274661 | 20 | #define MAX_CLOUD_USER_ID_LEN 32 |
| ocomeni | 116:2296cf274661 | 21 | #define MAX_CLOUD_PASSWORD_LEN 32 |
| ocomeni | 78:07bb86e3ce14 | 22 | |
| ocomeni | 78:07bb86e3ce14 | 23 | /** ble configuration structure |
| ocomeni | 78:07bb86e3ce14 | 24 | */ |
| ocomeni | 92:ec9550034276 | 25 | typedef struct { |
| ocomeni | 79:a2187bbfa407 | 26 | char deviceName[BLE_MAX_DEVICE_NAME_LEN]; /* BLE Device Name */ |
| ocomeni | 79:a2187bbfa407 | 27 | uint16_t advInterval; /* advertising interval in msecs */ |
| ocomeni | 79:a2187bbfa407 | 28 | uint16_t advTimeout; /* advertising timeout in secs */ |
| ocomeni | 79:a2187bbfa407 | 29 | //Passkey_t pairingKey; /* pairing Key */ |
| ocomeni | 79:a2187bbfa407 | 30 | uint8_t pairingKey[6]; /* pairing Key */ |
| ocomeni | 78:07bb86e3ce14 | 31 | } ble_config_t; |
| ocomeni | 78:07bb86e3ce14 | 32 | |
| ocomeni | 116:2296cf274661 | 33 | /** login token configuration structure |
| ocomeni | 116:2296cf274661 | 34 | */ |
| ocomeni | 116:2296cf274661 | 35 | typedef struct { |
| ocomeni | 116:2296cf274661 | 36 | char userid[MAX_CLOUD_USER_ID_LEN]; /* cloud login userid */ |
| ocomeni | 116:2296cf274661 | 37 | char pass[MAX_CLOUD_PASSWORD_LEN]; /* cloud login password */ |
| ocomeni | 116:2296cf274661 | 38 | } login_config_t; |
| ocomeni | 116:2296cf274661 | 39 | |
| ocomeni | 103:7b566b522427 | 40 | /** wifi configuration structure |
| ocomeni | 78:07bb86e3ce14 | 41 | */ |
| ocomeni | 92:ec9550034276 | 42 | typedef struct { |
| ocomeni | 78:07bb86e3ce14 | 43 | char ssid[MAX_SSID_LEN]; /* WiFi SSID */ |
| ocomeni | 78:07bb86e3ce14 | 44 | char pass[MAX_PASSKEY_LEN]; /* WiFi Passkey */ |
| ocomeni | 78:07bb86e3ce14 | 45 | nsapi_security_t security; /* WiFi security */ |
| ocomeni | 78:07bb86e3ce14 | 46 | } wifi_config_t; |
| ocomeni | 78:07bb86e3ce14 | 47 | |
| ocomeni | 78:07bb86e3ce14 | 48 | |
| ocomeni | 92:ec9550034276 | 49 | typedef enum |
| ocomeni | 79:a2187bbfa407 | 50 | { |
| ocomeni | 114:b11bb96c09f3 | 51 | MAIN_IDLE, |
| ocomeni | 114:b11bb96c09f3 | 52 | START_BLE, |
| ocomeni | 114:b11bb96c09f3 | 53 | STOP_BLE, |
| ocomeni | 114:b11bb96c09f3 | 54 | START_WIFI, |
| ocomeni | 114:b11bb96c09f3 | 55 | STOP_WIFI |
| ocomeni | 114:b11bb96c09f3 | 56 | }main_states_t; |
| ocomeni | 114:b11bb96c09f3 | 57 | |
| ocomeni | 114:b11bb96c09f3 | 58 | |
| ocomeni | 114:b11bb96c09f3 | 59 | typedef enum |
| ocomeni | 114:b11bb96c09f3 | 60 | { |
| ocomeni | 104:11e9605093c9 | 61 | RESPONSE_OK, |
| ocomeni | 104:11e9605093c9 | 62 | TLS_CONNECTION_FAILED, |
| ocomeni | 104:11e9605093c9 | 63 | HTTP_REQUEST_FAILED |
| ocomeni | 104:11e9605093c9 | 64 | }http_result_t; |
| ocomeni | 104:11e9605093c9 | 65 | |
| ocomeni | 104:11e9605093c9 | 66 | typedef enum |
| ocomeni | 104:11e9605093c9 | 67 | { |
| ocomeni | 95:290859010c8c | 68 | WIFI_CONFIG_RESET, |
| ocomeni | 95:290859010c8c | 69 | WIFI_CONFIG_STORE, |
| ocomeni | 95:290859010c8c | 70 | WIFI_CONFIG_LOAD, |
| ocomeni | 95:290859010c8c | 71 | WIFI_CONFIG_ACTIVATE, |
| ocomeni | 95:290859010c8c | 72 | WIFI_CONFIG_DEACTIVATE |
| ocomeni | 95:290859010c8c | 73 | }action_id_t; |
| ocomeni | 95:290859010c8c | 74 | |
| ocomeni | 95:290859010c8c | 75 | |
| ocomeni | 95:290859010c8c | 76 | typedef enum |
| ocomeni | 95:290859010c8c | 77 | { |
| ocomeni | 79:a2187bbfa407 | 78 | WIFI_CMD_NONE, |
| ocomeni | 81:637a87eb8170 | 79 | WIFI_CMD_CONFIG, |
| ocomeni | 81:637a87eb8170 | 80 | WIFI_CMD_INTERNET_CONFIG, |
| ocomeni | 79:a2187bbfa407 | 81 | WIFI_CMD_SCAN, |
| ocomeni | 81:637a87eb8170 | 82 | WIFI_CMD_DETAILED_SCAN, |
| ocomeni | 79:a2187bbfa407 | 83 | WIFI_CMD_CONNECT, |
| ocomeni | 79:a2187bbfa407 | 84 | WIFI_CMD_DISCONNECT, |
| ocomeni | 95:290859010c8c | 85 | WIFI_CMD_NETWORK_STATUS, |
| ocomeni | 95:290859010c8c | 86 | WIFI_CMD_WIFI_STATUS, |
| ocomeni | 79:a2187bbfa407 | 87 | WIFI_CMD_SEND_HTTPS_REQ, |
| ocomeni | 79:a2187bbfa407 | 88 | WIFI_CMD_SEND_HTTP_REQ |
| ocomeni | 79:a2187bbfa407 | 89 | }wifi_cmd_t; |
| ocomeni | 79:a2187bbfa407 | 90 | |
| ocomeni | 92:ec9550034276 | 91 | typedef enum |
| ocomeni | 81:637a87eb8170 | 92 | { |
| ocomeni | 100:80ef4bc31b7a | 93 | AT_RESP_NONE = 0, |
| ocomeni | 100:80ef4bc31b7a | 94 | AT_SCAN_RESP = 1, |
| ocomeni | 100:80ef4bc31b7a | 95 | AT_DETAILED_SCAN_RESP = 2, |
| ocomeni | 100:80ef4bc31b7a | 96 | AT_CONNECT_RESP = 3, |
| ocomeni | 100:80ef4bc31b7a | 97 | AT_DISCONNECT_RESP = 4, |
| ocomeni | 100:80ef4bc31b7a | 98 | WIFI_RECONNECT_INFO = 5, |
| ocomeni | 100:80ef4bc31b7a | 99 | WIFI_DISCONNECT_INFO = 6, |
| ocomeni | 100:80ef4bc31b7a | 100 | AT_CONFIG_RESP = 7, |
| ocomeni | 100:80ef4bc31b7a | 101 | AT_INTERNET_CONFIG_RESP = 8, |
| ocomeni | 100:80ef4bc31b7a | 102 | AT_NETWORK_STATUS_RESP = 9, |
| ocomeni | 100:80ef4bc31b7a | 103 | AT_WIFI_STATUS_RESP = 10, |
| ocomeni | 100:80ef4bc31b7a | 104 | AT_HTTPS_RESP = 11, |
| ocomeni | 100:80ef4bc31b7a | 105 | AT_HTTPS_RESP_DOWNLOAD = 12, |
| ocomeni | 100:80ef4bc31b7a | 106 | AT_HTTP_RESP = 13, |
| ocomeni | 100:80ef4bc31b7a | 107 | AT_HTTP_RESP_DOWNLOAD = 14, |
| ocomeni | 100:80ef4bc31b7a | 108 | AT_EVENT = 15, |
| ocomeni | 100:80ef4bc31b7a | 109 | CONNECT_EVENT = 16, |
| ocomeni | 100:80ef4bc31b7a | 110 | DATA_EVENT = 17, |
| ocomeni | 104:11e9605093c9 | 111 | AT_COMMAND_FAILED = 18, |
| ocomeni | 104:11e9605093c9 | 112 | WIFI_WATCH_DOG = 19 |
| ocomeni | 81:637a87eb8170 | 113 | }at_cmd_resp_t; |
| ocomeni | 81:637a87eb8170 | 114 | |
| ocomeni | 90:ed0267eca7b5 | 115 | typedef enum edm_msg_id |
| ocomeni | 90:ed0267eca7b5 | 116 | { |
| ocomeni | 90:ed0267eca7b5 | 117 | CONNECT_MSG_ID = 0x0010, |
| ocomeni | 90:ed0267eca7b5 | 118 | DISCONNECT_MSG_ID = 0x0020, |
| ocomeni | 90:ed0267eca7b5 | 119 | DATA_MSG_ID = 0x0030, |
| ocomeni | 90:ed0267eca7b5 | 120 | AT_MSG_ID = 0x0040 |
| ocomeni | 90:ed0267eca7b5 | 121 | }edm_msg_id_t; |
| ocomeni | 90:ed0267eca7b5 | 122 | |
| ocomeni | 90:ed0267eca7b5 | 123 | |
| ocomeni | 90:ed0267eca7b5 | 124 | typedef enum edm_msg_type |
| ocomeni | 90:ed0267eca7b5 | 125 | { |
| ocomeni | 90:ed0267eca7b5 | 126 | EVENT_MSG_TYPE = 0x01, |
| ocomeni | 90:ed0267eca7b5 | 127 | INDICATION_MSG_TYPE = 0x02, |
| ocomeni | 90:ed0267eca7b5 | 128 | RESPONSE_MSG_TYPE = 0x03, |
| ocomeni | 90:ed0267eca7b5 | 129 | REQUEST_MSG_TYPE = 0x04, |
| ocomeni | 90:ed0267eca7b5 | 130 | CONFIRMATION_MSG_TYPE = 0x05, |
| ocomeni | 90:ed0267eca7b5 | 131 | COMMAND_MSG_TYPE = 0x06 |
| ocomeni | 90:ed0267eca7b5 | 132 | }edm_msg_type_t; |
| ocomeni | 90:ed0267eca7b5 | 133 | |
| ocomeni | 90:ed0267eca7b5 | 134 | typedef enum channel_id |
| ocomeni | 90:ed0267eca7b5 | 135 | { |
| ocomeni | 90:ed0267eca7b5 | 136 | WIFI_CHANNEL = 0x00, |
| ocomeni | 93:06e755a80187 | 137 | BLE_CHANNEL = 0x01, |
| ocomeni | 93:06e755a80187 | 138 | NO_CHANNEL = 0xFF |
| ocomeni | 90:ed0267eca7b5 | 139 | }channel_id_t; |
| ocomeni | 90:ed0267eca7b5 | 140 | |
| ocomeni | 90:ed0267eca7b5 | 141 | |
| ocomeni | 81:637a87eb8170 | 142 | |
| ocomeni | 81:637a87eb8170 | 143 | typedef enum at_data_mode |
| ocomeni | 81:637a87eb8170 | 144 | { |
| ocomeni | 81:637a87eb8170 | 145 | AT_CMD_DATA_MODE, |
| ocomeni | 81:637a87eb8170 | 146 | AT_STD_DATA_MODE, |
| ocomeni | 81:637a87eb8170 | 147 | AT_EXT_DATA_MODE |
| ocomeni | 81:637a87eb8170 | 148 | }at_data_mode_t; |
| ocomeni | 81:637a87eb8170 | 149 | |
| ocomeni | 83:9c271a50a70b | 150 | typedef enum edm_payload_id |
| ocomeni | 83:9c271a50a70b | 151 | { |
| ocomeni | 99:05398b3184f8 | 152 | CONNECT_EVENT_ID = 0x0011, |
| ocomeni | 99:05398b3184f8 | 153 | DISCONNECT_EVENT_ID = 0x0021, |
| ocomeni | 99:05398b3184f8 | 154 | DATA_EVENT_ID = 0x0031, |
| ocomeni | 99:05398b3184f8 | 155 | DATA_COMMAND_ID = 0x0036, |
| ocomeni | 99:05398b3184f8 | 156 | AT_REQUEST_ID = 0x0044, |
| ocomeni | 99:05398b3184f8 | 157 | AT_CONFIRMATION_ID = 0x0045, |
| ocomeni | 99:05398b3184f8 | 158 | AT_EVENT_ID = 0x0041 |
| ocomeni | 83:9c271a50a70b | 159 | }edm_payload_id_t; |
| ocomeni | 83:9c271a50a70b | 160 | |
| ocomeni | 81:637a87eb8170 | 161 | typedef enum conn_scheme |
| ocomeni | 81:637a87eb8170 | 162 | { |
| ocomeni | 81:637a87eb8170 | 163 | INVALID_SCHEME, |
| ocomeni | 81:637a87eb8170 | 164 | ALWAYS_CONNECTED, |
| ocomeni | 81:637a87eb8170 | 165 | EXTERNAL_CONNECT |
| ocomeni | 81:637a87eb8170 | 166 | }conn_scheme_t; |
| ocomeni | 81:637a87eb8170 | 167 | |
| ocomeni | 79:a2187bbfa407 | 168 | |
| ocomeni | 79:a2187bbfa407 | 169 | typedef struct { |
| ocomeni | 79:a2187bbfa407 | 170 | wifi_cmd_t wifi_cmd; /* wifi command */ |
| ocomeni | 93:06e755a80187 | 171 | uint8_t padding[4-sizeof(wifi_cmd_t)]; /* padding */ |
| ocomeni | 79:a2187bbfa407 | 172 | } wifi_cmd_message_t; |
| ocomeni | 79:a2187bbfa407 | 173 | |
| ocomeni | 80:e8f0e92e3ac9 | 174 | typedef struct { |
| ocomeni | 81:637a87eb8170 | 175 | at_cmd_resp_t at_resp; /* AT response */ |
| ocomeni | 81:637a87eb8170 | 176 | } at_resp_message_t; |
| ocomeni | 81:637a87eb8170 | 177 | |
| ocomeni | 81:637a87eb8170 | 178 | typedef struct { |
| ocomeni | 80:e8f0e92e3ac9 | 179 | wifi_cmd_t wifi_cmd; /* wifi data command */ |
| ocomeni | 93:06e755a80187 | 180 | uint8_t padding[4-sizeof(wifi_cmd_t)]; /* padding */ |
| ocomeni | 81:637a87eb8170 | 181 | int dataLen; /* size of data in buffer */ |
| ocomeni | 81:637a87eb8170 | 182 | uint8_t buffer[TX_BUFFER_LEN]; /* buffer length */ |
| ocomeni | 80:e8f0e92e3ac9 | 183 | } wifi_data_msg_t; |
| ocomeni | 80:e8f0e92e3ac9 | 184 | |
| ocomeni | 81:637a87eb8170 | 185 | typedef struct { |
| ocomeni | 81:637a87eb8170 | 186 | at_cmd_resp_t at_resp; /* AT response */ |
| ocomeni | 81:637a87eb8170 | 187 | int dataLen; /* size of data in buffer */ |
| ocomeni | 81:637a87eb8170 | 188 | uint8_t buffer[TX_BUFFER_LEN]; /* buffer length */ |
| ocomeni | 81:637a87eb8170 | 189 | } at_data_msg_t; |
| ocomeni | 81:637a87eb8170 | 190 | |
| ocomeni | 81:637a87eb8170 | 191 | typedef struct { |
| ocomeni | 84:7c7add00f4bf | 192 | http_method method; /* POST/GET etc... */ |
| ocomeni | 90:ed0267eca7b5 | 193 | char * request_URI; /* request URI/path */ |
| ocomeni | 90:ed0267eca7b5 | 194 | char * http_version; /* http verstion HTTP/1.1 */ |
| ocomeni | 90:ed0267eca7b5 | 195 | char * hostName; /* host name */ |
| ocomeni | 90:ed0267eca7b5 | 196 | char * AcceptVal; /* types accepted */ |
| ocomeni | 90:ed0267eca7b5 | 197 | char * contentType; /* content type */ |
| ocomeni | 90:ed0267eca7b5 | 198 | char * contentLen; /* content length */ |
| ocomeni | 90:ed0267eca7b5 | 199 | uint8_t * body; /* body */ |
| ocomeni | 90:ed0267eca7b5 | 200 | uint8_t buffer[TX_BUFFER_LEN - 8*sizeof(char *) |
| ocomeni | 90:ed0267eca7b5 | 201 | - sizeof(http_method)]; // buffer |
| ocomeni | 84:7c7add00f4bf | 202 | } http_request_t; |
| ocomeni | 81:637a87eb8170 | 203 | |
| ocomeni | 81:637a87eb8170 | 204 | typedef struct { |
| ocomeni | 83:9c271a50a70b | 205 | uint8_t startByte; /* start Byte 0xAA */ |
| ocomeni | 83:9c271a50a70b | 206 | uint16_t payloadLen; /* payload Length */ |
| ocomeni | 83:9c271a50a70b | 207 | uint16_t payloadID; /* payload identifier */ |
| ocomeni | 90:ed0267eca7b5 | 208 | channel_id_t channel_id; /* channel_id_t*/ |
| ocomeni | 83:9c271a50a70b | 209 | } edm_header_t; |
| ocomeni | 83:9c271a50a70b | 210 | |
| ocomeni | 83:9c271a50a70b | 211 | typedef struct { |
| ocomeni | 81:637a87eb8170 | 212 | string contentType; /* content type */ |
| ocomeni | 81:637a87eb8170 | 213 | int bodyLen; /* body length */ |
| ocomeni | 81:637a87eb8170 | 214 | uint8_t body[900]; /* body */ |
| ocomeni | 81:637a87eb8170 | 215 | } http_response_t; |
| ocomeni | 81:637a87eb8170 | 216 | |
| ocomeni | 81:637a87eb8170 | 217 | typedef struct { |
| ocomeni | 81:637a87eb8170 | 218 | uint8_t peer_id ; /* peer id */ |
| ocomeni | 81:637a87eb8170 | 219 | conn_scheme_t connectionScheme; /* connection scheme */ |
| ocomeni | 90:ed0267eca7b5 | 220 | char url[MAX_URL_LEN]; /* url string */ |
| ocomeni | 100:80ef4bc31b7a | 221 | char local_IPv4Address[MAX_IPv4_LEN]; /* local Ip address */ |
| ocomeni | 100:80ef4bc31b7a | 222 | char remote_IPv4Address[MAX_IPv4_LEN]; /* remote IP address */ |
| ocomeni | 100:80ef4bc31b7a | 223 | uint16_t remote_port; /* remote port */ |
| ocomeni | 81:637a87eb8170 | 224 | } internet_config_t; |
| ocomeni | 81:637a87eb8170 | 225 | |
| ocomeni | 116:2296cf274661 | 226 | |
| ocomeni | 116:2296cf274661 | 227 | /** application configuration structure |
| ocomeni | 116:2296cf274661 | 228 | */ |
| ocomeni | 116:2296cf274661 | 229 | typedef struct { |
| ocomeni | 116:2296cf274661 | 230 | wifi_config_t wifi_config; /* wifi configuration */ |
| ocomeni | 116:2296cf274661 | 231 | ble_config_t ble_config; /* ble configuration */ |
| ocomeni | 116:2296cf274661 | 232 | internet_config_t internet_config; /* cloud configuration */ |
| ocomeni | 116:2296cf274661 | 233 | login_config_t login_config; /* cloud login credentials */ |
| ocomeni | 116:2296cf274661 | 234 | } app_config_t; |
| ocomeni | 116:2296cf274661 | 235 | |
| ocomeni | 116:2296cf274661 | 236 | |
| ocomeni | 78:07bb86e3ce14 | 237 | #endif // __COMMON_TYPES_H__ |