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 static void rci_output_error_id(rci_t * const rci)
spastor 0:1c358ea10753 14 {
spastor 0:1c358ea10753 15
spastor 0:1c358ea10753 16 connector_remote_config_t const * const response = &rci->shared.callback_data;
spastor 0:1c358ea10753 17 uint32_t value;
spastor 0:1c358ea10753 18
spastor 0:1c358ea10753 19 if (rci->error.command_error)
spastor 0:1c358ea10753 20 {
spastor 0:1c358ea10753 21 #define BINARY_RCI_COMMAND_LOWER_ERROR_ID_MASK UINT32_C(0x7FF)
spastor 0:1c358ea10753 22 #define BINARY_RCI_COMMAND_UPPER_ERROR_ID_MASK (~UINT32_C(0x1FFF))
spastor 0:1c358ea10753 23 /* Command Error ID is [:13][10:0] */
spastor 0:1c358ea10753 24 value = (response->error_id & BINARY_RCI_COMMAND_LOWER_ERROR_ID_MASK);
spastor 0:1c358ea10753 25 value |= ((response->error_id << UINT32_C(2)) & BINARY_RCI_COMMAND_UPPER_ERROR_ID_MASK);
spastor 0:1c358ea10753 26 }
spastor 0:1c358ea10753 27 else
spastor 0:1c358ea10753 28 {
spastor 0:1c358ea10753 29 /* Error Id is [:13][10:7][5:0] */
spastor 0:1c358ea10753 30 #define BINARY_RCI_LOWER_ERROR_ID_MASK UINT32_C(0x3F)
spastor 0:1c358ea10753 31 #define BINARY_RCI_MIDDLE_ERROR_ID_MASK UINT32_C(0x780)
spastor 0:1c358ea10753 32 #define BINARY_RCI_UPPER_ERROR_ID_MASK ()~UINT32_C(0x1FFF))
spastor 0:1c358ea10753 33
spastor 0:1c358ea10753 34 value = response->error_id & BINARY_RCI_LOWER_ERROR_ID_MASK;
spastor 0:1c358ea10753 35 value |= (response->error_id << 1) & BINARY_RCI_MIDDLE_ERROR_ID_MASK;
spastor 0:1c358ea10753 36 value |= (response->error_id << 3) & BINARY_RCI_MIDDLE_ERROR_ID_MASK;
spastor 0:1c358ea10753 37
spastor 0:1c358ea10753 38 }
spastor 0:1c358ea10753 39
spastor 0:1c358ea10753 40 value |= BINARY_RCI_ERROR_INDICATOR_BIT;
spastor 0:1c358ea10753 41
spastor 0:1c358ea10753 42 {
spastor 0:1c358ea10753 43 connector_bool_t const overflow = rci_output_uint32(rci, value);
spastor 0:1c358ea10753 44
spastor 0:1c358ea10753 45 if (!overflow)
spastor 0:1c358ea10753 46 set_rci_error_state(rci, rci_error_state_description);
spastor 0:1c358ea10753 47 }
spastor 0:1c358ea10753 48 }
spastor 0:1c358ea10753 49
spastor 0:1c358ea10753 50 static void rci_output_error_description(rci_t * const rci)
spastor 0:1c358ea10753 51 {
spastor 0:1c358ea10753 52 #if defined RCI_PARSER_USES_ERROR_DESCRIPTIONS
spastor 0:1c358ea10753 53 char const * const description = rci->error.description+1;
spastor 0:1c358ea10753 54 size_t const length = (size_t)*rci->error.description;
spastor 0:1c358ea10753 55 #else
spastor 0:1c358ea10753 56 char * description = NULL;
spastor 0:1c358ea10753 57 size_t const length = 0;
spastor 0:1c358ea10753 58 #endif
spastor 0:1c358ea10753 59
spastor 0:1c358ea10753 60 connector_bool_t const overflow = rci_output_string(rci, description, length);
spastor 0:1c358ea10753 61
spastor 0:1c358ea10753 62 if (!overflow)
spastor 0:1c358ea10753 63 set_rci_error_state(rci, rci_error_state_hint);
spastor 0:1c358ea10753 64 }
spastor 0:1c358ea10753 65
spastor 0:1c358ea10753 66 static void rci_output_error_hint(rci_t * const rci)
spastor 0:1c358ea10753 67 {
spastor 0:1c358ea10753 68 connector_remote_config_t const * const remote_config_ = &rci->shared.callback_data;
spastor 0:1c358ea10753 69 size_t const description_length = (remote_config_->response.error_hint == NULL) ? 0 : strlen(remote_config_->response.error_hint);
spastor 0:1c358ea10753 70 connector_bool_t const overflow = rci_output_string(rci, remote_config_->response.error_hint, description_length);
spastor 0:1c358ea10753 71
spastor 0:1c358ea10753 72 if (!overflow)
spastor 0:1c358ea10753 73 {
spastor 0:1c358ea10753 74 set_rci_error_state(rci, rci_error_state_callback);
spastor 0:1c358ea10753 75 }
spastor 0:1c358ea10753 76 }
spastor 0:1c358ea10753 77
spastor 0:1c358ea10753 78
spastor 0:1c358ea10753 79 static void rci_generate_error(rci_t * const rci)
spastor 0:1c358ea10753 80 {
spastor 0:1c358ea10753 81 rci_buffer_t * const output = &rci->buffer.output;
spastor 0:1c358ea10753 82
spastor 0:1c358ea10753 83 if (pending_rci_callback(rci))
spastor 0:1c358ea10753 84 {
spastor 0:1c358ea10753 85 if (!rci_callback(rci))
spastor 0:1c358ea10753 86 goto done;
spastor 0:1c358ea10753 87 }
spastor 0:1c358ea10753 88
spastor 0:1c358ea10753 89 if (rci_buffer_remaining(output) != 0)
spastor 0:1c358ea10753 90 {
spastor 0:1c358ea10753 91 switch (rci->error.state)
spastor 0:1c358ea10753 92 {
spastor 0:1c358ea10753 93 case rci_error_state_id:
spastor 0:1c358ea10753 94 rci_output_error_id(rci);
spastor 0:1c358ea10753 95 break;
spastor 0:1c358ea10753 96
spastor 0:1c358ea10753 97 case rci_error_state_description:
spastor 0:1c358ea10753 98 rci_output_error_description(rci);
spastor 0:1c358ea10753 99 break;
spastor 0:1c358ea10753 100
spastor 0:1c358ea10753 101 case rci_error_state_hint:
spastor 0:1c358ea10753 102 rci_output_error_hint(rci);
spastor 0:1c358ea10753 103 break;
spastor 0:1c358ea10753 104
spastor 0:1c358ea10753 105 case rci_error_state_callback:
spastor 0:1c358ea10753 106 {
spastor 0:1c358ea10753 107 connector_request_id_remote_config_t const remote_config_request = rci->callback.request.remote_config_request;
spastor 0:1c358ea10753 108
spastor 0:1c358ea10753 109 switch (remote_config_request)
spastor 0:1c358ea10753 110 {
spastor 0:1c358ea10753 111 case connector_request_id_remote_config_action_start:
spastor 0:1c358ea10753 112 case connector_request_id_remote_config_group_end:
spastor 0:1c358ea10753 113 trigger_rci_callback(rci, connector_request_id_remote_config_action_end);
spastor 0:1c358ea10753 114 break;
spastor 0:1c358ea10753 115 case connector_request_id_remote_config_session_start:
spastor 0:1c358ea10753 116 trigger_rci_callback(rci, connector_request_id_remote_config_session_end);
spastor 0:1c358ea10753 117 break;
spastor 0:1c358ea10753 118 case connector_request_id_remote_config_action_end:
spastor 0:1c358ea10753 119 {
spastor 0:1c358ea10753 120 connector_bool_t const overflow = rci_output_terminator(rci);
spastor 0:1c358ea10753 121 if (overflow) goto done;
spastor 0:1c358ea10753 122 }
spastor 0:1c358ea10753 123 trigger_rci_callback(rci, connector_request_id_remote_config_session_end);
spastor 0:1c358ea10753 124 break;
spastor 0:1c358ea10753 125
spastor 0:1c358ea10753 126 case connector_request_id_remote_config_group_process:
spastor 0:1c358ea10753 127 case connector_request_id_remote_config_group_start:
spastor 0:1c358ea10753 128 {
spastor 0:1c358ea10753 129 connector_bool_t const overflow = rci_output_terminator(rci);
spastor 0:1c358ea10753 130 if (overflow) goto done;
spastor 0:1c358ea10753 131 }
spastor 0:1c358ea10753 132 trigger_rci_callback(rci, connector_request_id_remote_config_group_end);
spastor 0:1c358ea10753 133 break;
spastor 0:1c358ea10753 134
spastor 0:1c358ea10753 135 case connector_request_id_remote_config_session_cancel:
spastor 0:1c358ea10753 136 ASSERT(connector_false);
spastor 0:1c358ea10753 137 break;
spastor 0:1c358ea10753 138
spastor 0:1c358ea10753 139 case connector_request_id_remote_config_session_end:
spastor 0:1c358ea10753 140 rci->status = rci_status_complete;
spastor 0:1c358ea10753 141 break;
spastor 0:1c358ea10753 142 }
spastor 0:1c358ea10753 143 break;
spastor 0:1c358ea10753 144 }
spastor 0:1c358ea10753 145 }
spastor 0:1c358ea10753 146 }
spastor 0:1c358ea10753 147
spastor 0:1c358ea10753 148 #if defined RCI_DEBUG
spastor 0:1c358ea10753 149 {
spastor 0:1c358ea10753 150 size_t const bytes = rci_buffer_used(&rci->buffer.output);
spastor 0:1c358ea10753 151 if (bytes > 0)
spastor 0:1c358ea10753 152 {
spastor 0:1c358ea10753 153 connector_debug_hexvalue("Response", rci->buffer.output.start, bytes);
spastor 0:1c358ea10753 154 }
spastor 0:1c358ea10753 155 }
spastor 0:1c358ea10753 156 #endif
spastor 0:1c358ea10753 157
spastor 0:1c358ea10753 158 done:
spastor 0:1c358ea10753 159 return;
spastor 0:1c358ea10753 160 }
spastor 0:1c358ea10753 161
spastor 0:1c358ea10753 162
spastor 0:1c358ea10753 163