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 #ifndef CONNECTOR_SM_DEF_H
spastor 0:1c358ea10753 13 #define CONNECTOR_SM_DEF_H
spastor 0:1c358ea10753 14
spastor 0:1c358ea10753 15 #if (defined CONNECTOR_COMPRESSION)
spastor 0:1c358ea10753 16 #include "zlib.h"
spastor 0:1c358ea10753 17 #endif
spastor 0:1c358ea10753 18
spastor 0:1c358ea10753 19 #include "ei_packet.h"
spastor 0:1c358ea10753 20
spastor 0:1c358ea10753 21 #define SM_UDP_VERSION 0x01
spastor 0:1c358ea10753 22
spastor 0:1c358ea10753 23 #if defined SM_PACKET_SIZE_UDP
spastor 0:1c358ea10753 24 #if defined CONNECTOR_SM_MULTIPART
spastor 0:1c358ea10753 25 #error "SM_PACKET_SIZE_UDP cannot be override if multi-packet messaging is ON (defined CONNECTOR_SM_MULTIPART)"
spastor 0:1c358ea10753 26 #endif
spastor 0:1c358ea10753 27 #else
spastor 0:1c358ea10753 28 #define SM_PACKET_SIZE_UDP 1472
spastor 0:1c358ea10753 29 #endif
spastor 0:1c358ea10753 30
spastor 0:1c358ea10753 31 #define SM_PACKET_SIZE_SMS 128
spastor 0:1c358ea10753 32 #define SM_PACKET_SIZE_SMS_ENCODED ((SM_PACKET_SIZE_SMS/4) * 5)
spastor 0:1c358ea10753 33 #define SM_REQUEST_ID_MASK 0x3FF /* 10 bits */
spastor 0:1c358ea10753 34 #define SM_DEFAULT_REQUEST_ID 0x01
spastor 0:1c358ea10753 35 #define SM_WAIT_FOREVER 0
spastor 0:1c358ea10753 36
spastor 0:1c358ea10753 37 /* NOTE: Some of these bits are tied to protocol, so please don't change them
spastor 0:1c358ea10753 38 without referring to SM protocol */
spastor 0:1c358ea10753 39 #define SM_ERROR 0x0001
spastor 0:1c358ea10753 40 #define SM_LAST_DATA 0x0002
spastor 0:1c358ea10753 41 #define SM_MULTI_PART 0x0004
spastor 0:1c358ea10753 42 #define SM_RESPONSE_NEEDED 0x0008
spastor 0:1c358ea10753 43 #define SM_RESPONSE_DATA 0x0010
spastor 0:1c358ea10753 44 #define SM_CLIENT_OWNED 0x0020
spastor 0:1c358ea10753 45 #define SM_ENCODED 0x0040
spastor 0:1c358ea10753 46 #define SM_COMPRESSED 0x0080
spastor 0:1c358ea10753 47 #define SM_REBOOT 0x0100
spastor 0:1c358ea10753 48 #define SM_TARGET_IN_PAYLOAD 0x0200
spastor 0:1c358ea10753 49 #define SM_DATA_POINT 0x8000
spastor 0:1c358ea10753 50
spastor 0:1c358ea10753 51 #define SmIsBitSet(flag, bit) (connector_bool(((flag) & (bit)) == (bit)))
spastor 0:1c358ea10753 52 #define SmIsBitClear(flag, bit) (connector_bool(((flag) & (bit)) == 0))
spastor 0:1c358ea10753 53 #define SmBitSet(flag, bit) ((flag) |= (bit))
spastor 0:1c358ea10753 54 #define SmBitClear(flag, bit) ((flag) &= ~(bit))
spastor 0:1c358ea10753 55
spastor 0:1c358ea10753 56 #define SmIsError(flag) SmIsBitSet((flag), SM_ERROR)
spastor 0:1c358ea10753 57 #define SmIsResponse(flag) SmIsBitSet((flag), SM_RESPONSE_DATA)
spastor 0:1c358ea10753 58 #define SmIsResponseNeeded(flag) SmIsBitSet((flag), SM_RESPONSE_NEEDED)
spastor 0:1c358ea10753 59 #define SmIsLastData(flag) SmIsBitSet((flag), SM_LAST_DATA)
spastor 0:1c358ea10753 60 #define SmIsMultiPart(flag) SmIsBitSet((flag), SM_MULTI_PART)
spastor 0:1c358ea10753 61 #define SmIsCompressed(flag) SmIsBitSet((flag), SM_COMPRESSED)
spastor 0:1c358ea10753 62 #define SmIsClientOwned(flag) SmIsBitSet((flag), SM_CLIENT_OWNED)
spastor 0:1c358ea10753 63 #define SmIsEncoded(flag) SmIsBitSet((flag), SM_ENCODED)
spastor 0:1c358ea10753 64 #define SmIsReboot(flag) SmIsBitSet((flag), SM_REBOOT)
spastor 0:1c358ea10753 65 #define SmIsDatapoint(flag) SmIsBitSet((flag), SM_DATA_POINT)
spastor 0:1c358ea10753 66 #define SmIsTargetInPayload(flag) SmIsBitSet((flag), SM_TARGET_IN_PAYLOAD)
spastor 0:1c358ea10753 67
spastor 0:1c358ea10753 68 #define SmIsRequest(flag) SmIsBitClear((flag), SM_RESPONSE_DATA)
spastor 0:1c358ea10753 69 #define SmIsNotLastData(flag) SmIsBitClear((flag), SM_LAST_DATA)
spastor 0:1c358ea10753 70 #define SmIsNotMultiPart(flag) SmIsBitClear((flag), SM_MULTI_PART)
spastor 0:1c358ea10753 71 #define SmIsCloudOwned(flag) SmIsBitClear((flag), SM_CLIENT_OWNED)
spastor 0:1c358ea10753 72 #define SmNotCompressed(flag) SmIsBitClear((flag), SM_COMPRESSED)
spastor 0:1c358ea10753 73 #define SmIsNoResponseNeeded(flag) SmIsBitClear((flag), SM_RESPONSE_NEEDED)
spastor 0:1c358ea10753 74
spastor 0:1c358ea10753 75 #define SmSetError(flag) SmBitSet((flag), SM_ERROR)
spastor 0:1c358ea10753 76 #define SmSetResponse(flag) SmBitSet((flag), SM_RESPONSE_DATA)
spastor 0:1c358ea10753 77 #define SmSetResponseNeeded(flag) SmBitSet((flag), SM_RESPONSE_NEEDED)
spastor 0:1c358ea10753 78 #define SmSetLastData(flag) SmBitSet((flag), SM_LAST_DATA)
spastor 0:1c358ea10753 79 #define SmSetMultiPart(flag) SmBitSet((flag), SM_MULTI_PART)
spastor 0:1c358ea10753 80 #define SmSetCompressed(flag) SmBitSet((flag), SM_COMPRESSED)
spastor 0:1c358ea10753 81 #define SmSetClientOwned(flag) SmBitSet((flag), SM_CLIENT_OWNED)
spastor 0:1c358ea10753 82 #define SmSetEncoded(flag) SmBitSet((flag), SM_ENCODED)
spastor 0:1c358ea10753 83 #define SmSetReboot(flag) SmBitSet((flag), SM_REBOOT)
spastor 0:1c358ea10753 84 #define SmSetDatapoint(flag) SmBitSet((flag), SM_DATA_POINT)
spastor 0:1c358ea10753 85 #define SmSetTargetInPayload(flag) SmBitSet((flag), SM_TARGET_IN_PAYLOAD)
spastor 0:1c358ea10753 86
spastor 0:1c358ea10753 87 #define SmClearError(flag) SmBitClear((flag), SM_ERROR)
spastor 0:1c358ea10753 88 #define SmClearResponse(flag) SmBitClear((flag), SM_RESPONSE_DATA)
spastor 0:1c358ea10753 89 #define SmClearResponseNeeded(flag) SmBitClear((flag), SM_RESPONSE_NEEDED)
spastor 0:1c358ea10753 90 #define SmClearLastData(flag) SmBitClear((flag), SM_LAST_DATA)
spastor 0:1c358ea10753 91 #define SmClearMultiPart(flag) SmBitClear((flag), SM_MULTI_PART)
spastor 0:1c358ea10753 92 #define SmClearCompressed(flag) SmBitClear((flag), SM_COMPRESSED)
spastor 0:1c358ea10753 93 #define SmClearTargetInPayload(flag) SmBitClear((flag), SM_TARGET_IN_PAYLOAD)
spastor 0:1c358ea10753 94
spastor 0:1c358ea10753 95 #define SMS_SERVICEID_WRAPPER_TX_SIZE 1 /* 'service-id ' */
spastor 0:1c358ea10753 96 #define SMS_SERVICEID_WRAPPER_RX_SIZE 3 /* '(service-id):' */
spastor 0:1c358ea10753 97
spastor 0:1c358ea10753 98 typedef enum
spastor 0:1c358ea10753 99 {
spastor 0:1c358ea10753 100 connector_sm_cmd_ping,
spastor 0:1c358ea10753 101 connector_sm_cmd_connect,
spastor 0:1c358ea10753 102 connector_sm_cmd_reboot,
spastor 0:1c358ea10753 103 connector_sm_cmd_cli,
spastor 0:1c358ea10753 104 connector_sm_cmd_pack,
spastor 0:1c358ea10753 105 connector_sm_cmd_pad,
spastor 0:1c358ea10753 106 connector_sm_cmd_config,
spastor 0:1c358ea10753 107 connector_sm_cmd_data,
spastor 0:1c358ea10753 108 connector_sm_cmd_no_path_data,
spastor 0:1c358ea10753 109 /* Add new commands here */
spastor 0:1c358ea10753 110 connector_sm_cmd_opaque_response
spastor 0:1c358ea10753 111 } connector_sm_cmd_t;
spastor 0:1c358ea10753 112
spastor 0:1c358ea10753 113 typedef enum
spastor 0:1c358ea10753 114 {
spastor 0:1c358ea10753 115 connector_sm_id_type_device_id,
spastor 0:1c358ea10753 116 connector_sm_id_type_imei,
spastor 0:1c358ea10753 117 connector_sm_id_type_none,
spastor 0:1c358ea10753 118 connector_sm_id_type_service_id
spastor 0:1c358ea10753 119 } connector_sm_id_type_t;
spastor 0:1c358ea10753 120
spastor 0:1c358ea10753 121 typedef enum
spastor 0:1c358ea10753 122 {
spastor 0:1c358ea10753 123 connector_sm_state_get_total_length,
spastor 0:1c358ea10753 124 connector_sm_state_prepare_payload,
spastor 0:1c358ea10753 125 connector_sm_state_more_data,
spastor 0:1c358ea10753 126 connector_sm_state_compress,
spastor 0:1c358ea10753 127 connector_sm_state_prepare_segment,
spastor 0:1c358ea10753 128 connector_sm_state_encoding,
spastor 0:1c358ea10753 129 connector_sm_state_send_data,
spastor 0:1c358ea10753 130 connector_sm_state_receive_data,
spastor 0:1c358ea10753 131 connector_sm_state_decompress,
spastor 0:1c358ea10753 132 connector_sm_state_process_payload,
spastor 0:1c358ea10753 133 connector_sm_state_complete,
spastor 0:1c358ea10753 134 connector_sm_state_error
spastor 0:1c358ea10753 135 } connector_sm_state_t;
spastor 0:1c358ea10753 136
spastor 0:1c358ea10753 137 typedef enum
spastor 0:1c358ea10753 138 {
spastor 0:1c358ea10753 139 connector_sm_error_none,
spastor 0:1c358ea10753 140 connector_sm_error_in_request,
spastor 0:1c358ea10753 141 connector_sm_error_unavailable,
spastor 0:1c358ea10753 142 connector_sm_error_unknown,
spastor 0:1c358ea10753 143 connector_sm_error_complete,
spastor 0:1c358ea10753 144 connector_sm_error_cancel,
spastor 0:1c358ea10753 145 connector_sm_error_timeout,
spastor 0:1c358ea10753 146 connector_sm_error_no_resource
spastor 0:1c358ea10753 147 } connector_sm_error_id_t;
spastor 0:1c358ea10753 148
spastor 0:1c358ea10753 149 typedef struct
spastor 0:1c358ea10753 150 {
spastor 0:1c358ea10753 151 uint8_t * data;
spastor 0:1c358ea10753 152 size_t bytes;
spastor 0:1c358ea10753 153 } sm_data_block_t;
spastor 0:1c358ea10753 154
spastor 0:1c358ea10753 155 typedef struct connector_sm_session_t
spastor 0:1c358ea10753 156 {
spastor 0:1c358ea10753 157 struct
spastor 0:1c358ea10753 158 {
spastor 0:1c358ea10753 159 void * context;
spastor 0:1c358ea10753 160 void const * header;
spastor 0:1c358ea10753 161 } user;
spastor 0:1c358ea10753 162
spastor 0:1c358ea10753 163 connector_transport_t transport;
spastor 0:1c358ea10753 164 connector_sm_state_t sm_state;
spastor 0:1c358ea10753 165 connector_sm_cmd_t command;
spastor 0:1c358ea10753 166 connector_sm_error_id_t error;
spastor 0:1c358ea10753 167 unsigned long start_time;
spastor 0:1c358ea10753 168 uint32_t request_id;
spastor 0:1c358ea10753 169 uint32_t flags;
spastor 0:1c358ea10753 170
spastor 0:1c358ea10753 171 sm_data_block_t in;
spastor 0:1c358ea10753 172 size_t bytes_processed;
spastor 0:1c358ea10753 173
spastor 0:1c358ea10753 174 #if (defined CONNECTOR_COMPRESSION)
spastor 0:1c358ea10753 175 struct
spastor 0:1c358ea10753 176 {
spastor 0:1c358ea10753 177 z_stream zlib;
spastor 0:1c358ea10753 178 sm_data_block_t out;
spastor 0:1c358ea10753 179 } compress;
spastor 0:1c358ea10753 180 #endif
spastor 0:1c358ea10753 181
spastor 0:1c358ea10753 182 struct connector_sm_session_t * next;
spastor 0:1c358ea10753 183 struct connector_sm_session_t * prev;
spastor 0:1c358ea10753 184
spastor 0:1c358ea10753 185 struct
spastor 0:1c358ea10753 186 {
spastor 0:1c358ea10753 187 uint16_t * size_array;
spastor 0:1c358ea10753 188 uint8_t count;
spastor 0:1c358ea10753 189 uint8_t processed;
spastor 0:1c358ea10753 190 } segments;
spastor 0:1c358ea10753 191 } connector_sm_session_t;
spastor 0:1c358ea10753 192
spastor 0:1c358ea10753 193 typedef struct connector_sm_packet_t
spastor 0:1c358ea10753 194 {
spastor 0:1c358ea10753 195 uint8_t * data;
spastor 0:1c358ea10753 196 size_t total_bytes;
spastor 0:1c358ea10753 197 size_t processed_bytes;
spastor 0:1c358ea10753 198 connector_sm_session_t * pending_session;
spastor 0:1c358ea10753 199 } connector_sm_packet_t;
spastor 0:1c358ea10753 200
spastor 0:1c358ea10753 201 typedef struct connector_sm_data_t
spastor 0:1c358ea10753 202 {
spastor 0:1c358ea10753 203 connector_status_t error_code;
spastor 0:1c358ea10753 204 unsigned long timeout_in_seconds; /* 0 means wait forever */
spastor 0:1c358ea10753 205
spastor 0:1c358ea10753 206 struct
spastor 0:1c358ea10753 207 {
spastor 0:1c358ea10753 208 size_t mtu;
spastor 0:1c358ea10753 209 size_t sm_mtu_tx;
spastor 0:1c358ea10753 210 size_t sm_mtu_rx;
spastor 0:1c358ea10753 211 uint8_t * id;
spastor 0:1c358ea10753 212 size_t id_length;
spastor 0:1c358ea10753 213 connector_sm_id_type_t id_type;
spastor 0:1c358ea10753 214 connector_transport_state_t state;
spastor 0:1c358ea10753 215 connector_connect_auto_type_t connect_type;
spastor 0:1c358ea10753 216 unsigned long int connect_at;
spastor 0:1c358ea10753 217 } transport;
spastor 0:1c358ea10753 218
spastor 0:1c358ea10753 219 struct
spastor 0:1c358ea10753 220 {
spastor 0:1c358ea10753 221 connector_close_status_t status;
spastor 0:1c358ea10753 222 connector_stop_condition_t stop_condition;
spastor 0:1c358ea10753 223 void * user_context;
spastor 0:1c358ea10753 224 connector_bool_t callback_needed;
spastor 0:1c358ea10753 225 } close;
spastor 0:1c358ea10753 226
spastor 0:1c358ea10753 227 struct
spastor 0:1c358ea10753 228 {
spastor 0:1c358ea10753 229 connector_sm_packet_t send_packet;
spastor 0:1c358ea10753 230 connector_sm_packet_t recv_packet;
spastor 0:1c358ea10753 231 connector_network_handle_t * handle;
spastor 0:1c358ea10753 232 connector_class_id_t class_id;
spastor 0:1c358ea10753 233 connector_transport_t transport;
spastor 0:1c358ea10753 234 } network;
spastor 0:1c358ea10753 235
spastor 0:1c358ea10753 236 struct
spastor 0:1c358ea10753 237 {
spastor 0:1c358ea10753 238 void const * data;
spastor 0:1c358ea10753 239 connector_initiate_request_t request;
spastor 0:1c358ea10753 240 uint32_t request_id;
spastor 0:1c358ea10753 241 connector_bool_t pending_internal;
spastor 0:1c358ea10753 242 } pending;
spastor 0:1c358ea10753 243
spastor 0:1c358ea10753 244 struct
spastor 0:1c358ea10753 245 {
spastor 0:1c358ea10753 246 connector_sm_session_t * head;
spastor 0:1c358ea10753 247 connector_sm_session_t * tail;
spastor 0:1c358ea10753 248 connector_sm_session_t * current;
spastor 0:1c358ea10753 249 size_t max_sessions;
spastor 0:1c358ea10753 250 size_t active_client_sessions;
spastor 0:1c358ea10753 251 size_t active_cloud_sessions;
spastor 0:1c358ea10753 252 size_t max_segments;
spastor 0:1c358ea10753 253 } session;
spastor 0:1c358ea10753 254
spastor 0:1c358ea10753 255 } connector_sm_data_t;
spastor 0:1c358ea10753 256
spastor 0:1c358ea10753 257 enum sm_segment_t
spastor 0:1c358ea10753 258 {
spastor 0:1c358ea10753 259 field_define(segment, info, uint8_t),
spastor 0:1c358ea10753 260 field_define(segment, request, uint8_t),
spastor 0:1c358ea10753 261 field_define(segment, cmd_status, uint8_t),
spastor 0:1c358ea10753 262 field_define(segment, crc, uint16_t),
spastor 0:1c358ea10753 263 record_end(segment)
spastor 0:1c358ea10753 264 };
spastor 0:1c358ea10753 265
spastor 0:1c358ea10753 266 enum sm_segment0_t
spastor 0:1c358ea10753 267 {
spastor 0:1c358ea10753 268 field_define(segment0, info, uint8_t),
spastor 0:1c358ea10753 269 field_define(segment0, request, uint8_t),
spastor 0:1c358ea10753 270 field_define(segment0, segment, uint8_t),
spastor 0:1c358ea10753 271 field_define(segment0, count, uint8_t),
spastor 0:1c358ea10753 272 field_define(segment0, cmd_status, uint8_t),
spastor 0:1c358ea10753 273 field_define(segment0, crc, uint16_t),
spastor 0:1c358ea10753 274 record_end(segment0)
spastor 0:1c358ea10753 275 };
spastor 0:1c358ea10753 276
spastor 0:1c358ea10753 277 enum sm_segmentn_t
spastor 0:1c358ea10753 278 {
spastor 0:1c358ea10753 279 field_define(segmentn, info, uint8_t),
spastor 0:1c358ea10753 280 field_define(segmentn, request, uint8_t),
spastor 0:1c358ea10753 281 field_define(segmentn, segment, uint8_t),
spastor 0:1c358ea10753 282 field_define(segmentn, crc, uint16_t),
spastor 0:1c358ea10753 283 record_end(segmentn)
spastor 0:1c358ea10753 284 };
spastor 0:1c358ea10753 285
spastor 0:1c358ea10753 286 #endif
spastor 0:1c358ea10753 287