mbed Connector Interface simplification API on top of mbed-client
Fork of mbedConnectorInterfaceV3 by
NOTE:
This repo has been replaced with https://github.com/ARMmbed/mbedConnectorInterface. No further updates will occur with this repo. Please use the github repo instead. Thanks!
source/Utils.cpp@6:d4d1105a1777, 2016-02-21 (annotated)
- Committer:
- ansond
- Date:
- Sun Feb 21 18:48:07 2016 +0000
- Revision:
- 6:d4d1105a1777
- Parent:
- 4:d9603064630c
- Child:
- 7:e94f0bd92545
updated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 1:16f0fb5b8d97 | 1 | /** |
ansond | 1:16f0fb5b8d97 | 2 | * @file Utils.cpp |
ansond | 1:16f0fb5b8d97 | 3 | * @brief mbed CoAP Endpoint misc utils collection |
ansond | 1:16f0fb5b8d97 | 4 | * @author Doug Anson |
ansond | 1:16f0fb5b8d97 | 5 | * @version 1.0 |
ansond | 1:16f0fb5b8d97 | 6 | * @see |
ansond | 1:16f0fb5b8d97 | 7 | * |
ansond | 1:16f0fb5b8d97 | 8 | * Copyright (c) 2014 |
ansond | 1:16f0fb5b8d97 | 9 | * |
ansond | 1:16f0fb5b8d97 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 1:16f0fb5b8d97 | 11 | * you may not use this file except in compliance with the License. |
ansond | 1:16f0fb5b8d97 | 12 | * You may obtain a copy of the License at |
ansond | 1:16f0fb5b8d97 | 13 | * |
ansond | 1:16f0fb5b8d97 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 1:16f0fb5b8d97 | 15 | * |
ansond | 1:16f0fb5b8d97 | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 1:16f0fb5b8d97 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 1:16f0fb5b8d97 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 1:16f0fb5b8d97 | 19 | * See the License for the specific language governing permissions and |
ansond | 1:16f0fb5b8d97 | 20 | * limitations under the License. |
ansond | 1:16f0fb5b8d97 | 21 | */ |
ansond | 1:16f0fb5b8d97 | 22 | |
ansond | 1:16f0fb5b8d97 | 23 | // mbed Endpoint includes |
ansond | 1:16f0fb5b8d97 | 24 | #include "mbed-connector-interface/ConnectorEndpoint.h" |
ansond | 1:16f0fb5b8d97 | 25 | #include "mbed-connector-interface/OptionsBuilder.h" |
ansond | 6:d4d1105a1777 | 26 | #include "mbed-connector-interface/mbedEndpointNetwork.h" |
ansond | 1:16f0fb5b8d97 | 27 | |
ansond | 1:16f0fb5b8d97 | 28 | // External references (defined in main.cpp) |
ansond | 1:16f0fb5b8d97 | 29 | Connector::Options *configure_endpoint(Connector::OptionsBuilder &builder); |
ansond | 1:16f0fb5b8d97 | 30 | extern Logger logger; |
ansond | 1:16f0fb5b8d97 | 31 | |
ansond | 1:16f0fb5b8d97 | 32 | // Our Endpoint configured Options |
ansond | 1:16f0fb5b8d97 | 33 | Connector::OptionsBuilder config; |
ansond | 1:16f0fb5b8d97 | 34 | Connector::Options *options = NULL; |
ansond | 1:16f0fb5b8d97 | 35 | |
ansond | 1:16f0fb5b8d97 | 36 | // ************************* NSDL Linkage - MDS CONFIGURATION (defaulted) ********************************* |
ansond | 1:16f0fb5b8d97 | 37 | |
ansond | 1:16f0fb5b8d97 | 38 | uint8_t app_MAC_address[NODE_MAC_ADDRESS_LENGTH] = NODE_MAC_ADDRESS; // Node MAC address |
ansond | 1:16f0fb5b8d97 | 39 | uint32_t channel_list = NODE_CHANNEL_LIST; // Node RF Channel list |
ansond | 1:16f0fb5b8d97 | 40 | |
ansond | 1:16f0fb5b8d97 | 41 | uint8_t mesh_network_id[MESH_NETWORK_ID_LENGTH] = MESH_DEF_NETWORK_ID; // 802.15.4 Network ID (6LowPAN) |
ansond | 1:16f0fb5b8d97 | 42 | uint8_t rf_channel = MESH_DEF_RF_CHANNEL; // 802.15.4 RF Channel (6LowPAN) |
ansond | 1:16f0fb5b8d97 | 43 | |
ansond | 1:16f0fb5b8d97 | 44 | // ************************* NSDL Linkage - MDS CONFIGURATION (defaulted) ********************************* |
ansond | 1:16f0fb5b8d97 | 45 | |
ansond | 1:16f0fb5b8d97 | 46 | // further simplifies the endpoint main() configuration by removing the final initialization details of the endpoint... |
ansond | 1:16f0fb5b8d97 | 47 | void utils_configure_endpoint(void *p) |
ansond | 1:16f0fb5b8d97 | 48 | { |
ansond | 1:16f0fb5b8d97 | 49 | // our Endpoint |
ansond | 1:16f0fb5b8d97 | 50 | Connector::Endpoint *ep = (Connector::Endpoint *)p; |
ansond | 1:16f0fb5b8d97 | 51 | |
ansond | 1:16f0fb5b8d97 | 52 | // NSP/NSDL default configuration - see mbedConnectorInterface.h for definitions... |
ansond | 1:16f0fb5b8d97 | 53 | logger.log("Endpoint: setting defaults..."); |
ansond | 1:16f0fb5b8d97 | 54 | config.setEndpointNodename(NODE_NAME); |
ansond | 1:16f0fb5b8d97 | 55 | config.setEndpointType(NSP_ENDPOINT_TYPE); |
ansond | 1:16f0fb5b8d97 | 56 | config.setRegUpdatePeriod(REG_UPDATE_PERIOD_MS); |
ansond | 1:16f0fb5b8d97 | 57 | config.setLifetime(REG_LIFETIME_SEC); |
ansond | 0:1f1f55e73248 | 58 | |
ansond | 1:16f0fb5b8d97 | 59 | // WiFi defaults |
ansond | 1:16f0fb5b8d97 | 60 | config.setWiFiSSID((char *)WIFI_DEFAULT_SSID); // default: changeme |
ansond | 1:16f0fb5b8d97 | 61 | config.setWiFiAuthType(WIFI_WPA_PERSONAL); // default: WPA Personal |
ansond | 1:16f0fb5b8d97 | 62 | config.setWiFiAuthKey((char *)WIFI_DEFAULT_AUTH_KEY); // default: changeme |
ansond | 1:16f0fb5b8d97 | 63 | |
ansond | 1:16f0fb5b8d97 | 64 | // 802.15.4 defaults (6LowPAN) |
ansond | 1:16f0fb5b8d97 | 65 | config.setNetworkID((char *)mesh_network_id); |
ansond | 1:16f0fb5b8d97 | 66 | config.setRadioChannel((int)mesh_network_id); |
ansond | 1:16f0fb5b8d97 | 67 | config.setRadioChannelList(NODE_CHANNEL_LIST); |
ansond | 1:16f0fb5b8d97 | 68 | 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 | 1:16f0fb5b8d97 | 69 | |
ansond | 1:16f0fb5b8d97 | 70 | // Establish default CoAP observation behavior |
ansond | 1:16f0fb5b8d97 | 71 | config.setImmedateObservationEnabled(true); |
ansond | 1:16f0fb5b8d97 | 72 | |
ansond | 1:16f0fb5b8d97 | 73 | // Establish default CoAP GET-based observation control behavior |
ansond | 1:16f0fb5b8d97 | 74 | config.setEnableGETObservationControl(false); |
ansond | 1:16f0fb5b8d97 | 75 | |
ansond | 1:16f0fb5b8d97 | 76 | // main.cpp can override or change any of the above defaults... |
ansond | 1:16f0fb5b8d97 | 77 | logger.log("Endpoint: gathering configuration overrides..."); |
ansond | 1:16f0fb5b8d97 | 78 | options = configure_endpoint(config); |
ansond | 1:16f0fb5b8d97 | 79 | ep->setOptions(options); |
ansond | 1:16f0fb5b8d97 | 80 | |
ansond | 1:16f0fb5b8d97 | 81 | // DONE |
ansond | 1:16f0fb5b8d97 | 82 | logger.log("Endpoint: endpoint configuration completed."); |
ansond | 1:16f0fb5b8d97 | 83 | } |
ansond | 1:16f0fb5b8d97 | 84 | |
ansond | 1:16f0fb5b8d97 | 85 | // initialize the Connector::Endpoint instance |
ansond | 1:16f0fb5b8d97 | 86 | void *utils_init_endpoint(bool canActAsRouterNode) { |
ansond | 1:16f0fb5b8d97 | 87 | // alloc Endpoint |
ansond | 1:16f0fb5b8d97 | 88 | logger.log("Endpoint: allocating endpoint instance..."); |
ansond | 1:16f0fb5b8d97 | 89 | Connector::Endpoint *ep = new Connector::Endpoint(&logger,options); |
ansond | 1:16f0fb5b8d97 | 90 | if (ep != NULL) { |
ansond | 1:16f0fb5b8d97 | 91 | ep->asRouterNode(canActAsRouterNode); |
ansond | 1:16f0fb5b8d97 | 92 | } |
ansond | 1:16f0fb5b8d97 | 93 | return (void *)ep; |
ansond | 1:16f0fb5b8d97 | 94 | } |
ansond | 1:16f0fb5b8d97 | 95 | |
ansond | 1:16f0fb5b8d97 | 96 | // register the endpoint and its resources |
ansond | 1:16f0fb5b8d97 | 97 | void utils_register_endpoint(void *p) |
ansond | 1:16f0fb5b8d97 | 98 | { |
ansond | 1:16f0fb5b8d97 | 99 | if (p != NULL) { |
ansond | 1:16f0fb5b8d97 | 100 | Connector::Endpoint *ep = (Connector::Endpoint *)p; |
ansond | 1:16f0fb5b8d97 | 101 | // initialize Endpoint resources |
ansond | 1:16f0fb5b8d97 | 102 | logger.log("Endpoint: registering endpoint and its resources..."); |
ansond | 1:16f0fb5b8d97 | 103 | ep->register_endpoint(); |
ansond | 1:16f0fb5b8d97 | 104 | |
ansond | 4:d9603064630c | 105 | // complete the registration |
ansond | 4:d9603064630c | 106 | logger.log("Completing Endpoint Registration"); |
ansond | 4:d9603064630c | 107 | ep->complete_endpoint_registration(ep->getServer(),ep->getObjectList()); |
ansond | 6:d4d1105a1777 | 108 | |
ansond | 6:d4d1105a1777 | 109 | // setup the shutdown button (if enabled for a given platform...) |
ansond | 6:d4d1105a1777 | 110 | net_setup_deregistration_button(p); |
ansond | 1:16f0fb5b8d97 | 111 | } |
ansond | 1:16f0fb5b8d97 | 112 | } |
ansond | 1:16f0fb5b8d97 | 113 |