nsp specific components for the NSP version of the impact endpoint
Dependents: mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet mbed_nsp_endpoint_nxp
Diff: MBEDEndpoint.cpp
- Revision:
- 4:7f7fe167d9c0
- Parent:
- 0:e1c4378df3fe
- Child:
- 5:94d000e6fa70
diff -r 53a7333dd07a -r 7f7fe167d9c0 MBEDEndpoint.cpp --- a/MBEDEndpoint.cpp Thu Mar 27 03:53:23 2014 +0000 +++ b/MBEDEndpoint.cpp Fri Mar 28 17:08:22 2014 +0000 @@ -19,13 +19,13 @@ #include "NSPTransport.h" #include "MBEDEndpoint.h" - // MBED Light support + // Light Personality Support: MBED Light support #include "MBEDLight.h" - // NSP Resource Factory - #include "NSPResourceFactory.h" + // Light Personality Support: NSP Resource Factory + #include "NSPLightResourceFactory.h" - // NSP Actions we can act on + // Light Personality Support: NSP Actions we can act on #include "NSPLightDimmerAction.h" #include "NSPLightSwitchAction.h" @@ -56,7 +56,7 @@ if (success) success = this->initializeEthernet(ethernet); if (success) this->logger()->turnLEDYellow(); if (success) success = this->initializeTransports(); - if (success) success = this->initializeLights(); + if (success) success = this->initializePersonalities(); if (success) this->logger()->turnLEDOrange(); this->logger()->lcdStatusOnly(true); if (!success) closedown(2); @@ -66,7 +66,7 @@ MBEDEndpoint::~MBEDEndpoint() { bool success = true; if (success) this->logger()->turnLEDYellow(); - if (success) success = this->closeLights(); + if (success) success = this->closePersonalities(); if (success) success = this->closeTransports(); if (success) success = this->closeEthernet(); if (success) this->logger()->turnLEDBlue(); @@ -93,48 +93,63 @@ memset(this->m_lcd_status,0,TEMP_BUFFER_LEN+1); // look at Light#0 to determine the IOC linkage ID... - char *ioc = this->m_lights[0]->getResourceFactory()->getResourceValue(IOC_LINKAGE_RESOURCE); + char *ioc = this->m_personalities[0]->getResourceFactory()->getResourceValue(EXTERNAL_LINKAGE_RESOURCE); // color our LED depending on whether we have IOC linkage or not... - if (ioc == NULL || strcmp(ioc,IOC_LINKAGE_UNSET) == 0) this->logger()->turnLEDOrange(); + if (ioc == NULL || strcmp(ioc,EXTERNAL_LINKAGE_UNSET) == 0) this->logger()->turnLEDOrange(); else this->logger()->turnLEDGreen(); sprintf(this->m_lcd_status,"Node: %s\nNSP IP: %s\nIOC Link: %s",this->getEndpointName(),this->getNSPAddress(),ioc); return this->m_lcd_status; } + + // initialize our Personalities + bool MBEDEndpoint::initializePersonalities() { + #ifdef LIGHT_PERSONALITY + return this->initializeLights(); + #else + return false; + #endif + } // initialize the Lights bool MBEDEndpoint::initializeLights() { - int index = this->preferences()->getIntPreference("endpoint_id",LIGHT_NAME_INDEX); - this->logger()->log("Initializing Lights..."); - for(int i=0;i<NUM_LIGHTS;++i) { - this->m_lights[i] = new MBEDLight(this->logger(),this->m_transports,i+index,this); - this->m_lights[i]->setDimmerAction(new NSPLightDimmerAction(this->logger(),this->m_lights[i])); - this->m_lights[i]->setSwitchAction(new NSPLightSwitchAction(this->logger(),this->m_lights[i])); + int index = this->preferences()->getIntPreference("endpoint_id",PERSONALITY_NAME_INDEX); + this->logger()->log("Initializing Personality(Light)..."); + for(int i=0;i<NUM_PERSONALITY_INSTANCES;++i) { + this->m_personalities[i] = new MBEDLight(this->logger(),this->m_transports,i+index,this); + ((Light *)this->m_personalities[i])->setDimmerAction(new NSPLightDimmerAction(this->logger(),(Light *)this->m_personalities[i])); + ((Light *)this->m_personalities[i])->setSwitchAction(new NSPLightSwitchAction(this->logger(),(Light *)this->m_personalities[i])); } return true; } // send any observations we may have void MBEDEndpoint::sendObservations() { - for(int i=0;i<NUM_LIGHTS;++i) { - if (this->m_lights[i] != NULL) { - NSPResourceFactory *resource_factory = (NSPResourceFactory *)(this->m_lights[i]->getResourceFactory()); - resource_factory->sendObservations(); + for(int i=0;i<NUM_PERSONALITY_INSTANCES;++i) { + if (this->m_personalities[i] != NULL) { + NSPResourceFactory *resource_factory = (NSPResourceFactory *)(this->m_personalities[i]->getResourceFactory()); + if (resource_factory != NULL) resource_factory->sendObservations(); } } } // initialize our ResourceFactory - ResourceFactory *MBEDEndpoint::initResourceFactory() { return new NSPResourceFactory(this->logger(),(void *)this); } + ResourceFactory *MBEDEndpoint::initResourceFactory() { +#ifdef LIGHT_PERSONALITY + return new NSPLightResourceFactory(this->logger(),(void *)this); +#else + return NULL; +#endif + } // Initialize the Endpoint Name - will be the first Light resource name (and there must be one...) void MBEDEndpoint::initEndpointName() { - this->m_instance_id = this->preferences()->getIntPreference("endpoint_id",LIGHT_NAME_INDEX); - memset(_endpoint_name,0,LIGHT_NAME_LEN+1); - memset(this->m_endpoint_name,0,LIGHT_NAME_LEN+1); - sprintf(this->m_endpoint_name,LIGHT_NAME,this->m_instance_id); - sprintf(_endpoint_name,LIGHT_NAME,this->m_instance_id); + this->m_instance_id = this->preferences()->getIntPreference("endpoint_id",PERSONALITY_NAME_INDEX); + memset(_endpoint_name,0,PERSONALITY_NAME_LEN+1); + memset(this->m_endpoint_name,0,PERSONALITY_NAME_LEN+1); + sprintf(this->m_endpoint_name,PERSONALITY_NAME,this->m_instance_id); + sprintf(_endpoint_name,PERSONALITY_NAME,this->m_instance_id); } // get our endpoint name @@ -204,10 +219,10 @@ return success; } - // close down the Lights - bool MBEDEndpoint::closeLights() { + // close down the Personalities + bool MBEDEndpoint::closePersonalities() { bool success = true; - this->logger()->log("Closing down Lights..."); + this->logger()->log("Closing down Personalities..."); return success; }