Etherios Cloud Connector very first porting for mbed. Tested in an LPC1768

Etherios Cloud Connector for Embedded v2.1.0.3 library for mbed. Early porting.

This port is centered mainly in the platform code. So it should work properly with the provided examples of send_data, device_request, data_points, RCI and firmware_update (stub implementation, not a real one... yet ;-)). Filesystem is not implemented yet, and some examples might need changes.

To run, it needs the following libraries: - mbed - mbed-rtos - EthernetInterface

Find more information (and the source code!) about Etherios Cloud Connector for Embedded here: http://www.etherios.com/products/devicecloud/support/connector and in: http://www.etherios.com

Committer:
spastor
Date:
Tue Dec 03 13:34:02 2013 +0000
Revision:
0:1c358ea10753
First commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spastor 0:1c358ea10753 1 /*
spastor 0:1c358ea10753 2 * Copyright (c) 2013 Digi International Inc.,
spastor 0:1c358ea10753 3 * All rights not expressly granted are reserved.
spastor 0:1c358ea10753 4 *
spastor 0:1c358ea10753 5 * This Source Code Form is subject to the terms of the Mozilla Public
spastor 0:1c358ea10753 6 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
spastor 0:1c358ea10753 7 * You can obtain one at http://mozilla.org/MPL/2.0/.
spastor 0:1c358ea10753 8 *
spastor 0:1c358ea10753 9 * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
spastor 0:1c358ea10753 10 * =======================================================================
spastor 0:1c358ea10753 11 */
spastor 0:1c358ea10753 12
spastor 0:1c358ea10753 13 #ifndef CONNECTOR_EDP_DEF_H_
spastor 0:1c358ea10753 14 #define CONNECTOR_EDP_DEF_H_
spastor 0:1c358ea10753 15
spastor 0:1c358ea10753 16 #include "ei_packet.h"
spastor 0:1c358ea10753 17
spastor 0:1c358ea10753 18 #if !defined MSG_MAX_RECV_PACKET_SIZE
spastor 0:1c358ea10753 19 #define MSG_MAX_RECV_PACKET_SIZE 1600
spastor 0:1c358ea10753 20 #endif
spastor 0:1c358ea10753 21 #if !defined MSG_MAX_SEND_PACKET_SIZE
spastor 0:1c358ea10753 22 #define MSG_MAX_SEND_PACKET_SIZE 512
spastor 0:1c358ea10753 23 #endif
spastor 0:1c358ea10753 24
spastor 0:1c358ea10753 25 #define EDP_MT_VERSION 2
spastor 0:1c358ea10753 26
spastor 0:1c358ea10753 27 #define DEVICE_TYPE_LENGTH 32
spastor 0:1c358ea10753 28 #define CONNECTOR_MAX_TRANSACTIONS_LIMIT 255
spastor 0:1c358ea10753 29
spastor 0:1c358ea10753 30 /* these are limits for Tx and Rx keepalive
spastor 0:1c358ea10753 31 * interval in seconds.
spastor 0:1c358ea10753 32 */
spastor 0:1c358ea10753 33 #define MIN_TX_KEEPALIVE_INTERVAL_IN_SECONDS 5
spastor 0:1c358ea10753 34 #define MAX_TX_KEEPALIVE_INTERVAL_IN_SECONDS 7200
spastor 0:1c358ea10753 35 #define MIN_RX_KEEPALIVE_INTERVAL_IN_SECONDS 5
spastor 0:1c358ea10753 36 #define MAX_RX_KEEPALIVE_INTERVAL_IN_SECONDS 7200
spastor 0:1c358ea10753 37
spastor 0:1c358ea10753 38 /* Limits for wait count (number of
spastor 0:1c358ea10753 39 * keepalive packets)
spastor 0:1c358ea10753 40 */
spastor 0:1c358ea10753 41 #define WAIT_COUNT_MIN 2
spastor 0:1c358ea10753 42 #define WAIT_COUNT_MAX 64
spastor 0:1c358ea10753 43
spastor 0:1c358ea10753 44 /*
spastor 0:1c358ea10753 45 * MT version 2 message type defines.
spastor 0:1c358ea10753 46 * Refer to EDP specification rev. 14.2 for a description of MT version 2.
spastor 0:1c358ea10753 47 */
spastor 0:1c358ea10753 48 #define E_MSG_MT2_TYPE_VERSION UINT32_C(0x0004) /* C -> S */
spastor 0:1c358ea10753 49 #define E_MSG_MT2_TYPE_LEGACY_EDP_VERSION UINT32_C(0x0004) /* C -> S */
spastor 0:1c358ea10753 50 #define E_MSG_MT2_TYPE_LEGACY_EDP_VER_RESP UINT32_C(0x0001) /* C <- S */
spastor 0:1c358ea10753 51 #define E_MSG_MT2_TYPE_VERSION_OK UINT32_C(0x0010) /* C <- S */
spastor 0:1c358ea10753 52 #define E_MSG_MT2_TYPE_VERSION_BAD UINT32_C(0x0011) /* C <- S */
spastor 0:1c358ea10753 53 #define E_MSG_MT2_TYPE_CLOUD_OVERLOAD UINT32_C(0x0012) /* C <- S */
spastor 0:1c358ea10753 54 #define E_MSG_MT2_TYPE_KA_RX_INTERVAL UINT32_C(0x0020) /* C -> S */
spastor 0:1c358ea10753 55 #define E_MSG_MT2_TYPE_KA_TX_INTERVAL UINT32_C(0x0021) /* C -> S */
spastor 0:1c358ea10753 56 #define E_MSG_MT2_TYPE_KA_WAIT UINT32_C(0x0022) /* C -> S */
spastor 0:1c358ea10753 57 #define E_MSG_MT2_TYPE_KA_KEEPALIVE UINT32_C(0x0030) /* bi-directional */
spastor 0:1c358ea10753 58 #define E_MSG_MT2_TYPE_PAYLOAD UINT32_C(0x0040) /* bi-directional */
spastor 0:1c358ea10753 59
spastor 0:1c358ea10753 60 #define URL_PREFIX "en://"
spastor 0:1c358ea10753 61 #define GET_PACKET_DATA_POINTER(p, s) (uint8_t *)(((uint8_t *)p) + (s))
spastor 0:1c358ea10753 62
spastor 0:1c358ea10753 63
spastor 0:1c358ea10753 64 #if (defined CONNECTOR_TX_KEEPALIVE_IN_SECONDS)
spastor 0:1c358ea10753 65 #define GET_TX_KEEPALIVE_INTERVAL(connector_ptr) CONNECTOR_TX_KEEPALIVE_IN_SECONDS
spastor 0:1c358ea10753 66 #else
spastor 0:1c358ea10753 67 #define GET_TX_KEEPALIVE_INTERVAL(connector_ptr) connector_ptr->edp_data.config.tx_keepalive_interval
spastor 0:1c358ea10753 68 #endif
spastor 0:1c358ea10753 69
spastor 0:1c358ea10753 70 #if (defined CONNECTOR_RX_KEEPALIVE_IN_SECONDS)
spastor 0:1c358ea10753 71 #define GET_RX_KEEPALIVE_INTERVAL(connector_ptr) CONNECTOR_RX_KEEPALIVE_IN_SECONDS
spastor 0:1c358ea10753 72 #else
spastor 0:1c358ea10753 73 #define GET_RX_KEEPALIVE_INTERVAL(connector_ptr) connector_ptr->edp_data.config.rx_keepalive_interval
spastor 0:1c358ea10753 74 #endif
spastor 0:1c358ea10753 75
spastor 0:1c358ea10753 76 #if (defined CONNECTOR_WAIT_COUNT)
spastor 0:1c358ea10753 77 #define GET_WAIT_COUNT(connector_ptr) CONNECTOR_WAIT_COUNT
spastor 0:1c358ea10753 78 #else
spastor 0:1c358ea10753 79 #define GET_WAIT_COUNT(connector_ptr) connector_ptr->edp_data.config.wait_count
spastor 0:1c358ea10753 80 #endif
spastor 0:1c358ea10753 81
spastor 0:1c358ea10753 82 #define MAX_RECEIVE_TIMEOUT_IN_SECONDS 1
spastor 0:1c358ea10753 83 #define MIN_RECEIVE_TIMEOUT_IN_SECONDS 0
spastor 0:1c358ea10753 84
spastor 0:1c358ea10753 85 /* IRL EDP States */
spastor 0:1c358ea10753 86 typedef enum {
spastor 0:1c358ea10753 87 edp_communication_connect_to_cloud,
spastor 0:1c358ea10753 88 edp_communication_send_version,
spastor 0:1c358ea10753 89 edp_communication_receive_version_response,
spastor 0:1c358ea10753 90 edp_communication_send_keepalive,
spastor 0:1c358ea10753 91 edp_initialization_send_protocol_version,
spastor 0:1c358ea10753 92 edp_initialization_receive_protocol_version,
spastor 0:1c358ea10753 93 edp_security_send_identity_verification,
spastor 0:1c358ea10753 94 edp_security_send_device_id,
spastor 0:1c358ea10753 95 #if (CONNECTOR_VERSION >= 0x02010000)
spastor 0:1c358ea10753 96 edp_security_receive_device_id,
spastor 0:1c358ea10753 97 #endif
spastor 0:1c358ea10753 98 edp_security_send_device_cloud_url,
spastor 0:1c358ea10753 99 edp_security_send_password,
spastor 0:1c358ea10753 100 edp_discovery_send_vendor_id,
spastor 0:1c358ea10753 101 edp_discovery_send_device_type,
spastor 0:1c358ea10753 102 edp_discovery_facility,
spastor 0:1c358ea10753 103 edp_discovery_send_complete,
spastor 0:1c358ea10753 104 edp_facility_process
spastor 0:1c358ea10753 105
spastor 0:1c358ea10753 106 } connector_edp_state_t;
spastor 0:1c358ea10753 107
spastor 0:1c358ea10753 108 typedef enum {
spastor 0:1c358ea10753 109 facility_callback_delete,
spastor 0:1c358ea10753 110 facility_callback_cleanup
spastor 0:1c358ea10753 111 } connector_supported_facility_cb_index_t;
spastor 0:1c358ea10753 112
spastor 0:1c358ea10753 113 struct connector_data;
spastor 0:1c358ea10753 114
spastor 0:1c358ea10753 115 typedef connector_status_t (* send_complete_cb_t)(struct connector_data * const connector_ptr, uint8_t const * const packet, connector_status_t const status, void * const user_data);
spastor 0:1c358ea10753 116
spastor 0:1c358ea10753 117 typedef struct connector_buffer {
spastor 0:1c358ea10753 118 /* this buffer must be FIRST field in the structure
spastor 0:1c358ea10753 119 * since this is used between network interface
spastor 0:1c358ea10753 120 * and all facilities and facilities release the buffer
spastor 0:1c358ea10753 121 * by returning the pointer of the buffer.
spastor 0:1c358ea10753 122 */
spastor 0:1c358ea10753 123 uint8_t buffer[MSG_MAX_RECV_PACKET_SIZE];
spastor 0:1c358ea10753 124 struct connector_buffer * next;
spastor 0:1c358ea10753 125 connector_bool_t in_use;
spastor 0:1c358ea10753 126 } connector_buffer_t;
spastor 0:1c358ea10753 127
spastor 0:1c358ea10753 128 typedef struct connector_facility {
spastor 0:1c358ea10753 129 unsigned int service_index;
spastor 0:1c358ea10753 130 size_t size;
spastor 0:1c358ea10753 131 connector_buffer_t * packet_buffer;
spastor 0:1c358ea10753 132 void * facility_data;
spastor 0:1c358ea10753 133 struct connector_facility * next;
spastor 0:1c358ea10753 134 struct connector_facility * prev;
spastor 0:1c358ea10753 135 uint16_t facility_num;
spastor 0:1c358ea10753 136 } connector_facility_t;
spastor 0:1c358ea10753 137
spastor 0:1c358ea10753 138 typedef struct connector_edp_data {
spastor 0:1c358ea10753 139
spastor 0:1c358ea10753 140 struct {
spastor 0:1c358ea10753 141 #if !(defined CONNECTOR_VENDOR_ID)
spastor 0:1c358ea10753 142 uint32_t vendor_id;
spastor 0:1c358ea10753 143 #endif
spastor 0:1c358ea10753 144
spastor 0:1c358ea10753 145 #if !(defined CONNECTOR_DEVICE_TYPE)
spastor 0:1c358ea10753 146 char * device_type;
spastor 0:1c358ea10753 147 size_t device_type_length;
spastor 0:1c358ea10753 148 #endif
spastor 0:1c358ea10753 149
spastor 0:1c358ea10753 150 uint8_t * ip_addr;
spastor 0:1c358ea10753 151 size_t ip_addr_length;
spastor 0:1c358ea10753 152
spastor 0:1c358ea10753 153 char cloud_url[CLOUD_URL_LENGTH];
spastor 0:1c358ea10753 154 size_t cloud_url_length;
spastor 0:1c358ea10753 155
spastor 0:1c358ea10753 156 #if !(defined CONNECTOR_IDENTITY_VERIFICATION)
spastor 0:1c358ea10753 157 connector_identity_verification_t identity_verification;
spastor 0:1c358ea10753 158 #endif
spastor 0:1c358ea10753 159
spastor 0:1c358ea10753 160 char * password;
spastor 0:1c358ea10753 161 size_t password_length;
spastor 0:1c358ea10753 162
spastor 0:1c358ea10753 163 #if !(defined CONNECTOR_TX_KEEPALIVE_IN_SECONDS)
spastor 0:1c358ea10753 164 uint16_t tx_keepalive_interval;
spastor 0:1c358ea10753 165 #endif
spastor 0:1c358ea10753 166
spastor 0:1c358ea10753 167 #if !(defined CONNECTOR_RX_KEEPALIVE_IN_SECONDS)
spastor 0:1c358ea10753 168 uint16_t rx_keepalive_interval;
spastor 0:1c358ea10753 169 #endif
spastor 0:1c358ea10753 170
spastor 0:1c358ea10753 171 #if !(defined CONNECTOR_WAIT_COUNT)
spastor 0:1c358ea10753 172 uint16_t wait_count;
spastor 0:1c358ea10753 173 #endif
spastor 0:1c358ea10753 174 } config;
spastor 0:1c358ea10753 175
spastor 0:1c358ea10753 176 struct {
spastor 0:1c358ea10753 177 connector_transport_state_t initiate;
spastor 0:1c358ea10753 178 connector_transport_state_t active;
spastor 0:1c358ea10753 179 connector_edp_state_t edp;
spastor 0:1c358ea10753 180 } state;
spastor 0:1c358ea10753 181
spastor 0:1c358ea10753 182 struct {
spastor 0:1c358ea10753 183 struct {
spastor 0:1c358ea10753 184 uint8_t buffer[MSG_MAX_SEND_PACKET_SIZE];
spastor 0:1c358ea10753 185 connector_bool_t in_use;
spastor 0:1c358ea10753 186 } packet_buffer;
spastor 0:1c358ea10753 187 uint8_t * ptr;
spastor 0:1c358ea10753 188 size_t bytes_sent;
spastor 0:1c358ea10753 189 size_t total_length;
spastor 0:1c358ea10753 190 send_complete_cb_t complete_cb;
spastor 0:1c358ea10753 191 void * user_data;
spastor 0:1c358ea10753 192 } send_packet;
spastor 0:1c358ea10753 193
spastor 0:1c358ea10753 194 struct {
spastor 0:1c358ea10753 195 connector_buffer_t packet_buffer;
spastor 0:1c358ea10753 196 connector_buffer_t * free_packet_buffer;
spastor 0:1c358ea10753 197 connector_buffer_t * data_packet;
spastor 0:1c358ea10753 198 uint8_t * ptr;
spastor 0:1c358ea10753 199 int index;
spastor 0:1c358ea10753 200 unsigned int timeout;
spastor 0:1c358ea10753 201 uint16_t packet_type;
spastor 0:1c358ea10753 202 uint16_t packet_length;
spastor 0:1c358ea10753 203 size_t bytes_received;
spastor 0:1c358ea10753 204 size_t total_length;
spastor 0:1c358ea10753 205 } receive_packet;
spastor 0:1c358ea10753 206
spastor 0:1c358ea10753 207 struct {
spastor 0:1c358ea10753 208 connector_facility_t * current;
spastor 0:1c358ea10753 209 connector_facility_t * list;
spastor 0:1c358ea10753 210 uint16_t supported_mask;
spastor 0:1c358ea10753 211 } facilities;
spastor 0:1c358ea10753 212
spastor 0:1c358ea10753 213 struct {
spastor 0:1c358ea10753 214 uint8_t send_rx_packet[PACKET_EDP_HEADER_SIZE];
spastor 0:1c358ea10753 215 unsigned long last_rx_sent_time;
spastor 0:1c358ea10753 216 unsigned long last_tx_received_time;
spastor 0:1c358ea10753 217 uint16_t miss_tx_count;
spastor 0:1c358ea10753 218 } keepalive;
spastor 0:1c358ea10753 219
spastor 0:1c358ea10753 220 unsigned long int connect_at;
spastor 0:1c358ea10753 221
spastor 0:1c358ea10753 222 connector_close_status_t close_status;
spastor 0:1c358ea10753 223 connector_network_handle_t * network_handle;
spastor 0:1c358ea10753 224
spastor 0:1c358ea10753 225 struct {
spastor 0:1c358ea10753 226 connector_bool_t is_set;
spastor 0:1c358ea10753 227 connector_stop_condition_t condition;
spastor 0:1c358ea10753 228 void * user_context;
spastor 0:1c358ea10753 229 connector_bool_t auto_connect;
spastor 0:1c358ea10753 230 } stop;
spastor 0:1c358ea10753 231
spastor 0:1c358ea10753 232 #if !(defined CONNECTOR_NETWORK_TCP_START)
spastor 0:1c358ea10753 233 connector_connect_auto_type_t connect_type;
spastor 0:1c358ea10753 234 #endif
spastor 0:1c358ea10753 235
spastor 0:1c358ea10753 236 } connector_edp_data_t;
spastor 0:1c358ea10753 237
spastor 0:1c358ea10753 238 #endif
spastor 0:1c358ea10753 239