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 static connector_status_t layer_remove_facilities(connector_data_t * const connector_ptr, connector_supported_facility_cb_index_t cb_index);
spastor 0:1c358ea10753 13
spastor 0:1c358ea10753 14 #if (defined CONNECTOR_DEBUG)
spastor 0:1c358ea10753 15
spastor 0:1c358ea10753 16 static char const * close_status_to_string(connector_close_status_t const value)
spastor 0:1c358ea10753 17 {
spastor 0:1c358ea10753 18 char const * result = NULL;
spastor 0:1c358ea10753 19 switch (value)
spastor 0:1c358ea10753 20 {
spastor 0:1c358ea10753 21 enum_to_case(connector_close_status_cloud_disconnected);
spastor 0:1c358ea10753 22 enum_to_case(connector_close_status_cloud_redirected);
spastor 0:1c358ea10753 23 enum_to_case(connector_close_status_device_terminated);
spastor 0:1c358ea10753 24 enum_to_case(connector_close_status_device_stopped);
spastor 0:1c358ea10753 25 enum_to_case(connector_close_status_no_keepalive);
spastor 0:1c358ea10753 26 enum_to_case(connector_close_status_abort);
spastor 0:1c358ea10753 27 enum_to_case(connector_close_status_device_error);
spastor 0:1c358ea10753 28
spastor 0:1c358ea10753 29 default:
spastor 0:1c358ea10753 30 {
spastor 0:1c358ea10753 31 connector_debug_printf("Unknown close status %d\n", value);
spastor 0:1c358ea10753 32 }
spastor 0:1c358ea10753 33 }
spastor 0:1c358ea10753 34 return result;
spastor 0:1c358ea10753 35 }
spastor 0:1c358ea10753 36 #else
spastor 0:1c358ea10753 37
spastor 0:1c358ea10753 38 #define close_status_to_string(value) NULL
spastor 0:1c358ea10753 39 #endif
spastor 0:1c358ea10753 40
spastor 0:1c358ea10753 41 static connector_status_t tcp_close_cloud(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 42 {
spastor 0:1c358ea10753 43 connector_status_t result = connector_idle;
spastor 0:1c358ea10753 44 connector_close_status_t close_status = edp_get_close_status(connector_ptr);
spastor 0:1c358ea10753 45
spastor 0:1c358ea10753 46 if (edp_get_edp_state(connector_ptr) != edp_communication_connect_to_cloud)
spastor 0:1c358ea10753 47 {
spastor 0:1c358ea10753 48 connector_callback_status_t status;
spastor 0:1c358ea10753 49 connector_request_id_t request_id;
spastor 0:1c358ea10753 50
spastor 0:1c358ea10753 51 connector_network_close_t close_data;
spastor 0:1c358ea10753 52
spastor 0:1c358ea10753 53 close_data.handle = connector_ptr->edp_data.network_handle;
spastor 0:1c358ea10753 54 close_data.status = edp_get_close_status(connector_ptr);
spastor 0:1c358ea10753 55 close_data.reconnect = connector_true;
spastor 0:1c358ea10753 56
spastor 0:1c358ea10753 57 connector_debug_printf("tcp_close_cloud: status = %s\n", close_status_to_string(close_data.status));
spastor 0:1c358ea10753 58 request_id.network_request = connector_request_id_network_close;
spastor 0:1c358ea10753 59
spastor 0:1c358ea10753 60 status = connector_callback(connector_ptr->callback, connector_class_id_network_tcp, request_id, &close_data);
spastor 0:1c358ea10753 61 ASSERT(status != connector_callback_unrecognized);
spastor 0:1c358ea10753 62 switch (status)
spastor 0:1c358ea10753 63 {
spastor 0:1c358ea10753 64 case connector_callback_busy:
spastor 0:1c358ea10753 65 result = connector_pending;
spastor 0:1c358ea10753 66 goto done;
spastor 0:1c358ea10753 67
spastor 0:1c358ea10753 68 case connector_callback_continue:
spastor 0:1c358ea10753 69 result = connector_working;
spastor 0:1c358ea10753 70 break;
spastor 0:1c358ea10753 71
spastor 0:1c358ea10753 72 default:
spastor 0:1c358ea10753 73 result = connector_abort;
spastor 0:1c358ea10753 74 close_status = connector_close_status_abort;
spastor 0:1c358ea10753 75 break;
spastor 0:1c358ea10753 76 }
spastor 0:1c358ea10753 77
spastor 0:1c358ea10753 78
spastor 0:1c358ea10753 79 {
spastor 0:1c358ea10753 80 connector_ptr->edp_data.stop.auto_connect = close_data.reconnect;
spastor 0:1c358ea10753 81 edp_set_active_state(connector_ptr, connector_transport_idle);
spastor 0:1c358ea10753 82
spastor 0:1c358ea10753 83 tcp_send_complete_callback(connector_ptr, connector_abort);
spastor 0:1c358ea10753 84
spastor 0:1c358ea10753 85 }
spastor 0:1c358ea10753 86 edp_set_edp_state(connector_ptr, edp_communication_connect_to_cloud);
spastor 0:1c358ea10753 87
spastor 0:1c358ea10753 88 layer_remove_facilities(connector_ptr, facility_callback_cleanup);
spastor 0:1c358ea10753 89
spastor 0:1c358ea10753 90 edp_reset_initial_data(connector_ptr);
spastor 0:1c358ea10753 91 }
spastor 0:1c358ea10753 92 else
spastor 0:1c358ea10753 93 edp_set_active_state(connector_ptr, connector_transport_idle);
spastor 0:1c358ea10753 94
spastor 0:1c358ea10753 95 switch (close_status)
spastor 0:1c358ea10753 96 {
spastor 0:1c358ea10753 97 case connector_close_status_device_terminated:
spastor 0:1c358ea10753 98 case connector_close_status_abort:
spastor 0:1c358ea10753 99 {
spastor 0:1c358ea10753 100 /*
spastor 0:1c358ea10753 101 * Terminated by connector_dispatch call
spastor 0:1c358ea10753 102 * Free all memory.
spastor 0:1c358ea10753 103 */
spastor 0:1c358ea10753 104 connector_status_t const status = layer_remove_facilities(connector_ptr, facility_callback_delete);
spastor 0:1c358ea10753 105 if (status != connector_working && status != connector_idle)
spastor 0:1c358ea10753 106 {
spastor 0:1c358ea10753 107 connector_debug_printf("tcp_close_cloud: layer_remove_facilities failed %d\n", result);
spastor 0:1c358ea10753 108 }
spastor 0:1c358ea10753 109 edp_set_active_state(connector_ptr, connector_transport_terminate);
spastor 0:1c358ea10753 110 result = (close_status == connector_close_status_device_terminated) ? connector_device_terminated : connector_abort;
spastor 0:1c358ea10753 111 goto done;
spastor 0:1c358ea10753 112 }
spastor 0:1c358ea10753 113 default:
spastor 0:1c358ea10753 114 break;
spastor 0:1c358ea10753 115 }
spastor 0:1c358ea10753 116
spastor 0:1c358ea10753 117 done:
spastor 0:1c358ea10753 118 return result;
spastor 0:1c358ea10753 119 }
spastor 0:1c358ea10753 120
spastor 0:1c358ea10753 121 static connector_status_t edp_close_process(connector_data_t * const connector_ptr)
spastor 0:1c358ea10753 122 {
spastor 0:1c358ea10753 123 connector_status_t result;
spastor 0:1c358ea10753 124
spastor 0:1c358ea10753 125 result = tcp_close_cloud(connector_ptr);
spastor 0:1c358ea10753 126
spastor 0:1c358ea10753 127 return result;
spastor 0:1c358ea10753 128 }
spastor 0:1c358ea10753 129