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

Dependencies:   mbed-http

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers common_types.h Source File

common_types.h

00001 #ifndef __COMMON_TYPES_H__
00002 #define __COMMON_TYPES_H__
00003 #include <mbed.h>
00004 #include <string>
00005 #include "ble/BLE.h"
00006 #include "SecurityManager.h"
00007 #include "http_request.h"
00008 #include "common_config.h"
00009 #define BLE_MAX_DEVICE_NAME_LEN 10
00010 #define MAX_SSID_LEN 32
00011 #define MAX_PASSKEY_LEN 32
00012 #define EDM_START_BYTE       0xAA
00013 #define EDM_STOP_BYTE        0x55
00014 #define EDM_HDR_LEN          6
00015 #define MAX_EDM_PAYLOAD_LEN  (4096-1)
00016 #define MIN_EDM_PAYLOAD_LEN (2)
00017 #define MAX_HTTP_HEADER_LINES
00018 #define MAX_URL_LEN          100
00019 #define MAX_IPv4_LEN         16
00020 #define MAX_CLOUD_USER_ID_LEN   32
00021 #define MAX_CLOUD_PASSWORD_LEN  32
00022 #define REC_DB_MSGTYPE          0x09
00023 #define BAR_DB_MSGTYPE          0x06
00024 /** ble configuration structure
00025 */
00026 typedef struct  {
00027     char      deviceName[BLE_MAX_DEVICE_NAME_LEN]; /* BLE Device Name */
00028     uint16_t  advInterval; /* advertising interval in msecs */
00029     uint16_t  advTimeout;  /* advertising timeout in secs */
00030     //Passkey_t pairingKey;  /* pairing Key */
00031     uint8_t   pairingKey[6];  /* pairing Key */
00032 } ble_config_t;
00033 
00034 /** login token configuration structure
00035 */
00036 typedef struct  {
00037     char             userid[MAX_CLOUD_USER_ID_LEN];  /* cloud login userid */
00038     char             pass[MAX_CLOUD_PASSWORD_LEN]; /* cloud login password  */
00039 } login_config_t;
00040 
00041 /** wifi configuration structure
00042 */
00043 typedef struct  {
00044     char             ssid[MAX_SSID_LEN]; /* WiFi SSID */
00045     char             pass[MAX_PASSKEY_LEN]; /* WiFi Passkey */
00046     nsapi_security_t security;  /* WiFi security */
00047 } wifi_config_t;
00048 
00049 
00050 typedef enum
00051 {
00052   MAIN_IDLE,
00053   START_BLE,
00054   STOP_BLE,
00055   START_WIFI,
00056   STOP_WIFI
00057 }main_states_t;
00058 
00059 
00060 typedef enum
00061 {
00062   RESPONSE_OK,
00063   TLS_CONNECTION_FAILED,
00064   HTTP_REQUEST_FAILED
00065 }http_result_t;
00066 
00067 typedef enum
00068 {
00069   WIFI_CONFIG_RESET,
00070   WIFI_CONFIG_STORE,
00071   WIFI_CONFIG_LOAD,
00072   WIFI_CONFIG_ACTIVATE,
00073   WIFI_CONFIG_DEACTIVATE
00074 }action_id_t;
00075 
00076 
00077 typedef enum
00078 {
00079   WIFI_CMD_NONE,
00080   WIFI_CMD_CONFIG,
00081   WIFI_CMD_INTERNET_CONFIG,
00082   WIFI_CMD_SCAN,
00083   WIFI_CMD_DETAILED_SCAN,
00084   WIFI_CMD_CONNECT,
00085   WIFI_CMD_DISCONNECT,
00086   WIFI_CMD_NETWORK_STATUS,
00087   WIFI_CMD_WIFI_STATUS,
00088   WIFI_CMD_WIFI_MAC_ADDR,
00089   WIFI_CMD_SEND_HTTPS_REQ,
00090   WIFI_CMD_SEND_HTTP_REQ,
00091   WIFI_CMD_TLS_CONNECT,
00092   WIFI_CMD_INTERNET_KEEP_ALIVE,
00093   WIFI_CMD_GET_TOKEN
00094 }wifi_cmd_t;
00095 
00096 typedef enum
00097 {
00098   AT_RESP_NONE = 0,
00099   AT_SCAN_RESP = 1,
00100   AT_DETAILED_SCAN_RESP = 2,
00101   AT_CONNECT_RESP = 3,
00102   AT_DISCONNECT_RESP = 4,
00103   WIFI_RECONNECT_INFO = 5,
00104   WIFI_DISCONNECT_INFO = 6,
00105   AT_CONFIG_RESP = 7,
00106   AT_INTERNET_CONFIG_RESP = 8,
00107   AT_NETWORK_STATUS_RESP = 9,
00108   AT_WIFI_STATUS_RESP = 10,
00109   AT_HTTPS_RESP = 11,
00110   AT_HTTPS_RESP_DOWNLOAD = 12,
00111   AT_HTTP_RESP = 13,
00112   AT_HTTP_RESP_DOWNLOAD = 14,
00113   AT_EVENT = 15,
00114   CONNECT_EVENT = 16,
00115   DATA_EVENT = 17,
00116   AT_COMMAND_FAILED = 18,
00117   WIFI_WATCH_DOG = 19,
00118   BLE_CONNECT_EVENT = 20,
00119   AT_BLE_EVENT = 21,
00120   AT_BLE_RESPONSE = 22,
00121   AT_SOCKET_KEEP_ALIVE_OK = 23,
00122   AT_SOCKET_KEEP_ALIVE_FAILED = 24,
00123   BLE_DISCONNECT_EVENT = 25,
00124   AT_WIFI_MAC_RESP = 26,
00125   AT_BLE_MAC_RESP = 27,
00126   AT_BLE_NAME_RESP = 28,
00127   AT_ACCESS_TOKEN_SUCCESS = 29,
00128   AT_ACCESS_TOKEN_FAILED = 30
00129 }at_cmd_resp_t;
00130 
00131 typedef enum edm_msg_id
00132 {
00133   CONNECT_MSG_ID    = 0x0010,
00134   DISCONNECT_MSG_ID = 0x0020,
00135   DATA_MSG_ID       = 0x0030,
00136   AT_MSG_ID         = 0x0040   
00137 }edm_msg_id_t;
00138 
00139 
00140 typedef enum edm_msg_type
00141 {
00142   EVENT_MSG_TYPE        = 0x01,
00143   INDICATION_MSG_TYPE   = 0x02,
00144   RESPONSE_MSG_TYPE     = 0x03,
00145   REQUEST_MSG_TYPE      = 0x04,
00146   CONFIRMATION_MSG_TYPE = 0x05,
00147   COMMAND_MSG_TYPE      = 0x06
00148 }edm_msg_type_t;
00149 
00150 typedef enum channel_id
00151 {
00152   WIFI_CHANNEL          = 0x00,
00153   BLE_CHANNEL           = 0x01,
00154   NO_CHANNEL            = 0xFF
00155 }channel_id_t;
00156 
00157 
00158 
00159 typedef enum at_data_mode
00160 {
00161   AT_CMD_DATA_MODE,
00162   AT_STD_DATA_MODE,
00163   AT_EXT_DATA_MODE
00164 }at_data_mode_t;
00165 
00166 typedef enum edm_payload_id
00167 {
00168   CONNECT_EVENT_ID    = 0x0011,
00169   DISCONNECT_EVENT_ID = 0x0021,
00170   DATA_EVENT_ID       = 0x0031,
00171   DATA_COMMAND_ID     = 0x0036,
00172   AT_REQUEST_ID       = 0x0044,
00173   AT_CONFIRMATION_ID  = 0x0045,
00174   AT_EVENT_ID         = 0x0041
00175 }edm_payload_id_t;
00176 
00177 typedef enum conn_scheme
00178 {
00179   INVALID_SCHEME,
00180   ALWAYS_CONNECTED,
00181   EXTERNAL_CONNECT
00182 }conn_scheme_t;
00183 
00184 
00185 typedef enum nvstore_key
00186 {
00187   APP_CONFIG_0 = 1,
00188   APP_CONFIG_1 = 2,
00189   APP_CONFIG_2 = 4
00190 }nvstore_key_t;
00191 
00192 
00193 typedef struct {
00194     int     baudrate;  /* baud rate */
00195     uint8_t flow_ctrl; /* 2 = no flow control */
00196     uint8_t data_bits; /* 8 data bits */
00197     uint8_t stop_bits; /* 1 start bit */
00198     uint8_t parity;    /* 1 parity bit */
00199     uint8_t change_after_confirm; /* 1 */
00200 } uart_config_t;
00201 
00202 
00203 
00204 typedef struct {
00205     wifi_cmd_t    wifi_cmd;   /* wifi command */
00206     uint8_t       padding[4-sizeof(wifi_cmd_t)];   /* padding */
00207 } wifi_cmd_message_t;
00208 
00209 typedef struct {
00210     at_cmd_resp_t    at_resp;   /* AT response */
00211 } at_resp_message_t;
00212 
00213 typedef struct {
00214     wifi_cmd_t    wifi_cmd;              /* wifi data command */
00215     uint8_t       padding[4-sizeof(wifi_cmd_t)];   /* padding */
00216     int           dataLen;              /* size of data in buffer */
00217     uint8_t       buffer[TX_BUFFER_LEN]; /* buffer length     */
00218 } wifi_data_msg_t;
00219 
00220 typedef struct {
00221     at_cmd_resp_t at_resp;              /* AT response */
00222     int           dataLen;              /* size of data in buffer */
00223     uint8_t       buffer[TX_BUFFER_LEN]; /* buffer length     */
00224 } at_data_msg_t;
00225 
00226 typedef struct {
00227     http_method   method;       /* POST/GET etc... */
00228     char *        request_URI;  /* request URI/path */
00229     char *        http_version; /* http verstion HTTP/1.1 */
00230     char *        hostName;     /* host name */
00231     char *        AcceptVal;    /* types accepted */
00232     char *        contentType;  /* content type */
00233     char *        contentLen;   /* content length   */
00234     char *        X_Amz_Target;   /* X-Amz-Target   */
00235     uint8_t *     body;         /* body     */
00236     uint8_t       buffer[TX_BUFFER_LEN - 8*sizeof(char *) 
00237                                      - sizeof(http_method)]; // buffer   
00238 } http_request_t;
00239 
00240 typedef struct {
00241     uint8_t       startByte;   /* start Byte 0xAA */
00242     uint16_t      payloadLen;  /* payload Length */
00243     uint16_t      payloadID;   /* payload identifier     */
00244     channel_id_t  channel_id;   /* channel_id_t*/
00245 } edm_header_t;
00246 
00247 typedef struct {
00248     string        contentType;  /* content type */
00249     int           bodyLen;      /* body length     */
00250     uint8_t       body[900];    /* body     */
00251 } http_response_t;
00252 
00253 typedef struct {
00254     uint8_t       peer_id          ;  /* peer id */
00255     conn_scheme_t connectionScheme;   /* connection scheme     */
00256     char          url[MAX_URL_LEN];   /* url string     */
00257     char          local_IPv4Address[MAX_IPv4_LEN];    /* local Ip address     */
00258     char          remote_IPv4Address[MAX_IPv4_LEN];   /* remote IP address     */
00259     uint16_t      remote_port;                        /* remote port     */
00260 } internet_config_t;
00261 
00262 typedef struct {
00263     bool          ble_enable;  /* enable BLE on startup */
00264     bool          wifi_enable; /* enable WiFi on startup */
00265 } startup_config_t;
00266 
00267 
00268 /** application configuration structure
00269 */
00270 typedef struct  {
00271     startup_config_t  startup_config;
00272     uart_config_t     uart_config;      /* UART configuration      */
00273     wifi_config_t     wifi_config;      /* wifi configuration      */
00274     ble_config_t      ble_config;       /* ble configuration       */
00275     internet_config_t internet_config;  /* cloud configuration     */
00276     login_config_t    login_config;     /* cloud login credentials */
00277 } app_config_t;
00278 
00279 
00280 /* BLE data types */
00281 
00282 typedef enum
00283 {
00284   BLE_CMD_NONE,
00285   BLE_CMD_CONFIG,
00286   BLE_CMD_MAC_ADDR,
00287   BLE_CMD_DEVICE_NAME,
00288   BLE_CMD_CONNECT,
00289   BLE_CMD_DISCONNECT,
00290   BLE_CMD_SEND_RX_DATA_2AT,
00291   BLE_CMD_SEND_AT_DATA_2BLE
00292 }ble_cmd_t;
00293 
00294 
00295 
00296 typedef struct {
00297     ble_cmd_t     ble_cmd;                     /* BLE command             */
00298     int           dataLen;                     /* size of data in buffer */
00299     uint8_t       buffer[MAX_BLE_POOL_DATA_SIZE]; /* buffer length     */
00300 } at_ble_msg_t;
00301 
00302 
00303 typedef struct {
00304     at_cmd_resp_t at_resp;              /* AT response */
00305     int           dataLen;              /* size of data in buffer */
00306     uint8_t       buffer[MAX_BLE_POOL_DATA_SIZE]; /* buffer length     */
00307 } ble_at_msg_t;
00308 
00309 
00310 #endif  // __COMMON_TYPES_H__