Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: C027 C12832 EthernetInterface StatusReporter LM75B MQTT-ansond endpoint_core endpoint_mqtt mbed-rtos mbed
EmulatedResourceFactory.cpp@35:27484c1273f9, 2014-02-28 (annotated)
- Committer:
- ansond
- Date:
- Fri Feb 28 23:45:13 2014 +0000
- Revision:
- 35:27484c1273f9
- Parent:
- 31:a95cf856ce4e
- Child:
- 36:210f3956038c
updates
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ansond | 0:ae2a45502448 | 1 | /* Copyright C2013 Doug Anson, MIT License |
| ansond | 0:ae2a45502448 | 2 | * |
| ansond | 0:ae2a45502448 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
| ansond | 0:ae2a45502448 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
| ansond | 0:ae2a45502448 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
| ansond | 0:ae2a45502448 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
| ansond | 0:ae2a45502448 | 7 | * furnished to do so, subject to the following conditions: |
| ansond | 0:ae2a45502448 | 8 | * |
| ansond | 0:ae2a45502448 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
| ansond | 0:ae2a45502448 | 10 | * substantial portions of the Software. |
| ansond | 0:ae2a45502448 | 11 | * |
| ansond | 0:ae2a45502448 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
| ansond | 0:ae2a45502448 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| ansond | 0:ae2a45502448 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
| ansond | 0:ae2a45502448 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| ansond | 0:ae2a45502448 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| ansond | 0:ae2a45502448 | 17 | */ |
| ansond | 0:ae2a45502448 | 18 | |
| ansond | 0:ae2a45502448 | 19 | // class definition |
| ansond | 0:ae2a45502448 | 20 | #include "EmulatedResourceFactory.h" |
| ansond | 0:ae2a45502448 | 21 | |
| ansond | 0:ae2a45502448 | 22 | // Ethernet |
| ansond | 0:ae2a45502448 | 23 | #include "EthernetInterface.h" |
| ansond | 0:ae2a45502448 | 24 | extern EthernetInterface ethernet; |
| ansond | 0:ae2a45502448 | 25 | |
| ansond | 0:ae2a45502448 | 26 | // NSP supports Light Dimming |
| ansond | 0:ae2a45502448 | 27 | extern void emulated_light_dimming_cb(); |
| ansond | 0:ae2a45502448 | 28 | |
| ansond | 0:ae2a45502448 | 29 | // NSP supports Light Switch |
| ansond | 0:ae2a45502448 | 30 | extern void emulated_light_switch_cb(); |
| ansond | 0:ae2a45502448 | 31 | |
| ansond | 0:ae2a45502448 | 32 | // default constructor |
| ansond | 0:ae2a45502448 | 33 | EmulatedResourceFactory::EmulatedResourceFactory(ErrorHandler *error_handler) : ResourceFactory(error_handler) { |
| ansond | 0:ae2a45502448 | 34 | } |
| ansond | 0:ae2a45502448 | 35 | |
| ansond | 0:ae2a45502448 | 36 | // default destructor |
| ansond | 0:ae2a45502448 | 37 | EmulatedResourceFactory::~EmulatedResourceFactory() { |
| ansond | 0:ae2a45502448 | 38 | } |
| ansond | 0:ae2a45502448 | 39 | |
| ansond | 0:ae2a45502448 | 40 | // create resources |
| ansond | 0:ae2a45502448 | 41 | void EmulatedResourceFactory::createResources(char *endpoint_name) { |
| ansond | 0:ae2a45502448 | 42 | // create all of the resources we expect for this endpoint |
| ansond | 2:90a84a216c58 | 43 | this->createResource("/dev/addldata","AdditionalData"); |
| ansond | 9:ff877db53cfd | 44 | this->createResource("/dev/location",ENDPOINT_LOCATION); |
| ansond | 9:ff877db53cfd | 45 | this->createResource("/dev/bat","0.0"); |
| ansond | 35:27484c1273f9 | 46 | this->createResource("/sen/I","0.0"); |
| ansond | 2:90a84a216c58 | 47 | this->createResource("/nw/ipaddr",ethernet.getIPAddress()); |
| ansond | 2:90a84a216c58 | 48 | this->createResource(endpoint_name,"/lt/0/dim","25",(void *)&emulated_light_dimming_cb); // Action: dim/brighten light |
| ansond | 9:ff877db53cfd | 49 | this->createResource("/nw/eripaddr","N/A"); |
| ansond | 2:90a84a216c58 | 50 | this->createResource(endpoint_name,"/lt/0/on","1",(void *)&emulated_light_switch_cb); // Action: light on/off |
| ansond | 9:ff877db53cfd | 51 | this->createResource("/dev/mdl","MQTT MBED Light"); |
| ansond | 9:ff877db53cfd | 52 | this->createResource("/gps/int","0"); |
| ansond | 2:90a84a216c58 | 53 | this->createResource("/gps/fix","1"); |
| ansond | 9:ff877db53cfd | 54 | this->createResource("/nw/pipaddr","N/A"); |
| ansond | 9:ff877db53cfd | 55 | this->createResource("/nw/prssi","N/A"); |
| ansond | 35:27484c1273f9 | 56 | this->createResource("/sen/temp","0.0"); |
| ansond | 35:27484c1273f9 | 57 | this->createResource("/sen/V","5.0"); |
| ansond | 9:ff877db53cfd | 58 | this->createResource("/gps/loc",ENDPOINT_GPS_COORDS); |
| ansond | 8:45f9a920e82c | 59 | } |
| ansond | 8:45f9a920e82c | 60 | |
| ansond | 8:45f9a920e82c | 61 | // set a resource value (AND trigger the Emulated actions if registered) |
| ansond | 8:45f9a920e82c | 62 | bool EmulatedResourceFactory::setResourceValue(char *name, char *value) { |
| ansond | 8:45f9a920e82c | 63 | // set the resource value |
| ansond | 31:a95cf856ce4e | 64 | bool success = ResourceFactory::setResourceValue(name,value); |
| ansond | 8:45f9a920e82c | 65 | if (success) { |
| ansond | 8:45f9a920e82c | 66 | // invoke an action if registered |
| ansond | 8:45f9a920e82c | 67 | EmulatedCallbackPointer cb = (EmulatedCallbackPointer)this->getCallbackPointer(name); |
| ansond | 8:45f9a920e82c | 68 | if (cb != NULL) { |
| ansond | 8:45f9a920e82c | 69 | // invoke the callback |
| ansond | 8:45f9a920e82c | 70 | this->logger()->log("Invoking Action..."); |
| ansond | 8:45f9a920e82c | 71 | cb(); |
| ansond | 8:45f9a920e82c | 72 | } |
| ansond | 8:45f9a920e82c | 73 | } |
| ansond | 8:45f9a920e82c | 74 | return success; |
| ansond | 8:45f9a920e82c | 75 | } |