mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface

Committer:
ansond
Date:
Fri Feb 19 17:32:14 2016 +0000
Revision:
0:1f1f55e73248
Child:
1:16f0fb5b8d97
initial checkin

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:1f1f55e73248 1 /**
ansond 0:1f1f55e73248 2 * @file Utils.cpp
ansond 0:1f1f55e73248 3 * @brief mbed CoAP Endpoint misc utils collection
ansond 0:1f1f55e73248 4 * @author Doug Anson
ansond 0:1f1f55e73248 5 * @version 1.0
ansond 0:1f1f55e73248 6 * @see
ansond 0:1f1f55e73248 7 *
ansond 0:1f1f55e73248 8 * Copyright (c) 2014
ansond 0:1f1f55e73248 9 *
ansond 0:1f1f55e73248 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 0:1f1f55e73248 11 * you may not use this file except in compliance with the License.
ansond 0:1f1f55e73248 12 * You may obtain a copy of the License at
ansond 0:1f1f55e73248 13 *
ansond 0:1f1f55e73248 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 0:1f1f55e73248 15 *
ansond 0:1f1f55e73248 16 * Unless required by applicable law or agreed to in writing, software
ansond 0:1f1f55e73248 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 0:1f1f55e73248 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 0:1f1f55e73248 19 * See the License for the specific language governing permissions and
ansond 0:1f1f55e73248 20 * limitations under the License.
ansond 0:1f1f55e73248 21 */
ansond 0:1f1f55e73248 22
ansond 0:1f1f55e73248 23 // mbed Endpoint includes
ansond 0:1f1f55e73248 24 #include "mbed-connector-interface/ConnectorEndpoint.h"
ansond 0:1f1f55e73248 25 #include "mbed-connector-interface/OptionsBuilder.h"
ansond 0:1f1f55e73248 26
ansond 0:1f1f55e73248 27 // External references (defined in main.cpp)
ansond 0:1f1f55e73248 28 Connector::Options *configure_endpoint(Connector::OptionsBuilder &builder);
ansond 0:1f1f55e73248 29 extern Logger logger;
ansond 0:1f1f55e73248 30
ansond 0:1f1f55e73248 31 // Our Endpoint
ansond 0:1f1f55e73248 32 Connector::Endpoint *__endpoint = NULL;
ansond 0:1f1f55e73248 33
ansond 0:1f1f55e73248 34 // Our Endpoint configured Options
ansond 0:1f1f55e73248 35 Connector::OptionsBuilder config;
ansond 0:1f1f55e73248 36 Connector::Options *options = NULL;
ansond 0:1f1f55e73248 37
ansond 0:1f1f55e73248 38 // Shutdown button (K64F only...)
ansond 0:1f1f55e73248 39 #if defined(TARGET_K64F)
ansond 0:1f1f55e73248 40 InterruptIn shutdown_button(SW3);
ansond 0:1f1f55e73248 41 #endif
ansond 0:1f1f55e73248 42
ansond 0:1f1f55e73248 43 // ************************* NSDL Linkage - MDS CONFIGURATION (defaulted) *********************************
ansond 0:1f1f55e73248 44
ansond 0:1f1f55e73248 45 uint8_t app_MAC_address[NODE_MAC_ADDRESS_LENGTH] = NODE_MAC_ADDRESS; // Node MAC address
ansond 0:1f1f55e73248 46 uint32_t channel_list = NODE_CHANNEL_LIST; // Node RF Channel list
ansond 0:1f1f55e73248 47
ansond 0:1f1f55e73248 48 uint8_t mesh_network_id[MESH_NETWORK_ID_LENGTH] = MESH_DEF_NETWORK_ID; // 802.15.4 Network ID (6LowPAN)
ansond 0:1f1f55e73248 49 uint8_t rf_channel = MESH_DEF_RF_CHANNEL; // 802.15.4 RF Channel (6LowPAN)
ansond 0:1f1f55e73248 50
ansond 0:1f1f55e73248 51 // ************************* NSDL Linkage - MDS CONFIGURATION (defaulted) *********************************
ansond 0:1f1f55e73248 52
ansond 0:1f1f55e73248 53 // further simplifies the endpoint main() configuration by removing the final initialization details of the endpoint...
ansond 0:1f1f55e73248 54 void utils_configure_endpoint(void)
ansond 0:1f1f55e73248 55 {
ansond 0:1f1f55e73248 56 // NSP/NSDL default configuration - see mbedConnectorInterface.h for definitions...
ansond 0:1f1f55e73248 57 logger.log("Endpoint: setting defaults...");
ansond 0:1f1f55e73248 58 config.setEndpointNodename(NODE_NAME);
ansond 0:1f1f55e73248 59 config.setEndpointType(NSP_ENDPOINT_TYPE);
ansond 0:1f1f55e73248 60 config.setRegUpdatePeriod(REG_UPDATE_PERIOD_MS);
ansond 0:1f1f55e73248 61 config.setLifetime(REG_LIFETIME_SEC);
ansond 0:1f1f55e73248 62
ansond 0:1f1f55e73248 63 // WiFi defaults
ansond 0:1f1f55e73248 64 config.setWiFiSSID((char *)WIFI_DEFAULT_SSID); // default: changeme
ansond 0:1f1f55e73248 65 config.setWiFiAuthType(WIFI_WPA_PERSONAL); // default: WPA Personal
ansond 0:1f1f55e73248 66 config.setWiFiAuthKey((char *)WIFI_DEFAULT_AUTH_KEY); // default: changeme
ansond 0:1f1f55e73248 67
ansond 0:1f1f55e73248 68 // 802.15.4 defaults (6LowPAN)
ansond 0:1f1f55e73248 69 config.setNetworkID((char *)mesh_network_id);
ansond 0:1f1f55e73248 70 config.setRadioChannel((int)mesh_network_id);
ansond 0:1f1f55e73248 71 config.setRadioChannelList(NODE_CHANNEL_LIST);
ansond 0:1f1f55e73248 72 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 0:1f1f55e73248 73
ansond 0:1f1f55e73248 74 // Establish default CoAP observation behavior
ansond 0:1f1f55e73248 75 config.setImmedateObservationEnabled(true);
ansond 0:1f1f55e73248 76
ansond 0:1f1f55e73248 77 // Establish default CoAP GET-based observation control behavior
ansond 0:1f1f55e73248 78 config.setEnableGETObservationControl(false);
ansond 0:1f1f55e73248 79
ansond 0:1f1f55e73248 80 // main.cpp can override or change any of the above defaults...
ansond 0:1f1f55e73248 81 logger.log("Endpoint: gathering configuration overrides...");
ansond 0:1f1f55e73248 82 options = configure_endpoint(config);
ansond 0:1f1f55e73248 83
ansond 0:1f1f55e73248 84 // DONE
ansond 0:1f1f55e73248 85 logger.log("Endpoint: endpoint configuration completed.");
ansond 0:1f1f55e73248 86 }
ansond 0:1f1f55e73248 87
ansond 0:1f1f55e73248 88 // setup shutdown button (K64F only...)
ansond 0:1f1f55e73248 89 #if defined(TARGET_K64F)
ansond 0:1f1f55e73248 90 void utils_setup_deregistration_button(void) {
ansond 0:1f1f55e73248 91 if (__endpoint != NULL) {
ansond 0:1f1f55e73248 92 logger.log("Endpoint: setting up shutdown button (SW2) for K64F...");
ansond 0:1f1f55e73248 93 shutdown_button.rise(__endpoint,&Connector::Endpoint::closedown_endpoint);
ansond 0:1f1f55e73248 94 }
ansond 0:1f1f55e73248 95 }
ansond 0:1f1f55e73248 96 #endif
ansond 0:1f1f55e73248 97
ansond 0:1f1f55e73248 98 // initialize and register the endpoint and its resources
ansond 0:1f1f55e73248 99 void utils_init_and_register_endpoint(void)
ansond 0:1f1f55e73248 100 {
ansond 0:1f1f55e73248 101 // alloc Endpoint
ansond 0:1f1f55e73248 102 logger.log("Endpoint: allocating endpoint instance...");
ansond 0:1f1f55e73248 103 if (__endpoint == NULL) __endpoint = new Connector::Endpoint(&logger,options);
ansond 0:1f1f55e73248 104
ansond 0:1f1f55e73248 105 // initialize Endpoint resources
ansond 0:1f1f55e73248 106 logger.log("Endpoint: registering endpoint and its resources...");
ansond 0:1f1f55e73248 107 __endpoint->register_endpoint();
ansond 0:1f1f55e73248 108
ansond 0:1f1f55e73248 109 // setup the shutdown button (K64F only...)
ansond 0:1f1f55e73248 110 #if defined(TARGET_K64F)
ansond 0:1f1f55e73248 111 utils_setup_deregistration_button();
ansond 0:1f1f55e73248 112 #endif
ansond 0:1f1f55e73248 113 }
ansond 0:1f1f55e73248 114