added max-age and content-format

Fork of mbedConnectorInterface by Doug Anson

Revision:
16:383ad1356963
Parent:
14:5cfaeee144bc
Child:
19:e2cbaeeea509
--- a/api/Utils.cpp	Thu Feb 05 14:49:04 2015 +0000
+++ b/api/Utils.cpp	Fri Feb 06 04:07:51 2015 +0000
@@ -28,6 +28,13 @@
 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 NSP_address_bytes[NSP_IP_ADDRESS_LENGTH] = NSP_IP_ADDRESS;     // which MDS instance we want to bind to...
@@ -39,15 +46,18 @@
 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 wifi_ssid[WIFI_SSID_LENGTH];                                   // WiFi SSID
+WiFiAuthTypes wifi_auth_type;                                          // WiFi Auth Type
+uint8_t wifi_auth_key[WIFI_AUTH_KEY_LENGTH];                           // WiFi Auth Key
+
 // ************************* NSDL Linkage - MDS CONFIGURATION (defaulted)  *********************************
 
 
 // further simplifies the endpoint main() configuration by removing the final initialization details of the endpoint...
-void configure_endpoint()
+void utils_configure_endpoint()
 {    
     // NSP/NSDL default configuration - see mbedConnectorInterface.h for definitions...
-    logger.log("configure_endpoint: setting defaults...");
-    Connector::OptionsBuilder config;
+    logger.log("utils_configure_endpoint: setting defaults...");
     config.setNSPAddress(NSP_address_bytes);
     config.setNSPPortNumber(NSP_COAP_UDP_PORT);
     config.setDomain(NSP_DOMAIN);
@@ -61,12 +71,17 @@
     config.setEndpointNodename(NODE_NAME); 
     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
     
+    // WiFi defaults
+    config.setWiFiSSID(WIFI_DEFAULT_SSID);          // default: changeme
+    config.setWiFiAuthType(WIFI_WPA_PERSONAL);      // default: WPA Personal
+    config.setWiFiAuthKey(WIFI_DEFAULT_AUTH_KEY);   // default: changeme
+    
     // main.cpp can override or change any of the above defaults...
-    logger.log("configure_endpoint: enabling default configuration overrides...");
-    Connector::Options *options = configure_endpoint(config);
+    logger.log("utils_configure_endpoint: gathering configuration overrides...");
+    options = configure_endpoint(config);
         
     // with options, lets set the underlying NSDL globals...
-    logger.log("configure_endpoint: updating external NSDL globals...");
+    logger.log("utils_configure_endpoint: finalizing configuration...");
     memcpy(NSP_address_bytes,options->getNSPAddress(),NSP_IP_ADDRESS_LENGTH);
     memcpy(endpoint_name,options->getEndpointNodename().c_str(),options->getEndpointNodename().size());
     memcpy(domain_name,options->getDomain().c_str(),options->getDomain().size());
@@ -75,15 +90,29 @@
     memcpy(lifetime_ptr,options->getLifetime(),NSP_LIFE_TIME_LENGTH);
     memcpy(app_MAC_address,options->getMACAddress(),NODE_MAC_ADDRESS_LENGTH); // TODO: arm_ns_tasklet_create() should call Endpoint::plumbNetwork()... currently its called before this MAC address can be (re)set
     channel_list = options->getRadioChannelList();
+    
+    // WiFi Configration
+    memcpy(wifi_ssid,options->getWiFiSSID().c_str(),options->getWiFiSSID().size());
+    wifi_auth_type = options->getWiFiAuthType();
+    memcpy(wifi_auth_key,options->getWiFiAuthKey().c_str(),options->getWiFiAuthKey().size());
+
+    // DONE
+    logger.log("utils_configure_endpoint: endpoint configuration completed.");
+}
+
+// initialize and register the endpoint and its resources
+void utils_init_and_register_endpoint(void) 
+{
+    // initialize NSDL
+    logger.log("net_stubs_post_plumb_network: initializing NSP..\r\n.");
+    nsdl_init();
+    nsdl_set_nsp_address();
 
     // alloc Endpoint
-    logger.log("configure_endpoint: allocating endpoint...");
-    Connector::Endpoint endpoint(&logger,options);
+    logger.log("utils_init_and_register_endpoint: allocating endpoint instance...");
+    if (endpoint == NULL) endpoint = new Connector::Endpoint(&logger,options);
 
     // initialize Endpoint resources
-    logger.log("configure_endpoint: binding endpoint resources...");
-    endpoint.initialize();
-
-    // DONE
-    logger.log("configure_endpoint: endpoint setup complete.");
+    logger.log("utils_init_and_register_endpoint: registering endpoint and its resources...");
+    endpoint->register_endpoint();
 }