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 traverse_rci_command(rci_t * const rci)
spastor 0:1c358ea10753 14 {
spastor 0:1c358ea10753 15 trigger_rci_callback(rci, connector_request_id_remote_config_action_start);
spastor 0:1c358ea10753 16
spastor 0:1c358ea10753 17 set_rci_output_state(rci, rci_output_state_command_id);
spastor 0:1c358ea10753 18 state_call(rci, rci_parser_state_output);
spastor 0:1c358ea10753 19
spastor 0:1c358ea10753 20 }
spastor 0:1c358ea10753 21 static void traverse_group_id(rci_t * const rci)
spastor 0:1c358ea10753 22 {
spastor 0:1c358ea10753 23 trigger_rci_callback(rci, connector_request_id_remote_config_group_start);
spastor 0:1c358ea10753 24
spastor 0:1c358ea10753 25 set_rci_output_state(rci, rci_output_state_group_id);
spastor 0:1c358ea10753 26 state_call(rci, rci_parser_state_output);
spastor 0:1c358ea10753 27 }
spastor 0:1c358ea10753 28
spastor 0:1c358ea10753 29 static void traverse_element_id(rci_t * const rci)
spastor 0:1c358ea10753 30 {
spastor 0:1c358ea10753 31
spastor 0:1c358ea10753 32 connector_group_element_t const * const element = get_current_element(rci);
spastor 0:1c358ea10753 33
spastor 0:1c358ea10753 34 if ((rci->shared.callback_data.action == connector_remote_action_query) &&
spastor 0:1c358ea10753 35 (element->access == connector_element_access_write_only))
spastor 0:1c358ea10753 36 {
spastor 0:1c358ea10753 37 goto done;
spastor 0:1c358ea10753 38 }
spastor 0:1c358ea10753 39
spastor 0:1c358ea10753 40 trigger_rci_callback(rci, connector_request_id_remote_config_group_process);
spastor 0:1c358ea10753 41 set_rci_output_state(rci, rci_output_state_field_id);
spastor 0:1c358ea10753 42 state_call(rci, rci_parser_state_output);
spastor 0:1c358ea10753 43
spastor 0:1c358ea10753 44 done:
spastor 0:1c358ea10753 45 return;
spastor 0:1c358ea10753 46 }
spastor 0:1c358ea10753 47
spastor 0:1c358ea10753 48 static void traverse_element_end(rci_t * const rci)
spastor 0:1c358ea10753 49 {
spastor 0:1c358ea10753 50 trigger_rci_callback(rci, connector_request_id_remote_config_group_end);
spastor 0:1c358ea10753 51
spastor 0:1c358ea10753 52 set_rci_output_state(rci, rci_output_state_field_terminator);
spastor 0:1c358ea10753 53 state_call(rci, rci_parser_state_output);
spastor 0:1c358ea10753 54 }
spastor 0:1c358ea10753 55
spastor 0:1c358ea10753 56 static void traverse_group_end(rci_t * const rci)
spastor 0:1c358ea10753 57 {
spastor 0:1c358ea10753 58 trigger_rci_callback(rci, connector_request_id_remote_config_action_end);
spastor 0:1c358ea10753 59 set_rci_output_state(rci, rci_output_state_group_terminator);
spastor 0:1c358ea10753 60 state_call(rci, rci_parser_state_output);
spastor 0:1c358ea10753 61
spastor 0:1c358ea10753 62 }
spastor 0:1c358ea10753 63
spastor 0:1c358ea10753 64 static connector_bool_t traverse_all_elements(rci_t * const rci)
spastor 0:1c358ea10753 65 {
spastor 0:1c358ea10753 66 connector_bool_t done = connector_false;
spastor 0:1c358ea10753 67
spastor 0:1c358ea10753 68 if (!have_element_id(rci))
spastor 0:1c358ea10753 69 {
spastor 0:1c358ea10753 70 /* all fields */
spastor 0:1c358ea10753 71 set_element_id(rci, 0);
spastor 0:1c358ea10753 72 traverse_element_id(rci);
spastor 0:1c358ea10753 73 }
spastor 0:1c358ea10753 74 else
spastor 0:1c358ea10753 75 {
spastor 0:1c358ea10753 76 connector_group_t const * const group = get_current_group(rci);
spastor 0:1c358ea10753 77 unsigned int const id = get_element_id(rci) + 1;
spastor 0:1c358ea10753 78
spastor 0:1c358ea10753 79 if (id < group->elements.count)
spastor 0:1c358ea10753 80 {
spastor 0:1c358ea10753 81 set_element_id(rci, id);
spastor 0:1c358ea10753 82 traverse_element_id(rci);
spastor 0:1c358ea10753 83 }
spastor 0:1c358ea10753 84 else
spastor 0:1c358ea10753 85 {
spastor 0:1c358ea10753 86 traverse_element_end(rci);
spastor 0:1c358ea10753 87 done = connector_true;
spastor 0:1c358ea10753 88 }
spastor 0:1c358ea10753 89 }
spastor 0:1c358ea10753 90 return done;
spastor 0:1c358ea10753 91 }
spastor 0:1c358ea10753 92
spastor 0:1c358ea10753 93 static connector_bool_t traverse_all_group_instances(rci_t * const rci)
spastor 0:1c358ea10753 94 {
spastor 0:1c358ea10753 95 connector_bool_t done = connector_false;
spastor 0:1c358ea10753 96
spastor 0:1c358ea10753 97 switch (rci->traverse.process_state)
spastor 0:1c358ea10753 98 {
spastor 0:1c358ea10753 99 case rci_traverse_process_group:
spastor 0:1c358ea10753 100 case rci_traverse_process_element:
spastor 0:1c358ea10753 101 if (traverse_all_elements(rci))
spastor 0:1c358ea10753 102 rci->traverse.process_state = rci_traverse_process_next_instance;
spastor 0:1c358ea10753 103 break;
spastor 0:1c358ea10753 104 case rci_traverse_process_next_instance:
spastor 0:1c358ea10753 105 {
spastor 0:1c358ea10753 106 connector_group_t const * const group = get_current_group(rci);
spastor 0:1c358ea10753 107 if (group->instances > 1 && group->instances > get_group_index(rci))
spastor 0:1c358ea10753 108 {
spastor 0:1c358ea10753 109 /* next instances */
spastor 0:1c358ea10753 110 increment_group_index(rci);
spastor 0:1c358ea10753 111 traverse_group_id(rci);
spastor 0:1c358ea10753 112 rci->traverse.process_state = rci_traverse_process_element;
spastor 0:1c358ea10753 113 }
spastor 0:1c358ea10753 114 else
spastor 0:1c358ea10753 115 {
spastor 0:1c358ea10753 116 /* no more instances */
spastor 0:1c358ea10753 117 done = connector_true;
spastor 0:1c358ea10753 118 }
spastor 0:1c358ea10753 119 }
spastor 0:1c358ea10753 120 break;
spastor 0:1c358ea10753 121 }
spastor 0:1c358ea10753 122
spastor 0:1c358ea10753 123 return done;
spastor 0:1c358ea10753 124 }
spastor 0:1c358ea10753 125
spastor 0:1c358ea10753 126 static connector_bool_t traverse_all_groups(rci_t * const rci)
spastor 0:1c358ea10753 127 {
spastor 0:1c358ea10753 128 connector_bool_t done = connector_false;
spastor 0:1c358ea10753 129
spastor 0:1c358ea10753 130 switch (rci->traverse.process_state)
spastor 0:1c358ea10753 131 {
spastor 0:1c358ea10753 132 case rci_traverse_process_group:
spastor 0:1c358ea10753 133 {
spastor 0:1c358ea10753 134 connector_remote_group_table_t const * const table = (connector_rci_config_data.group_table + rci->shared.callback_data.group.type);
spastor 0:1c358ea10753 135
spastor 0:1c358ea10753 136 if (table->count == 0)
spastor 0:1c358ea10753 137 {
spastor 0:1c358ea10753 138 traverse_group_end(rci);
spastor 0:1c358ea10753 139 }
spastor 0:1c358ea10753 140 else if (!have_group_id(rci))
spastor 0:1c358ea10753 141 {
spastor 0:1c358ea10753 142 set_group_id(rci, 0);
spastor 0:1c358ea10753 143 set_group_index(rci, 1);
spastor 0:1c358ea10753 144 traverse_group_id(rci);
spastor 0:1c358ea10753 145 rci->traverse.process_state = rci_traverse_process_element;
spastor 0:1c358ea10753 146 }
spastor 0:1c358ea10753 147 else
spastor 0:1c358ea10753 148 {
spastor 0:1c358ea10753 149
spastor 0:1c358ea10753 150 size_t const id = get_group_id(rci) + 1;
spastor 0:1c358ea10753 151
spastor 0:1c358ea10753 152 if (id == table->count)
spastor 0:1c358ea10753 153 {
spastor 0:1c358ea10753 154 /* done all groups */
spastor 0:1c358ea10753 155 traverse_group_end(rci);
spastor 0:1c358ea10753 156 done = connector_true;
spastor 0:1c358ea10753 157 }
spastor 0:1c358ea10753 158 else
spastor 0:1c358ea10753 159 {
spastor 0:1c358ea10753 160 connector_group_t const * const group = get_current_group(rci);
spastor 0:1c358ea10753 161 if (group->instances > 1 && group->instances > get_group_index(rci))
spastor 0:1c358ea10753 162 {
spastor 0:1c358ea10753 163 /* next instances */
spastor 0:1c358ea10753 164 increment_group_index(rci);
spastor 0:1c358ea10753 165 }
spastor 0:1c358ea10753 166 else
spastor 0:1c358ea10753 167 {
spastor 0:1c358ea10753 168 /* next group */
spastor 0:1c358ea10753 169 increment_group_id(rci);
spastor 0:1c358ea10753 170 set_group_index(rci, 1);
spastor 0:1c358ea10753 171 }
spastor 0:1c358ea10753 172 traverse_group_id(rci);
spastor 0:1c358ea10753 173 rci->traverse.process_state = rci_traverse_process_element;
spastor 0:1c358ea10753 174 }
spastor 0:1c358ea10753 175 }
spastor 0:1c358ea10753 176 break;
spastor 0:1c358ea10753 177 }
spastor 0:1c358ea10753 178 case rci_traverse_process_element:
spastor 0:1c358ea10753 179 if (traverse_all_elements(rci))
spastor 0:1c358ea10753 180 rci->traverse.process_state = rci_traverse_process_group;
spastor 0:1c358ea10753 181 break;
spastor 0:1c358ea10753 182
spastor 0:1c358ea10753 183 case rci_traverse_process_next_instance:
spastor 0:1c358ea10753 184 break;
spastor 0:1c358ea10753 185 }
spastor 0:1c358ea10753 186
spastor 0:1c358ea10753 187 return done;
spastor 0:1c358ea10753 188 }
spastor 0:1c358ea10753 189
spastor 0:1c358ea10753 190 static void rci_traverse_data(rci_t * const rci)
spastor 0:1c358ea10753 191 {
spastor 0:1c358ea10753 192 connector_bool_t done_state = connector_true;
spastor 0:1c358ea10753 193
spastor 0:1c358ea10753 194 rci_debug_printf("traverse: %s\n", rci_traverse_state_t_as_string(rci->traverse.state));
spastor 0:1c358ea10753 195
spastor 0:1c358ea10753 196 switch (rci->traverse.state)
spastor 0:1c358ea10753 197 {
spastor 0:1c358ea10753 198 case rci_traverse_state_none:
spastor 0:1c358ea10753 199 if (get_rci_input_state(rci) == rci_input_state_done)
spastor 0:1c358ea10753 200 state_call(rci, rci_parser_state_output);
spastor 0:1c358ea10753 201 else
spastor 0:1c358ea10753 202 state_call(rci, rci_parser_state_input);
spastor 0:1c358ea10753 203 break;
spastor 0:1c358ea10753 204
spastor 0:1c358ea10753 205 case rci_traverse_state_command_id:
spastor 0:1c358ea10753 206 traverse_rci_command(rci);
spastor 0:1c358ea10753 207 break;
spastor 0:1c358ea10753 208
spastor 0:1c358ea10753 209 case rci_traverse_state_all_groups:
spastor 0:1c358ea10753 210 done_state = traverse_all_groups(rci);
spastor 0:1c358ea10753 211 break;
spastor 0:1c358ea10753 212
spastor 0:1c358ea10753 213 case rci_traverse_state_group_id:
spastor 0:1c358ea10753 214 traverse_group_id(rci);
spastor 0:1c358ea10753 215 break;
spastor 0:1c358ea10753 216
spastor 0:1c358ea10753 217 case rci_traverse_state_all_group_instances:
spastor 0:1c358ea10753 218 done_state = traverse_all_group_instances(rci);
spastor 0:1c358ea10753 219 break;
spastor 0:1c358ea10753 220
spastor 0:1c358ea10753 221 case rci_traverse_state_element_id:
spastor 0:1c358ea10753 222 traverse_element_id(rci);
spastor 0:1c358ea10753 223 break;
spastor 0:1c358ea10753 224
spastor 0:1c358ea10753 225 case rci_traverse_state_all_elements:
spastor 0:1c358ea10753 226 done_state = traverse_all_elements(rci);
spastor 0:1c358ea10753 227 break;
spastor 0:1c358ea10753 228
spastor 0:1c358ea10753 229 case rci_traverse_state_element_end:
spastor 0:1c358ea10753 230 traverse_element_end(rci);
spastor 0:1c358ea10753 231 break;
spastor 0:1c358ea10753 232
spastor 0:1c358ea10753 233 case rci_traverse_state_group_end:
spastor 0:1c358ea10753 234 traverse_group_end(rci);
spastor 0:1c358ea10753 235 break;
spastor 0:1c358ea10753 236 }
spastor 0:1c358ea10753 237
spastor 0:1c358ea10753 238 if (done_state)
spastor 0:1c358ea10753 239 {
spastor 0:1c358ea10753 240 rci->traverse.process_state = rci_traverse_process_group;
spastor 0:1c358ea10753 241 set_rci_traverse_state(rci, rci_traverse_state_none);
spastor 0:1c358ea10753 242 }
spastor 0:1c358ea10753 243
spastor 0:1c358ea10753 244 return;
spastor 0:1c358ea10753 245 }
spastor 0:1c358ea10753 246
spastor 0:1c358ea10753 247