Core Base Classes for the Light Endpoints

Dependencies:   BufferedSerial

Dependents:   mbed_mqtt_endpoint_ublox_ethernet mbed_mqtt_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet ... more

Committer:
ansond
Date:
Mon Mar 03 03:32:42 2014 +0000
Revision:
60:76728655fa12
Parent:
56:604a75f111fd
Child:
106:e2be56eadda8
updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 36:73e343ddca7f 1 /* Copyright C2013 Doug Anson, MIT License
ansond 36:73e343ddca7f 2 *
ansond 36:73e343ddca7f 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 36:73e343ddca7f 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 36:73e343ddca7f 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 36:73e343ddca7f 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 36:73e343ddca7f 7 * furnished to do so, subject to the following conditions:
ansond 36:73e343ddca7f 8 *
ansond 36:73e343ddca7f 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 36:73e343ddca7f 10 * substantial portions of the Software.
ansond 36:73e343ddca7f 11 *
ansond 36:73e343ddca7f 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 36:73e343ddca7f 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 36:73e343ddca7f 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 36:73e343ddca7f 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 36:73e343ddca7f 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 36:73e343ddca7f 17 */
ansond 36:73e343ddca7f 18
ansond 36:73e343ddca7f 19 #include "MBEDio.h"
ansond 36:73e343ddca7f 20
ansond 36:73e343ddca7f 21 // default constructor
ansond 36:73e343ddca7f 22 MBEDio::MBEDio(ErrorHandler *error_handler,Resource *resource) {
ansond 36:73e343ddca7f 23 this->m_error_handler = error_handler;
ansond 36:73e343ddca7f 24 this->m_resource = resource;
ansond 40:eae89a487d86 25 if (resource != NULL) resource->setIO(this);
ansond 36:73e343ddca7f 26 }
ansond 36:73e343ddca7f 27
ansond 36:73e343ddca7f 28 // destructor
ansond 36:73e343ddca7f 29 MBEDio::~MBEDio() {
ansond 36:73e343ddca7f 30 }
ansond 36:73e343ddca7f 31
ansond 36:73e343ddca7f 32 // get the float value
ansond 36:73e343ddca7f 33 float MBEDio::floatValue() {
ansond 36:73e343ddca7f 34 this->update();
ansond 36:73e343ddca7f 35 float floatValue = 0.0;
ansond 56:604a75f111fd 36 if (this->resource() != NULL && this->resource()->getValuePointer() != NULL) sscanf(this->resource()->getValuePointer(),"%f",&floatValue);
ansond 36:73e343ddca7f 37 return floatValue;
ansond 36:73e343ddca7f 38 }
ansond 36:73e343ddca7f 39
ansond 36:73e343ddca7f 40 // get the int value
ansond 36:73e343ddca7f 41 int MBEDio::intValue() {
ansond 36:73e343ddca7f 42 this->update();
ansond 36:73e343ddca7f 43 int intValue = 0;
ansond 56:604a75f111fd 44 if (this->resource() != NULL && this->resource()->getValuePointer() != NULL) sscanf(this->resource()->getValuePointer(),"%d",&intValue);
ansond 36:73e343ddca7f 45 return intValue;
ansond 36:73e343ddca7f 46 }
ansond 36:73e343ddca7f 47
ansond 36:73e343ddca7f 48 // get the string value
ansond 36:73e343ddca7f 49 char *MBEDio::stringValue() {
ansond 60:76728655fa12 50 if (this->resource() != NULL) {
ansond 60:76728655fa12 51 this->update();
ansond 60:76728655fa12 52 return this->resource()->getValuePointer();
ansond 60:76728655fa12 53 }
ansond 60:76728655fa12 54 else {
ansond 60:76728655fa12 55 this->logger()->log("stringValue: returning NULL - no resource bound to me");
ansond 60:76728655fa12 56 return NULL;
ansond 60:76728655fa12 57 }
ansond 36:73e343ddca7f 58 }
ansond 36:73e343ddca7f 59
ansond 36:73e343ddca7f 60 // get the Error Logger
ansond 56:604a75f111fd 61 ErrorHandler *MBEDio::logger() { return this->m_error_handler; }
ansond 56:604a75f111fd 62
ansond 56:604a75f111fd 63 // get the Resource
ansond 56:604a75f111fd 64 Resource *MBEDio::resource() { return this->m_resource; }