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 "rci_binary_support.h"
spastor 0:1c358ea10753 14 #include "rci_binary_debug.h"
spastor 0:1c358ea10753 15 #include "rci_binary_util.h"
spastor 0:1c358ea10753 16 #include "rci_binary_buffer.h"
spastor 0:1c358ea10753 17 #include "rci_binary_string.h"
spastor 0:1c358ea10753 18 #include "rci_binary_group.h"
spastor 0:1c358ea10753 19 #include "rci_binary_element.h"
spastor 0:1c358ea10753 20 #include "rci_binary_callback.h"
spastor 0:1c358ea10753 21 #include "rci_binary_output.h"
spastor 0:1c358ea10753 22 #include "rci_binary_input.h"
spastor 0:1c358ea10753 23 #include "rci_binary_traverse.h"
spastor 0:1c358ea10753 24 #include "rci_binary_error.h"
spastor 0:1c358ea10753 25
spastor 0:1c358ea10753 26 static connector_bool_t rci_action_session_start(rci_t * const rci, rci_service_data_t * service_data)
spastor 0:1c358ea10753 27 {
spastor 0:1c358ea10753 28 ASSERT(rci->service_data == NULL);
spastor 0:1c358ea10753 29 rci->service_data = service_data;
spastor 0:1c358ea10753 30 ASSERT(rci->service_data != NULL);
spastor 0:1c358ea10753 31
spastor 0:1c358ea10753 32 rci_set_buffer(&rci->buffer.input, &rci->service_data->input);
spastor 0:1c358ea10753 33 rci_set_buffer(&rci->buffer.output, &rci->service_data->output);
spastor 0:1c358ea10753 34 #if defined RCI_DEBUG
spastor 0:1c358ea10753 35 memset(rci->service_data->output.data, 0, rci->service_data->output.bytes);
spastor 0:1c358ea10753 36 #endif
spastor 0:1c358ea10753 37
spastor 0:1c358ea10753 38 rci->input.destination = rci_buffer_position(&rci->buffer.input);
spastor 0:1c358ea10753 39 reset_input_content(rci);
spastor 0:1c358ea10753 40
spastor 0:1c358ea10753 41 invalidate_group_id(rci);
spastor 0:1c358ea10753 42 invalidate_group_index(rci);
spastor 0:1c358ea10753 43 invalidate_element_id(rci);
spastor 0:1c358ea10753 44
spastor 0:1c358ea10753 45 rci->shared.callback_data.response.element_value = &rci->shared.value;
spastor 0:1c358ea10753 46
spastor 0:1c358ea10753 47 rci->status = rci_status_busy;
spastor 0:1c358ea10753 48 rci->error.command_error = connector_false;
spastor 0:1c358ea10753 49 rci->input.flag = 0;
spastor 0:1c358ea10753 50
spastor 0:1c358ea10753 51 trigger_rci_callback(rci, connector_request_id_remote_config_session_start);
spastor 0:1c358ea10753 52 set_rci_input_state(rci, rci_input_state_command_id);
spastor 0:1c358ea10753 53 state_call(rci, rci_parser_state_input);
spastor 0:1c358ea10753 54
spastor 0:1c358ea10753 55 set_rci_error_state(rci, rci_error_state_id);
spastor 0:1c358ea10753 56
spastor 0:1c358ea10753 57 return connector_true;
spastor 0:1c358ea10753 58 }
spastor 0:1c358ea10753 59
spastor 0:1c358ea10753 60 static connector_bool_t rci_action_session_active(rci_t * const rci)
spastor 0:1c358ea10753 61 {
spastor 0:1c358ea10753 62 connector_bool_t success = connector_true;
spastor 0:1c358ea10753 63
spastor 0:1c358ea10753 64 switch (rci->status)
spastor 0:1c358ea10753 65 {
spastor 0:1c358ea10753 66 case rci_status_error:
spastor 0:1c358ea10753 67 case rci_status_complete:
spastor 0:1c358ea10753 68 {
spastor 0:1c358ea10753 69 rci->status = rci_status_internal_error;
spastor 0:1c358ea10753 70 /* no break; */
spastor 0:1c358ea10753 71 }
spastor 0:1c358ea10753 72
spastor 0:1c358ea10753 73 case rci_status_internal_error:
spastor 0:1c358ea10753 74 {
spastor 0:1c358ea10753 75 success = connector_false;
spastor 0:1c358ea10753 76 break;
spastor 0:1c358ea10753 77 }
spastor 0:1c358ea10753 78
spastor 0:1c358ea10753 79 case rci_status_busy:
spastor 0:1c358ea10753 80 {
spastor 0:1c358ea10753 81 break;
spastor 0:1c358ea10753 82 }
spastor 0:1c358ea10753 83
spastor 0:1c358ea10753 84 case rci_status_more_input:
spastor 0:1c358ea10753 85 {
spastor 0:1c358ea10753 86 connector_debug_hexvalue("rci_binary more request", rci->service_data->input.data, rci->service_data->input.bytes);
spastor 0:1c358ea10753 87 rci_set_buffer(&rci->buffer.input, &rci->service_data->input);
spastor 0:1c358ea10753 88 if (!destination_in_storage(rci))
spastor 0:1c358ea10753 89 {
spastor 0:1c358ea10753 90 rci->input.destination = rci_buffer_position(&rci->buffer.input);
spastor 0:1c358ea10753 91 }
spastor 0:1c358ea10753 92 rci->status = rci_status_busy;
spastor 0:1c358ea10753 93 break;
spastor 0:1c358ea10753 94 }
spastor 0:1c358ea10753 95
spastor 0:1c358ea10753 96 case rci_status_flush_output:
spastor 0:1c358ea10753 97 {
spastor 0:1c358ea10753 98 rci_set_buffer(&rci->buffer.output, &rci->service_data->output);
spastor 0:1c358ea10753 99 #if defined RCI_DEBUG
spastor 0:1c358ea10753 100 memset(rci->service_data->output.data, 0, rci->service_data->output.bytes);
spastor 0:1c358ea10753 101 #endif
spastor 0:1c358ea10753 102 rci->status = rci_status_busy;
spastor 0:1c358ea10753 103 break;
spastor 0:1c358ea10753 104 }
spastor 0:1c358ea10753 105 }
spastor 0:1c358ea10753 106
spastor 0:1c358ea10753 107 return success;
spastor 0:1c358ea10753 108 }
spastor 0:1c358ea10753 109
spastor 0:1c358ea10753 110 static connector_bool_t rci_action_session_lost(rci_t * const rci)
spastor 0:1c358ea10753 111 {
spastor 0:1c358ea10753 112 trigger_rci_callback(rci, connector_request_id_remote_config_session_cancel);
spastor 0:1c358ea10753 113 {
spastor 0:1c358ea10753 114 connector_bool_t const success = rci_callback(rci);
spastor 0:1c358ea10753 115 ASSERT(success); UNUSED_VARIABLE(success);
spastor 0:1c358ea10753 116 }
spastor 0:1c358ea10753 117
spastor 0:1c358ea10753 118 rci->status = rci_status_complete;
spastor 0:1c358ea10753 119
spastor 0:1c358ea10753 120 return connector_false;
spastor 0:1c358ea10753 121 }
spastor 0:1c358ea10753 122
spastor 0:1c358ea10753 123
spastor 0:1c358ea10753 124 static rci_status_t rci_binary(rci_session_t const action, ...)
spastor 0:1c358ea10753 125 {
spastor 0:1c358ea10753 126 static rci_t rci;
spastor 0:1c358ea10753 127
spastor 0:1c358ea10753 128 {
spastor 0:1c358ea10753 129 connector_bool_t success;
spastor 0:1c358ea10753 130 va_list ap;
spastor 0:1c358ea10753 131
spastor 0:1c358ea10753 132 switch (action)
spastor 0:1c358ea10753 133 {
spastor 0:1c358ea10753 134 case rci_session_start:
spastor 0:1c358ea10753 135 va_start(ap, action);
spastor 0:1c358ea10753 136 success = rci_action_session_start(&rci, va_arg(ap, rci_service_data_t *));
spastor 0:1c358ea10753 137 va_end(ap);
spastor 0:1c358ea10753 138 break;
spastor 0:1c358ea10753 139
spastor 0:1c358ea10753 140 case rci_session_active:
spastor 0:1c358ea10753 141 success = rci_action_session_active(&rci);
spastor 0:1c358ea10753 142 break;
spastor 0:1c358ea10753 143
spastor 0:1c358ea10753 144 case rci_session_lost:
spastor 0:1c358ea10753 145 success = rci_action_session_lost(&rci);
spastor 0:1c358ea10753 146 break;
spastor 0:1c358ea10753 147
spastor 0:1c358ea10753 148 default:
spastor 0:1c358ea10753 149 success = connector_false;
spastor 0:1c358ea10753 150 break;
spastor 0:1c358ea10753 151 }
spastor 0:1c358ea10753 152
spastor 0:1c358ea10753 153 if (!success) goto done;
spastor 0:1c358ea10753 154 }
spastor 0:1c358ea10753 155
spastor 0:1c358ea10753 156 if (pending_rci_callback(&rci))
spastor 0:1c358ea10753 157 {
spastor 0:1c358ea10753 158 connector_remote_config_t * const remote_config = &rci.shared.callback_data;
spastor 0:1c358ea10753 159
spastor 0:1c358ea10753 160 if (!rci_callback(&rci))
spastor 0:1c358ea10753 161 goto done;
spastor 0:1c358ea10753 162
spastor 0:1c358ea10753 163 if (remote_config->error_id != connector_success)
spastor 0:1c358ea10753 164 {
spastor 0:1c358ea10753 165 rci_group_error(&rci, remote_config->error_id, remote_config->response.error_hint);
spastor 0:1c358ea10753 166 goto done;
spastor 0:1c358ea10753 167 }
spastor 0:1c358ea10753 168 }
spastor 0:1c358ea10753 169
spastor 0:1c358ea10753 170 switch (rci.parser.state)
spastor 0:1c358ea10753 171 {
spastor 0:1c358ea10753 172 case rci_parser_state_input:
spastor 0:1c358ea10753 173 rci_parse_input(&rci);
spastor 0:1c358ea10753 174 break;
spastor 0:1c358ea10753 175
spastor 0:1c358ea10753 176 case rci_parser_state_output:
spastor 0:1c358ea10753 177 rci_generate_output(&rci);
spastor 0:1c358ea10753 178 break;
spastor 0:1c358ea10753 179
spastor 0:1c358ea10753 180 case rci_parser_state_traverse:
spastor 0:1c358ea10753 181 rci_traverse_data(&rci);
spastor 0:1c358ea10753 182 break;
spastor 0:1c358ea10753 183
spastor 0:1c358ea10753 184 case rci_parser_state_error:
spastor 0:1c358ea10753 185 rci_generate_error(&rci);
spastor 0:1c358ea10753 186 break;
spastor 0:1c358ea10753 187 }
spastor 0:1c358ea10753 188
spastor 0:1c358ea10753 189 done:
spastor 0:1c358ea10753 190
spastor 0:1c358ea10753 191 switch (rci.status)
spastor 0:1c358ea10753 192 {
spastor 0:1c358ea10753 193 case rci_status_busy:
spastor 0:1c358ea10753 194 break;
spastor 0:1c358ea10753 195 case rci_status_more_input:
spastor 0:1c358ea10753 196 rci_debug_printf("Need more input\n");
spastor 0:1c358ea10753 197 break;
spastor 0:1c358ea10753 198 case rci_status_flush_output:
spastor 0:1c358ea10753 199 rci.service_data->output.bytes = rci_buffer_used(&rci.buffer.output);
spastor 0:1c358ea10753 200 break;
spastor 0:1c358ea10753 201 case rci_status_complete:
spastor 0:1c358ea10753 202 rci.service_data->output.bytes = rci_buffer_used(&rci.buffer.output);
spastor 0:1c358ea10753 203 /* no break; */
spastor 0:1c358ea10753 204 case rci_status_internal_error:
spastor 0:1c358ea10753 205 case rci_status_error:
spastor 0:1c358ea10753 206 rci.service_data = NULL;
spastor 0:1c358ea10753 207 break;
spastor 0:1c358ea10753 208 }
spastor 0:1c358ea10753 209
spastor 0:1c358ea10753 210 return rci.status;
spastor 0:1c358ea10753 211 }
spastor 0:1c358ea10753 212
spastor 0:1c358ea10753 213