Dreamforce 2015 BLE-based mDS HeartRate Monitor Endpoint
Dependencies: GroveEarbudSensor mbed mbedConnectorInterface mbedEndpointNetwork_BLE
main.cpp@42:9741365cff35, 2015-07-25 (annotated)
- Committer:
- ansond
- Date:
- Sat Jul 25 20:42:45 2015 +0000
- Revision:
- 42:9741365cff35
- Parent:
- 41:b135f327b28c
- Child:
- 43:0c80682b673d
updated and added BLE Location
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 | 37:55a66b48199a | 36 | // Only Nordic boards are supported... |
ansond | 5:4609a86755be | 37 | #ifdef TARGET_NRF51_DK |
ansond | 5:4609a86755be | 38 | #define NORDIC_MODEL "nRF51822-DK" |
ansond | 39:45355870bead | 39 | #define MY_ENDPOINT_NAME "mbed-ble-hrm-dk" |
ansond | 38:80c070ecdb64 | 40 | #define NORDIC_SDA SDA |
ansond | 38:80c070ecdb64 | 41 | #define NORDIC_SCL SCL |
ansond | 2:9d7c4bad311e | 42 | #endif |
ansond | 5:4609a86755be | 43 | #ifdef TARGET_NRF51_DONGLE |
ansond | 5:4609a86755be | 44 | #define NORDIC_MODEL "nRF51822-DONGLE" |
ansond | 39:45355870bead | 45 | #define MY_ENDPOINT_NAME "mbed-ble-hrm-dongle" |
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 | 39:45355870bead | 51 | #define MY_ENDPOINT_NAME "mbed-ble-hrm-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 | 42:9741365cff35 | 75 | // Location Resource |
ansond | 42:9741365cff35 | 76 | #include "LocationResource.h" |
ansond | 42:9741365cff35 | 77 | LocationResource location(&logger,"999/0/1234",true); // observable |
ansond | 42:9741365cff35 | 78 | |
ansond | 0:6b414fe5f8db | 79 | // My NSP Domain |
ansond | 37:55a66b48199a | 80 | #define MY_NSP_DOMAIN "domain" |
ansond | 0:6b414fe5f8db | 81 | |
ansond | 37:55a66b48199a | 82 | // Customization Example: My custom NSP IPv4 address and NSP CoAP port |
ansond | 42:9741365cff35 | 83 | uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {23,99,29,171}; // connector (api.connector.mbed.org) |
ansond | 35:4adef21fd8b6 | 84 | int my_nsp_coap_port = 5683; |
ansond | 0:6b414fe5f8db | 85 | |
ansond | 0:6b414fe5f8db | 86 | // called from the Endpoint::start() below to create resources and the endpoint internals... |
ansond | 0:6b414fe5f8db | 87 | Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) |
ansond | 0:6b414fe5f8db | 88 | { |
ansond | 0:6b414fe5f8db | 89 | // Build the endpoint configuration parameters |
ansond | 0:6b414fe5f8db | 90 | logger.log("configure_endpoint: building endpoint configuration..."); |
ansond | 0:6b414fe5f8db | 91 | return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name |
ansond | 0:6b414fe5f8db | 92 | .setNSPAddress(my_nsp_address) // custom NSP address |
ansond | 0:6b414fe5f8db | 93 | .setDomain(MY_NSP_DOMAIN) // custom NSP domain |
ansond | 0:6b414fe5f8db | 94 | .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port |
ansond | 0:6b414fe5f8db | 95 | |
ansond | 35:4adef21fd8b6 | 96 | // enable or disable(default) immediate observationing control |
ansond | 35:4adef21fd8b6 | 97 | .setImmedateObservationEnabled(true) |
ansond | 35:4adef21fd8b6 | 98 | |
ansond | 35:4adef21fd8b6 | 99 | // enable or disable(default) GET-based observation control |
ansond | 35:4adef21fd8b6 | 100 | .setEnableGETObservationControl(false) |
ansond | 35:4adef21fd8b6 | 101 | |
ansond | 0:6b414fe5f8db | 102 | // add the static resource representing this endpoint |
ansond | 0:6b414fe5f8db | 103 | .addResource(&mfg) |
ansond | 0:6b414fe5f8db | 104 | .addResource(&model) |
ansond | 0:6b414fe5f8db | 105 | |
ansond | 0:6b414fe5f8db | 106 | // add the heartrate resource |
ansond | 42:9741365cff35 | 107 | .addResource(&hr) // Resource implements its own observationing... |
ansond | 42:9741365cff35 | 108 | .addResource(&location,30000) // observe every 30 seconds |
ansond | 0:6b414fe5f8db | 109 | |
ansond | 0:6b414fe5f8db | 110 | // finalize the configuration... |
ansond | 0:6b414fe5f8db | 111 | .build(); |
ansond | 0:6b414fe5f8db | 112 | } |
ansond | 0:6b414fe5f8db | 113 | |
ansond | 0:6b414fe5f8db | 114 | // main entry point... |
ansond | 0:6b414fe5f8db | 115 | int main() |
ansond | 0:6b414fe5f8db | 116 | { |
ansond | 0:6b414fe5f8db | 117 | // Announce |
ansond | 0:6b414fe5f8db | 118 | logger.log("\r\n\r\nmbed mDS BLE Heartrate Endpoint"); |
ansond | 0:6b414fe5f8db | 119 | |
ansond | 0:6b414fe5f8db | 120 | // we have to plumb our network first |
ansond | 0:6b414fe5f8db | 121 | Connector::Endpoint::plumbNetwork(); |
ansond | 0:6b414fe5f8db | 122 | |
ansond | 0:6b414fe5f8db | 123 | // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events... |
ansond | 0:6b414fe5f8db | 124 | logger.log("Start the endpoint to finish setup and enter the main loop..."); |
ansond | 0:6b414fe5f8db | 125 | Connector::Endpoint::start(); |
ansond | 5:4609a86755be | 126 | } |