added max-age and content-format
Fork of mbedConnectorInterface by
api/Utils.cpp@3:11b2f4e58378, 2015-01-28 (annotated)
- Committer:
- ansond
- Date:
- Wed Jan 28 11:52:09 2015 +0000
- Revision:
- 3:11b2f4e58378
- Parent:
- 2:853f9ecc12df
- Child:
- 4:84159d67d32d
updates to enable global modification of low level NSDL configuration
Who changed what in which revision?
User | Revision | Line number | New 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 | 3:11b2f4e58378 | 33 | uint8_t NSP_address_bytes[NSP_IP_ADDRESS_LENGTH] = NSP_IP_ADDRESS; // which MDS instance we want to bind to... |
ansond | 3:11b2f4e58378 | 34 | uint8_t endpoint_name[24] = NODE_NAME; // our NODE name |
ansond | 3:11b2f4e58378 | 35 | uint8_t ep_type[] = NSP_ENDPOINT_TYPE; // our NODE type |
ansond | 3:11b2f4e58378 | 36 | uint8_t lifetime_ptr[] = { NSP_LIFE_TIME }; // MDS lifetime |
ansond | 3:11b2f4e58378 | 37 | uint8_t app_MAC_address[NODE_MAC_ADDRESS_LENGTH] = NODE_MAC_ADDRESS; // Node MAC address |
ansond | 3:11b2f4e58378 | 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 | 3:11b2f4e58378 | 64 | |
ansond | 3:11b2f4e58378 | 65 | uint8_ t *tmp = options->getNSPAddress(); |
ansond | 3:11b2f4e58378 | 66 | |
ansond | 3:11b2f4e58378 | 67 | // with options, lets set the underlying NSDL globals... |
ansond | 3:11b2f4e58378 | 68 | logger.log("configure_endpoint: updating external NSDL globals..."); |
ansond | 3:11b2f4e58378 | 69 | NSP_address_bytes = options->getNSPAddress(); |
ansond | 3:11b2f4e58378 | 70 | endpoint_name = options->getEndpointNodename(); |
ansond | 3:11b2f4e58378 | 71 | ep_type = options->getEndpointType(); |
ansond | 3:11b2f4e58378 | 72 | lifetime_ptr = options->getLifetime(); |
ansond | 3:11b2f4e58378 | 73 | app_MAC_address = options->getMACAddress(); |
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 | } |