added max-age and content-format

Fork of mbedConnectorInterface by Doug Anson

Committer:
ansond
Date:
Wed Jan 28 12:11:22 2015 +0000
Revision:
4:84159d67d32d
Parent:
3:11b2f4e58378
Child:
5:a929d65eb385
updates

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