custom for >5 resources

Fork of mbedConnectorInterface by Doug Anson

Committer:
ansond
Date:
Sun Feb 01 14:54:18 2015 +0000
Revision:
8:b518d1c01df1
Parent:
7:09c5d9ae56cb
Child:
11:c1b2b4b6c341
renamed endpoint files due to name collisions in mbed network stack

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 4:84159d67d32d 36 uint8_t ep_type[NSP_ENDPOINT_TYPE_LENGTH] = NSP_ENDPOINT_TYPE; // our NODE type
ansond 4:84159d67d32d 37 uint8_t lifetime_ptr[NSP_LIFE_TIME_LENGTH] = { NSP_LIFE_TIME }; // NSDL lifetime
ansond 4:84159d67d32d 38 uint8_t app_MAC_address[NODE_MAC_ADDRESS_LENGTH] = NODE_MAC_ADDRESS; // Node MAC address
ansond 4:84159d67d32d 39 uint32_t channel_list = NODE_CHANNEL_LIST; // Node RF Channel list
ansond 3:11b2f4e58378 40
ansond 3:11b2f4e58378 41 // ************************* NSDL Linkage - MDS CONFIGURATION (defaulted) *********************************
ansond 3:11b2f4e58378 42
ansond 3:11b2f4e58378 43
ansond 1:cabdd0350707 44 // further simplifies the endpoint main() configuration by removing the final initialization details of the endpoint...
sam_grove 2:853f9ecc12df 45 void configure_endpoint()
ansond 3:11b2f4e58378 46 {
ansond 3:11b2f4e58378 47 // NSP/NSDL default configuration - see mbedConnectorInterface.h for definitions...
ansond 3:11b2f4e58378 48 logger.log("configure_endpoint: setting defaults...");
ansond 3:11b2f4e58378 49 Connector::OptionsBuilder config;
ansond 3:11b2f4e58378 50 config.setNSPAddress(NSP_address_bytes);
ansond 3:11b2f4e58378 51 config.setNSPPortNumber(NSP_COAP_UDP_PORT);
ansond 3:11b2f4e58378 52 config.setDomain(NSP_DOMAIN);
ansond 3:11b2f4e58378 53 config.setEndpointType(NSP_ENDPOINT_TYPE);
ansond 3:11b2f4e58378 54 config.setLifetime(NSP_LIFE_TIME);
ansond 3:11b2f4e58378 55
ansond 3:11b2f4e58378 56 // Node default configuration - see mbedConnectorInterface.h for definitions...
ansond 3:11b2f4e58378 57 config.setRadioChannelList(NODE_CHANNEL_LIST);
ansond 3:11b2f4e58378 58 config.setReadUpdatePeriod(NSP_RD_UPDATE_PERIOD);
ansond 3:11b2f4e58378 59 config.setEndpointNodename(NODE_NAME);
ansond 5:a929d65eb385 60 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 61
ansond 3:11b2f4e58378 62 // main.cpp can override or change any of the above defaults...
ansond 3:11b2f4e58378 63 logger.log("configure_endpoint: enabling default configuration overrides...");
ansond 3:11b2f4e58378 64 Connector::Options *options = configure_endpoint(config);
ansond 4:84159d67d32d 65
ansond 3:11b2f4e58378 66 // with options, lets set the underlying NSDL globals...
ansond 3:11b2f4e58378 67 logger.log("configure_endpoint: updating external NSDL globals...");
ansond 4:84159d67d32d 68 memcpy(NSP_address_bytes,options->getNSPAddress(),NSP_IP_ADDRESS_LENGTH);
ansond 7:09c5d9ae56cb 69 memcpy(endpoint_name,options->getEndpointNodename().c_str(),options->getEndpointNodename().size());
ansond 7:09c5d9ae56cb 70 memcpy(domain_name,options->getDomain().c_str(),options->getDomain().size());
ansond 7:09c5d9ae56cb 71 memcpy(ep_type,options->getEndpointType().c_str(),options->getEndpointType().size());
ansond 4:84159d67d32d 72 memcpy(lifetime_ptr,options->getLifetime(),NSP_LIFE_TIME_LENGTH);
ansond 5:a929d65eb385 73 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 74 channel_list = options->getRadioChannelList();
sam_grove 2:853f9ecc12df 75
ansond 3:11b2f4e58378 76 // alloc Endpoint
ansond 3:11b2f4e58378 77 logger.log("configure_endpoint: allocating endpoint...");
ansond 1:cabdd0350707 78 Connector::Endpoint endpoint(&logger,options);
sam_grove 2:853f9ecc12df 79
ansond 3:11b2f4e58378 80 // initialize Endpoint resources
ansond 3:11b2f4e58378 81 logger.log("configure_endpoint: binding endpoint resources...");
sam_grove 2:853f9ecc12df 82 endpoint.initialize();
sam_grove 2:853f9ecc12df 83
ansond 1:cabdd0350707 84 // DONE
ansond 3:11b2f4e58378 85 logger.log("configure_endpoint: endpoint setup complete.");
sam_grove 2:853f9ecc12df 86 }