fork of chris cause ide is stupid
Dependencies: Chainable_RGB_LED mbed mbedConnectorInterface mbedEndpointNetwork
Fork of Trail by
main.cpp@0:a7458d25d9c9, 2015-04-16 (annotated)
- Committer:
- michaeljkoster
- Date:
- Thu Apr 16 13:56:23 2015 +0000
- Revision:
- 0:a7458d25d9c9
- Child:
- 1:b96a11b680dc
Demo for class and hackathon
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
michaeljkoster | 0:a7458d25d9c9 | 1 | /** |
michaeljkoster | 0:a7458d25d9c9 | 2 | * @file main.cpp |
michaeljkoster | 0:a7458d25d9c9 | 3 | * @brief mbed Connected Home Endpoint main entry point |
michaeljkoster | 0:a7458d25d9c9 | 4 | * @author Doug Anson |
michaeljkoster | 0:a7458d25d9c9 | 5 | * @version 1.0 |
michaeljkoster | 0:a7458d25d9c9 | 6 | * @see |
michaeljkoster | 0:a7458d25d9c9 | 7 | * |
michaeljkoster | 0:a7458d25d9c9 | 8 | * Copyright (c) 2014 |
michaeljkoster | 0:a7458d25d9c9 | 9 | * |
michaeljkoster | 0:a7458d25d9c9 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
michaeljkoster | 0:a7458d25d9c9 | 11 | * you may not use this file except in compliance with the License. |
michaeljkoster | 0:a7458d25d9c9 | 12 | * You may obtain a copy of the License at |
michaeljkoster | 0:a7458d25d9c9 | 13 | * |
michaeljkoster | 0:a7458d25d9c9 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
michaeljkoster | 0:a7458d25d9c9 | 15 | * |
michaeljkoster | 0:a7458d25d9c9 | 16 | * Unless required by applicable law or agreed to in writing, software |
michaeljkoster | 0:a7458d25d9c9 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
michaeljkoster | 0:a7458d25d9c9 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michaeljkoster | 0:a7458d25d9c9 | 19 | * See the License for the specific language governing permissions and |
michaeljkoster | 0:a7458d25d9c9 | 20 | * limitations under the License. |
michaeljkoster | 0:a7458d25d9c9 | 21 | */ |
michaeljkoster | 0:a7458d25d9c9 | 22 | |
michaeljkoster | 0:a7458d25d9c9 | 23 | // mbed Connector Interface (configuration) |
michaeljkoster | 0:a7458d25d9c9 | 24 | #include "mbedConnectorInterface.h" |
michaeljkoster | 0:a7458d25d9c9 | 25 | |
michaeljkoster | 0:a7458d25d9c9 | 26 | // Ethernet Interface |
michaeljkoster | 0:a7458d25d9c9 | 27 | #include "EthernetInterface.h" |
michaeljkoster | 0:a7458d25d9c9 | 28 | EthernetInterface ethernet; |
michaeljkoster | 0:a7458d25d9c9 | 29 | |
michaeljkoster | 0:a7458d25d9c9 | 30 | // mbed Connector Endpoint includes |
michaeljkoster | 0:a7458d25d9c9 | 31 | #include "ConnectorEndpoint.h" |
michaeljkoster | 0:a7458d25d9c9 | 32 | #include "OptionsBuilder.h" |
michaeljkoster | 0:a7458d25d9c9 | 33 | |
michaeljkoster | 0:a7458d25d9c9 | 34 | // USB Serial port access for debugging/logging |
michaeljkoster | 0:a7458d25d9c9 | 35 | RawSerial pc(USBTX,USBRX); |
michaeljkoster | 0:a7458d25d9c9 | 36 | |
michaeljkoster | 0:a7458d25d9c9 | 37 | // Logging facility |
michaeljkoster | 0:a7458d25d9c9 | 38 | Logger logger(&pc); |
michaeljkoster | 0:a7458d25d9c9 | 39 | |
michaeljkoster | 0:a7458d25d9c9 | 40 | // Static Resources |
michaeljkoster | 0:a7458d25d9c9 | 41 | #include "StaticResource.h" |
michaeljkoster | 0:a7458d25d9c9 | 42 | StaticResource mfg(&logger,"3/0/0","Freescale"); |
michaeljkoster | 0:a7458d25d9c9 | 43 | StaticResource model(&logger,"3/0/1","K64F mbed Ethernet demo"); |
michaeljkoster | 0:a7458d25d9c9 | 44 | |
michaeljkoster | 0:a7458d25d9c9 | 45 | // |
michaeljkoster | 0:a7458d25d9c9 | 46 | // Dynamic Resource Note: |
michaeljkoster | 0:a7458d25d9c9 | 47 | // |
michaeljkoster | 0:a7458d25d9c9 | 48 | // mbedConnectorInterface supports up to IPT_MAX_ENTRIES |
michaeljkoster | 0:a7458d25d9c9 | 49 | // (currently 5) independent dynamic resources. |
michaeljkoster | 0:a7458d25d9c9 | 50 | // |
michaeljkoster | 0:a7458d25d9c9 | 51 | // You can increase this (at the cost of memory) |
michaeljkoster | 0:a7458d25d9c9 | 52 | // in mbedConnectorinterface.h |
michaeljkoster | 0:a7458d25d9c9 | 53 | // |
michaeljkoster | 0:a7458d25d9c9 | 54 | |
michaeljkoster | 0:a7458d25d9c9 | 55 | // Light Resource |
michaeljkoster | 0:a7458d25d9c9 | 56 | #include "LightResource.h" |
michaeljkoster | 0:a7458d25d9c9 | 57 | LightResource light(&logger,"3311/0/5706"); |
michaeljkoster | 0:a7458d25d9c9 | 58 | |
michaeljkoster | 0:a7458d25d9c9 | 59 | // LED Resource |
michaeljkoster | 0:a7458d25d9c9 | 60 | #include "OnBoardLED.h" |
michaeljkoster | 0:a7458d25d9c9 | 61 | LEDResource led(&logger,"3311/1/5706"); |
michaeljkoster | 0:a7458d25d9c9 | 62 | |
michaeljkoster | 0:a7458d25d9c9 | 63 | // SLide control Resource |
michaeljkoster | 0:a7458d25d9c9 | 64 | #include "SliderResource.h" |
michaeljkoster | 0:a7458d25d9c9 | 65 | SliderResource slider(&logger,"3202/0/5600", true); /* true if observable */ |
michaeljkoster | 0:a7458d25d9c9 | 66 | |
michaeljkoster | 0:a7458d25d9c9 | 67 | // Set our own unique endpoint name |
michaeljkoster | 0:a7458d25d9c9 | 68 | #define MY_ENDPOINT_NAME "Changeme-LED-demo" |
michaeljkoster | 0:a7458d25d9c9 | 69 | |
michaeljkoster | 0:a7458d25d9c9 | 70 | // My NSP Domain |
michaeljkoster | 0:a7458d25d9c9 | 71 | #define MY_NSP_DOMAIN "domain2" |
michaeljkoster | 0:a7458d25d9c9 | 72 | |
michaeljkoster | 0:a7458d25d9c9 | 73 | // Customization Example: My custom NSP IPv4 or IPv6 address and NSP CoAP port |
michaeljkoster | 0:a7458d25d9c9 | 74 | //uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {192,168,1,199}; /* local */ |
michaeljkoster | 0:a7458d25d9c9 | 75 | uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {108,201,184,41}; /* smartobjectservice.com */ |
michaeljkoster | 0:a7458d25d9c9 | 76 | int my_nsp_coap_port = 5683; |
michaeljkoster | 0:a7458d25d9c9 | 77 | |
michaeljkoster | 0:a7458d25d9c9 | 78 | // called from the Endpoint::start() below to create resources and the endpoint internals... |
michaeljkoster | 0:a7458d25d9c9 | 79 | Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) |
michaeljkoster | 0:a7458d25d9c9 | 80 | { |
michaeljkoster | 0:a7458d25d9c9 | 81 | // Build the endpoint configuration parameters |
michaeljkoster | 0:a7458d25d9c9 | 82 | logger.log("configure_endpoint: building endpoint configuration..."); |
michaeljkoster | 0:a7458d25d9c9 | 83 | slider.setMaxAge(0); /* MaxAge = 0 to disable caching of the slide value in the Device Server */ |
michaeljkoster | 0:a7458d25d9c9 | 84 | return config.setEndpointNodename(MY_ENDPOINT_NAME) // custom endpoint name |
michaeljkoster | 0:a7458d25d9c9 | 85 | .setNSPAddress(my_nsp_address) // custom NSP address |
michaeljkoster | 0:a7458d25d9c9 | 86 | .setDomain(MY_NSP_DOMAIN) // custom NSP domain |
michaeljkoster | 0:a7458d25d9c9 | 87 | .setNSPPortNumber(my_nsp_coap_port) // custom NSP CoAP port |
michaeljkoster | 0:a7458d25d9c9 | 88 | |
michaeljkoster | 0:a7458d25d9c9 | 89 | // add the static resource representing this endpoint |
michaeljkoster | 0:a7458d25d9c9 | 90 | .addResource(&mfg) |
michaeljkoster | 0:a7458d25d9c9 | 91 | .addResource(&model) |
michaeljkoster | 0:a7458d25d9c9 | 92 | |
michaeljkoster | 0:a7458d25d9c9 | 93 | // Add my specific physical dynamic resources... |
michaeljkoster | 0:a7458d25d9c9 | 94 | .addResource(&light) |
michaeljkoster | 0:a7458d25d9c9 | 95 | .addResource(&slider, 10000) |
michaeljkoster | 0:a7458d25d9c9 | 96 | .addResource(&led) |
michaeljkoster | 0:a7458d25d9c9 | 97 | |
michaeljkoster | 0:a7458d25d9c9 | 98 | // finalize the configuration... |
michaeljkoster | 0:a7458d25d9c9 | 99 | .build(); |
michaeljkoster | 0:a7458d25d9c9 | 100 | } |
michaeljkoster | 0:a7458d25d9c9 | 101 | |
michaeljkoster | 0:a7458d25d9c9 | 102 | // main entry point... |
michaeljkoster | 0:a7458d25d9c9 | 103 | int main() |
michaeljkoster | 0:a7458d25d9c9 | 104 | { |
michaeljkoster | 0:a7458d25d9c9 | 105 | // Announce |
michaeljkoster | 0:a7458d25d9c9 | 106 | logger.log("\r\n\r\nmbed mDS Sample Endpoint v1.0 (Ethernet)"); |
michaeljkoster | 0:a7458d25d9c9 | 107 | |
michaeljkoster | 0:a7458d25d9c9 | 108 | // we have to plumb our network first |
michaeljkoster | 0:a7458d25d9c9 | 109 | Connector::Endpoint::plumbNetwork(); |
michaeljkoster | 0:a7458d25d9c9 | 110 | |
michaeljkoster | 0:a7458d25d9c9 | 111 | // starts the endpoint by finalizing its configuration (configure_endpoint() above called),creating a Thread and reading NSP events... |
michaeljkoster | 0:a7458d25d9c9 | 112 | logger.log("Start the endpoint to finish setup and enter the main loop..."); |
michaeljkoster | 0:a7458d25d9c9 | 113 | Connector::Endpoint::start(); |
michaeljkoster | 0:a7458d25d9c9 | 114 | } |