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

Committer:
ansond
Date:
Fri Mar 28 17:08:22 2014 +0000
Revision:
4:7f7fe167d9c0
Child:
6:edf306673e54
refactor personality

Who changed what in which revision?

UserRevisionLine numberNew 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 4:7f7fe167d9c0 22 // Ethernet Interface
ansond 4:7f7fe167d9c0 23 #include "EthernetInterface.h"
ansond 4:7f7fe167d9c0 24 extern EthernetInterface ethernet;
ansond 4:7f7fe167d9c0 25
ansond 4:7f7fe167d9c0 26 // MBED supports GPS location observation
ansond 4:7f7fe167d9c0 27 #include "gps.h"
ansond 4:7f7fe167d9c0 28
ansond 4:7f7fe167d9c0 29 // MBED supports RSSI observation
ansond 4:7f7fe167d9c0 30 #include "rssi.h"
ansond 4:7f7fe167d9c0 31
ansond 4:7f7fe167d9c0 32 // MBED supports Temperature Sensing
ansond 4:7f7fe167d9c0 33 #include "temperature.h"
ansond 4:7f7fe167d9c0 34
ansond 4:7f7fe167d9c0 35 // MBED supports Battery Emulation
ansond 4:7f7fe167d9c0 36 #include "battery.h"
ansond 4:7f7fe167d9c0 37
ansond 4:7f7fe167d9c0 38 // MBED supports Voltage Emulation
ansond 4:7f7fe167d9c0 39 #include "voltage.h"
ansond 4:7f7fe167d9c0 40
ansond 4:7f7fe167d9c0 41 // MBED supports Wattage Emulation
ansond 4:7f7fe167d9c0 42 #include "wattage.h"
ansond 4:7f7fe167d9c0 43
ansond 4:7f7fe167d9c0 44 // MBED support Current Emulation
ansond 4:7f7fe167d9c0 45 #include "current.h"
ansond 4:7f7fe167d9c0 46
ansond 4:7f7fe167d9c0 47 // MBED support Dimming Operations
ansond 4:7f7fe167d9c0 48 #include "dimmer.h"
ansond 4:7f7fe167d9c0 49
ansond 4:7f7fe167d9c0 50 // MBED support Light Switch Operations
ansond 4:7f7fe167d9c0 51 #include "switch.h"
ansond 4:7f7fe167d9c0 52
ansond 4:7f7fe167d9c0 53 // MBED support AddlData for IOC Integration
ansond 4:7f7fe167d9c0 54 #include "addldata.h"
ansond 4:7f7fe167d9c0 55
ansond 4:7f7fe167d9c0 56 // MBED supports observable MDL text
ansond 4:7f7fe167d9c0 57 #include "mdltext.h"
ansond 4:7f7fe167d9c0 58
ansond 4:7f7fe167d9c0 59 // MBED supports observable MFG text
ansond 4:7f7fe167d9c0 60 #include "mfgtext.h"
ansond 4:7f7fe167d9c0 61
ansond 4:7f7fe167d9c0 62 // MBED supports observable location text
ansond 4:7f7fe167d9c0 63 #include "locationtext.h"
ansond 4:7f7fe167d9c0 64
ansond 4:7f7fe167d9c0 65 // default constructor
ansond 4:7f7fe167d9c0 66 NSPLightResourceFactory::NSPLightResourceFactory(ErrorHandler *error_handler,void *endpoint) : NSPResourceFactory(error_handler,endpoint) {
ansond 4:7f7fe167d9c0 67 }
ansond 4:7f7fe167d9c0 68
ansond 4:7f7fe167d9c0 69 // default destructor
ansond 4:7f7fe167d9c0 70 NSPLightResourceFactory::~NSPLightResourceFactory() {
ansond 4:7f7fe167d9c0 71 }
ansond 4:7f7fe167d9c0 72
ansond 4:7f7fe167d9c0 73 // create resources modeling a Light personality
ansond 4:7f7fe167d9c0 74 void NSPLightResourceFactory::createResources(char *ep_name) {
ansond 4:7f7fe167d9c0 75 // record the endpoint name
ansond 4:7f7fe167d9c0 76 this->setEndpointName(ep_name);
ansond 4:7f7fe167d9c0 77
ansond 4:7f7fe167d9c0 78 // initialize resource structures
ansond 4:7f7fe167d9c0 79 this->initResourceStructures();
ansond 4:7f7fe167d9c0 80
ansond 4:7f7fe167d9c0 81 // create all of the resources we expect for this endpoint
ansond 4:7f7fe167d9c0 82 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 83 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 84 this->createResource("/fw/devtype",NSP_NODE_TYPE,"core#s","ns:devtype");
ansond 4:7f7fe167d9c0 85 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 86 this->createResource(ep_name,"/sen/I","0.1",(void *)&current_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_current,(char *)NULL,"ucum:A");
ansond 4:7f7fe167d9c0 87 this->createResource(ep_name,"/dev/I","0.1",(void *)&current_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_current,(char *)NULL,"ucum:A");
ansond 4:7f7fe167d9c0 88 this->createResource("/nw/ipaddr",ethernet.getIPAddress(),"core#s","ns:v4addr");
ansond 4:7f7fe167d9c0 89 this->createResource(ep_name,"/lt/0/dim","25",(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 90 this->createResource("/nw/eripaddr","N/A","core#s","ns:v4addr");
ansond 4:7f7fe167d9c0 91 this->createResource(ep_name,"/lt/0/on","1",(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 4:7f7fe167d9c0 92 //this->createResource(ep_name,"/lt/0/ctr","1",(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 4:7f7fe167d9c0 93 this->createResource(ep_name,"/dev/mdl","Sensinode MBED Light",(void *)&mdltext_cb,(sn_grs_resource_acl_e)SN_GRS_GET_ALLOWED,(void *)&init_mdltext,"core#s","ipso:dev-mdl");
ansond 4:7f7fe167d9c0 94 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 95 this->createResource("/gps/int","60","core#s","ns:counter");
ansond 4:7f7fe167d9c0 96 this->createResource("/gps/fix","1","core#s","ns:boolean");
ansond 4:7f7fe167d9c0 97 this->createResource("/nw/pipaddr","N/A","core#s","ns:v4addr");
ansond 4:7f7fe167d9c0 98 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 99 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 100 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 101 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 102 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 103 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 104 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 4:7f7fe167d9c0 105 this->createResource("/ns/nspaddr",NSP_ADDRESS,"core#s","ns:v4addr");
ansond 4:7f7fe167d9c0 106 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 107
ansond 4:7f7fe167d9c0 108 #ifdef MAC_ADDRESS
ansond 4:7f7fe167d9c0 109 extern char fmt_mac[RESOURCE_VALUE_LEN+1];
ansond 4:7f7fe167d9c0 110 this->createResource("/nw/macaddr",fmt_mac,"core#s","ns:euid64");
ansond 4:7f7fe167d9c0 111 #else
ansond 4:7f7fe167d9c0 112 this->createResource("/nw/macaddr","00:00:00:00:00","core#s","ns:euid64");
ansond 4:7f7fe167d9c0 113 #endif
ansond 4:7f7fe167d9c0 114
ansond 4:7f7fe167d9c0 115 // finalize the registration
ansond 4:7f7fe167d9c0 116 this->finalizeRegistration();
ansond 4:7f7fe167d9c0 117 }