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 14:10:48 2013 +0000
Revision:
1:908afea5a49d
Parent:
0:1c358ea10753
Use internal Thread.h instead of Threads.h

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 <stddef.h>
spastor 0:1c358ea10753 14
spastor 0:1c358ea10753 15 #include "connector_edp_util.h"
spastor 0:1c358ea10753 16
spastor 0:1c358ea10753 17 #include "connector_tcp_config.h"
spastor 0:1c358ea10753 18 #include "connector_tcp_send.h"
spastor 0:1c358ea10753 19 #include "connector_tcp_recv.h"
spastor 0:1c358ea10753 20 #include "connector_tcp_open.h"
spastor 0:1c358ea10753 21 #include "connector_tcp_close.h"
spastor 0:1c358ea10753 22
spastor 0:1c358ea10753 23 #include "connector_cc.h"
spastor 0:1c358ea10753 24
spastor 0:1c358ea10753 25 #if (defined CONNECTOR_DATA_SERVICE) || (defined CONNECTOR_FILE_SYSTEM) || (defined CONNECTOR_RCI_SERVICE)
spastor 0:1c358ea10753 26 #include "connector_msg.h"
spastor 0:1c358ea10753 27 #endif
spastor 0:1c358ea10753 28 #if (defined CONNECTOR_DATA_SERVICE)
spastor 0:1c358ea10753 29 #include "connector_data_service.h"
spastor 0:1c358ea10753 30 #endif
spastor 0:1c358ea10753 31 #if (defined CONNECTOR_FILE_SYSTEM)
spastor 0:1c358ea10753 32 #include "connector_file_system.h"
spastor 0:1c358ea10753 33 #endif
spastor 0:1c358ea10753 34
spastor 0:1c358ea10753 35 #if (defined CONNECTOR_FIRMWARE_SERVICE)
spastor 0:1c358ea10753 36 #include "connector_firmware.h"
spastor 0:1c358ea10753 37 #endif
spastor 0:1c358ea10753 38
spastor 0:1c358ea10753 39 #include "layer.h"
spastor 0:1c358ea10753 40
spastor 0:1c358ea10753 41
spastor 0:1c358ea10753 42 static connector_status_t edp_config_init(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 43 {
spastor 0:1c358ea10753 44 connector_status_t result = connector_working;
spastor 0:1c358ea10753 45
spastor 0:1c358ea10753 46 if (connector_ptr->device_id_method == connector_device_id_method_manual)
spastor 0:1c358ea10753 47 {
spastor 0:1c358ea10753 48 /* then we have to obtain connection type from the callback */
spastor 0:1c358ea10753 49 result = get_config_connection_type(connector_ptr);
spastor 0:1c358ea10753 50 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 51 }
spastor 0:1c358ea10753 52
spastor 0:1c358ea10753 53 switch (connector_ptr->connection_type)
spastor 0:1c358ea10753 54 {
spastor 0:1c358ea10753 55 case connector_connection_type_lan:
spastor 0:1c358ea10753 56 break;
spastor 0:1c358ea10753 57 case connector_connection_type_wan:
spastor 0:1c358ea10753 58 #if (!defined CONNECTOR_WAN_LINK_SPEED_IN_BITS_PER_SECOND)
spastor 0:1c358ea10753 59 result = get_config_link_speed(connector_ptr);
spastor 0:1c358ea10753 60 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 61 #endif
spastor 0:1c358ea10753 62
spastor 0:1c358ea10753 63 #if (!defined CONNECTOR_WAN_PHONE_NUMBER_DIALED)
spastor 0:1c358ea10753 64 result = get_config_phone_number(connector_ptr);
spastor 0:1c358ea10753 65 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 66 #endif
spastor 0:1c358ea10753 67
spastor 0:1c358ea10753 68 break;
spastor 0:1c358ea10753 69 }
spastor 0:1c358ea10753 70
spastor 0:1c358ea10753 71 #if !(defined CONNECTOR_VENDOR_ID)
spastor 0:1c358ea10753 72 result = get_config_vendor_id(connector_ptr);
spastor 0:1c358ea10753 73 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 74 #endif
spastor 0:1c358ea10753 75
spastor 0:1c358ea10753 76 #if !(defined CONNECTOR_DEVICE_TYPE)
spastor 0:1c358ea10753 77 result = get_config_device_type(connector_ptr);
spastor 0:1c358ea10753 78 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 79 #endif
spastor 0:1c358ea10753 80
spastor 0:1c358ea10753 81 #if !(defined CONNECTOR_TX_KEEPALIVE_IN_SECONDS)
spastor 0:1c358ea10753 82 result = get_config_keepalive(connector_ptr, connector_request_id_config_tx_keepalive);
spastor 0:1c358ea10753 83 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 84 #endif
spastor 0:1c358ea10753 85
spastor 0:1c358ea10753 86 #if !(defined CONNECTOR_RX_KEEPALIVE_IN_SECONDS)
spastor 0:1c358ea10753 87 result = get_config_keepalive(connector_ptr, connector_request_id_config_rx_keepalive);
spastor 0:1c358ea10753 88 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 89 #endif
spastor 0:1c358ea10753 90
spastor 0:1c358ea10753 91 #if !(defined CONNECTOR_WAIT_COUNT)
spastor 0:1c358ea10753 92 result = get_config_wait_count(connector_ptr);
spastor 0:1c358ea10753 93 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 94 #endif
spastor 0:1c358ea10753 95
spastor 0:1c358ea10753 96 #if !(defined CONNECTOR_NETWORK_TCP_START)
spastor 0:1c358ea10753 97 {
spastor 0:1c358ea10753 98 connector_config_connect_type_t config_connect;
spastor 0:1c358ea10753 99
spastor 0:1c358ea10753 100 result = get_config_connect_status(connector_ptr, connector_request_id_config_network_tcp, &config_connect);
spastor 0:1c358ea10753 101 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 102
spastor 0:1c358ea10753 103 connector_ptr->edp_data.connect_type = config_connect.type;
spastor 0:1c358ea10753 104 connector_ptr->edp_data.stop.auto_connect = connector_bool(config_connect.type == connector_connect_auto);
spastor 0:1c358ea10753 105 }
spastor 0:1c358ea10753 106 #else
spastor 0:1c358ea10753 107 ASSERT((CONNECTOR_NETWORK_TCP_START == connector_connect_auto) || (CONNECTOR_NETWORK_TCP_START == connector_connect_manual));
spastor 0:1c358ea10753 108 if (CONNECTOR_NETWORK_TCP_START == connector_connect_auto)
spastor 0:1c358ea10753 109 {
spastor 0:1c358ea10753 110 edp_set_active_state(connector_ptr, connector_transport_open);
spastor 0:1c358ea10753 111 }
spastor 0:1c358ea10753 112 connector_ptr->edp_data.stop.auto_connect = connector_bool(CONNECTOR_NETWORK_TCP_START == connector_connect_auto);
spastor 0:1c358ea10753 113 #endif
spastor 0:1c358ea10753 114
spastor 0:1c358ea10753 115
spastor 0:1c358ea10753 116 #if !(defined CONNECTOR_IDENTITY_VERIFICATION)
spastor 0:1c358ea10753 117 result = get_config_identity_verification(connector_ptr);
spastor 0:1c358ea10753 118 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 119 {
spastor 0:1c358ea10753 120 connector_identity_verification_t const identity_verification = connector_ptr->edp_data.config.identity_verification;
spastor 0:1c358ea10753 121 #else
spastor 0:1c358ea10753 122 {
spastor 0:1c358ea10753 123 ASSERT((CONNECTOR_IDENTITY_VERIFICATION == connector_identity_verification_simple) || (CONNECTOR_IDENTITY_VERIFICATION == connector_identity_verification_password));
spastor 0:1c358ea10753 124 connector_identity_verification_t const identity_verification = CONNECTOR_IDENTITY_VERIFICATION;
spastor 0:1c358ea10753 125 #endif
spastor 0:1c358ea10753 126
spastor 0:1c358ea10753 127 if (identity_verification == connector_identity_verification_password)
spastor 0:1c358ea10753 128 {
spastor 0:1c358ea10753 129 /* get password for password identity verification */
spastor 0:1c358ea10753 130 result = get_config_password(connector_ptr);
spastor 0:1c358ea10753 131 COND_ELSE_GOTO(result == connector_working, done);
spastor 0:1c358ea10753 132 }
spastor 0:1c358ea10753 133 }
spastor 0:1c358ea10753 134
spastor 0:1c358ea10753 135
spastor 0:1c358ea10753 136 done:
spastor 0:1c358ea10753 137 return result;
spastor 0:1c358ea10753 138 }
spastor 0:1c358ea10753 139
spastor 0:1c358ea10753 140
spastor 0:1c358ea10753 141 connector_status_t connector_edp_init(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 142 {
spastor 0:1c358ea10753 143
spastor 0:1c358ea10753 144 connector_status_t result = connector_working;
spastor 0:1c358ea10753 145
spastor 0:1c358ea10753 146 edp_reset_initial_data(connector_ptr);
spastor 0:1c358ea10753 147 connector_ptr->edp_data.facilities.list = NULL;
spastor 0:1c358ea10753 148 connector_ptr->edp_data.facilities.supported_mask = 0;
spastor 0:1c358ea10753 149
spastor 0:1c358ea10753 150 edp_set_active_state(connector_ptr, connector_transport_idle);
spastor 0:1c358ea10753 151 edp_set_initiate_state(connector_ptr, connector_transport_idle);
spastor 0:1c358ea10753 152
spastor 0:1c358ea10753 153 result = edp_config_init(connector_ptr);
spastor 0:1c358ea10753 154 if (result != connector_working)
spastor 0:1c358ea10753 155 {
spastor 0:1c358ea10753 156 goto done;
spastor 0:1c358ea10753 157 }
spastor 0:1c358ea10753 158
spastor 0:1c358ea10753 159 result = edp_layer_get_supported_facilities(connector_ptr);
spastor 0:1c358ea10753 160 if (result != connector_working)
spastor 0:1c358ea10753 161 {
spastor 0:1c358ea10753 162 goto done;
spastor 0:1c358ea10753 163 }
spastor 0:1c358ea10753 164
spastor 0:1c358ea10753 165 result = edp_layer_initialize_facilities(connector_ptr);
spastor 0:1c358ea10753 166 if (result != connector_working)
spastor 0:1c358ea10753 167 {
spastor 0:1c358ea10753 168 goto done;
spastor 0:1c358ea10753 169 }
spastor 0:1c358ea10753 170
spastor 0:1c358ea10753 171 edp_get_device_cloud(connector_ptr);
spastor 0:1c358ea10753 172
spastor 0:1c358ea10753 173 done:
spastor 0:1c358ea10753 174 return result;
spastor 0:1c358ea10753 175 }
spastor 0:1c358ea10753 176
spastor 0:1c358ea10753 177
spastor 0:1c358ea10753 178 connector_status_t connector_edp_step(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 179 {
spastor 0:1c358ea10753 180 connector_status_t result = connector_idle;
spastor 0:1c358ea10753 181 connector_transport_state_t init_active_state = edp_get_active_state(connector_ptr);
spastor 0:1c358ea10753 182
spastor 0:1c358ea10753 183 while (result == connector_idle)
spastor 0:1c358ea10753 184 {
spastor 0:1c358ea10753 185 switch (edp_get_active_state(connector_ptr))
spastor 0:1c358ea10753 186 {
spastor 0:1c358ea10753 187 case connector_transport_idle:
spastor 0:1c358ea10753 188 if (connector_ptr->edp_data.stop.auto_connect)
spastor 0:1c358ea10753 189 {
spastor 0:1c358ea10753 190 edp_set_active_state(connector_ptr, connector_transport_open);
spastor 0:1c358ea10753 191 }
spastor 0:1c358ea10753 192
spastor 0:1c358ea10753 193 goto check_state;
spastor 0:1c358ea10753 194
spastor 0:1c358ea10753 195 case connector_transport_open:
spastor 0:1c358ea10753 196 result = edp_tcp_open_process(connector_ptr);
spastor 0:1c358ea10753 197 break;
spastor 0:1c358ea10753 198
spastor 0:1c358ea10753 199 case connector_transport_send:
spastor 0:1c358ea10753 200 case connector_transport_receive:
spastor 0:1c358ea10753 201
spastor 0:1c358ea10753 202 switch (edp_get_active_state(connector_ptr))
spastor 0:1c358ea10753 203 {
spastor 0:1c358ea10753 204 case connector_transport_send:
spastor 0:1c358ea10753 205 result = edp_tcp_send_process(connector_ptr);
spastor 0:1c358ea10753 206
spastor 0:1c358ea10753 207 if (edp_get_active_state(connector_ptr) == connector_transport_send)
spastor 0:1c358ea10753 208 {
spastor 0:1c358ea10753 209 edp_set_active_state(connector_ptr, connector_transport_receive);
spastor 0:1c358ea10753 210 }
spastor 0:1c358ea10753 211 break;
spastor 0:1c358ea10753 212 case connector_transport_receive:
spastor 0:1c358ea10753 213 result = edp_tcp_receive_process(connector_ptr);
spastor 0:1c358ea10753 214
spastor 0:1c358ea10753 215 if (edp_get_active_state(connector_ptr) == connector_transport_receive)
spastor 0:1c358ea10753 216 {
spastor 0:1c358ea10753 217 edp_set_active_state(connector_ptr, connector_transport_send);
spastor 0:1c358ea10753 218 }
spastor 0:1c358ea10753 219 break;
spastor 0:1c358ea10753 220 default:
spastor 0:1c358ea10753 221 break;
spastor 0:1c358ea10753 222 }
spastor 0:1c358ea10753 223
spastor 0:1c358ea10753 224 break;
spastor 0:1c358ea10753 225 case connector_transport_close:
spastor 0:1c358ea10753 226 case connector_transport_terminate:
spastor 0:1c358ea10753 227 result = edp_close_process(connector_ptr);
spastor 0:1c358ea10753 228 break;
spastor 0:1c358ea10753 229
spastor 0:1c358ea10753 230 case connector_transport_redirect:
spastor 0:1c358ea10753 231 result = edp_redirect_process(connector_ptr);
spastor 0:1c358ea10753 232 break;
spastor 0:1c358ea10753 233
spastor 0:1c358ea10753 234 case connector_transport_wait_for_reconnect:
spastor 0:1c358ea10753 235 {
spastor 0:1c358ea10753 236 if (connector_ptr->edp_data.connect_at == 0)
spastor 0:1c358ea10753 237 {
spastor 0:1c358ea10753 238 connector_debug_printf("Waiting %d second before reconnecting TCP transport\n", CONNECTOR_TRANSPORT_RECONNECT_AFTER);
spastor 0:1c358ea10753 239 result = get_system_time(connector_ptr, &connector_ptr->edp_data.connect_at);
spastor 0:1c358ea10753 240 if (result != connector_working)
spastor 0:1c358ea10753 241 goto done;
spastor 0:1c358ea10753 242 connector_ptr->edp_data.connect_at += CONNECTOR_TRANSPORT_RECONNECT_AFTER;
spastor 0:1c358ea10753 243 } else {
spastor 0:1c358ea10753 244 unsigned long int uptime;
spastor 0:1c358ea10753 245
spastor 0:1c358ea10753 246 result = get_system_time(connector_ptr, &uptime);
spastor 0:1c358ea10753 247 if (result != connector_working)
spastor 0:1c358ea10753 248 goto done;
spastor 0:1c358ea10753 249 if (uptime >= connector_ptr->edp_data.connect_at)
spastor 0:1c358ea10753 250 edp_set_active_state(connector_ptr, connector_transport_open);
spastor 0:1c358ea10753 251 }
spastor 0:1c358ea10753 252 break;
spastor 0:1c358ea10753 253 }
spastor 0:1c358ea10753 254 }
spastor 0:1c358ea10753 255
spastor 0:1c358ea10753 256 if (result == connector_device_terminated
spastor 0:1c358ea10753 257 || result == connector_abort
spastor 0:1c358ea10753 258
spastor 0:1c358ea10753 259 )
spastor 0:1c358ea10753 260 {
spastor 0:1c358ea10753 261 connector_debug_printf("connector_edp_step: done with status = %d\n", result);
spastor 0:1c358ea10753 262 goto done;
spastor 0:1c358ea10753 263 }
spastor 0:1c358ea10753 264
spastor 0:1c358ea10753 265
spastor 0:1c358ea10753 266 /* done all cases */
spastor 0:1c358ea10753 267 if (edp_get_active_state(connector_ptr) == init_active_state) break;
spastor 0:1c358ea10753 268 }
spastor 0:1c358ea10753 269
spastor 0:1c358ea10753 270 check_state:
spastor 0:1c358ea10753 271 switch (edp_get_initiate_state(connector_ptr))
spastor 0:1c358ea10753 272 {
spastor 0:1c358ea10753 273 case connector_transport_close:
spastor 0:1c358ea10753 274 switch (edp_get_active_state(connector_ptr))
spastor 0:1c358ea10753 275 {
spastor 0:1c358ea10753 276 case connector_transport_idle:
spastor 0:1c358ea10753 277 connector_ptr->edp_data.stop.auto_connect = connector_false;
spastor 0:1c358ea10753 278 edp_set_initiate_state(connector_ptr, connector_transport_idle);
spastor 0:1c358ea10753 279
spastor 0:1c358ea10753 280 if (edp_is_stop_request(connector_ptr))
spastor 0:1c358ea10753 281 {
spastor 0:1c358ea10753 282 result = connector_stop_callback(connector_ptr, connector_transport_tcp, connector_ptr->edp_data.stop.user_context);
spastor 0:1c358ea10753 283
spastor 0:1c358ea10753 284 if (result == connector_pending)
spastor 0:1c358ea10753 285 {
spastor 0:1c358ea10753 286 /* restore the initiate state */
spastor 0:1c358ea10753 287 edp_set_initiate_state(connector_ptr, connector_transport_close);
spastor 0:1c358ea10753 288 }
spastor 0:1c358ea10753 289 else if (result == connector_working)
spastor 0:1c358ea10753 290 {
spastor 0:1c358ea10753 291 edp_clear_stop_request(connector_ptr);
spastor 0:1c358ea10753 292 }
spastor 0:1c358ea10753 293 }
spastor 0:1c358ea10753 294 /* exit edp so let connector_step does next step */
spastor 0:1c358ea10753 295 goto done;
spastor 0:1c358ea10753 296
spastor 0:1c358ea10753 297 case connector_transport_close:
spastor 0:1c358ea10753 298 connector_ptr->edp_data.stop.auto_connect = connector_false;
spastor 0:1c358ea10753 299 /* no break */
spastor 0:1c358ea10753 300 case connector_transport_terminate:
spastor 0:1c358ea10753 301 break;
spastor 0:1c358ea10753 302
spastor 0:1c358ea10753 303 default:
spastor 0:1c358ea10753 304 if (!tcp_is_send_active(connector_ptr) && result == connector_idle)
spastor 0:1c358ea10753 305 {
spastor 0:1c358ea10753 306 edp_set_stop_condition(connector_ptr, connector_stop_immediately);
spastor 0:1c358ea10753 307 }
spastor 0:1c358ea10753 308 if (edp_is_stop_immediately(connector_ptr))
spastor 0:1c358ea10753 309 {
spastor 0:1c358ea10753 310 connector_ptr->edp_data.stop.auto_connect = connector_false;
spastor 0:1c358ea10753 311 edp_set_close_status(connector_ptr, connector_close_status_device_stopped);
spastor 0:1c358ea10753 312 edp_set_active_state(connector_ptr, connector_transport_close);
spastor 0:1c358ea10753 313 }
spastor 0:1c358ea10753 314 break;
spastor 0:1c358ea10753 315 }
spastor 0:1c358ea10753 316 break;
spastor 0:1c358ea10753 317 case connector_transport_open:
spastor 0:1c358ea10753 318 switch (edp_get_active_state(connector_ptr))
spastor 0:1c358ea10753 319 {
spastor 0:1c358ea10753 320 case connector_transport_terminate:
spastor 0:1c358ea10753 321 break;
spastor 0:1c358ea10753 322 case connector_transport_close:
spastor 0:1c358ea10753 323 case connector_transport_idle:
spastor 0:1c358ea10753 324 if (result != connector_open_error)
spastor 0:1c358ea10753 325 edp_set_active_state(connector_ptr, connector_transport_open);
spastor 0:1c358ea10753 326 else
spastor 0:1c358ea10753 327 edp_set_initiate_state(connector_ptr, connector_transport_idle);
spastor 0:1c358ea10753 328 break;
spastor 0:1c358ea10753 329 default:
spastor 0:1c358ea10753 330 edp_set_initiate_state(connector_ptr, connector_transport_idle);
spastor 0:1c358ea10753 331 break;
spastor 0:1c358ea10753 332 }
spastor 0:1c358ea10753 333 break;
spastor 0:1c358ea10753 334
spastor 0:1c358ea10753 335 case connector_transport_terminate:
spastor 0:1c358ea10753 336 edp_set_close_status(connector_ptr, connector_close_status_device_terminated);
spastor 0:1c358ea10753 337 edp_set_active_state(connector_ptr, connector_transport_close);
spastor 0:1c358ea10753 338 break;
spastor 0:1c358ea10753 339 default:
spastor 0:1c358ea10753 340 break;
spastor 0:1c358ea10753 341 }
spastor 0:1c358ea10753 342
spastor 0:1c358ea10753 343 done:
spastor 0:1c358ea10753 344 return result;
spastor 0:1c358ea10753 345 }
spastor 0:1c358ea10753 346
spastor 0:1c358ea10753 347 connector_status_t edp_initiate_action(connector_data_t * const connector_ptr, connector_initiate_request_t const request, void const * const request_data)
spastor 0:1c358ea10753 348 {
spastor 0:1c358ea10753 349 connector_status_t result = connector_init_error;
spastor 0:1c358ea10753 350
spastor 0:1c358ea10753 351 switch (request)
spastor 0:1c358ea10753 352 {
spastor 0:1c358ea10753 353 case connector_initiate_terminate:
spastor 0:1c358ea10753 354 UNUSED_PARAMETER(request_data);
spastor 0:1c358ea10753 355 edp_set_initiate_state(connector_ptr, connector_transport_terminate);
spastor 0:1c358ea10753 356 result = connector_success;
spastor 0:1c358ea10753 357 break;
spastor 0:1c358ea10753 358
spastor 0:1c358ea10753 359 #if (defined CONNECTOR_DATA_SERVICE)
spastor 0:1c358ea10753 360 case connector_initiate_send_data:
spastor 0:1c358ea10753 361 if (edp_get_edp_state(connector_ptr) == edp_communication_connect_to_cloud) goto done;
spastor 0:1c358ea10753 362
spastor 0:1c358ea10753 363 switch (edp_get_active_state(connector_ptr))
spastor 0:1c358ea10753 364 {
spastor 0:1c358ea10753 365 case connector_transport_idle:
spastor 0:1c358ea10753 366 result = connector_unavailable;
spastor 0:1c358ea10753 367 goto done;
spastor 0:1c358ea10753 368
spastor 0:1c358ea10753 369 case connector_transport_close:
spastor 0:1c358ea10753 370 if (edp_get_initiate_state(connector_ptr) == connector_transport_open)
spastor 0:1c358ea10753 371 {
spastor 0:1c358ea10753 372 break;
spastor 0:1c358ea10753 373 }
spastor 0:1c358ea10753 374 /* no break to return error */
spastor 0:1c358ea10753 375 case connector_transport_redirect:
spastor 0:1c358ea10753 376 result = connector_unavailable;
spastor 0:1c358ea10753 377 goto done;
spastor 0:1c358ea10753 378
spastor 0:1c358ea10753 379 case connector_transport_wait_for_reconnect:
spastor 0:1c358ea10753 380 case connector_transport_terminate:
spastor 0:1c358ea10753 381 goto done;
spastor 0:1c358ea10753 382
spastor 0:1c358ea10753 383 case connector_transport_open:
spastor 0:1c358ea10753 384 case connector_transport_send:
spastor 0:1c358ea10753 385 case connector_transport_receive:
spastor 0:1c358ea10753 386 switch (edp_get_initiate_state(connector_ptr))
spastor 0:1c358ea10753 387 {
spastor 0:1c358ea10753 388 case connector_transport_close:
spastor 0:1c358ea10753 389 result = connector_unavailable;
spastor 0:1c358ea10753 390 goto done;
spastor 0:1c358ea10753 391 default:
spastor 0:1c358ea10753 392 break;
spastor 0:1c358ea10753 393 }
spastor 0:1c358ea10753 394 break;
spastor 0:1c358ea10753 395 }
spastor 0:1c358ea10753 396 result = data_service_initiate(connector_ptr, request_data);
spastor 0:1c358ea10753 397 break;
spastor 0:1c358ea10753 398 #endif
spastor 0:1c358ea10753 399 #if (defined CONNECTOR_DATA_POINTS)
spastor 0:1c358ea10753 400 case connector_initiate_data_point_single:
spastor 0:1c358ea10753 401 case connector_initiate_data_point_binary:
spastor 0:1c358ea10753 402 if (edp_get_edp_state(connector_ptr) == edp_communication_connect_to_cloud) goto done;
spastor 0:1c358ea10753 403
spastor 0:1c358ea10753 404 switch (edp_get_active_state(connector_ptr))
spastor 0:1c358ea10753 405 {
spastor 0:1c358ea10753 406 case connector_transport_idle:
spastor 0:1c358ea10753 407 result = connector_unavailable;
spastor 0:1c358ea10753 408 goto done;
spastor 0:1c358ea10753 409
spastor 0:1c358ea10753 410 case connector_transport_close:
spastor 0:1c358ea10753 411 if (edp_get_initiate_state(connector_ptr) == connector_transport_open)
spastor 0:1c358ea10753 412 {
spastor 0:1c358ea10753 413 break;
spastor 0:1c358ea10753 414 }
spastor 0:1c358ea10753 415 /* no break to return error */
spastor 0:1c358ea10753 416 case connector_transport_redirect:
spastor 0:1c358ea10753 417 result = connector_unavailable;
spastor 0:1c358ea10753 418 goto done;
spastor 0:1c358ea10753 419
spastor 0:1c358ea10753 420 case connector_transport_wait_for_reconnect:
spastor 0:1c358ea10753 421 case connector_transport_terminate:
spastor 0:1c358ea10753 422 goto done;
spastor 0:1c358ea10753 423
spastor 0:1c358ea10753 424 case connector_transport_open:
spastor 0:1c358ea10753 425 case connector_transport_send:
spastor 0:1c358ea10753 426 case connector_transport_receive:
spastor 0:1c358ea10753 427 switch (edp_get_initiate_state(connector_ptr))
spastor 0:1c358ea10753 428 {
spastor 0:1c358ea10753 429 case connector_transport_close:
spastor 0:1c358ea10753 430 result = connector_unavailable;
spastor 0:1c358ea10753 431 goto done;
spastor 0:1c358ea10753 432 default:
spastor 0:1c358ea10753 433 break;
spastor 0:1c358ea10753 434 }
spastor 0:1c358ea10753 435 break;
spastor 0:1c358ea10753 436 }
spastor 0:1c358ea10753 437 switch (request)
spastor 0:1c358ea10753 438 {
spastor 0:1c358ea10753 439 case connector_initiate_data_point_single:
spastor 0:1c358ea10753 440 result = dp_initiate_data_point_single(request_data);
spastor 0:1c358ea10753 441 break;
spastor 0:1c358ea10753 442 case connector_initiate_data_point_binary:
spastor 0:1c358ea10753 443 result = dp_initiate_data_point_binary(request_data);
spastor 0:1c358ea10753 444 break;
spastor 0:1c358ea10753 445 /* default: */
spastor 0:1c358ea10753 446 case connector_initiate_transport_start:
spastor 0:1c358ea10753 447 case connector_initiate_transport_stop:
spastor 0:1c358ea10753 448 #if (defined CONNECTOR_DATA_SERVICE)
spastor 0:1c358ea10753 449 case connector_initiate_send_data:
spastor 0:1c358ea10753 450 #endif
spastor 0:1c358ea10753 451 #if (defined CONNECTOR_SHORT_MESSAGE)
spastor 0:1c358ea10753 452 case connector_initiate_ping_request:
spastor 0:1c358ea10753 453 case connector_initiate_session_cancel:
spastor 0:1c358ea10753 454 #if (CONNECTOR_VERSION >= 0x02010000)
spastor 0:1c358ea10753 455 case connector_initiate_session_cancel_all:
spastor 0:1c358ea10753 456 #endif
spastor 0:1c358ea10753 457 #endif
spastor 0:1c358ea10753 458 case connector_initiate_terminate:
spastor 0:1c358ea10753 459 break;
spastor 0:1c358ea10753 460 }
spastor 0:1c358ea10753 461 break;
spastor 0:1c358ea10753 462 #endif
spastor 0:1c358ea10753 463
spastor 0:1c358ea10753 464 case connector_initiate_transport_stop:
spastor 0:1c358ea10753 465 switch (edp_get_active_state(connector_ptr))
spastor 0:1c358ea10753 466 {
spastor 0:1c358ea10753 467 case connector_transport_open:
spastor 0:1c358ea10753 468 case connector_transport_send:
spastor 0:1c358ea10753 469 case connector_transport_receive:
spastor 0:1c358ea10753 470 case connector_transport_redirect:
spastor 0:1c358ea10753 471 break;
spastor 0:1c358ea10753 472
spastor 0:1c358ea10753 473 case connector_transport_idle:
spastor 0:1c358ea10753 474 case connector_transport_close:
spastor 0:1c358ea10753 475 /* Return busy if start initiate action was called and cannot stop now */
spastor 0:1c358ea10753 476 if (edp_get_initiate_state(connector_ptr) == connector_transport_open)
spastor 0:1c358ea10753 477 {
spastor 0:1c358ea10753 478 result = connector_service_busy;
spastor 0:1c358ea10753 479 goto done;
spastor 0:1c358ea10753 480 }
spastor 0:1c358ea10753 481 break;
spastor 0:1c358ea10753 482
spastor 0:1c358ea10753 483 default:
spastor 0:1c358ea10753 484 goto done;
spastor 0:1c358ea10753 485 }
spastor 0:1c358ea10753 486
spastor 0:1c358ea10753 487 if (edp_get_initiate_state(connector_ptr) == connector_transport_close &&
spastor 0:1c358ea10753 488 edp_is_stop_request(connector_ptr))
spastor 0:1c358ea10753 489 {
spastor 0:1c358ea10753 490 /* already requesting stop before */
spastor 0:1c358ea10753 491 result = connector_service_busy;
spastor 0:1c358ea10753 492 }
spastor 0:1c358ea10753 493 else
spastor 0:1c358ea10753 494 {
spastor 0:1c358ea10753 495 connector_initiate_stop_request_t const * const stop_request = request_data;
spastor 0:1c358ea10753 496
spastor 0:1c358ea10753 497 edp_set_stop_condition(connector_ptr, stop_request->condition);
spastor 0:1c358ea10753 498
spastor 0:1c358ea10753 499 if (stop_request->transport == connector_transport_tcp)
spastor 0:1c358ea10753 500 {
spastor 0:1c358ea10753 501 edp_set_stop_request(connector_ptr, stop_request->user_context);
spastor 0:1c358ea10753 502 }
spastor 0:1c358ea10753 503
spastor 0:1c358ea10753 504 edp_set_initiate_state(connector_ptr, connector_transport_close);
spastor 0:1c358ea10753 505 result = connector_success;
spastor 0:1c358ea10753 506 }
spastor 0:1c358ea10753 507 break;
spastor 0:1c358ea10753 508
spastor 0:1c358ea10753 509 case connector_initiate_transport_start:
spastor 0:1c358ea10753 510 if (request_data == NULL)
spastor 0:1c358ea10753 511 {
spastor 0:1c358ea10753 512 result = connector_invalid_data;
spastor 0:1c358ea10753 513 goto done;
spastor 0:1c358ea10753 514 }
spastor 0:1c358ea10753 515 switch (edp_get_active_state(connector_ptr))
spastor 0:1c358ea10753 516 {
spastor 0:1c358ea10753 517 case connector_transport_open:
spastor 0:1c358ea10753 518 case connector_transport_send:
spastor 0:1c358ea10753 519 case connector_transport_receive:
spastor 0:1c358ea10753 520 case connector_transport_redirect:
spastor 0:1c358ea10753 521 /* Return busy if stop initiate action was called and cannot start now */
spastor 0:1c358ea10753 522 result = (edp_get_initiate_state(connector_ptr) == connector_transport_close) ? connector_service_busy : connector_success;
spastor 0:1c358ea10753 523 break;
spastor 0:1c358ea10753 524
spastor 0:1c358ea10753 525 case connector_transport_idle:
spastor 0:1c358ea10753 526 case connector_transport_close:
spastor 0:1c358ea10753 527 if (edp_get_initiate_state(connector_ptr) == connector_transport_close)
spastor 0:1c358ea10753 528 {
spastor 0:1c358ea10753 529 result = connector_service_busy;
spastor 0:1c358ea10753 530 }
spastor 0:1c358ea10753 531 else
spastor 0:1c358ea10753 532 {
spastor 0:1c358ea10753 533 edp_set_initiate_state(connector_ptr, connector_transport_open);
spastor 0:1c358ea10753 534 edp_get_device_cloud(connector_ptr);
spastor 0:1c358ea10753 535 result = connector_success;
spastor 0:1c358ea10753 536 }
spastor 0:1c358ea10753 537 break;
spastor 0:1c358ea10753 538
spastor 0:1c358ea10753 539 case connector_transport_wait_for_reconnect:
spastor 0:1c358ea10753 540 case connector_transport_terminate:
spastor 0:1c358ea10753 541 goto done;
spastor 0:1c358ea10753 542 }
spastor 0:1c358ea10753 543
spastor 0:1c358ea10753 544 break;
spastor 0:1c358ea10753 545
spastor 0:1c358ea10753 546 default:
spastor 0:1c358ea10753 547 ASSERT(connector_false);
spastor 0:1c358ea10753 548 result = connector_abort;
spastor 0:1c358ea10753 549 break;
spastor 0:1c358ea10753 550 }
spastor 0:1c358ea10753 551
spastor 0:1c358ea10753 552 done:
spastor 0:1c358ea10753 553
spastor 0:1c358ea10753 554 return result;
spastor 0:1c358ea10753 555 }
spastor 0:1c358ea10753 556