nsp specific components for the NSP version of the impact endpoint
Dependents: mbed_nsp_endpoint_ublox_cellular mbed_nsp_endpoint_ublox_ethernet mbed_nsp_endpoint_nxp
NSPLightResourceFactory.cpp@17:4fe123d805e3, 2014-04-11 (annotated)
- Committer:
- ansond
- Date:
- Fri Apr 11 01:51:21 2014 +0000
- Revision:
- 17:4fe123d805e3
- Parent:
- 13:6998d9c2410e
- Child:
- 18:0e32c41b238e
updates
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ansond | 4:7f7fe167d9c0 | 1 | /* Copyright C2013 Doug Anson, MIT License |
ansond | 4:7f7fe167d9c0 | 2 | * |
ansond | 4:7f7fe167d9c0 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
ansond | 4:7f7fe167d9c0 | 4 | * and associated documentation files the "Software", to deal in the Software without restriction, |
ansond | 4:7f7fe167d9c0 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
ansond | 4:7f7fe167d9c0 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
ansond | 4:7f7fe167d9c0 | 7 | * furnished to do so, subject to the following conditions: |
ansond | 4:7f7fe167d9c0 | 8 | * |
ansond | 4:7f7fe167d9c0 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
ansond | 4:7f7fe167d9c0 | 10 | * substantial portions of the Software. |
ansond | 4:7f7fe167d9c0 | 11 | * |
ansond | 4:7f7fe167d9c0 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
ansond | 4:7f7fe167d9c0 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
ansond | 4:7f7fe167d9c0 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
ansond | 4:7f7fe167d9c0 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
ansond | 4:7f7fe167d9c0 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
ansond | 4:7f7fe167d9c0 | 17 | */ |
ansond | 4:7f7fe167d9c0 | 18 | |
ansond | 4:7f7fe167d9c0 | 19 | // class support |
ansond | 4:7f7fe167d9c0 | 20 | #include "NSPLightResourceFactory.h" |
ansond | 4:7f7fe167d9c0 | 21 | |
ansond | 6:edf306673e54 | 22 | #ifndef CELLULAR_NETWORK |
ansond | 6:edf306673e54 | 23 | #include "EthernetInterface.h" |
ansond | 6:edf306673e54 | 24 | extern EthernetInterface ethernet; |
ansond | 6:edf306673e54 | 25 | #endif |
ansond | 4:7f7fe167d9c0 | 26 | |
ansond | 4:7f7fe167d9c0 | 27 | // MBED supports GPS location observation |
ansond | 4:7f7fe167d9c0 | 28 | #include "gps.h" |
ansond | 4:7f7fe167d9c0 | 29 | |
ansond | 4:7f7fe167d9c0 | 30 | // MBED supports RSSI observation |
ansond | 4:7f7fe167d9c0 | 31 | #include "rssi.h" |
ansond | 4:7f7fe167d9c0 | 32 | |
ansond | 4:7f7fe167d9c0 | 33 | // MBED supports Temperature Sensing |
ansond | 4:7f7fe167d9c0 | 34 | #include "temperature.h" |
ansond | 4:7f7fe167d9c0 | 35 | |
ansond | 4:7f7fe167d9c0 | 36 | // MBED supports Battery Emulation |
ansond | 4:7f7fe167d9c0 | 37 | #include "battery.h" |
ansond | 4:7f7fe167d9c0 | 38 | |
ansond | 4:7f7fe167d9c0 | 39 | // MBED supports Voltage Emulation |
ansond | 4:7f7fe167d9c0 | 40 | #include "voltage.h" |
ansond | 4:7f7fe167d9c0 | 41 | |
ansond | 4:7f7fe167d9c0 | 42 | // MBED supports Wattage Emulation |
ansond | 4:7f7fe167d9c0 | 43 | #include "wattage.h" |
ansond | 4:7f7fe167d9c0 | 44 | |
ansond | 4:7f7fe167d9c0 | 45 | // MBED support Current Emulation |
ansond | 4:7f7fe167d9c0 | 46 | #include "current.h" |
ansond | 4:7f7fe167d9c0 | 47 | |
ansond | 4:7f7fe167d9c0 | 48 | // MBED support Dimming Operations |
ansond | 4:7f7fe167d9c0 | 49 | #include "dimmer.h" |
ansond | 4:7f7fe167d9c0 | 50 | |
ansond | 4:7f7fe167d9c0 | 51 | // MBED support Light Switch Operations |
ansond | 4:7f7fe167d9c0 | 52 | #include "switch.h" |
ansond | 4:7f7fe167d9c0 | 53 | |
ansond | 4:7f7fe167d9c0 | 54 | // MBED support AddlData for IOC Integration |
ansond | 4:7f7fe167d9c0 | 55 | #include "addldata.h" |
ansond | 4:7f7fe167d9c0 | 56 | |
ansond | 4:7f7fe167d9c0 | 57 | // MBED supports observable MDL text |
ansond | 4:7f7fe167d9c0 | 58 | #include "mdltext.h" |
ansond | 4:7f7fe167d9c0 | 59 | |
ansond | 4:7f7fe167d9c0 | 60 | // MBED supports observable MFG text |
ansond | 4:7f7fe167d9c0 | 61 | #include "mfgtext.h" |
ansond | 4:7f7fe167d9c0 | 62 | |
ansond | 4:7f7fe167d9c0 | 63 | // MBED supports observable location text |
ansond | 4:7f7fe167d9c0 | 64 | #include "locationtext.h" |
ansond | 4:7f7fe167d9c0 | 65 | |
ansond | 17:4fe123d805e3 | 66 | // MBEDEndpoint support |
ansond | 17:4fe123d805e3 | 67 | #include "MBEDEndpoint.h" |
ansond | 17:4fe123d805e3 | 68 | |
ansond | 4:7f7fe167d9c0 | 69 | // default constructor |
ansond | 4:7f7fe167d9c0 | 70 | NSPLightResourceFactory::NSPLightResourceFactory(ErrorHandler *error_handler,void *endpoint) : NSPResourceFactory(error_handler,endpoint) { |
ansond | 4:7f7fe167d9c0 | 71 | } |
ansond | 4:7f7fe167d9c0 | 72 | |
ansond | 4:7f7fe167d9c0 | 73 | // default destructor |
ansond | 4:7f7fe167d9c0 | 74 | NSPLightResourceFactory::~NSPLightResourceFactory() { |
ansond | 4:7f7fe167d9c0 | 75 | } |
ansond | 4:7f7fe167d9c0 | 76 | |
ansond | 4:7f7fe167d9c0 | 77 | // create resources modeling a Light personality |
ansond | 4:7f7fe167d9c0 | 78 | void NSPLightResourceFactory::createResources(char *ep_name) { |
ansond | 17:4fe123d805e3 | 79 | MBEDEndpoint *endpoint = (MBEDEndpoint *)this->getEndpoint(); |
ansond | 17:4fe123d805e3 | 80 | |
ansond | 4:7f7fe167d9c0 | 81 | // record the endpoint name |
ansond | 4:7f7fe167d9c0 | 82 | this->setEndpointName(ep_name); |
ansond | 4:7f7fe167d9c0 | 83 | |
ansond | 4:7f7fe167d9c0 | 84 | // initialize resource structures |
ansond | 4:7f7fe167d9c0 | 85 | this->initResourceStructures(); |
ansond | 4:7f7fe167d9c0 | 86 | |
ansond | 4:7f7fe167d9c0 | 87 | // create all of the resources we expect for this endpoint |
ansond | 4:7f7fe167d9c0 | 88 | this->createResource(ep_name,"/dev/addldata","id:0",(void *)&addldata_cb,(sn_grs_resource_acl_e)(SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED),(void *)&init_addldata,"core#s",(char *)NULL); |
ansond | 4:7f7fe167d9c0 | 89 | this->createResource(ep_name,"/dev/location",ENDPOINT_LOCATION,(void *)&locationtext_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_locationtext,"core#s","ns:location"); |
ansond | 4:7f7fe167d9c0 | 90 | this->createResource("/fw/devtype",NSP_NODE_TYPE,"core#s","ns:devtype"); |
ansond | 4:7f7fe167d9c0 | 91 | this->createResource(ep_name,"/dev/bat","5.0V",(void *)&battery_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_battery,(char *)NULL,"ipso:dev-bat"); |
ansond | 4:7f7fe167d9c0 | 92 | this->createResource(ep_name,"/sen/I","0.1",(void *)¤t_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_current,(char *)NULL,"ucum:A"); |
ansond | 4:7f7fe167d9c0 | 93 | this->createResource(ep_name,"/dev/I","0.1",(void *)¤t_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_current,(char *)NULL,"ucum:A"); |
ansond | 6:edf306673e54 | 94 | #ifndef CELLULAR_NETWORK |
ansond | 4:7f7fe167d9c0 | 95 | this->createResource("/nw/ipaddr",ethernet.getIPAddress(),"core#s","ns:v4addr"); |
ansond | 6:edf306673e54 | 96 | #else |
ansond | 6:edf306673e54 | 97 | this->createResource("/nw/ipaddr","0.0.0.0","core#s","ns:v4addr"); |
ansond | 6:edf306673e54 | 98 | #endif |
ansond | 9:5ee9393f444e | 99 | this->createResource(ep_name,"/lt/0/dim",LIGHT_DIM_STATE,(void *)&dimmer_cb,(sn_grs_resource_acl_e)(SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED),(void *)&init_dimmer,(char *)NULL,"ipso:lt-dim"); // Action: dim/brighten light |
ansond | 4:7f7fe167d9c0 | 100 | this->createResource("/nw/eripaddr","N/A","core#s","ns:v4addr"); |
ansond | 9:5ee9393f444e | 101 | this->createResource(ep_name,"/lt/0/on",LIGHT_DEFAULT_STATE,(void *)&switch_cb,(sn_grs_resource_acl_e)(SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED),(void *)&init_switch,(char *)NULL,"ipso:lt-on"); // Action: light on/off |
ansond | 9:5ee9393f444e | 102 | //this->createResource(ep_name,"/lt/0/ctr",LIGHT_DEFAULT_STATE,(void *)&switch_cb,(sn_grs_resource_acl_e)(SN_GRS_GET_ALLOWED|SN_GRS_PUT_ALLOWED),(void *)&init_switch,(char *)NULL,"ns:boolean"); // Action: light on/off |
ansond | 13:6998d9c2410e | 103 | this->createResource(ep_name,"/dev/mdl",NSP_ENDPOINT_TYPE,(void *)&mdltext_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_mdltext,"core#s","ipso:dev-mdl"); |
ansond | 4:7f7fe167d9c0 | 104 | this->createResource(ep_name,"/dev/mfg",PLATFORM_STRING,(void *)&mfgtext_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_mfgtext,"core#s","ipso:dev-mfg"); |
ansond | 4:7f7fe167d9c0 | 105 | this->createResource("/gps/int","60","core#s","ns:counter"); |
ansond | 4:7f7fe167d9c0 | 106 | this->createResource("/gps/fix","1","core#s","ns:boolean"); |
ansond | 4:7f7fe167d9c0 | 107 | this->createResource("/nw/pipaddr","N/A","core#s","ns:v4addr"); |
ansond | 4:7f7fe167d9c0 | 108 | this->createResource(ep_name,"/nw/prssi","-75",(void *)&rssi_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_rssi,"core#s","ns:rssi"); |
ansond | 4:7f7fe167d9c0 | 109 | this->createResource(ep_name,"/dev/W","0.1",(void *)&wattage_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_wattage,(char *)NULL,"ucum:W"); |
ansond | 4:7f7fe167d9c0 | 110 | this->createResource(ep_name,"/sen/temp","10.0",(void *)&temp_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_temp,(char *)NULL,"ucum:Cel"); |
ansond | 4:7f7fe167d9c0 | 111 | this->createResource(ep_name,"/dev/t","10.0",(void *)&temp_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_temp,(char *)NULL,"ucum:Cel"); |
ansond | 4:7f7fe167d9c0 | 112 | this->createResource(ep_name,"/sen/V","5.0",(void *)&voltage_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_voltage,(char *)NULL,"ucum:V"); |
ansond | 4:7f7fe167d9c0 | 113 | this->createResource(ep_name,"/dev/V","5.0",(void *)&voltage_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_voltage,(char *)NULL,"ucum:V"); |
ansond | 4:7f7fe167d9c0 | 114 | this->createResource(ep_name,"/gps/loc",ENDPOINT_GPS_COORDS,(void *)&gps_location_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_gps,"core#s","ns:gpsloc"); |
ansond | 17:4fe123d805e3 | 115 | this->createResource("/ns/nspaddr",endpoint->getNSPAddress(),"core#s","ns:v4addr"); |
ansond | 4:7f7fe167d9c0 | 116 | this->createResource(ep_name,"/dev/panic","0",(void *)&switch_cb,(sn_grs_resource_acl_e)(SN_GRS_GET_ALLOWED),(void *)&init_switch,"core#s","ns:panic"); |
ansond | 4:7f7fe167d9c0 | 117 | |
ansond | 4:7f7fe167d9c0 | 118 | #ifdef MAC_ADDRESS |
ansond | 4:7f7fe167d9c0 | 119 | extern char fmt_mac[RESOURCE_VALUE_LEN+1]; |
ansond | 4:7f7fe167d9c0 | 120 | this->createResource("/nw/macaddr",fmt_mac,"core#s","ns:euid64"); |
ansond | 4:7f7fe167d9c0 | 121 | #else |
ansond | 4:7f7fe167d9c0 | 122 | this->createResource("/nw/macaddr","00:00:00:00:00","core#s","ns:euid64"); |
ansond | 4:7f7fe167d9c0 | 123 | #endif |
ansond | 4:7f7fe167d9c0 | 124 | |
ansond | 4:7f7fe167d9c0 | 125 | // finalize the registration |
ansond | 4:7f7fe167d9c0 | 126 | this->finalizeRegistration(); |
ansond | 4:7f7fe167d9c0 | 127 | } |