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 #include <stdarg.h>
spastor 0:1c358ea10753 14
spastor 0:1c358ea10753 15 #define BINARY_RCI_ATTRIBUTE_BIT UINT32_C(0x40) /* bit 6 */
spastor 0:1c358ea10753 16
spastor 0:1c358ea10753 17 #define BINARY_RCI_NO_VALUE UINT32_C(0xE0)
spastor 0:1c358ea10753 18 #define BINARY_RCI_TERMINATOR UINT32_C(0xE1)
spastor 0:1c358ea10753 19
spastor 0:1c358ea10753 20 #define BINARY_RCI_ERROR_INDICATOR_BIT UINT32_C(0x1000) /* bit 12 */
spastor 0:1c358ea10753 21
spastor 0:1c358ea10753 22 #define BINARY_RCI_FIELD_TYPE_INDICATOR_BIT UINT32_C(0x40) /* bit 6 */
spastor 0:1c358ea10753 23 #define BINARY_RCI_FIELD_ATTRIBUTE_BIT UINT32_C(0x400) /* bit 10 */
spastor 0:1c358ea10753 24 /* #define BINARY_RCI_FIELD_ASCENDING_INDICATOR_BIT (0x1 << 6) */
spastor 0:1c358ea10753 25
spastor 0:1c358ea10753 26 /*
spastor 0:1c358ea10753 27 * 7 6 5 4 3 2 1 0 bit
spastor 0:1c358ea10753 28 * 0 X X X X X X X (0 : 0x7F)
spastor 0:1c358ea10753 29 * 1 0 0 X X X X X + 1 byte followed (0: 0x1FFF)
spastor 0:1c358ea10753 30 * 1 0 1 0 0 0 0 0 + 2 bytes followed (0: 0xFFFF)
spastor 0:1c358ea10753 31 * 1 0 1 0 0 0 0 1 + 4 bytes followed (0: 0xFFFFFFFF)
spastor 0:1c358ea10753 32 * 1 0 1 0 0 0 1 0 + 8 bytes followed (0: 0xFFFFFFFFFFFFFFFF)
spastor 0:1c358ea10753 33 * 1 1 0 0 - - - - Reserved
spastor 0:1c358ea10753 34 * 1 1 1 0 0 0 0 0 NONUM (No Value)
spastor 0:1c358ea10753 35 * 1 1 1 0 0 0 0 1 TRM (Terminator)
spastor 0:1c358ea10753 36 */
spastor 0:1c358ea10753 37 #define BINARY_RCI_SIZE_ALTERNATE_FLAG UINT32_C(0x80) /* bit 7 */
spastor 0:1c358ea10753 38 #define BINARY_RCI_SIZE_MODIFIER_MASK UINT32_C(0x60) /* bits 6:5 */
spastor 0:1c358ea10753 39 #define BINARY_RCI_SIZE_MODIFIER(value) (rci_size_modifier_t)((value & BINARY_RCI_SIZE_MODIFIER_MASK) >> UINT32_C(5))
spastor 0:1c358ea10753 40
spastor 0:1c358ea10753 41 typedef enum {
spastor 0:1c358ea10753 42 binary_rci_one_follow_byte,
spastor 0:1c358ea10753 43 binary_rci_multi_follow_byte,
spastor 0:1c358ea10753 44 binary_rci_special_value = 3
spastor 0:1c358ea10753 45 } rci_size_modifier_t;
spastor 0:1c358ea10753 46
spastor 0:1c358ea10753 47
spastor 0:1c358ea10753 48 #define BINARY_RCI_MULTI_FOLLOW_BYTE_MASK UINT32_C(0x03)
spastor 0:1c358ea10753 49 #define BINARY_RCI_MULTI_FOLLOW_BYTES(value) (value & BINARY_RCI_MULTI_FOLLOW_BYTE_MASK)
spastor 0:1c358ea10753 50 #define BINARY_RCI_SET_MULTI_FOLLOW_BYTES(value) (BINARY_RCI_SIZE_ALTERNATE_FLAG | (binary_rci_multi_follow_byte << UINT32_C(5)) |value)
spastor 0:1c358ea10753 51
spastor 0:1c358ea10753 52 enum {
spastor 0:1c358ea10753 53 binary_rci_two_follow_byte,
spastor 0:1c358ea10753 54 binary_rci_four_follow_byte,
spastor 0:1c358ea10753 55 binary_rci_eight_follow_byte
spastor 0:1c358ea10753 56 };
spastor 0:1c358ea10753 57
spastor 0:1c358ea10753 58 #define RCI_FLAG_GET_ALL_INSTANCES UINT32_C(0x01)
spastor 0:1c358ea10753 59
spastor 0:1c358ea10753 60 #define RCI_NO_HINT NULL
spastor 0:1c358ea10753 61 #define INVALID_ID UINT_MAX
spastor 0:1c358ea10753 62 #define INVALID_INDEX UINT_MAX
spastor 0:1c358ea10753 63 #define INVALID_COUNT ((size_t)-1)
spastor 0:1c358ea10753 64
spastor 0:1c358ea10753 65 #define ROUND_UP(value, interval) ((value) + -(value) % (interval))
spastor 0:1c358ea10753 66
spastor 0:1c358ea10753 67 #define UNHANDLED_CASES_ARE_INVALID default: ASSERT(connector_false); break;
spastor 0:1c358ea10753 68
spastor 0:1c358ea10753 69 static char const nul = '\0';
spastor 0:1c358ea10753 70
spastor 0:1c358ea10753 71 enum rci_ber {
spastor 0:1c358ea10753 72 field_define(rci_ber, value, uint8_t),
spastor 0:1c358ea10753 73 record_end(rci_ber)
spastor 0:1c358ea10753 74 };
spastor 0:1c358ea10753 75
spastor 0:1c358ea10753 76 enum rci_ber_u8 {
spastor 0:1c358ea10753 77 field_define(rci_ber_u8, opcode, uint8_t),
spastor 0:1c358ea10753 78 field_define(rci_ber_u8, value, uint8_t),
spastor 0:1c358ea10753 79 record_end(rci_ber_u8)
spastor 0:1c358ea10753 80 };
spastor 0:1c358ea10753 81
spastor 0:1c358ea10753 82 enum rci_ber_u16 {
spastor 0:1c358ea10753 83 field_define(rci_ber_u16, opcode, uint8_t),
spastor 0:1c358ea10753 84 field_define(rci_ber_u16, value, uint16_t),
spastor 0:1c358ea10753 85 record_end(rci_ber_u16)
spastor 0:1c358ea10753 86 };
spastor 0:1c358ea10753 87
spastor 0:1c358ea10753 88 enum rci_ber_u32 {
spastor 0:1c358ea10753 89 field_define(rci_ber_u32, opcode, uint8_t),
spastor 0:1c358ea10753 90 field_define(rci_ber_u32, value, uint32_t),
spastor 0:1c358ea10753 91 record_end(rci_ber_u32)
spastor 0:1c358ea10753 92 };
spastor 0:1c358ea10753 93
spastor 0:1c358ea10753 94
spastor 0:1c358ea10753 95 enum
spastor 0:1c358ea10753 96 {
spastor 0:1c358ea10753 97 rci_field_type_none,
spastor 0:1c358ea10753 98 rci_field_type_string,
spastor 0:1c358ea10753 99 rci_field_type_multiline_string,
spastor 0:1c358ea10753 100 rci_field_type_password,
spastor 0:1c358ea10753 101 rci_field_type_int23,
spastor 0:1c358ea10753 102 rci_field_type_uint32,
spastor 0:1c358ea10753 103 rci_field_type_hex32,
spastor 0:1c358ea10753 104 rci_field_type_0x_hex32,
spastor 0:1c358ea10753 105 rci_field_type_float,
spastor 0:1c358ea10753 106 rci_field_type_enum,
spastor 0:1c358ea10753 107 rci_field_type_on_off = 0x0B,
spastor 0:1c358ea10753 108 rci_field_type_boolean,
spastor 0:1c358ea10753 109 rci_field_type_ip4,
spastor 0:1c358ea10753 110 rci_field_type_fqdnv4,
spastor 0:1c358ea10753 111 rci_field_type_fqdnv6,
spastor 0:1c358ea10753 112 rci_field_type_datetime = 0x16
spastor 0:1c358ea10753 113 };
spastor 0:1c358ea10753 114
spastor 0:1c358ea10753 115 enum {
spastor 0:1c358ea10753 116 rci_command_query_setting = 1,
spastor 0:1c358ea10753 117 rci_command_set_setting,
spastor 0:1c358ea10753 118 rci_command_query_state,
spastor 0:1c358ea10753 119 rci_command_set_state
spastor 0:1c358ea10753 120 };
spastor 0:1c358ea10753 121
spastor 0:1c358ea10753 122 typedef enum
spastor 0:1c358ea10753 123 {
spastor 0:1c358ea10753 124 rci_session_start,
spastor 0:1c358ea10753 125 rci_session_active,
spastor 0:1c358ea10753 126 rci_session_lost
spastor 0:1c358ea10753 127 } rci_session_t;
spastor 0:1c358ea10753 128
spastor 0:1c358ea10753 129 typedef enum
spastor 0:1c358ea10753 130 {
spastor 0:1c358ea10753 131 rci_status_internal_error, /* bad code path */
spastor 0:1c358ea10753 132 rci_status_complete, /* all done */
spastor 0:1c358ea10753 133 rci_status_busy, /* user callback returned busy */
spastor 0:1c358ea10753 134 rci_status_more_input, /* have output buffer space to process more input */
spastor 0:1c358ea10753 135 rci_status_flush_output, /* need more output space, so send out the current buffer */
spastor 0:1c358ea10753 136 rci_status_error /* error occurred, RCI service should inform messaging layer to cancel the session */
spastor 0:1c358ea10753 137 } rci_status_t;
spastor 0:1c358ea10753 138
spastor 0:1c358ea10753 139 typedef struct
spastor 0:1c358ea10753 140 {
spastor 0:1c358ea10753 141 uint8_t * data;
spastor 0:1c358ea10753 142 size_t bytes;
spastor 0:1c358ea10753 143 unsigned int flags;
spastor 0:1c358ea10753 144 } rci_service_buffer_t;
spastor 0:1c358ea10753 145
spastor 0:1c358ea10753 146 typedef struct
spastor 0:1c358ea10753 147 {
spastor 0:1c358ea10753 148 connector_data_t * connector_ptr;
spastor 0:1c358ea10753 149 rci_service_buffer_t input;
spastor 0:1c358ea10753 150 rci_service_buffer_t output;
spastor 0:1c358ea10753 151 } rci_service_data_t;
spastor 0:1c358ea10753 152
spastor 0:1c358ea10753 153 typedef struct
spastor 0:1c358ea10753 154 {
spastor 0:1c358ea10753 155 uint8_t * start;
spastor 0:1c358ea10753 156 uint8_t * end;
spastor 0:1c358ea10753 157 uint8_t * current;
spastor 0:1c358ea10753 158 } rci_buffer_t;
spastor 0:1c358ea10753 159
spastor 0:1c358ea10753 160 typedef enum
spastor 0:1c358ea10753 161 {
spastor 0:1c358ea10753 162 rci_parser_state_input,
spastor 0:1c358ea10753 163 rci_parser_state_output,
spastor 0:1c358ea10753 164 rci_parser_state_traverse,
spastor 0:1c358ea10753 165 rci_parser_state_error
spastor 0:1c358ea10753 166 } rci_parser_state_t;
spastor 0:1c358ea10753 167
spastor 0:1c358ea10753 168
spastor 0:1c358ea10753 169 typedef enum
spastor 0:1c358ea10753 170 {
spastor 0:1c358ea10753 171 rci_input_state_command_id,
spastor 0:1c358ea10753 172 rci_input_state_command_attribute,
spastor 0:1c358ea10753 173 rci_input_state_group_id,
spastor 0:1c358ea10753 174 rci_input_state_group_attribute,
spastor 0:1c358ea10753 175 rci_input_state_field_id,
spastor 0:1c358ea10753 176 rci_input_state_field_type,
spastor 0:1c358ea10753 177 rci_input_state_field_no_value,
spastor 0:1c358ea10753 178 rci_input_state_field_value,
spastor 0:1c358ea10753 179 rci_input_state_done
spastor 0:1c358ea10753 180 } rci_input_state_t;
spastor 0:1c358ea10753 181
spastor 0:1c358ea10753 182 typedef enum
spastor 0:1c358ea10753 183 {
spastor 0:1c358ea10753 184 rci_output_state_command_id,
spastor 0:1c358ea10753 185 rci_output_state_group_id,
spastor 0:1c358ea10753 186 rci_output_state_group_attribute,
spastor 0:1c358ea10753 187 rci_output_state_field_id,
spastor 0:1c358ea10753 188 rci_output_state_field_value,
spastor 0:1c358ea10753 189 rci_output_state_field_terminator,
spastor 0:1c358ea10753 190 rci_output_state_group_terminator,
spastor 0:1c358ea10753 191 rci_output_state_response_done,
spastor 0:1c358ea10753 192 rci_output_state_done
spastor 0:1c358ea10753 193 } rci_output_state_t;
spastor 0:1c358ea10753 194
spastor 0:1c358ea10753 195 typedef enum
spastor 0:1c358ea10753 196 {
spastor 0:1c358ea10753 197 rci_traverse_state_none,
spastor 0:1c358ea10753 198 rci_traverse_state_command_id,
spastor 0:1c358ea10753 199 rci_traverse_state_group_id,
spastor 0:1c358ea10753 200 rci_traverse_state_element_id,
spastor 0:1c358ea10753 201 rci_traverse_state_element_end,
spastor 0:1c358ea10753 202 rci_traverse_state_group_end,
spastor 0:1c358ea10753 203 rci_traverse_state_all_groups,
spastor 0:1c358ea10753 204 rci_traverse_state_all_group_instances,
spastor 0:1c358ea10753 205 rci_traverse_state_all_elements
spastor 0:1c358ea10753 206 } rci_traverse_state_t;
spastor 0:1c358ea10753 207
spastor 0:1c358ea10753 208 typedef enum
spastor 0:1c358ea10753 209 {
spastor 0:1c358ea10753 210 rci_traverse_process_group,
spastor 0:1c358ea10753 211 rci_traverse_process_element,
spastor 0:1c358ea10753 212 rci_traverse_process_next_instance
spastor 0:1c358ea10753 213 } rci_traverse_process_state_t;
spastor 0:1c358ea10753 214
spastor 0:1c358ea10753 215 typedef enum
spastor 0:1c358ea10753 216 {
spastor 0:1c358ea10753 217 rci_error_state_id,
spastor 0:1c358ea10753 218 rci_error_state_description,
spastor 0:1c358ea10753 219 rci_error_state_hint,
spastor 0:1c358ea10753 220 rci_error_state_callback
spastor 0:1c358ea10753 221 } rci_error_state_t;
spastor 0:1c358ea10753 222
spastor 0:1c358ea10753 223 typedef struct
spastor 0:1c358ea10753 224 {
spastor 0:1c358ea10753 225 uint8_t * data;
spastor 0:1c358ea10753 226 size_t length;
spastor 0:1c358ea10753 227 } rcistr_t;
spastor 0:1c358ea10753 228
spastor 0:1c358ea10753 229 typedef struct
spastor 0:1c358ea10753 230 {
spastor 0:1c358ea10753 231 rcistr_t name;
spastor 0:1c358ea10753 232 rcistr_t value;
spastor 0:1c358ea10753 233 } rci_attribute_t;
spastor 0:1c358ea10753 234
spastor 0:1c358ea10753 235 typedef struct
spastor 0:1c358ea10753 236 {
spastor 0:1c358ea10753 237 rci_service_data_t * service_data;
spastor 0:1c358ea10753 238 rci_status_t status;
spastor 0:1c358ea10753 239 struct {
spastor 0:1c358ea10753 240 connector_request_id_t request;
spastor 0:1c358ea10753 241 connector_callback_status_t status;
spastor 0:1c358ea10753 242 } callback;
spastor 0:1c358ea10753 243
spastor 0:1c358ea10753 244 struct {
spastor 0:1c358ea10753 245 rci_buffer_t input;
spastor 0:1c358ea10753 246 rci_buffer_t output;
spastor 0:1c358ea10753 247 } buffer;
spastor 0:1c358ea10753 248
spastor 0:1c358ea10753 249 struct {
spastor 0:1c358ea10753 250 rci_parser_state_t state;
spastor 0:1c358ea10753 251 } parser;
spastor 0:1c358ea10753 252
spastor 0:1c358ea10753 253 struct {
spastor 0:1c358ea10753 254 rci_traverse_state_t state;
spastor 0:1c358ea10753 255 rci_traverse_process_state_t process_state;
spastor 0:1c358ea10753 256 } traverse;
spastor 0:1c358ea10753 257
spastor 0:1c358ea10753 258 struct {
spastor 0:1c358ea10753 259 rci_input_state_t state;
spastor 0:1c358ea10753 260 unsigned int flag;
spastor 0:1c358ea10753 261 uint8_t * destination;
spastor 0:1c358ea10753 262 uint8_t storage[CONNECTOR_RCI_MAXIMUM_CONTENT_LENGTH + sizeof nul + sizeof(uint32_t)];
spastor 0:1c358ea10753 263 } input;
spastor 0:1c358ea10753 264
spastor 0:1c358ea10753 265 struct {
spastor 0:1c358ea10753 266 rcistr_t content;
spastor 0:1c358ea10753 267 rci_output_state_t state;
spastor 0:1c358ea10753 268 } output;
spastor 0:1c358ea10753 269
spastor 0:1c358ea10753 270 struct {
spastor 0:1c358ea10753 271 rci_error_state_t state;
spastor 0:1c358ea10753 272 connector_bool_t command_error;
spastor 0:1c358ea10753 273 char const * description;
spastor 0:1c358ea10753 274 } error;
spastor 0:1c358ea10753 275
spastor 0:1c358ea10753 276 struct {
spastor 0:1c358ea10753 277 rcistr_t content;
spastor 0:1c358ea10753 278
spastor 0:1c358ea10753 279 struct {
spastor 0:1c358ea10753 280 unsigned int id;
spastor 0:1c358ea10753 281 unsigned int index;
spastor 0:1c358ea10753 282 } group;
spastor 0:1c358ea10753 283
spastor 0:1c358ea10753 284 struct {
spastor 0:1c358ea10753 285 unsigned int id;
spastor 0:1c358ea10753 286 } element;
spastor 0:1c358ea10753 287
spastor 0:1c358ea10753 288 connector_element_value_t value;
spastor 0:1c358ea10753 289 size_t string_value_length;
spastor 0:1c358ea10753 290
spastor 0:1c358ea10753 291 connector_remote_config_t callback_data;
spastor 0:1c358ea10753 292 } shared;
spastor 0:1c358ea10753 293 } rci_t;
spastor 0:1c358ea10753 294
spastor 0:1c358ea10753 295 #define set_rci_input_flag(rci, value) (rci)->input.flag |= (value)
spastor 0:1c358ea10753 296 #define is_rci_input_flag(rci, value) (((rci)->input.flag & (value)) == (value))
spastor 0:1c358ea10753 297 #define clea_rci_input_flag(rci, value) (rci)->input.flag &= ~(value)
spastor 0:1c358ea10753 298
spastor 0:1c358ea10753 299 #define set_rci_input_state(rci, value) (rci)->input.state = (value)
spastor 0:1c358ea10753 300 #define get_rci_input_state(rci) (rci)->input.state
spastor 0:1c358ea10753 301
spastor 0:1c358ea10753 302 #define set_rci_traverse_state(rci, value) (rci)->traverse.state = (value)
spastor 0:1c358ea10753 303 #define get_rci_traverse_state(rci) (rci)->traverse.state
spastor 0:1c358ea10753 304
spastor 0:1c358ea10753 305 #define set_rci_output_state(rci, value) (rci)->output.state = (value)
spastor 0:1c358ea10753 306 #define get_rci_output_state(rci) (rci)->output.state
spastor 0:1c358ea10753 307
spastor 0:1c358ea10753 308 #define set_rci_error_state(rci, value) (rci)->error.state = (value);
spastor 0:1c358ea10753 309 #define get_rci_error_state(rci) (rci)->error.state;
spastor 0:1c358ea10753 310
spastor 0:1c358ea10753 311 #define set_rci_command_error(rci) (rci)->error.command_error = connector_true;
spastor 0:1c358ea10753 312 #define clear_rci_command_error(rci) (rci)->error.command_error = connector_false;
spastor 0:1c358ea10753 313
spastor 0:1c358ea10753 314