mbed Connector Endpoint interface. This interface permits a mbed endpoint to easily setup MDS resources and emit those resources to an MDS server.

Dependents:   IoT_LED_demo ServoTest uWater_Project hackathon ... more

Committer:
ansond
Date:
Tue Feb 03 06:51:34 2015 +0000
Revision:
14:5cfaeee144bc
Parent:
11:c1b2b4b6c341
Child:
16:383ad1356963
updates and now working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 1:cabdd0350707 1 /**
ansond 1:cabdd0350707 2 * @file Utils.cpp
ansond 1:cabdd0350707 3 * @brief mbed CoAP Endpoint misc utils collection
ansond 1:cabdd0350707 4 * @author Doug Anson
ansond 1:cabdd0350707 5 * @version 1.0
sam_grove 2:853f9ecc12df 6 * @see
ansond 1:cabdd0350707 7 *
ansond 1:cabdd0350707 8 * Copyright (c) 2014
ansond 1:cabdd0350707 9 *
ansond 1:cabdd0350707 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 1:cabdd0350707 11 * you may not use this file except in compliance with the License.
ansond 1:cabdd0350707 12 * You may obtain a copy of the License at
ansond 1:cabdd0350707 13 *
ansond 1:cabdd0350707 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 1:cabdd0350707 15 *
ansond 1:cabdd0350707 16 * Unless required by applicable law or agreed to in writing, software
ansond 1:cabdd0350707 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 1:cabdd0350707 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 1:cabdd0350707 19 * See the License for the specific language governing permissions and
ansond 1:cabdd0350707 20 * limitations under the License.
ansond 1:cabdd0350707 21 */
sam_grove 2:853f9ecc12df 22
ansond 1:cabdd0350707 23 // mbed Endpoint includes
ansond 8:b518d1c01df1 24 #include "ConnectorEndpoint.h"
ansond 1:cabdd0350707 25 #include "OptionsBuilder.h"
ansond 1:cabdd0350707 26
ansond 1:cabdd0350707 27 // External references (defined in main.cpp)
ansond 1:cabdd0350707 28 Connector::Options *configure_endpoint(Connector::OptionsBuilder &builder);
ansond 1:cabdd0350707 29 extern Logger logger;
ansond 1:cabdd0350707 30
ansond 3:11b2f4e58378 31 // ************************* NSDL Linkage - MDS CONFIGURATION (defaulted) *********************************
ansond 3:11b2f4e58378 32
ansond 4:84159d67d32d 33 uint8_t NSP_address_bytes[NSP_IP_ADDRESS_LENGTH] = NSP_IP_ADDRESS; // which MDS instance we want to bind to...
ansond 4:84159d67d32d 34 uint8_t endpoint_name[NODE_NAME_LENGTH] = NODE_NAME; // our NODE name
ansond 6:516a88842a2b 35 uint8_t domain_name[NSP_DOMAIN_LENGTH] = NSP_DOMAIN; // our MDS domain name
ansond 11:c1b2b4b6c341 36 int nsp_port = NSP_COAP_UDP_PORT; // our MDS UDP port
ansond 4:84159d67d32d 37 uint8_t ep_type[NSP_ENDPOINT_TYPE_LENGTH] = NSP_ENDPOINT_TYPE; // our NODE type
ansond 4:84159d67d32d 38 uint8_t lifetime_ptr[NSP_LIFE_TIME_LENGTH] = { NSP_LIFE_TIME }; // NSDL lifetime
ansond 4:84159d67d32d 39 uint8_t app_MAC_address[NODE_MAC_ADDRESS_LENGTH] = NODE_MAC_ADDRESS; // Node MAC address
ansond 4:84159d67d32d 40 uint32_t channel_list = NODE_CHANNEL_LIST; // Node RF Channel list
ansond 3:11b2f4e58378 41
ansond 3:11b2f4e58378 42 // ************************* NSDL Linkage - MDS CONFIGURATION (defaulted) *********************************
ansond 3:11b2f4e58378 43
ansond 3:11b2f4e58378 44
ansond 1:cabdd0350707 45 // further simplifies the endpoint main() configuration by removing the final initialization details of the endpoint...
sam_grove 2:853f9ecc12df 46 void configure_endpoint()
ansond 3:11b2f4e58378 47 {
ansond 3:11b2f4e58378 48 // NSP/NSDL default configuration - see mbedConnectorInterface.h for definitions...
ansond 3:11b2f4e58378 49 logger.log("configure_endpoint: setting defaults...");
ansond 3:11b2f4e58378 50 Connector::OptionsBuilder config;
ansond 3:11b2f4e58378 51 config.setNSPAddress(NSP_address_bytes);
ansond 3:11b2f4e58378 52 config.setNSPPortNumber(NSP_COAP_UDP_PORT);
ansond 3:11b2f4e58378 53 config.setDomain(NSP_DOMAIN);
ansond 14:5cfaeee144bc 54 config.setEndpointNodename(NODE_NAME);
ansond 3:11b2f4e58378 55 config.setEndpointType(NSP_ENDPOINT_TYPE);
ansond 3:11b2f4e58378 56 config.setLifetime(NSP_LIFE_TIME);
ansond 3:11b2f4e58378 57
ansond 3:11b2f4e58378 58 // Node default configuration - see mbedConnectorInterface.h for definitions...
ansond 3:11b2f4e58378 59 config.setRadioChannelList(NODE_CHANNEL_LIST);
ansond 3:11b2f4e58378 60 config.setReadUpdatePeriod(NSP_RD_UPDATE_PERIOD);
ansond 3:11b2f4e58378 61 config.setEndpointNodename(NODE_NAME);
ansond 5:a929d65eb385 62 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
ansond 3:11b2f4e58378 63
ansond 3:11b2f4e58378 64 // main.cpp can override or change any of the above defaults...
ansond 3:11b2f4e58378 65 logger.log("configure_endpoint: enabling default configuration overrides...");
ansond 3:11b2f4e58378 66 Connector::Options *options = configure_endpoint(config);
ansond 4:84159d67d32d 67
ansond 3:11b2f4e58378 68 // with options, lets set the underlying NSDL globals...
ansond 3:11b2f4e58378 69 logger.log("configure_endpoint: updating external NSDL globals...");
ansond 4:84159d67d32d 70 memcpy(NSP_address_bytes,options->getNSPAddress(),NSP_IP_ADDRESS_LENGTH);
ansond 7:09c5d9ae56cb 71 memcpy(endpoint_name,options->getEndpointNodename().c_str(),options->getEndpointNodename().size());
ansond 7:09c5d9ae56cb 72 memcpy(domain_name,options->getDomain().c_str(),options->getDomain().size());
ansond 11:c1b2b4b6c341 73 nsp_port = options->getNSPPortNumber();
ansond 7:09c5d9ae56cb 74 memcpy(ep_type,options->getEndpointType().c_str(),options->getEndpointType().size());
ansond 4:84159d67d32d 75 memcpy(lifetime_ptr,options->getLifetime(),NSP_LIFE_TIME_LENGTH);
ansond 5:a929d65eb385 76 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
ansond 3:11b2f4e58378 77 channel_list = options->getRadioChannelList();
sam_grove 2:853f9ecc12df 78
ansond 3:11b2f4e58378 79 // alloc Endpoint
ansond 3:11b2f4e58378 80 logger.log("configure_endpoint: allocating endpoint...");
ansond 1:cabdd0350707 81 Connector::Endpoint endpoint(&logger,options);
sam_grove 2:853f9ecc12df 82
ansond 3:11b2f4e58378 83 // initialize Endpoint resources
ansond 3:11b2f4e58378 84 logger.log("configure_endpoint: binding endpoint resources...");
sam_grove 2:853f9ecc12df 85 endpoint.initialize();
sam_grove 2:853f9ecc12df 86
ansond 1:cabdd0350707 87 // DONE
ansond 3:11b2f4e58378 88 logger.log("configure_endpoint: endpoint setup complete.");
sam_grove 2:853f9ecc12df 89 }