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:
Fri Sep 26 05:16:07 2014 +0000
Revision:
192:54b758a8eaaa
Parent:
134:58e7537a8c5f
updates to new logger name

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 134:58e7537a8c5f 1 /* Copyright C2013 Doug Anson, MIT License
ansond 134:58e7537a8c5f 2 *
ansond 134:58e7537a8c5f 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 134:58e7537a8c5f 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 134:58e7537a8c5f 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 134:58e7537a8c5f 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 134:58e7537a8c5f 7 * furnished to do so, subject to the following conditions:
ansond 134:58e7537a8c5f 8 *
ansond 134:58e7537a8c5f 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 134:58e7537a8c5f 10 * substantial portions of the Software.
ansond 134:58e7537a8c5f 11 *
ansond 134:58e7537a8c5f 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 134:58e7537a8c5f 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 134:58e7537a8c5f 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 134:58e7537a8c5f 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 134:58e7537a8c5f 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 134:58e7537a8c5f 17 */
ansond 134:58e7537a8c5f 18
ansond 134:58e7537a8c5f 19 // class support
ansond 134:58e7537a8c5f 20 #include "Personality.h"
ansond 134:58e7537a8c5f 21
ansond 134:58e7537a8c5f 22 // MBED Endpoint linkage
ansond 134:58e7537a8c5f 23 #include "MBEDEndpoint.h"
ansond 134:58e7537a8c5f 24
ansond 134:58e7537a8c5f 25 // default constructor
ansond 192:54b758a8eaaa 26 Personality::Personality(Logger *logger,Transport *transports[NUM_TRANSPORTS],int instance,void *endpoint,char *type) : BaseClass(logger,endpoint) {
ansond 134:58e7537a8c5f 27 this->m_resources = ((MBEDEndpoint *)endpoint)->initResourceFactory();
ansond 134:58e7537a8c5f 28 this->m_external_id = 0;
ansond 134:58e7537a8c5f 29
ansond 134:58e7537a8c5f 30 for(int i=0;i<NUM_TRANSPORTS;++i) this->m_transports[i] = transports[i];
ansond 134:58e7537a8c5f 31 memset(this->m_name,0,PERSONALITY_NAME_LEN+1);
ansond 134:58e7537a8c5f 32 memset(this->m_type,0,PERSONALITY_NAME_LEN+1);
ansond 134:58e7537a8c5f 33 strcpy(this->m_type,type);
ansond 134:58e7537a8c5f 34 sprintf(this->m_name,PERSONALITY_NAME,instance);
ansond 134:58e7537a8c5f 35 this->getResourceFactory()->createResources(this->getName());
ansond 134:58e7537a8c5f 36 }
ansond 134:58e7537a8c5f 37
ansond 134:58e7537a8c5f 38 // default destructor
ansond 134:58e7537a8c5f 39 Personality::~Personality() {
ansond 134:58e7537a8c5f 40 if (this->m_resources != NULL) delete this->m_resources;
ansond 134:58e7537a8c5f 41 }
ansond 134:58e7537a8c5f 42
ansond 134:58e7537a8c5f 43 // get the resource factory
ansond 134:58e7537a8c5f 44 ResourceFactory *Personality::getResourceFactory() { return this->m_resources; }
ansond 134:58e7537a8c5f 45
ansond 134:58e7537a8c5f 46 // get the Personality name
ansond 134:58e7537a8c5f 47 char *Personality::getName() { return this->m_name; }
ansond 134:58e7537a8c5f 48
ansond 134:58e7537a8c5f 49 // get the Personality type
ansond 134:58e7537a8c5f 50 char *Personality::getType() { return this->m_type; }
ansond 134:58e7537a8c5f 51
ansond 134:58e7537a8c5f 52 // set the External ID
ansond 134:58e7537a8c5f 53 void Personality::setExternalID(int external_id) {
ansond 134:58e7537a8c5f 54 this->m_external_id = external_id;
ansond 134:58e7537a8c5f 55 char buffer[PREFERENCE_VALUE_LEN+1];
ansond 134:58e7537a8c5f 56 memset(buffer,0,PREFERENCE_VALUE_LEN+1);
ansond 134:58e7537a8c5f 57 sprintf(buffer,"id:%d",external_id);
ansond 134:58e7537a8c5f 58 this->getResourceFactory()->setResourceValue(EXTERNAL_LINKAGE_RESOURCE,buffer);
ansond 134:58e7537a8c5f 59 }
ansond 134:58e7537a8c5f 60
ansond 134:58e7537a8c5f 61 // get the External ID
ansond 134:58e7537a8c5f 62 int Personality::getExternalID() { return this->m_external_id; }
ansond 134:58e7537a8c5f 63
ansond 134:58e7537a8c5f 64
ansond 134:58e7537a8c5f 65