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
private/rci_service.h@0:1c358ea10753, 2013-12-03 (annotated)
- Committer:
- spastor
- Date:
- Tue Dec 03 13:34:02 2013 +0000
- Revision:
- 0:1c358ea10753
First commit
Who changed what in which revision?
User | Revision | Line number | New 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 | #define CONNECTOR_RCI_PARSER_INTERNAL_DATA |
spastor | 0:1c358ea10753 | 13 | #define CONNECTOR_CONST_PROTECTION |
spastor | 0:1c358ea10753 | 14 | |
spastor | 0:1c358ea10753 | 15 | #include "remote_config.h" |
spastor | 0:1c358ea10753 | 16 | |
spastor | 0:1c358ea10753 | 17 | #include "rci_binary.h" |
spastor | 0:1c358ea10753 | 18 | |
spastor | 0:1c358ea10753 | 19 | static uint32_t rci_get_firmware_target_zero_version(void) |
spastor | 0:1c358ea10753 | 20 | { |
spastor | 0:1c358ea10753 | 21 | return connector_rci_config_data.firmware_target_zero_version; |
spastor | 0:1c358ea10753 | 22 | } |
spastor | 0:1c358ea10753 | 23 | |
spastor | 0:1c358ea10753 | 24 | static void set_rci_service_error(msg_service_request_t * const service_request, connector_session_error_t const error_code) |
spastor | 0:1c358ea10753 | 25 | { |
spastor | 0:1c358ea10753 | 26 | service_request->error_value = error_code; |
spastor | 0:1c358ea10753 | 27 | service_request->service_type = msg_service_type_error; |
spastor | 0:1c358ea10753 | 28 | } |
spastor | 0:1c358ea10753 | 29 | |
spastor | 0:1c358ea10753 | 30 | static connector_status_t rci_service_callback(connector_data_t * const connector_ptr, msg_service_request_t * const service_request) |
spastor | 0:1c358ea10753 | 31 | { |
spastor | 0:1c358ea10753 | 32 | connector_status_t status = connector_working; |
spastor | 0:1c358ea10753 | 33 | connector_session_error_t error_status = connector_session_error_none; |
spastor | 0:1c358ea10753 | 34 | msg_session_t * session; |
spastor | 0:1c358ea10753 | 35 | rci_service_data_t * service_data; |
spastor | 0:1c358ea10753 | 36 | |
spastor | 0:1c358ea10753 | 37 | ASSERT_GOTO(connector_ptr != NULL, done); |
spastor | 0:1c358ea10753 | 38 | ASSERT_GOTO(service_request != NULL, done); |
spastor | 0:1c358ea10753 | 39 | |
spastor | 0:1c358ea10753 | 40 | session = service_request->session; |
spastor | 0:1c358ea10753 | 41 | ASSERT_GOTO(session != NULL, done); |
spastor | 0:1c358ea10753 | 42 | |
spastor | 0:1c358ea10753 | 43 | service_data = session->service_context; |
spastor | 0:1c358ea10753 | 44 | |
spastor | 0:1c358ea10753 | 45 | switch (service_request->service_type) |
spastor | 0:1c358ea10753 | 46 | { |
spastor | 0:1c358ea10753 | 47 | case msg_service_type_need_data: |
spastor | 0:1c358ea10753 | 48 | case msg_service_type_have_data: |
spastor | 0:1c358ea10753 | 49 | { |
spastor | 0:1c358ea10753 | 50 | rci_status_t rci_status; |
spastor | 0:1c358ea10753 | 51 | rci_session_t parser_action = rci_session_active; |
spastor | 0:1c358ea10753 | 52 | |
spastor | 0:1c358ea10753 | 53 | ASSERT_GOTO(service_request->have_data != NULL, done); |
spastor | 0:1c358ea10753 | 54 | ASSERT_GOTO(service_request->need_data != NULL, done); |
spastor | 0:1c358ea10753 | 55 | |
spastor | 0:1c358ea10753 | 56 | if (session->service_context == NULL) |
spastor | 0:1c358ea10753 | 57 | { |
spastor | 0:1c358ea10753 | 58 | /* 1st time here so let's allocate service context memory for rci parser */ |
spastor | 0:1c358ea10753 | 59 | void * ptr; |
spastor | 0:1c358ea10753 | 60 | |
spastor | 0:1c358ea10753 | 61 | status = malloc_data_buffer(connector_ptr, sizeof *service_data, named_buffer_id(msg_service), &ptr); |
spastor | 0:1c358ea10753 | 62 | if (status != connector_working) |
spastor | 0:1c358ea10753 | 63 | { |
spastor | 0:1c358ea10753 | 64 | if (status != connector_pending) |
spastor | 0:1c358ea10753 | 65 | { |
spastor | 0:1c358ea10753 | 66 | error_status = connector_session_error_cancel; |
spastor | 0:1c358ea10753 | 67 | } |
spastor | 0:1c358ea10753 | 68 | goto done; |
spastor | 0:1c358ea10753 | 69 | } |
spastor | 0:1c358ea10753 | 70 | |
spastor | 0:1c358ea10753 | 71 | service_data = ptr; |
spastor | 0:1c358ea10753 | 72 | session->service_context = service_data; |
spastor | 0:1c358ea10753 | 73 | |
spastor | 0:1c358ea10753 | 74 | MsgSetStart(service_request->need_data->flags); |
spastor | 0:1c358ea10753 | 75 | |
spastor | 0:1c358ea10753 | 76 | connector_debug_hexvalue("rci_service.request", service_request->have_data->data_ptr, service_request->have_data->length_in_bytes); |
spastor | 0:1c358ea10753 | 77 | parser_action = rci_session_start; |
spastor | 0:1c358ea10753 | 78 | } |
spastor | 0:1c358ea10753 | 79 | |
spastor | 0:1c358ea10753 | 80 | ASSERT(service_data != NULL); |
spastor | 0:1c358ea10753 | 81 | |
spastor | 0:1c358ea10753 | 82 | service_data->connector_ptr = connector_ptr; |
spastor | 0:1c358ea10753 | 83 | |
spastor | 0:1c358ea10753 | 84 | service_data->input.data = service_request->have_data->data_ptr; |
spastor | 0:1c358ea10753 | 85 | service_data->input.bytes = service_request->have_data->length_in_bytes; |
spastor | 0:1c358ea10753 | 86 | |
spastor | 0:1c358ea10753 | 87 | service_data->output.data = service_request->need_data->data_ptr; |
spastor | 0:1c358ea10753 | 88 | service_data->output.bytes = service_request->need_data->length_in_bytes; |
spastor | 0:1c358ea10753 | 89 | |
spastor | 0:1c358ea10753 | 90 | service_data->input.flags = service_request->have_data->flags; |
spastor | 0:1c358ea10753 | 91 | service_data->output.flags = service_request->need_data->flags; |
spastor | 0:1c358ea10753 | 92 | rci_status = rci_binary(parser_action, service_data); |
spastor | 0:1c358ea10753 | 93 | |
spastor | 0:1c358ea10753 | 94 | switch (rci_status) |
spastor | 0:1c358ea10753 | 95 | { |
spastor | 0:1c358ea10753 | 96 | case rci_status_complete: |
spastor | 0:1c358ea10753 | 97 | status = connector_working; |
spastor | 0:1c358ea10753 | 98 | MsgSetLastData(service_request->need_data->flags); |
spastor | 0:1c358ea10753 | 99 | MsgSetSendNow(service_request->need_data->flags); |
spastor | 0:1c358ea10753 | 100 | connector_debug_hexvalue("rci_service.response", service_data->output.data, service_data->output.bytes); |
spastor | 0:1c358ea10753 | 101 | service_request->need_data->length_in_bytes = service_data->output.bytes; |
spastor | 0:1c358ea10753 | 102 | break; |
spastor | 0:1c358ea10753 | 103 | |
spastor | 0:1c358ea10753 | 104 | case rci_status_busy: |
spastor | 0:1c358ea10753 | 105 | status = connector_pending; |
spastor | 0:1c358ea10753 | 106 | break; |
spastor | 0:1c358ea10753 | 107 | |
spastor | 0:1c358ea10753 | 108 | case rci_status_more_input: |
spastor | 0:1c358ea10753 | 109 | status = connector_working; |
spastor | 0:1c358ea10753 | 110 | break; |
spastor | 0:1c358ea10753 | 111 | |
spastor | 0:1c358ea10753 | 112 | case rci_status_flush_output: |
spastor | 0:1c358ea10753 | 113 | MsgSetSendNow(service_request->need_data->flags); |
spastor | 0:1c358ea10753 | 114 | connector_debug_hexvalue("rci_service.response", service_data->output.data, service_data->output.bytes); |
spastor | 0:1c358ea10753 | 115 | service_request->need_data->length_in_bytes = service_data->output.bytes; |
spastor | 0:1c358ea10753 | 116 | status = connector_active; |
spastor | 0:1c358ea10753 | 117 | break; |
spastor | 0:1c358ea10753 | 118 | |
spastor | 0:1c358ea10753 | 119 | case rci_status_error: |
spastor | 0:1c358ea10753 | 120 | status = connector_abort; |
spastor | 0:1c358ea10753 | 121 | |
spastor | 0:1c358ea10753 | 122 | /* no break; */ |
spastor | 0:1c358ea10753 | 123 | case rci_status_internal_error: |
spastor | 0:1c358ea10753 | 124 | error_status = connector_session_error_cancel; |
spastor | 0:1c358ea10753 | 125 | break; |
spastor | 0:1c358ea10753 | 126 | } |
spastor | 0:1c358ea10753 | 127 | break; |
spastor | 0:1c358ea10753 | 128 | } |
spastor | 0:1c358ea10753 | 129 | case msg_service_type_error: |
spastor | 0:1c358ea10753 | 130 | { |
spastor | 0:1c358ea10753 | 131 | rci_status_t const rci_status = rci_binary(rci_session_lost, service_data); |
spastor | 0:1c358ea10753 | 132 | |
spastor | 0:1c358ea10753 | 133 | switch (rci_status) |
spastor | 0:1c358ea10753 | 134 | { |
spastor | 0:1c358ea10753 | 135 | case rci_status_complete: |
spastor | 0:1c358ea10753 | 136 | status = connector_working; |
spastor | 0:1c358ea10753 | 137 | break; |
spastor | 0:1c358ea10753 | 138 | |
spastor | 0:1c358ea10753 | 139 | case rci_status_busy: |
spastor | 0:1c358ea10753 | 140 | status = connector_pending; |
spastor | 0:1c358ea10753 | 141 | break; |
spastor | 0:1c358ea10753 | 142 | |
spastor | 0:1c358ea10753 | 143 | case rci_status_more_input: |
spastor | 0:1c358ea10753 | 144 | case rci_status_flush_output: |
spastor | 0:1c358ea10753 | 145 | ASSERT(connector_false); |
spastor | 0:1c358ea10753 | 146 | break; |
spastor | 0:1c358ea10753 | 147 | |
spastor | 0:1c358ea10753 | 148 | case rci_status_error: |
spastor | 0:1c358ea10753 | 149 | status = connector_abort; |
spastor | 0:1c358ea10753 | 150 | break; |
spastor | 0:1c358ea10753 | 151 | |
spastor | 0:1c358ea10753 | 152 | case rci_status_internal_error: |
spastor | 0:1c358ea10753 | 153 | /* just ignore */ |
spastor | 0:1c358ea10753 | 154 | break; |
spastor | 0:1c358ea10753 | 155 | |
spastor | 0:1c358ea10753 | 156 | } |
spastor | 0:1c358ea10753 | 157 | break; |
spastor | 0:1c358ea10753 | 158 | } |
spastor | 0:1c358ea10753 | 159 | case msg_service_type_free: |
spastor | 0:1c358ea10753 | 160 | status = free_data_buffer(connector_ptr, named_buffer_id(msg_service), session->service_context); |
spastor | 0:1c358ea10753 | 161 | break; |
spastor | 0:1c358ea10753 | 162 | |
spastor | 0:1c358ea10753 | 163 | default: |
spastor | 0:1c358ea10753 | 164 | ASSERT(connector_false); |
spastor | 0:1c358ea10753 | 165 | break; |
spastor | 0:1c358ea10753 | 166 | |
spastor | 0:1c358ea10753 | 167 | } |
spastor | 0:1c358ea10753 | 168 | |
spastor | 0:1c358ea10753 | 169 | done: |
spastor | 0:1c358ea10753 | 170 | if (error_status != connector_session_error_none) |
spastor | 0:1c358ea10753 | 171 | { |
spastor | 0:1c358ea10753 | 172 | set_rci_service_error(service_request, error_status); |
spastor | 0:1c358ea10753 | 173 | } |
spastor | 0:1c358ea10753 | 174 | |
spastor | 0:1c358ea10753 | 175 | return status; |
spastor | 0:1c358ea10753 | 176 | } |
spastor | 0:1c358ea10753 | 177 | |
spastor | 0:1c358ea10753 | 178 | static connector_status_t connector_facility_rci_service_cleanup(connector_data_t * const connector_ptr) |
spastor | 0:1c358ea10753 | 179 | { |
spastor | 0:1c358ea10753 | 180 | msg_service_id_t const service_id = msg_service_id_brci; |
spastor | 0:1c358ea10753 | 181 | return msg_cleanup_all_sessions(connector_ptr, service_id); |
spastor | 0:1c358ea10753 | 182 | } |
spastor | 0:1c358ea10753 | 183 | |
spastor | 0:1c358ea10753 | 184 | static connector_status_t connector_facility_rci_service_delete(connector_data_t * const connector_ptr) |
spastor | 0:1c358ea10753 | 185 | { |
spastor | 0:1c358ea10753 | 186 | msg_service_id_t const service_id = msg_service_id_brci; |
spastor | 0:1c358ea10753 | 187 | return msg_delete_facility(connector_ptr, service_id); |
spastor | 0:1c358ea10753 | 188 | } |
spastor | 0:1c358ea10753 | 189 | |
spastor | 0:1c358ea10753 | 190 | static connector_status_t connector_facility_rci_service_init(connector_data_t * const connector_ptr, unsigned int const facility_index) |
spastor | 0:1c358ea10753 | 191 | { |
spastor | 0:1c358ea10753 | 192 | connector_status_t result; |
spastor | 0:1c358ea10753 | 193 | |
spastor | 0:1c358ea10753 | 194 | msg_service_id_t const service_id = msg_service_id_brci; |
spastor | 0:1c358ea10753 | 195 | |
spastor | 0:1c358ea10753 | 196 | #if (defined connector_request_id_remote_config_configurations) |
spastor | 0:1c358ea10753 | 197 | { |
spastor | 0:1c358ea10753 | 198 | |
spastor | 0:1c358ea10753 | 199 | connector_request_id_t request_id; |
spastor | 0:1c358ea10753 | 200 | connector_callback_status_t callback_status; |
spastor | 0:1c358ea10753 | 201 | |
spastor | 0:1c358ea10753 | 202 | request_id.remote_config_request = (connector_request_id_remote_config_t)connector_request_id_remote_config_configurations; |
spastor | 0:1c358ea10753 | 203 | callback_status = connector_callback(connector_ptr->callback, connector_class_id_remote_config, |
spastor | 0:1c358ea10753 | 204 | request_id, &connector_rci_config_data); |
spastor | 0:1c358ea10753 | 205 | switch (callback_status) |
spastor | 0:1c358ea10753 | 206 | { |
spastor | 0:1c358ea10753 | 207 | case connector_callback_unrecognized: |
spastor | 0:1c358ea10753 | 208 | result = connector_idle; |
spastor | 0:1c358ea10753 | 209 | goto done; |
spastor | 0:1c358ea10753 | 210 | |
spastor | 0:1c358ea10753 | 211 | case connector_callback_continue: |
spastor | 0:1c358ea10753 | 212 | ASSERT(connector_rci_config_data.group_table != NULL); |
spastor | 0:1c358ea10753 | 213 | if (connector_rci_config_data.global_error_count < connector_rci_error_COUNT) connector_rci_config_data.global_error_count = connector_rci_error_COUNT; |
spastor | 0:1c358ea10753 | 214 | break; |
spastor | 0:1c358ea10753 | 215 | |
spastor | 0:1c358ea10753 | 216 | default: |
spastor | 0:1c358ea10753 | 217 | result = connector_abort; |
spastor | 0:1c358ea10753 | 218 | goto done; |
spastor | 0:1c358ea10753 | 219 | |
spastor | 0:1c358ea10753 | 220 | } |
spastor | 0:1c358ea10753 | 221 | |
spastor | 0:1c358ea10753 | 222 | } |
spastor | 0:1c358ea10753 | 223 | #endif |
spastor | 0:1c358ea10753 | 224 | |
spastor | 0:1c358ea10753 | 225 | result = msg_init_facility(connector_ptr, facility_index, service_id, rci_service_callback); |
spastor | 0:1c358ea10753 | 226 | |
spastor | 0:1c358ea10753 | 227 | #if (defined connector_request_id_remote_config_configurations) |
spastor | 0:1c358ea10753 | 228 | done: |
spastor | 0:1c358ea10753 | 229 | #endif |
spastor | 0:1c358ea10753 | 230 | return result; |
spastor | 0:1c358ea10753 | 231 | } |
spastor | 0:1c358ea10753 | 232 |