Dreamforce 2015 BLE-based mDS HeartRate Monitor Endpoint
Dependencies: GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork_BLE
main.cpp@35:4adef21fd8b6, 2015-05-13 (annotated)
- Committer:
- ansond
- Date:
- Wed May 13 14:32:08 2015 +0000
- Revision:
- 35:4adef21fd8b6
- Parent:
- 26:9538393569fa
- Child:
- 37:55a66b48199a
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 0:6b414fe5f8db | 1 | /** |
ansond | 0:6b414fe5f8db | 2 | * @file main.cpp |
ansond | 0:6b414fe5f8db | 3 | * @brief mbed Connected Home Endpoint main entry point |
ansond | 0:6b414fe5f8db | 4 | * @author Doug Anson |
ansond | 0:6b414fe5f8db | 5 | * @version 1.0 |
ansond | 0:6b414fe5f8db | 6 | * @see |
ansond | 0:6b414fe5f8db | 7 | * |
ansond | 0:6b414fe5f8db | 8 | * Copyright (c) 2014 |
ansond | 0:6b414fe5f8db | 9 | * |
ansond | 0:6b414fe5f8db | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
ansond | 0:6b414fe5f8db | 11 | * you may not use this file except in compliance with the License. |
ansond | 0:6b414fe5f8db | 12 | * You may obtain a copy of the License at |
ansond | 0:6b414fe5f8db | 13 | * |
ansond | 0:6b414fe5f8db | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
ansond | 0:6b414fe5f8db | 15 | * |
ansond | 0:6b414fe5f8db | 16 | * Unless required by applicable law or agreed to in writing, software |
ansond | 0:6b414fe5f8db | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
ansond | 0:6b414fe5f8db | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
ansond | 0:6b414fe5f8db | 19 | * See the License for the specific language governing permissions and |
ansond | 0:6b414fe5f8db | 20 | * limitations under the License. |
ansond | 0:6b414fe5f8db | 21 | */ |
ansond | 0:6b414fe5f8db | 22 | |
ansond | 0:6b414fe5f8db | 23 | // mbed Connector Interface (configuration) |
ansond | 0:6b414fe5f8db | 24 | #include "mbedConnectorInterface.h" |
ansond | 0:6b414fe5f8db | 25 | |
ansond | 0:6b414fe5f8db | 26 | // mbed Connector Endpoint includes |
ansond | 0:6b414fe5f8db | 27 | #include "ConnectorEndpoint.h" |
ansond | 0:6b414fe5f8db | 28 | #include "OptionsBuilder.h" |
ansond | 0:6b414fe5f8db | 29 | |
ansond | 0:6b414fe5f8db | 30 | // USB Serial port access for debugging/logging |
ansond | 0:6b414fe5f8db | 31 | RawSerial pc(USBTX,USBRX); |
ansond | 0:6b414fe5f8db | 32 | |
ansond | 0:6b414fe5f8db | 33 | // Logging facility |
ansond | 0:6b414fe5f8db | 34 | Logger logger(&pc); |
ansond | 0:6b414fe5f8db | 35 | |
ansond | 5:4609a86755be | 36 | // which Nordic board? |
ansond | 5:4609a86755be | 37 | #ifdef TARGET_NRF51_DK |
ansond | 5:4609a86755be | 38 | #define NORDIC_MODEL "nRF51822-DK" |
ansond | 5:4609a86755be | 39 | #define MY_ENDPOINT_NAME "ble-hrm-endpt-dk" |
ansond | 6:759aab2880a7 | 40 | #define NORDIC_SDA P0_30 |
ansond | 6:759aab2880a7 | 41 | #define NORDIC_SCL P0_7 |
ansond | 2:9d7c4bad311e | 42 | #endif |
ansond | 5:4609a86755be | 43 | #ifdef TARGET_NRF51_DONGLE |
ansond | 5:4609a86755be | 44 | #define NORDIC_MODEL "nRF51822-DONGLE" |
ansond | 5:4609a86755be | 45 | #define MY_ENDPOINT_NAME "ble-hrm-endpt" |
ansond | 5:4609a86755be | 46 | #define NORDIC_SDA P0_20 |
ansond | 5:4609a86755be | 47 | #define NORDIC_SCL P0_19 |
ansond | 2:9d7c4bad311e | 48 | #endif |
ansond | 5:4609a86755be | 49 | #ifdef TARGET_NRF51_MKIT |
ansond | 5:4609a86755be | 50 | #define NORDIC_MODEL "nRF51822-MKIT" |
ansond | 5:4609a86755be | 51 | #define MY_ENDPOINT_NAME "ble-hrm-endpt-mkit" |
ansond | 5:4609a86755be | 52 | #define NORDIC_SDA P0_22 |
ansond | 5:4609a86755be | 53 | #define NORDIC_SCL P0_20 |
ansond | 2:9d7c4bad311e | 54 | #endif |
ansond | 2:9d7c4bad311e | 55 | |
ansond | 0:6b414fe5f8db | 56 | // Static Resources |
ansond | 0:6b414fe5f8db | 57 | #include "StaticResource.h" |
ansond | 0:6b414fe5f8db | 58 | StaticResource mfg(&logger,"dev/mfg","Nordic Semi"); |
ansond | 2:9d7c4bad311e | 59 | StaticResource model(&logger,"dev/mdl",NORDIC_MODEL); |
ansond | 0:6b414fe5f8db | 60 | |
ansond | 0:6b414fe5f8db | 61 | // |
ansond | 0:6b414fe5f8db | 62 | // Dynamic Resource Note: |
ansond | 0:6b414fe5f8db | 63 | // |
ansond | 0:6b414fe5f8db | 64 | // mbedConnectorInterface supports up to IPT_MAX_ENTRIES |
ansond | 0:6b414fe5f8db | 65 | // (currently 5) independent dynamic resources. |
ansond | 0:6b414fe5f8db | 66 | // |
ansond | 0:6b414fe5f8db | 67 | // You can increase this (at the cost of memory) in |
ansond | 0:6b414fe5f8db | 68 | // mbedConnectorinterface.h |
ansond | 0:6b414fe5f8db | 69 | // |
ansond | 0:6b414fe5f8db | 70 | |
ansond | 0:6b414fe5f8db | 71 | // Heartrate Resource |
ansond | 0:6b414fe5f8db | 72 | #include "HeartrateResource.h" |
ansond | 3:b0eb973cddda | 73 | HeartrateResource hr(&logger,"888/0/5850",true); // observable |
ansond | 0:6b414fe5f8db | 74 | |
ansond | 0:6b414fe5f8db | 75 | // My NSP Domain |
ansond | 0:6b414fe5f8db | 76 | #define MY_NSP_DOMAIN "domain" |
ansond | 0:6b414fe5f8db | 77 | |
ansond | 35:4adef21fd8b6 | 78 | // Point my BLE-based Endpoint towards mDS running in Azure - 70.37.91.233 |
ansond | 35:4adef21fd8b6 | 79 | uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {70,37,91,233}; |
ansond | 35:4adef21fd8b6 | 80 | int my_nsp_coap_port = 5683; |
ansond | 0:6b414fe5f8db | 81 | |
ansond | 0:6b414fe5f8db | 82 | |
ansond | 0:6b414fe5f8db | 83 | // called from the Endpoint::start() below to create resources and the endpoint internals... |
ansond | 0:6b414fe5f8db | 84 | Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) |
ansond | 0:6b414fe5f8db | 85 | { |
ansond | 0:6b414fe5f8db | 86 | // Build the endpoint configuration parameters |
ansond | 0:6b414fe5f8db | 87 | logger.log("configure_endpoint: building endpoint configuration..."); |
ansond | 0:6b414fe5f8db | 88 | return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name |
ansond | 0:6b414fe5f8db | 89 | .setNSPAddress(my_nsp_address) // custom NSP address |
ansond | 0:6b414fe5f8db | 90 | .setDomain(MY_NSP_DOMAIN) // custom NSP domain |
ansond | 0:6b414fe5f8db | 91 | .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port |
ansond | 0:6b414fe5f8db | 92 | |
ansond | 35:4adef21fd8b6 | 93 | // enable or disable(default) immediate observationing control |
ansond | 35:4adef21fd8b6 | 94 | .setImmedateObservationEnabled(true) |
ansond | 35:4adef21fd8b6 | 95 | |
ansond | 35:4adef21fd8b6 | 96 | // enable or disable(default) GET-based observation control |
ansond | 35:4adef21fd8b6 | 97 | .setEnableGETObservationControl(false) |
ansond | 35:4adef21fd8b6 | 98 | |
ansond | 0:6b414fe5f8db | 99 | // add the static resource representing this endpoint |
ansond | 0:6b414fe5f8db | 100 | .addResource(&mfg) |
ansond | 0:6b414fe5f8db | 101 | .addResource(&model) |
ansond | 0:6b414fe5f8db | 102 | |
ansond | 0:6b414fe5f8db | 103 | // add the heartrate resource |
ansond | 26:9538393569fa | 104 | .addResource(&hr) // Resource implements its own observationing... |
ansond | 0:6b414fe5f8db | 105 | |
ansond | 0:6b414fe5f8db | 106 | // finalize the configuration... |
ansond | 0:6b414fe5f8db | 107 | .build(); |
ansond | 0:6b414fe5f8db | 108 | } |
ansond | 0:6b414fe5f8db | 109 | |
ansond | 0:6b414fe5f8db | 110 | // main entry point... |
ansond | 0:6b414fe5f8db | 111 | int main() |
ansond | 0:6b414fe5f8db | 112 | { |
ansond | 0:6b414fe5f8db | 113 | // Announce |
ansond | 0:6b414fe5f8db | 114 | logger.log("\r\n\r\nmbed mDS BLE Heartrate Endpoint"); |
ansond | 0:6b414fe5f8db | 115 | |
ansond | 0:6b414fe5f8db | 116 | // we have to plumb our network first |
ansond | 0:6b414fe5f8db | 117 | Connector::Endpoint::plumbNetwork(); |
ansond | 0:6b414fe5f8db | 118 | |
ansond | 0:6b414fe5f8db | 119 | // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events... |
ansond | 0:6b414fe5f8db | 120 | logger.log("Start the endpoint to finish setup and enter the main loop..."); |
ansond | 0:6b414fe5f8db | 121 | Connector::Endpoint::start(); |
ansond | 5:4609a86755be | 122 | } |