Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: IoT_LED_demo ServoTest uWater_Project hackathon ... more
Utils.cpp
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 // Establish default CoAP observation behavior 00087 config.setImmedateObservationEnabled(false); // default: false (per CoAP spec) 00088 00089 // Establish default CoAP GET-based observation control behavior 00090 config.setEnableGETObservationControl(true); // default: true (CoAP spec) 00091 00092 // main.cpp can override or change any of the above defaults... 00093 logger.log("utils_configure_endpoint: gathering configuration overrides..."); 00094 options = configure_endpoint(config); 00095 00096 // with options, lets set the underlying NSDL globals... 00097 logger.log("utils_configure_endpoint: finalizing configuration..."); 00098 memcpy(NSP_address_bytes,options->getNSPAddress(),NSP_IP_ADDRESS_LENGTH); 00099 memset(endpoint_name,0,NODE_NAME_LENGTH); 00100 memcpy(endpoint_name,options->getEndpointNodename().c_str(),options->getEndpointNodename().size()); 00101 memset(domain_name,0,NSP_DOMAIN_LENGTH); 00102 memcpy(domain_name,options->getDomain().c_str(),options->getDomain().size()); 00103 nsp_port = options->getNSPPortNumber(); 00104 memset(ep_type,0,NSP_ENDPOINT_TYPE_LENGTH); 00105 memcpy(ep_type,options->getEndpointType().c_str(),options->getEndpointType().size()); 00106 memcpy(lifetime_ptr,options->getLifetime(),NSP_LIFE_TIME_LENGTH); 00107 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 00108 channel_list = options->getRadioChannelList(); 00109 00110 // WiFi Configration 00111 memcpy(wifi_ssid,options->getWiFiSSID().c_str(),options->getWiFiSSID().size()); 00112 wifi_auth_type = options->getWiFiAuthType(); 00113 memcpy(wifi_auth_key,options->getWiFiAuthKey().c_str(),options->getWiFiAuthKey().size()); 00114 00115 // 802.15.4 Configuration 00116 memcpy(mesh_network_id,options->getNetworkID().c_str(),options->getNetworkID().size()); 00117 rf_channel = options->getRadioChannel(); 00118 00119 // DONE 00120 logger.log("utils_configure_endpoint: endpoint configuration completed."); 00121 } 00122 00123 // initialize and register the endpoint and its resources 00124 void utils_init_and_register_endpoint(void) 00125 { 00126 // initialize NSDL 00127 logger.log("net_stubs_post_plumb_network: initializing NSP..\r\n."); 00128 nsdl_init(); 00129 nsdl_set_nsp_address(); 00130 00131 // alloc Endpoint 00132 logger.log("utils_init_and_register_endpoint: allocating endpoint instance..."); 00133 if (endpoint == NULL) endpoint = new Connector::Endpoint(&logger,options); 00134 00135 // initialize Endpoint resources 00136 logger.log("utils_init_and_register_endpoint: registering endpoint and its resources..."); 00137 endpoint->register_endpoint(); 00138 }
Generated on Tue Jul 12 2022 15:15:35 by
1.7.2