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 14:10:48 2013 +0000
Revision:
1:908afea5a49d
Parent:
0:1c358ea10753
Use internal Thread.h instead of Threads.h

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_DEF_H_
spastor 0:1c358ea10753 14 #define CONNECTOR_DEF_H_
spastor 0:1c358ea10753 15
spastor 0:1c358ea10753 16 #ifndef CONNECTOR_MAX_VENDOR_ID_NUMBER
spastor 0:1c358ea10753 17 #define CONNECTOR_MAX_VENDOR_ID_NUMBER 0xFE000000
spastor 0:1c358ea10753 18 #endif
spastor 0:1c358ea10753 19
spastor 0:1c358ea10753 20 #define UNUSED_VARIABLE(x) ((void) (x))
spastor 0:1c358ea10753 21 #define UNUSED_PARAMETER(x) UNUSED_VARIABLE(x)
spastor 0:1c358ea10753 22
spastor 0:1c358ea10753 23 #define ON_FALSE_DO_(cond, code) do { if (!(cond)) {code;} } while (0)
spastor 0:1c358ea10753 24
spastor 0:1c358ea10753 25 #if (defined CONNECTOR_DEBUG)
spastor 0:1c358ea10753 26 #define ON_ASSERT_DO_(cond, code, output) ON_FALSE_DO_((cond), {ASSERT(cond); code;})
spastor 0:1c358ea10753 27 #else
spastor 0:1c358ea10753 28 #define ON_ASSERT_DO_(cond, code, output) ON_FALSE_DO_((cond), {code})
spastor 0:1c358ea10753 29 #endif
spastor 0:1c358ea10753 30
spastor 0:1c358ea10753 31 #define ASSERT_GOTO(cond, label) ON_ASSERT_DO_((cond), {goto label;}, {})
spastor 0:1c358ea10753 32 #define CONFIRM(cond) do { switch(0) {case 0: case (cond):;} } while (0)
spastor 0:1c358ea10753 33
spastor 0:1c358ea10753 34 #define COND_ELSE_GOTO(cond, label) ON_FALSE_DO_((cond), {goto label;})
spastor 0:1c358ea10753 35
spastor 0:1c358ea10753 36
spastor 0:1c358ea10753 37 #define DEVICE_ID_LENGTH 16
spastor 0:1c358ea10753 38 #define CLOUD_URL_LENGTH 64
spastor 0:1c358ea10753 39
spastor 0:1c358ea10753 40 #define CONNECTOR_GSM_IMEI_LENGTH 8
spastor 0:1c358ea10753 41 #define CONNECTOR_ESN_HEX_LENGTH 4
spastor 0:1c358ea10753 42 #define CONNECTOR_MEID_HEX_LENGTH 7
spastor 0:1c358ea10753 43
spastor 0:1c358ea10753 44 #define MAC_ADDR_LENGTH 6
spastor 0:1c358ea10753 45
spastor 0:1c358ea10753 46 #define MIN_VALUE(x,y) (((x) < (y))? (x): (y))
spastor 0:1c358ea10753 47 #define MAX_VALUE(x,y) (((x) > (y))? (x): (y))
spastor 0:1c358ea10753 48
spastor 0:1c358ea10753 49 #define MAX_RECEIVE_TIMEOUT_IN_SECONDS 1
spastor 0:1c358ea10753 50 #define MIN_RECEIVE_TIMEOUT_IN_SECONDS 0
spastor 0:1c358ea10753 51
spastor 0:1c358ea10753 52 #if !(defined CONNECTOR_TRANSPORT_RECONNECT_AFTER)
spastor 0:1c358ea10753 53 #define CONNECTOR_TRANSPORT_RECONNECT_AFTER 30
spastor 0:1c358ea10753 54 #endif
spastor 0:1c358ea10753 55
spastor 0:1c358ea10753 56 typedef enum {
spastor 0:1c358ea10753 57 #if (defined CONNECTOR_TRANSPORT_TCP)
spastor 0:1c358ea10753 58 connector_network_tcp,
spastor 0:1c358ea10753 59 #endif
spastor 0:1c358ea10753 60 #if (defined CONNECTOR_TRANSPORT_UDP)
spastor 0:1c358ea10753 61 connector_network_udp,
spastor 0:1c358ea10753 62 #endif
spastor 0:1c358ea10753 63 #if (defined CONNECTOR_TRANSPORT_SMS)
spastor 0:1c358ea10753 64 connector_network_sms,
spastor 0:1c358ea10753 65 #endif
spastor 0:1c358ea10753 66 connector_network_count
spastor 0:1c358ea10753 67 } connector_network_type_t;
spastor 0:1c358ea10753 68
spastor 0:1c358ea10753 69 typedef enum {
spastor 0:1c358ea10753 70 connector_transport_idle,
spastor 0:1c358ea10753 71 connector_transport_open,
spastor 0:1c358ea10753 72 connector_transport_send,
spastor 0:1c358ea10753 73 connector_transport_receive,
spastor 0:1c358ea10753 74 connector_transport_close,
spastor 0:1c358ea10753 75 connector_transport_terminate,
spastor 0:1c358ea10753 76 connector_transport_redirect,
spastor 0:1c358ea10753 77 connector_transport_wait_for_reconnect
spastor 0:1c358ea10753 78 } connector_transport_state_t;
spastor 0:1c358ea10753 79
spastor 0:1c358ea10753 80 #define connector_bool(cond) ((cond) ? connector_true : connector_false)
spastor 0:1c358ea10753 81
spastor 0:1c358ea10753 82 #define add_list_node(head, tail, node) \
spastor 0:1c358ea10753 83 do { \
spastor 0:1c358ea10753 84 ASSERT(node != NULL); \
spastor 0:1c358ea10753 85 if (*head != NULL) \
spastor 0:1c358ea10753 86 {\
spastor 0:1c358ea10753 87 *head->prev = node;\
spastor 0:1c358ea10753 88 }\
spastor 0:1c358ea10753 89 node->next = *head;\
spastor 0:1c358ea10753 90 node->prev = NULL;\
spastor 0:1c358ea10753 91 *head = node;\
spastor 0:1c358ea10753 92 if ((tail != NULL) && (*tail == NULL)) \
spastor 0:1c358ea10753 93 { \
spastor 0:1c358ea10753 94 *tail = node; \
spastor 0:1c358ea10753 95 } \
spastor 0:1c358ea10753 96 } while (0)
spastor 0:1c358ea10753 97
spastor 0:1c358ea10753 98 #define remove_list_node(head, tail, node) \
spastor 0:1c358ea10753 99 do { \
spastor 0:1c358ea10753 100 ASSERT(node != NULL); \
spastor 0:1c358ea10753 101 if (node->next != NULL) \
spastor 0:1c358ea10753 102 {\
spastor 0:1c358ea10753 103 node->next->prev = node->prev;\
spastor 0:1c358ea10753 104 }\
spastor 0:1c358ea10753 105 if (node->prev != NULL) \
spastor 0:1c358ea10753 106 {\
spastor 0:1c358ea10753 107 node->prev->next = node->next;\
spastor 0:1c358ea10753 108 }\
spastor 0:1c358ea10753 109 if (node == *head)\
spastor 0:1c358ea10753 110 {\
spastor 0:1c358ea10753 111 *head = node->next;\
spastor 0:1c358ea10753 112 }\
spastor 0:1c358ea10753 113 if ((tail != NULL) && (node == *tail))\
spastor 0:1c358ea10753 114 {\
spastor 0:1c358ea10753 115 *tail = node->prev;\
spastor 0:1c358ea10753 116 }\
spastor 0:1c358ea10753 117 } while (0)
spastor 0:1c358ea10753 118
spastor 0:1c358ea10753 119 #define add_node(head, node) \
spastor 0:1c358ea10753 120 do { \
spastor 0:1c358ea10753 121 ASSERT(node != NULL); \
spastor 0:1c358ea10753 122 if (*head != NULL) \
spastor 0:1c358ea10753 123 {\
spastor 0:1c358ea10753 124 *head->prev = node;\
spastor 0:1c358ea10753 125 }\
spastor 0:1c358ea10753 126 node->next = *head;\
spastor 0:1c358ea10753 127 node->prev = NULL;\
spastor 0:1c358ea10753 128 *head = node;\
spastor 0:1c358ea10753 129 } while (0)
spastor 0:1c358ea10753 130
spastor 0:1c358ea10753 131 #define remove_node(head, node) \
spastor 0:1c358ea10753 132 do { \
spastor 0:1c358ea10753 133 ASSERT(node != NULL); \
spastor 0:1c358ea10753 134 if (node->next != NULL) \
spastor 0:1c358ea10753 135 {\
spastor 0:1c358ea10753 136 node->next->prev = node->prev;\
spastor 0:1c358ea10753 137 }\
spastor 0:1c358ea10753 138 if (node->prev != NULL) \
spastor 0:1c358ea10753 139 {\
spastor 0:1c358ea10753 140 node->prev->next = node->next;\
spastor 0:1c358ea10753 141 }\
spastor 0:1c358ea10753 142 if (node == *head)\
spastor 0:1c358ea10753 143 {\
spastor 0:1c358ea10753 144 *head = node->next;\
spastor 0:1c358ea10753 145 }\
spastor 0:1c358ea10753 146 } while (0)
spastor 0:1c358ea10753 147
spastor 0:1c358ea10753 148 struct connector_data;
spastor 0:1c358ea10753 149
spastor 0:1c358ea10753 150 #if (defined CONNECTOR_TRANSPORT_TCP)
spastor 0:1c358ea10753 151 #include "connector_edp_def.h"
spastor 0:1c358ea10753 152 #endif
spastor 0:1c358ea10753 153
spastor 0:1c358ea10753 154 #if defined(CONNECTOR_SHORT_MESSAGE)
spastor 0:1c358ea10753 155 #include "connector_sm_def.h"
spastor 0:1c358ea10753 156 #endif
spastor 0:1c358ea10753 157
spastor 0:1c358ea10753 158 typedef struct connector_data {
spastor 0:1c358ea10753 159
spastor 0:1c358ea10753 160 char const * signature;
spastor 0:1c358ea10753 161
spastor 0:1c358ea10753 162 uint8_t device_id[DEVICE_ID_LENGTH];
spastor 0:1c358ea10753 163 uint8_t * mac_addr;
spastor 0:1c358ea10753 164 uint8_t * wan_id;
spastor 0:1c358ea10753 165 size_t wan_id_length;
spastor 0:1c358ea10753 166
spastor 0:1c358ea10753 167 char * device_cloud_url;
spastor 0:1c358ea10753 168 size_t device_cloud_url_length;
spastor 0:1c358ea10753 169
spastor 0:1c358ea10753 170 char * device_cloud_phone;
spastor 0:1c358ea10753 171 size_t device_cloud_phone_length;
spastor 0:1c358ea10753 172
spastor 0:1c358ea10753 173 char * device_cloud_service_id;
spastor 0:1c358ea10753 174 size_t device_cloud_service_id_length;
spastor 0:1c358ea10753 175
spastor 0:1c358ea10753 176 connector_connection_type_t connection_type;
spastor 0:1c358ea10753 177
spastor 0:1c358ea10753 178 connector_wan_type_t wan_type;
spastor 0:1c358ea10753 179
spastor 0:1c358ea10753 180 #if !(defined CONNECTOR_WAN_LINK_SPEED_IN_BITS_PER_SECOND)
spastor 0:1c358ea10753 181 uint32_t link_speed;
spastor 0:1c358ea10753 182 #endif
spastor 0:1c358ea10753 183
spastor 0:1c358ea10753 184 #if !(defined CONNECTOR_WAN_PHONE_NUMBER_DIALED)
spastor 0:1c358ea10753 185 char * phone_dialed;
spastor 0:1c358ea10753 186 size_t phone_dialed_length;
spastor 0:1c358ea10753 187 #endif
spastor 0:1c358ea10753 188
spastor 0:1c358ea10753 189 connector_device_id_method_t device_id_method;
spastor 0:1c358ea10753 190 connector_bool_t connector_got_device_id;
spastor 0:1c358ea10753 191 #if (CONNECTOR_TRANSPORT_COUNT > 1)
spastor 0:1c358ea10753 192 connector_network_type_t first_running_network;
spastor 0:1c358ea10753 193 #endif
spastor 0:1c358ea10753 194
spastor 0:1c358ea10753 195 connector_callback_t callback;
spastor 0:1c358ea10753 196 connector_status_t error_code;
spastor 0:1c358ea10753 197
spastor 0:1c358ea10753 198 #if (defined CONNECTOR_TRANSPORT_UDP || defined CONNECTOR_TRANSPORT_SMS)
spastor 0:1c358ea10753 199 uint32_t last_request_id;
spastor 0:1c358ea10753 200 #endif
spastor 0:1c358ea10753 201
spastor 0:1c358ea10753 202 #if (defined CONNECTOR_TRANSPORT_UDP)
spastor 0:1c358ea10753 203 connector_sm_data_t sm_udp;
spastor 0:1c358ea10753 204 #endif
spastor 0:1c358ea10753 205
spastor 0:1c358ea10753 206 #if (defined CONNECTOR_TRANSPORT_SMS)
spastor 0:1c358ea10753 207 connector_sm_data_t sm_sms;
spastor 0:1c358ea10753 208 #endif
spastor 0:1c358ea10753 209
spastor 0:1c358ea10753 210 #if (defined CONNECTOR_TRANSPORT_TCP)
spastor 0:1c358ea10753 211 connector_edp_data_t edp_data;
spastor 0:1c358ea10753 212 #endif
spastor 0:1c358ea10753 213
spastor 0:1c358ea10753 214 struct {
spastor 0:1c358ea10753 215 enum {
spastor 0:1c358ea10753 216 connector_state_running,
spastor 0:1c358ea10753 217 connector_state_stop_by_initiate_action,
spastor 0:1c358ea10753 218 connector_state_terminate_by_initiate_action,
spastor 0:1c358ea10753 219 connector_state_abort_by_callback
spastor 0:1c358ea10753 220 } state;
spastor 0:1c358ea10753 221 connector_stop_condition_t condition;
spastor 0:1c358ea10753 222 void * user_context;
spastor 0:1c358ea10753 223 } stop;
spastor 0:1c358ea10753 224
spastor 0:1c358ea10753 225 } connector_data_t;
spastor 0:1c358ea10753 226
spastor 0:1c358ea10753 227 #endif
spastor 0:1c358ea10753 228