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
mbed_platform/os.cpp
- Committer:
- spastor
- Date:
- 2013-12-03
- Revision:
- 0:1c358ea10753
File content as of revision 0:1c358ea10753:
/* * Copyright (c) 2013 Digi International Inc., * All rights not expressly granted are reserved. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. * * Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343 * ======================================================================= */ #include "mbed.h" #include "Thread.h" #include <rtc_time.h> extern "C" { #include "connector_api.h" #include "ecc_platform.h" } #include <stdio.h> #include <stdlib.h> #include <stdarg.h> int connector_snprintf(char * const str, size_t const size, char const * const format, ...) { va_list args; int result; va_start(args, format); #if __STDC_VERSION__ >= 199901L result = vsnprintf(str, size, format, args); #else /************************************************************************* * NOTE: Decided to have 64 bytes here considering following assumption * * 1. In the worst case, only one format specifier will be used. * * 2. Maximum of 48 bytes are used to represent a single precision value * *************************************************************************/ #define SAFE_BUFFER_BYTES 64 if (size >= SAFE_BUFFER_BYTES) { result = vsprintf(str, format, args); } else { char local_buffer[SAFE_BUFFER_BYTES]; size_t const bytes_needed = vsprintf(local_buffer, format, args); result = (bytes_needed < size) ? bytes_needed : size - 1; if (result > 0) { memcpy(str, local_buffer, result); str[result] = '\0'; result = bytes_needed; } } #undef SAFE_BUFFER_BYTES #endif va_end(args); return result; } connector_callback_status_t app_os_malloc(size_t const size, void ** ptr) { connector_callback_status_t status = connector_callback_abort; *ptr = malloc(size); if (*ptr != NULL) { status = connector_callback_continue; } else { APP_DEBUG("app_os_malloc: Failed to malloc\n"); } return status; } connector_callback_status_t app_os_free(void const * const ptr) { void * const free_ptr = (void *)ptr; if (free_ptr != NULL) { free(free_ptr); } else { APP_DEBUG("app_os_free: called with NULL\n"); } return connector_callback_continue; } connector_callback_status_t app_os_get_system_time(unsigned long * const uptime) { static time_t start_system_up_time; time_t present_time = time(NULL); if (start_system_up_time == 0) start_system_up_time = present_time; present_time -= start_system_up_time; *uptime = (unsigned long) present_time; return connector_callback_continue; } connector_callback_status_t app_os_yield(connector_status_t const * const status) { wait(0.01); return connector_callback_continue; } extern "C" void mbed_reset(); static connector_callback_status_t app_os_reboot(void) { APP_DEBUG("app_os_reboot!\n"); mbed_reset(); return connector_callback_continue; } connector_callback_status_t app_os_handler(connector_request_id_os_t const request, void * const data) { connector_callback_status_t status; switch (request) { case connector_request_id_os_malloc: { connector_os_malloc_t * p = (connector_os_malloc_t *)data; status = app_os_malloc(p->size, &p->ptr); } break; case connector_request_id_os_free: { connector_os_free_t * p = (connector_os_free_t *)data; status = app_os_free(p->ptr); } break; case connector_request_id_os_system_up_time: { connector_os_system_up_time_t * p = (connector_os_system_up_time_t *)data; status = app_os_get_system_time(&p->sys_uptime); } break; case connector_request_id_os_yield: { connector_os_yield_t * p = (connector_os_yield_t *)data; status = app_os_yield(&p->status); } break; case connector_request_id_os_reboot: status = app_os_reboot(); break; default: APP_DEBUG("app_os_handler: unrecognized request [%d]\n", request); status = connector_callback_unrecognized; break; } return status; }