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

Committer:
ansond
Date:
Thu Aug 28 21:17:12 2014 +0000
Revision:
23:6f6e97a276b9
Parent:
22:0f2a0269ce6d
Child:
24:b62fec3ff73c
added status reporting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:e1c4378df3fe 1 /* Copyright C2013 Doug Anson, MIT License
ansond 0:e1c4378df3fe 2 *
ansond 0:e1c4378df3fe 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
ansond 0:e1c4378df3fe 4 * and associated documentation files the "Software", to deal in the Software without restriction,
ansond 0:e1c4378df3fe 5 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
ansond 0:e1c4378df3fe 6 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
ansond 0:e1c4378df3fe 7 * furnished to do so, subject to the following conditions:
ansond 0:e1c4378df3fe 8 *
ansond 0:e1c4378df3fe 9 * The above copyright notice and this permission notice shall be included in all copies or
ansond 0:e1c4378df3fe 10 * substantial portions of the Software.
ansond 0:e1c4378df3fe 11 *
ansond 0:e1c4378df3fe 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
ansond 0:e1c4378df3fe 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
ansond 0:e1c4378df3fe 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
ansond 0:e1c4378df3fe 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
ansond 0:e1c4378df3fe 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
ansond 0:e1c4378df3fe 17 */
ansond 0:e1c4378df3fe 18
ansond 0:e1c4378df3fe 19 #include "NSPTransport.h"
ansond 0:e1c4378df3fe 20 #include "MBEDEndpoint.h"
ansond 0:e1c4378df3fe 21
ansond 4:7f7fe167d9c0 22 // Light Personality Support: MBED Light support
ansond 0:e1c4378df3fe 23 #include "MBEDLight.h"
ansond 0:e1c4378df3fe 24
ansond 4:7f7fe167d9c0 25 // Light Personality Support: NSP Resource Factory
ansond 4:7f7fe167d9c0 26 #include "NSPLightResourceFactory.h"
ansond 0:e1c4378df3fe 27
ansond 4:7f7fe167d9c0 28 // Light Personality Support: NSP Actions we can act on
ansond 0:e1c4378df3fe 29 #include "NSPLightDimmerAction.h"
ansond 0:e1c4378df3fe 30 #include "NSPLightSwitchAction.h"
ansond 0:e1c4378df3fe 31
ansond 23:6f6e97a276b9 32 // Salesforce Status Reporting (if enabled)
ansond 23:6f6e97a276b9 33 #if SF_STATUS_REPORTING
ansond 23:6f6e97a276b9 34 #include "StatusReporter.h"
ansond 23:6f6e97a276b9 35 #endif
ansond 23:6f6e97a276b9 36
ansond 0:e1c4378df3fe 37 // shutdown endpoint reference
ansond 0:e1c4378df3fe 38 extern void closedown(int code);
ansond 0:e1c4378df3fe 39
ansond 0:e1c4378df3fe 40 // default constructor
ansond 23:6f6e97a276b9 41 MBEDEndpoint::MBEDEndpoint(ErrorHandler *error_handler,void *transport,void *status_reporter,void *extra) : BaseClass(error_handler,NULL) {
ansond 0:e1c4378df3fe 42 bool success = true;
ansond 0:e1c4378df3fe 43 this->m_preferences = NULL;
ansond 0:e1c4378df3fe 44 this->m_instance_id = 0;
ansond 23:6f6e97a276b9 45 this->m_status_reporter = status_reporter;
ansond 0:e1c4378df3fe 46 memset(this->m_lcd_status,0,TEMP_BUFFER_LEN+1);
ansond 0:e1c4378df3fe 47 memset(this->m_nsp_address,0,PREFERENCE_VALUE_LEN+1);
ansond 22:0f2a0269ce6d 48 memset(this->m_nsp_port_str_def,0,PREFERENCE_VALUE_LEN+1);
ansond 22:0f2a0269ce6d 49 sprintf(this->m_nsp_port_str_def,"%d",NSP_PORT);
ansond 0:e1c4378df3fe 50 for(int i=0;i<NUM_TRANSPORTS;++i) this->m_transports[i] = NULL;
ansond 5:94d000e6fa70 51 this->logger()->setEndpoint((void *)this);
ansond 0:e1c4378df3fe 52 if (success) this->initPreferences();
ansond 0:e1c4378df3fe 53 if (success) this->initEndpointName();
ansond 0:e1c4378df3fe 54 if (success) this->logger()->turnLEDBlue();
ansond 0:e1c4378df3fe 55 #ifdef MAC_ADDRESS
ansond 0:e1c4378df3fe 56 extern char fmt_mac[RESOURCE_VALUE_LEN+1];
ansond 0:e1c4378df3fe 57 if (success)this->logger()->log("%s (MAC: %s)",ENDPOINT_VERSION_ANNOUNCE,fmt_mac);
ansond 0:e1c4378df3fe 58 #else
ansond 0:e1c4378df3fe 59 if (success)this->logger()->log(ENDPOINT_VERSION_ANNOUNCE);
ansond 0:e1c4378df3fe 60 #endif
ansond 0:e1c4378df3fe 61 if (success) this->initNSPAddress();
ansond 0:e1c4378df3fe 62 if (PL_ENABLE && success) this->logger()->log("Philips Light ID: %d Philips Gateway IP: %s",PL_LIGHT_ID,PL_GW_ADDRESS);
ansond 11:c4d02616e10f 63 #ifdef CELLULAR_NETWORK
ansond 11:c4d02616e10f 64 this->m_cellular_modem = NULL;
ansond 11:c4d02616e10f 65 this->m_gps = NULL;
ansond 19:3cecccc1a3d4 66 this->logger()->log("initializing Cellular Modem...");
ansond 21:272df0444756 67 if (success) success = this->initializeCellularModem(transport);
ansond 19:3cecccc1a3d4 68 //this->logger()->log("initializing GPS Receiver...");
ansond 19:3cecccc1a3d4 69 //if (success) success = this->initializeGPSReceiver(this,extra);
ansond 11:c4d02616e10f 70 #else
ansond 21:272df0444756 71 if (success) success = this->initializeEthernet((EthernetInterface *)transport);
ansond 6:edf306673e54 72 #endif
ansond 0:e1c4378df3fe 73 if (success) this->logger()->turnLEDYellow();
ansond 16:6936310c9501 74 this->logger()->log("initializing transports...");
ansond 0:e1c4378df3fe 75 if (success) success = this->initializeTransports();
ansond 16:6936310c9501 76 this->logger()->log("initializing personalities...");
ansond 16:6936310c9501 77 if (success) success = this->initializePersonalities();
ansond 16:6936310c9501 78 this->logger()->log("initialization complete for endpoint...");
ansond 0:e1c4378df3fe 79 if (success) this->logger()->turnLEDOrange();
ansond 0:e1c4378df3fe 80 this->logger()->lcdStatusOnly(true);
ansond 0:e1c4378df3fe 81 if (!success) closedown(2);
ansond 0:e1c4378df3fe 82 }
ansond 0:e1c4378df3fe 83
ansond 0:e1c4378df3fe 84 // default destructor
ansond 0:e1c4378df3fe 85 MBEDEndpoint::~MBEDEndpoint() {
ansond 0:e1c4378df3fe 86 bool success = true;
ansond 0:e1c4378df3fe 87 if (success) this->logger()->turnLEDYellow();
ansond 4:7f7fe167d9c0 88 if (success) success = this->closePersonalities();
ansond 0:e1c4378df3fe 89 if (success) success = this->closeTransports();
ansond 11:c4d02616e10f 90 #ifdef CELLULAR_NETWORK
ansond 11:c4d02616e10f 91 if (success) success = this->closeCellularModem();
ansond 11:c4d02616e10f 92 if (success) success = this->closeGPSReceiver();
ansond 11:c4d02616e10f 93 if (this->m_cellular_modem != NULL) delete this->m_cellular_modem;
ansond 11:c4d02616e10f 94 if (this->m_gps != NULL) delete this->m_gps;
ansond 11:c4d02616e10f 95 #else
ansond 0:e1c4378df3fe 96 if (success) success = this->closeEthernet();
ansond 6:edf306673e54 97 #endif
ansond 0:e1c4378df3fe 98 if (success) this->logger()->turnLEDBlue();
ansond 0:e1c4378df3fe 99 }
ansond 0:e1c4378df3fe 100
ansond 0:e1c4378df3fe 101 // initialize our preferences
ansond 0:e1c4378df3fe 102 void MBEDEndpoint::initPreferences() { if (this->m_preferences == NULL) this->m_preferences = new Preferences(this->logger()); }
ansond 0:e1c4378df3fe 103
ansond 0:e1c4378df3fe 104 // get our preferences
ansond 0:e1c4378df3fe 105 Preferences *MBEDEndpoint::preferences() { return this->m_preferences; }
ansond 0:e1c4378df3fe 106
ansond 0:e1c4378df3fe 107 // initialize the NSP address from the configuration
ansond 0:e1c4378df3fe 108 void MBEDEndpoint::initNSPAddress() {
ansond 0:e1c4378df3fe 109 memset(this->m_nsp_address,0,PREFERENCE_VALUE_LEN+1);
ansond 22:0f2a0269ce6d 110 memset(this->m_nsp_port_str,0,PREFERENCE_VALUE_LEN+1);
ansond 22:0f2a0269ce6d 111 if (this->m_preferences != NULL) {
ansond 22:0f2a0269ce6d 112 this->preferences()->getPreference("nsp_address",this->m_nsp_address,PREFERENCE_VALUE_LEN,NSP_ADDRESS);
ansond 22:0f2a0269ce6d 113 this->preferences()->getPreference("nsp_port",this->m_nsp_port_str,PREFERENCE_VALUE_LEN,this->m_nsp_port_str_def);
ansond 22:0f2a0269ce6d 114 sscanf(this->m_nsp_port_str,"%d",&(this->m_nsp_port));
ansond 22:0f2a0269ce6d 115 this->logger()->log("NSP: %s:%d",this->getNSPAddress(),this->getNSPPort());
ansond 22:0f2a0269ce6d 116 }
ansond 0:e1c4378df3fe 117 }
ansond 0:e1c4378df3fe 118
ansond 0:e1c4378df3fe 119 // get our NSP address
ansond 0:e1c4378df3fe 120 char *MBEDEndpoint::getNSPAddress() { return this->m_nsp_address; }
ansond 0:e1c4378df3fe 121
ansond 22:0f2a0269ce6d 122 // get our NSP port
ansond 22:0f2a0269ce6d 123 int MBEDEndpoint::getNSPPort() { return this->m_nsp_port; }
ansond 22:0f2a0269ce6d 124
ansond 0:e1c4378df3fe 125 // get our LCD status
ansond 0:e1c4378df3fe 126 char *MBEDEndpoint::getLCDStatus() {
ansond 0:e1c4378df3fe 127 memset(this->m_lcd_status,0,TEMP_BUFFER_LEN+1);
ansond 0:e1c4378df3fe 128
ansond 0:e1c4378df3fe 129 // look at Light#0 to determine the IOC linkage ID...
ansond 4:7f7fe167d9c0 130 char *ioc = this->m_personalities[0]->getResourceFactory()->getResourceValue(EXTERNAL_LINKAGE_RESOURCE);
ansond 0:e1c4378df3fe 131
ansond 0:e1c4378df3fe 132 // color our LED depending on whether we have IOC linkage or not...
ansond 4:7f7fe167d9c0 133 if (ioc == NULL || strcmp(ioc,EXTERNAL_LINKAGE_UNSET) == 0) this->logger()->turnLEDOrange();
ansond 0:e1c4378df3fe 134 else this->logger()->turnLEDGreen();
ansond 0:e1c4378df3fe 135
ansond 22:0f2a0269ce6d 136 sprintf(this->m_lcd_status,"Node: %s\nNSP: %s:%d\nIOC Link: %s",this->getEndpointName(),this->getNSPAddress(),this->getNSPPort(),ioc);
ansond 0:e1c4378df3fe 137 return this->m_lcd_status;
ansond 0:e1c4378df3fe 138 }
ansond 4:7f7fe167d9c0 139
ansond 4:7f7fe167d9c0 140 // initialize our Personalities
ansond 4:7f7fe167d9c0 141 bool MBEDEndpoint::initializePersonalities() {
ansond 4:7f7fe167d9c0 142 #ifdef LIGHT_PERSONALITY
ansond 4:7f7fe167d9c0 143 return this->initializeLights();
ansond 7:0207dfb9c36b 144 #endif
ansond 7:0207dfb9c36b 145 #ifdef COPCAR_PERSONALITY
ansond 7:0207dfb9c36b 146 return this->initializeLights();
ansond 4:7f7fe167d9c0 147 #endif
ansond 4:7f7fe167d9c0 148 }
ansond 0:e1c4378df3fe 149
ansond 0:e1c4378df3fe 150 // initialize the Lights
ansond 0:e1c4378df3fe 151 bool MBEDEndpoint::initializeLights() {
ansond 4:7f7fe167d9c0 152 int index = this->preferences()->getIntPreference("endpoint_id",PERSONALITY_NAME_INDEX);
ansond 8:4060275b2246 153 this->logger()->log("Initializing Personality(%s)...",PERSONALITY_TYPE);
ansond 4:7f7fe167d9c0 154 for(int i=0;i<NUM_PERSONALITY_INSTANCES;++i) {
ansond 4:7f7fe167d9c0 155 this->m_personalities[i] = new MBEDLight(this->logger(),this->m_transports,i+index,this);
ansond 4:7f7fe167d9c0 156 ((Light *)this->m_personalities[i])->setDimmerAction(new NSPLightDimmerAction(this->logger(),(Light *)this->m_personalities[i]));
ansond 4:7f7fe167d9c0 157 ((Light *)this->m_personalities[i])->setSwitchAction(new NSPLightSwitchAction(this->logger(),(Light *)this->m_personalities[i]));
ansond 0:e1c4378df3fe 158 }
ansond 0:e1c4378df3fe 159 return true;
ansond 0:e1c4378df3fe 160 }
ansond 0:e1c4378df3fe 161
ansond 0:e1c4378df3fe 162 // send any observations we may have
ansond 0:e1c4378df3fe 163 void MBEDEndpoint::sendObservations() {
ansond 4:7f7fe167d9c0 164 for(int i=0;i<NUM_PERSONALITY_INSTANCES;++i) {
ansond 4:7f7fe167d9c0 165 if (this->m_personalities[i] != NULL) {
ansond 4:7f7fe167d9c0 166 NSPResourceFactory *resource_factory = (NSPResourceFactory *)(this->m_personalities[i]->getResourceFactory());
ansond 4:7f7fe167d9c0 167 if (resource_factory != NULL) resource_factory->sendObservations();
ansond 0:e1c4378df3fe 168 }
ansond 0:e1c4378df3fe 169 }
ansond 0:e1c4378df3fe 170 }
ansond 0:e1c4378df3fe 171
ansond 0:e1c4378df3fe 172 // initialize our ResourceFactory
ansond 4:7f7fe167d9c0 173 ResourceFactory *MBEDEndpoint::initResourceFactory() {
ansond 4:7f7fe167d9c0 174 #ifdef LIGHT_PERSONALITY
ansond 4:7f7fe167d9c0 175 return new NSPLightResourceFactory(this->logger(),(void *)this);
ansond 7:0207dfb9c36b 176 #endif
ansond 7:0207dfb9c36b 177 #ifdef COPCAR_PERSONALITY
ansond 7:0207dfb9c36b 178 return new NSPLightResourceFactory(this->logger(),(void *)this);
ansond 4:7f7fe167d9c0 179 #endif
ansond 4:7f7fe167d9c0 180 }
ansond 0:e1c4378df3fe 181
ansond 0:e1c4378df3fe 182 // Initialize the Endpoint Name - will be the first Light resource name (and there must be one...)
ansond 0:e1c4378df3fe 183 void MBEDEndpoint::initEndpointName() {
ansond 4:7f7fe167d9c0 184 this->m_instance_id = this->preferences()->getIntPreference("endpoint_id",PERSONALITY_NAME_INDEX);
ansond 4:7f7fe167d9c0 185 memset(_endpoint_name,0,PERSONALITY_NAME_LEN+1);
ansond 4:7f7fe167d9c0 186 memset(this->m_endpoint_name,0,PERSONALITY_NAME_LEN+1);
ansond 4:7f7fe167d9c0 187 sprintf(this->m_endpoint_name,PERSONALITY_NAME,this->m_instance_id);
ansond 4:7f7fe167d9c0 188 sprintf(_endpoint_name,PERSONALITY_NAME,this->m_instance_id);
ansond 0:e1c4378df3fe 189 }
ansond 0:e1c4378df3fe 190
ansond 0:e1c4378df3fe 191 // get our endpoint name
ansond 0:e1c4378df3fe 192 char *MBEDEndpoint::getEndpointName() { return this->m_endpoint_name; }
ansond 0:e1c4378df3fe 193
ansond 0:e1c4378df3fe 194 // get our instance id
ansond 0:e1c4378df3fe 195 int MBEDEndpoint::getInstanceID() { return this->m_instance_id; }
ansond 0:e1c4378df3fe 196
ansond 0:e1c4378df3fe 197 // initialize a specific transport
ansond 0:e1c4378df3fe 198 bool MBEDEndpoint::initializeTransport(int index,char *key,Transport *transport) {
ansond 0:e1c4378df3fe 199 bool success = false;
ansond 0:e1c4378df3fe 200 if (this->m_transports[index] == NULL) {
ansond 0:e1c4378df3fe 201 this->logger()->log("Initializing %s Transport...", key);
ansond 0:e1c4378df3fe 202 this->m_transports[index] = transport;
ansond 0:e1c4378df3fe 203 if (this->m_transports[index] != NULL) success = this->m_transports[index]->connect();
ansond 0:e1c4378df3fe 204 }
ansond 0:e1c4378df3fe 205 else {
ansond 0:e1c4378df3fe 206 this->logger()->log("%s already connected (OK)...", key);
ansond 0:e1c4378df3fe 207 success = true;
ansond 0:e1c4378df3fe 208 }
ansond 0:e1c4378df3fe 209 return success;
ansond 0:e1c4378df3fe 210 }
ansond 0:e1c4378df3fe 211
ansond 0:e1c4378df3fe 212 // initialize our transports
ansond 0:e1c4378df3fe 213 bool MBEDEndpoint::initializeTransports() {
ansond 0:e1c4378df3fe 214 bool success = true;
ansond 0:e1c4378df3fe 215
ansond 0:e1c4378df3fe 216 if (success == true) {
ansond 0:e1c4378df3fe 217 // NSP Initialization
ansond 5:94d000e6fa70 218 success = this->initializeTransport(NSP_TRANSPORT,"NSP",new NSPTransport(this->logger(),this));
ansond 0:e1c4378df3fe 219 }
ansond 0:e1c4378df3fe 220
ansond 0:e1c4378df3fe 221 if (success == true) {
ansond 0:e1c4378df3fe 222 // HTTP Initialization
ansond 5:94d000e6fa70 223 success = this->initializeTransport(HTTP_TRANSPORT,"HTTP",new HTTPTransport(this->logger(),this));
ansond 0:e1c4378df3fe 224 }
ansond 0:e1c4378df3fe 225
ansond 0:e1c4378df3fe 226 return success;
ansond 0:e1c4378df3fe 227 }
ansond 0:e1c4378df3fe 228
ansond 11:c4d02616e10f 229 #ifdef CELLULAR_NETWORK
ansond 21:272df0444756 230 bool MBEDEndpoint::initializeCellularModem(void *modem) {
ansond 11:c4d02616e10f 231 bool success = false;
ansond 11:c4d02616e10f 232
ansond 11:c4d02616e10f 233 // initialize
ansond 19:3cecccc1a3d4 234 if (this->m_cellular_modem == NULL) this->m_cellular_modem = new MBEDUbloxCellRadio(this->logger(),(void *)this,modem);
ansond 11:c4d02616e10f 235 if (this->m_cellular_modem != NULL) success = this->m_cellular_modem->connect();
ansond 11:c4d02616e10f 236
ansond 11:c4d02616e10f 237 // return our status
ansond 11:c4d02616e10f 238 return success;
ansond 11:c4d02616e10f 239 }
ansond 11:c4d02616e10f 240
ansond 19:3cecccc1a3d4 241 bool MBEDEndpoint::initializeGPSReceiver(void *gps) {
ansond 11:c4d02616e10f 242 bool success = false;
ansond 11:c4d02616e10f 243
ansond 11:c4d02616e10f 244 // initialize
ansond 19:3cecccc1a3d4 245 if (this->m_gps == NULL) this->m_gps = new MBEDUbloxGPS(this->logger(),(void *)this,gps);
ansond 11:c4d02616e10f 246 if (this->m_gps != NULL) success = this->m_gps->connect();
ansond 11:c4d02616e10f 247
ansond 11:c4d02616e10f 248 // return our status
ansond 11:c4d02616e10f 249 return success;
ansond 11:c4d02616e10f 250 }
ansond 11:c4d02616e10f 251 #endif
ansond 11:c4d02616e10f 252
ansond 6:edf306673e54 253 #ifndef CELLULAR_NETWORK
ansond 0:e1c4378df3fe 254 // initialize our Ethernet
ansond 0:e1c4378df3fe 255 bool MBEDEndpoint::initializeEthernet(EthernetInterface *ethernet) {
ansond 0:e1c4378df3fe 256 bool success = false;
ansond 0:e1c4378df3fe 257 this->m_ethernet = ethernet;
ansond 0:e1c4378df3fe 258 if (this->m_ethernet != NULL) {
ansond 0:e1c4378df3fe 259 this->logger()->log("Initializing Ethernet...");
ansond 0:e1c4378df3fe 260
ansond 0:e1c4378df3fe 261 // connect up ethernet
ansond 20:def10d2d9273 262 this->m_ethernet->init(); // DHCP
ansond 20:def10d2d9273 263 //this->m_ethernet->init("192.168.1.220","255.255.255.0","192.168.1.1");
ansond 0:e1c4378df3fe 264 this->m_ethernet->connect();
ansond 0:e1c4378df3fe 265
ansond 0:e1c4378df3fe 266 // display our IP address
ansond 0:e1c4378df3fe 267 char *ipaddr = this->m_ethernet->getIPAddress();
ansond 0:e1c4378df3fe 268 if (ipaddr != NULL && strlen(ipaddr) > 0) {
ansond 0:e1c4378df3fe 269 this->logger()->log("IPAddress: %s",this->m_ethernet->getIPAddress());
ansond 0:e1c4378df3fe 270 success = true;
ansond 0:e1c4378df3fe 271 }
ansond 0:e1c4378df3fe 272 else {
ansond 0:e1c4378df3fe 273 this->logger()->log("Ethernet Not Connected...");
ansond 0:e1c4378df3fe 274 success = false;
ansond 0:e1c4378df3fe 275 }
ansond 0:e1c4378df3fe 276 }
ansond 0:e1c4378df3fe 277 else {
ansond 0:e1c4378df3fe 278 this->logger()->log("No Ethernet instance found");
ansond 0:e1c4378df3fe 279 success = false;
ansond 0:e1c4378df3fe 280 }
ansond 0:e1c4378df3fe 281 return success;
ansond 0:e1c4378df3fe 282 }
ansond 6:edf306673e54 283 #endif
ansond 0:e1c4378df3fe 284
ansond 4:7f7fe167d9c0 285 // close down the Personalities
ansond 4:7f7fe167d9c0 286 bool MBEDEndpoint::closePersonalities() {
ansond 0:e1c4378df3fe 287 bool success = true;
ansond 4:7f7fe167d9c0 288 this->logger()->log("Closing down Personalities...");
ansond 0:e1c4378df3fe 289 return success;
ansond 0:e1c4378df3fe 290 }
ansond 0:e1c4378df3fe 291
ansond 0:e1c4378df3fe 292 // close a given transport
ansond 0:e1c4378df3fe 293 bool MBEDEndpoint::closeTransport(int index,char *key) {
ansond 0:e1c4378df3fe 294 this->logger()->log("Closing down %s Transport...", key);
ansond 0:e1c4378df3fe 295 if (this->m_transports[index] != NULL) delete this->m_transports[index];
ansond 0:e1c4378df3fe 296 return true;
ansond 0:e1c4378df3fe 297 }
ansond 0:e1c4378df3fe 298
ansond 0:e1c4378df3fe 299 // close down our transports
ansond 0:e1c4378df3fe 300 bool MBEDEndpoint::closeTransports() {
ansond 0:e1c4378df3fe 301 bool success = true;
ansond 0:e1c4378df3fe 302
ansond 0:e1c4378df3fe 303 if (success) {
ansond 0:e1c4378df3fe 304 // close NSP
ansond 0:e1c4378df3fe 305 success = this->closeTransport(NSP_TRANSPORT,"NSP");
ansond 0:e1c4378df3fe 306 }
ansond 0:e1c4378df3fe 307
ansond 0:e1c4378df3fe 308 return success;
ansond 0:e1c4378df3fe 309 }
ansond 0:e1c4378df3fe 310
ansond 11:c4d02616e10f 311 #ifdef CELLULAR_NETWORK
ansond 11:c4d02616e10f 312 bool MBEDEndpoint::closeCellularModem() {
ansond 11:c4d02616e10f 313 bool success = true;
ansond 11:c4d02616e10f 314 if (this->m_cellular_modem != NULL) success = this->m_cellular_modem->disconnect();
ansond 11:c4d02616e10f 315 return success;
ansond 11:c4d02616e10f 316 }
ansond 11:c4d02616e10f 317
ansond 11:c4d02616e10f 318 bool MBEDEndpoint::closeGPSReceiver() {
ansond 11:c4d02616e10f 319 bool success = true;
ansond 11:c4d02616e10f 320 if (this->m_gps != NULL) success = this->m_gps->disconnect();
ansond 11:c4d02616e10f 321 return success;
ansond 11:c4d02616e10f 322 }
ansond 11:c4d02616e10f 323 #endif
ansond 11:c4d02616e10f 324
ansond 6:edf306673e54 325 #ifndef CELLULAR_NETWORK
ansond 0:e1c4378df3fe 326 // close down our Ethernet
ansond 0:e1c4378df3fe 327 bool MBEDEndpoint::closeEthernet() {
ansond 0:e1c4378df3fe 328 this->logger()->log("Closing down Ethernet...");
ansond 0:e1c4378df3fe 329 if (this->m_ethernet != NULL) this->m_ethernet->disconnect();
ansond 0:e1c4378df3fe 330 return true;
ansond 0:e1c4378df3fe 331 }
ansond 6:edf306673e54 332 #endif
ansond 0:e1c4378df3fe 333
ansond 0:e1c4378df3fe 334 // main running loop
ansond 0:e1c4378df3fe 335 void MBEDEndpoint::run() {
ansond 0:e1c4378df3fe 336 this->logger()->log("Endpoint Main Loop");
ansond 0:e1c4378df3fe 337 this->m_transports[NSP_TRANSPORT]->checkAndProcess();
ansond 23:6f6e97a276b9 338 }
ansond 23:6f6e97a276b9 339
ansond 23:6f6e97a276b9 340 // do any extra work from within the event loop
ansond 23:6f6e97a276b9 341 void MBEDEndpoint::extraEventLoopWork() {
ansond 23:6f6e97a276b9 342 // check and send status reporting if enabled
ansond 23:6f6e97a276b9 343 #if SF_STATUS_REPORTING
ansond 23:6f6e97a276b9 344 if (this->m_status_reporter != NULL) {
ansond 23:6f6e97a276b9 345 StatusReporter *status_reporter = (StatusReporter *)this->m_status_reporter;
ansond 23:6f6e97a276b9 346 status_reporter->checkAndReportOnStatus();
ansond 23:6f6e97a276b9 347 }
ansond 23:6f6e97a276b9 348 #endif
ansond 23:6f6e97a276b9 349 }
ansond 0:e1c4378df3fe 350