observe updates
Fork of mbedConnectorInterface by
Embed:
(wiki syntax)
Show/hide line numbers
Utils.cpp
Go to the documentation of this file.
00001 /** 00002 * @file Utils.cpp 00003 * @brief mbed CoAP Endpoint misc utils collection 00004 * @author Doug Anson 00005 * @version 1.0 00006 * @see 00007 * 00008 * Copyright (c) 2014 00009 * 00010 * Licensed under the Apache License, Version 2.0 (the "License"); 00011 * you may not use this file except in compliance with the License. 00012 * You may obtain a copy of the License at 00013 * 00014 * http://www.apache.org/licenses/LICENSE-2.0 00015 * 00016 * Unless required by applicable law or agreed to in writing, software 00017 * distributed under the License is distributed on an "AS IS" BASIS, 00018 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00019 * See the License for the specific language governing permissions and 00020 * limitations under the License. 00021 */ 00022 00023 // mbed Endpoint includes 00024 #include "ConnectorEndpoint.h" 00025 #include "OptionsBuilder.h" 00026 00027 // External references (defined in main.cpp) 00028 Connector::Options *configure_endpoint(Connector::OptionsBuilder &builder); 00029 extern Logger logger; 00030 00031 // Our Endpoint 00032 Connector::Endpoint *endpoint = NULL; 00033 00034 // Our Endpoint configured Options 00035 Connector::OptionsBuilder config; 00036 Connector::Options *options = NULL; 00037 00038 // ************************* NSDL Linkage - MDS CONFIGURATION (defaulted) ********************************* 00039 00040 uint8_t NSP_address_bytes[NSP_IP_ADDRESS_LENGTH] = NSP_IP_ADDRESS; // which MDS instance we want to bind to... 00041 uint8_t endpoint_name[NODE_NAME_LENGTH] = NODE_NAME; // our NODE name 00042 uint8_t domain_name[NSP_DOMAIN_LENGTH] = NSP_DOMAIN; // our MDS domain name 00043 int nsp_port = NSP_COAP_UDP_PORT; // our MDS UDP port 00044 uint8_t ep_type[NSP_ENDPOINT_TYPE_LENGTH] = NSP_ENDPOINT_TYPE; // our NODE type 00045 uint8_t lifetime_ptr[NSP_LIFE_TIME_LENGTH] = { NSP_LIFE_TIME }; // NSDL lifetime 00046 uint8_t app_MAC_address[NODE_MAC_ADDRESS_LENGTH] = NODE_MAC_ADDRESS; // Node MAC address 00047 uint32_t channel_list = NODE_CHANNEL_LIST; // Node RF Channel list 00048 00049 uint8_t wifi_ssid[WIFI_SSID_LENGTH]; // WiFi SSID 00050 WiFiAuthTypes wifi_auth_type; // WiFi Auth Type 00051 uint8_t wifi_auth_key[WIFI_AUTH_KEY_LENGTH]; // WiFi Auth Key 00052 00053 uint8_t mesh_network_id[MESH_NETWORK_ID_LENGTH] = MESH_DEF_NETWORK_ID; // 802.15.4 Network ID (6LowPAN) 00054 uint8_t rf_channel = MESH_DEF_RF_CHANNEL; // 802.15.4 RF Channel (6LowPAN) 00055 00056 // ************************* NSDL Linkage - MDS CONFIGURATION (defaulted) ********************************* 00057 00058 00059 // further simplifies the endpoint main() configuration by removing the final initialization details of the endpoint... 00060 void utils_configure_endpoint() 00061 { 00062 // NSP/NSDL default configuration - see mbedConnectorInterface.h for definitions... 00063 logger.log("utils_configure_endpoint: setting defaults..."); 00064 config.setNSPAddress(NSP_address_bytes); 00065 config.setNSPPortNumber(NSP_COAP_UDP_PORT); 00066 config.setDomain(NSP_DOMAIN); 00067 config.setEndpointNodename(NODE_NAME); 00068 config.setEndpointType(NSP_ENDPOINT_TYPE); 00069 config.setLifetime(NSP_LIFE_TIME); 00070 00071 // Node default configuration - see mbedConnectorInterface.h for definitions... 00072 config.setRadioChannelList(NODE_CHANNEL_LIST); 00073 config.setReadUpdatePeriod(NSP_RD_UPDATE_PERIOD); 00074 config.setEndpointNodename(NODE_NAME); 00075 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 00076 00077 // WiFi defaults 00078 config.setWiFiSSID(WIFI_DEFAULT_SSID); // default: changeme 00079 config.setWiFiAuthType(WIFI_WPA_PERSONAL); // default: WPA Personal 00080 config.setWiFiAuthKey(WIFI_DEFAULT_AUTH_KEY); // default: changeme 00081 00082 // 802.15.4 defaults (6LowPAN) 00083 config.setNetworkID((char *)mesh_network_id); 00084 config.setRadioChannel((int)mesh_network_id); 00085 00086 // main.cpp can override or change any of the above defaults... 00087 logger.log("utils_configure_endpoint: gathering configuration overrides..."); 00088 options = configure_endpoint(config); 00089 00090 // with options, lets set the underlying NSDL globals... 00091 logger.log("utils_configure_endpoint: finalizing configuration..."); 00092 memcpy(NSP_address_bytes,options->getNSPAddress(),NSP_IP_ADDRESS_LENGTH); 00093 memset(endpoint_name,0,NODE_NAME_LENGTH); 00094 memcpy(endpoint_name,options->getEndpointNodename().c_str(),options->getEndpointNodename().size()); 00095 memset(domain_name,0,NSP_DOMAIN_LENGTH); 00096 memcpy(domain_name,options->getDomain().c_str(),options->getDomain().size()); 00097 nsp_port = options->getNSPPortNumber(); 00098 memset(ep_type,0,NSP_ENDPOINT_TYPE_LENGTH); 00099 memcpy(ep_type,options->getEndpointType().c_str(),options->getEndpointType().size()); 00100 memcpy(lifetime_ptr,options->getLifetime(),NSP_LIFE_TIME_LENGTH); 00101 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 00102 channel_list = options->getRadioChannelList(); 00103 00104 // WiFi Configration 00105 memcpy(wifi_ssid,options->getWiFiSSID().c_str(),options->getWiFiSSID().size()); 00106 wifi_auth_type = options->getWiFiAuthType(); 00107 memcpy(wifi_auth_key,options->getWiFiAuthKey().c_str(),options->getWiFiAuthKey().size()); 00108 00109 // 802.15.4 Configuration 00110 memcpy(mesh_network_id,options->getNetworkID().c_str(),options->getNetworkID().size()); 00111 rf_channel = options->getRadioChannel(); 00112 00113 // DONE 00114 logger.log("utils_configure_endpoint: endpoint configuration completed."); 00115 } 00116 00117 // initialize and register the endpoint and its resources 00118 void utils_init_and_register_endpoint(void) 00119 { 00120 // initialize NSDL 00121 logger.log("net_stubs_post_plumb_network: initializing NSP..\r\n."); 00122 nsdl_init(); 00123 nsdl_set_nsp_address(); 00124 00125 // alloc Endpoint 00126 logger.log("utils_init_and_register_endpoint: allocating endpoint instance..."); 00127 if (endpoint == NULL) endpoint = new Connector::Endpoint(&logger,options); 00128 00129 // initialize Endpoint resources 00130 logger.log("utils_init_and_register_endpoint: registering endpoint and its resources..."); 00131 endpoint->register_endpoint(); 00132 }
Generated on Wed Jul 13 2022 02:11:49 by
![doxygen](doxygen.png)