mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface

Revision:
8:f950fb1b78c0
Parent:
7:e94f0bd92545
Child:
10:3f79b5e67c22
--- a/source/Utils.cpp	Sun Feb 21 19:05:14 2016 +0000
+++ b/source/Utils.cpp	Wed Feb 24 05:52:00 2016 +0000
@@ -29,19 +29,23 @@
 Connector::Options *configure_endpoint(Connector::OptionsBuilder &builder);
 extern Logger logger;
 
+// Our Endpoint
+Connector::Endpoint *__endpoint = NULL;
+
 // Our Endpoint configured Options
 Connector::OptionsBuilder config;
 Connector::Options *options = NULL;
 
-// ************************* NSDL Linkage - MDS CONFIGURATION (defaulted) *********************************
-
-uint8_t app_MAC_address[NODE_MAC_ADDRESS_LENGTH] = NODE_MAC_ADDRESS;   // Node MAC address
-uint32_t channel_list = NODE_CHANNEL_LIST;                             // Node RF Channel list
-
-uint8_t mesh_network_id[MESH_NETWORK_ID_LENGTH] = MESH_DEF_NETWORK_ID; // 802.15.4 Network ID (6LowPAN)
-uint8_t rf_channel = MESH_DEF_RF_CHANNEL;                              // 802.15.4 RF Channel (6LowPAN)
-
-// ************************* NSDL Linkage - MDS CONFIGURATION (defaulted)  *********************************
+// initialize the Connector::Endpoint instance
+void *utils_init_endpoint(bool canActAsRouterNode) {
+	// alloc Endpoint
+    logger.log("Endpoint: allocating endpoint instance...");
+	Connector::Endpoint *ep = new Connector::Endpoint(&logger,options);
+	if (ep != NULL) {
+		ep->asRouterNode(canActAsRouterNode);
+    }
+    return (void *)ep;
+}
 
 // further simplifies the endpoint main() configuration by removing the final initialization details of the endpoint...
 void utils_configure_endpoint(void *p)
@@ -60,12 +64,14 @@
     config.setWiFiSSID((char *)WIFI_DEFAULT_SSID);          			// default: changeme
     config.setWiFiAuthType(WIFI_WPA_PERSONAL);      					// default: WPA Personal
     config.setWiFiAuthKey((char *)WIFI_DEFAULT_AUTH_KEY);   	// default: changeme
-
-    // 802.15.4 defaults (6LowPAN)
-    config.setNetworkID((char *)mesh_network_id);
-    config.setRadioChannel((int)mesh_network_id);
-    config.setRadioChannelList(NODE_CHANNEL_LIST);
-    config.setMACAddress(app_MAC_address);   // TODO: arm_ns_tasklet_create() should call Endpoint::plumbNetwork()... currently its called before this MAC address can be (re)set
+    
+    // 802.15.4 defaults
+    unsigned char psk[16];
+    unsigned char psk_identity[2];
+    memset(psk,0,16);
+    memset(psk_identity,0,2);
+    config.setPreSharedKey(psk);
+    config.setPreSharedKeyIdentity(psk_identity);
                  
     // Establish default CoAP observation behavior
     config.setImmedateObservationEnabled(true);    
@@ -76,38 +82,19 @@
     // main.cpp can override or change any of the above defaults...
     logger.log("Endpoint: gathering configuration overrides...");
     options = configure_endpoint(config);
-    ep->setOptions(options);
-
+	ep->setOptions(options);
+	
     // DONE
     logger.log("Endpoint: endpoint configuration completed.");
 }
 
-// initialize the Connector::Endpoint instance
-void *utils_init_endpoint(bool canActAsRouterNode) {
-	// alloc Endpoint
-    logger.log("Endpoint: allocating endpoint instance...");
-	Connector::Endpoint *ep = new Connector::Endpoint(&logger,options);
-	if (ep != NULL) {
-		ep->asRouterNode(canActAsRouterNode);
-    }
-    return (void *)ep;
-}
-
-// register the endpoint and its resources
-void utils_register_endpoint(void *p)
+// build out  the endpoint and its resources
+void utils_build_endpoint(void *p)
 {
     if (p != NULL) {
+    	// Build the Endpoint
+    	logger.log("Endpoint: building endpoint and its resources...");
 		Connector::Endpoint *ep = (Connector::Endpoint *)p;
-	    // initialize Endpoint resources
-	    logger.log("Endpoint: registering endpoint and its resources...");
-	    ep->register_endpoint();
-	    
-	    // complete the registration
-	    logger.log("Endpoint: completing endpoint registration...");
-   		ep->complete_endpoint_registration(ep->getServer(),ep->getObjectList());
-   		
-   		// setup the shutdown button (if enabled for a given platform...)
-    	net_setup_deregistration_button(p);
+	    ep->build_endpoint();
 	}
-}
-
+}
\ No newline at end of file