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 #define state_call(rci, value) ((rci)->parser.state = (value))
spastor 0:1c358ea10753 14
spastor 0:1c358ea10753 15 static connector_bool_t is_set_command(connector_remote_action_t const action)
spastor 0:1c358ea10753 16 {
spastor 0:1c358ea10753 17 return connector_bool(action == connector_remote_action_set);
spastor 0:1c358ea10753 18
spastor 0:1c358ea10753 19 }
spastor 0:1c358ea10753 20
spastor 0:1c358ea10753 21 static void rci_error(rci_t * const rci, unsigned int const id, char const * const description, char const * const hint)
spastor 0:1c358ea10753 22 {
spastor 0:1c358ea10753 23 rci->shared.callback_data.error_id = id;
spastor 0:1c358ea10753 24 rci->shared.callback_data.response.error_hint = hint;
spastor 0:1c358ea10753 25
spastor 0:1c358ea10753 26 rci->error.description = description;
spastor 0:1c358ea10753 27 }
spastor 0:1c358ea10753 28
spastor 0:1c358ea10753 29 #if defined RCI_PARSER_USES_ERROR_DESCRIPTIONS
spastor 0:1c358ea10753 30 #define get_rci_global_error(rci, id) connector_rci_config_data.error_table[(id) - connector_rci_error_OFFSET]
spastor 0:1c358ea10753 31 static char const * get_rci_group_error(rci_t * const rci, unsigned int const id)
spastor 0:1c358ea10753 32 {
spastor 0:1c358ea10753 33 connector_group_t const * const group = get_current_group(rci);
spastor 0:1c358ea10753 34 unsigned int const index = (id - connector_rci_config_data.global_error_count);
spastor 0:1c358ea10753 35
spastor 0:1c358ea10753 36 ASSERT(id >= connector_rci_config_data.global_error_count);
spastor 0:1c358ea10753 37 ASSERT(index < group->errors.count);
spastor 0:1c358ea10753 38
spastor 0:1c358ea10753 39 return group->errors.description[index];
spastor 0:1c358ea10753 40 }
spastor 0:1c358ea10753 41 #else
spastor 0:1c358ea10753 42 #define get_rci_global_error(rci, id) ((void) (rci), (void) (id), NULL)
spastor 0:1c358ea10753 43 #define get_rci_group_error(rci, id) ((void) (rci), (void) (id), NULL)
spastor 0:1c358ea10753 44 #endif
spastor 0:1c358ea10753 45
spastor 0:1c358ea10753 46 static void rci_global_error(rci_t * const rci, unsigned int const id, char const * const hint)
spastor 0:1c358ea10753 47 {
spastor 0:1c358ea10753 48 char const * const description = get_rci_global_error(rci, id);
spastor 0:1c358ea10753 49
spastor 0:1c358ea10753 50 rci_error(rci, id, description, hint);
spastor 0:1c358ea10753 51 }
spastor 0:1c358ea10753 52
spastor 0:1c358ea10753 53 static void rci_group_error(rci_t * const rci, unsigned int const id, char const * const hint)
spastor 0:1c358ea10753 54 {
spastor 0:1c358ea10753 55 if (id < connector_rci_config_data.global_error_count)
spastor 0:1c358ea10753 56 {
spastor 0:1c358ea10753 57 rci_global_error(rci, id, hint);
spastor 0:1c358ea10753 58 }
spastor 0:1c358ea10753 59 else
spastor 0:1c358ea10753 60 {
spastor 0:1c358ea10753 61 char const * const description = get_rci_group_error(rci, id);
spastor 0:1c358ea10753 62
spastor 0:1c358ea10753 63 rci_error(rci, id, description, hint);
spastor 0:1c358ea10753 64 }
spastor 0:1c358ea10753 65 }
spastor 0:1c358ea10753 66
spastor 0:1c358ea10753 67 static connector_bool_t pending_rci_callback(rci_t * const rci)
spastor 0:1c358ea10753 68 {
spastor 0:1c358ea10753 69 connector_bool_t const pending = connector_bool(rci->callback.status == connector_callback_busy);
spastor 0:1c358ea10753 70
spastor 0:1c358ea10753 71 return pending;
spastor 0:1c358ea10753 72 }
spastor 0:1c358ea10753 73
spastor 0:1c358ea10753 74 static void trigger_rci_callback(rci_t * const rci, connector_request_id_remote_config_t const remote_config_request)
spastor 0:1c358ea10753 75 {
spastor 0:1c358ea10753 76 switch (remote_config_request)
spastor 0:1c358ea10753 77 {
spastor 0:1c358ea10753 78 case connector_request_id_remote_config_session_cancel:
spastor 0:1c358ea10753 79 break;
spastor 0:1c358ea10753 80
spastor 0:1c358ea10753 81 case connector_request_id_remote_config_session_start:
spastor 0:1c358ea10753 82 case connector_request_id_remote_config_session_end:
spastor 0:1c358ea10753 83 case connector_request_id_remote_config_action_start:
spastor 0:1c358ea10753 84 case connector_request_id_remote_config_action_end:
spastor 0:1c358ea10753 85 break;
spastor 0:1c358ea10753 86
spastor 0:1c358ea10753 87 case connector_request_id_remote_config_group_start:
spastor 0:1c358ea10753 88 ASSERT(have_group_id(rci));
spastor 0:1c358ea10753 89 ASSERT(have_group_index(rci));
spastor 0:1c358ea10753 90
spastor 0:1c358ea10753 91 rci->shared.callback_data.group.id = get_group_id(rci);
spastor 0:1c358ea10753 92 rci->shared.callback_data.group.index = get_group_index(rci);
spastor 0:1c358ea10753 93 break;
spastor 0:1c358ea10753 94
spastor 0:1c358ea10753 95 case connector_request_id_remote_config_group_end:
spastor 0:1c358ea10753 96 ASSERT(have_group_id(rci));
spastor 0:1c358ea10753 97 ASSERT(have_group_index(rci));
spastor 0:1c358ea10753 98 break;
spastor 0:1c358ea10753 99
spastor 0:1c358ea10753 100 case connector_request_id_remote_config_group_process:
spastor 0:1c358ea10753 101 ASSERT(have_group_id(rci));
spastor 0:1c358ea10753 102 ASSERT(have_group_index(rci));
spastor 0:1c358ea10753 103 ASSERT(have_element_id(rci));
spastor 0:1c358ea10753 104
spastor 0:1c358ea10753 105 rci->shared.callback_data.element.id = get_element_id(rci);
spastor 0:1c358ea10753 106 {
spastor 0:1c358ea10753 107 connector_group_element_t const * const element = get_current_element(rci);
spastor 0:1c358ea10753 108
spastor 0:1c358ea10753 109 rci->shared.callback_data.element.type = element->type;
spastor 0:1c358ea10753 110 }
spastor 0:1c358ea10753 111
spastor 0:1c358ea10753 112 rci->shared.callback_data.element.value = is_set_command(rci->shared.callback_data.action) ? &rci->shared.value : NULL;
spastor 0:1c358ea10753 113 break;
spastor 0:1c358ea10753 114 }
spastor 0:1c358ea10753 115
spastor 0:1c358ea10753 116 rci->callback.request.remote_config_request = remote_config_request;
spastor 0:1c358ea10753 117 rci->callback.status = connector_callback_busy;
spastor 0:1c358ea10753 118 }
spastor 0:1c358ea10753 119
spastor 0:1c358ea10753 120 static connector_bool_t rci_callback(rci_t * const rci)
spastor 0:1c358ea10753 121 {
spastor 0:1c358ea10753 122 connector_bool_t callback_complete;
spastor 0:1c358ea10753 123 connector_remote_config_t * remote_config = &rci->shared.callback_data;
spastor 0:1c358ea10753 124 connector_remote_config_cancel_t remote_cancel;
spastor 0:1c358ea10753 125 void * callback_data = NULL;
spastor 0:1c358ea10753 126
spastor 0:1c358ea10753 127 switch (rci->callback.request.remote_config_request)
spastor 0:1c358ea10753 128 {
spastor 0:1c358ea10753 129 case connector_request_id_remote_config_session_start:
spastor 0:1c358ea10753 130 case connector_request_id_remote_config_session_end:
spastor 0:1c358ea10753 131 case connector_request_id_remote_config_action_start:
spastor 0:1c358ea10753 132 case connector_request_id_remote_config_action_end:
spastor 0:1c358ea10753 133 case connector_request_id_remote_config_group_start:
spastor 0:1c358ea10753 134 case connector_request_id_remote_config_group_end:
spastor 0:1c358ea10753 135 case connector_request_id_remote_config_group_process:
spastor 0:1c358ea10753 136 {
spastor 0:1c358ea10753 137 remote_config->error_id = connector_success;
spastor 0:1c358ea10753 138 callback_data = remote_config;
spastor 0:1c358ea10753 139 break;
spastor 0:1c358ea10753 140 }
spastor 0:1c358ea10753 141
spastor 0:1c358ea10753 142 case connector_request_id_remote_config_session_cancel:
spastor 0:1c358ea10753 143 {
spastor 0:1c358ea10753 144 remote_cancel.user_context = remote_config->user_context;
spastor 0:1c358ea10753 145 callback_data = &remote_cancel;
spastor 0:1c358ea10753 146 break;
spastor 0:1c358ea10753 147 }
spastor 0:1c358ea10753 148 }
spastor 0:1c358ea10753 149
spastor 0:1c358ea10753 150 rci->callback.status = connector_callback(rci->service_data->connector_ptr->callback, connector_class_id_remote_config, rci->callback.request, callback_data);
spastor 0:1c358ea10753 151
spastor 0:1c358ea10753 152 switch (rci->callback.status)
spastor 0:1c358ea10753 153 {
spastor 0:1c358ea10753 154 case connector_callback_abort:
spastor 0:1c358ea10753 155 callback_complete = connector_false;
spastor 0:1c358ea10753 156 rci->status = rci_status_error;
spastor 0:1c358ea10753 157 break;
spastor 0:1c358ea10753 158
spastor 0:1c358ea10753 159 case connector_callback_continue:
spastor 0:1c358ea10753 160 callback_complete = connector_true;
spastor 0:1c358ea10753 161 #if 0
spastor 0:1c358ea10753 162 if (response_data->error_id != connector_success)
spastor 0:1c358ea10753 163 {
spastor 0:1c358ea10753 164 switch (rci->callback.request.remote_config_request)
spastor 0:1c358ea10753 165 {
spastor 0:1c358ea10753 166 case connector_request_id_remote_config_session_end:
spastor 0:1c358ea10753 167 callback_complete = connector_false;
spastor 0:1c358ea10753 168 rci->status = rci_status_internal_error;
spastor 0:1c358ea10753 169 break;
spastor 0:1c358ea10753 170 default:
spastor 0:1c358ea10753 171 break;
spastor 0:1c358ea10753 172 }
spastor 0:1c358ea10753 173 }
spastor 0:1c358ea10753 174 #endif
spastor 0:1c358ea10753 175 break;
spastor 0:1c358ea10753 176
spastor 0:1c358ea10753 177 case connector_callback_busy:
spastor 0:1c358ea10753 178 callback_complete = connector_false;
spastor 0:1c358ea10753 179 break;
spastor 0:1c358ea10753 180
spastor 0:1c358ea10753 181 default:
spastor 0:1c358ea10753 182 callback_complete = connector_false;
spastor 0:1c358ea10753 183 rci->status = rci_status_error;
spastor 0:1c358ea10753 184 break;
spastor 0:1c358ea10753 185 }
spastor 0:1c358ea10753 186
spastor 0:1c358ea10753 187 return callback_complete;
spastor 0:1c358ea10753 188 }
spastor 0:1c358ea10753 189
spastor 0:1c358ea10753 190
spastor 0:1c358ea10753 191