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: C12832_lcd EthernetInterface StatusReporter LM75B MQTT-ansond endpoint_core endpoint_mqtt mbed-rtos mbed
Diff: MBEDEndpoint.cpp
- Revision:
- 24:7b3a5c927a53
- Parent:
- 23:793b2898522e
- Child:
- 25:8e960728d50a
--- a/MBEDEndpoint.cpp Fri Feb 28 02:52:04 2014 +0000
+++ b/MBEDEndpoint.cpp Fri Feb 28 03:11:02 2014 +0000
@@ -34,7 +34,6 @@
// default constructor
MBEDEndpoint::MBEDEndpoint(ErrorHandler *error_handler,EthernetInterface *ethernet) {
- this->m_ioc_id = -1;
bool success = true;
for(int i=0;i<NUM_TRANSPORTS;++i) this->m_transports[i] = NULL;
this->m_error_handler = error_handler;
@@ -59,13 +58,7 @@
if (success) this->logger()->turnLEDBlue();
if (this->m_map != NULL) delete this->m_map;
}
-
- // set the IOC ID
- void MBEDEndpoint::setIOCID(int ioc_id) { this->m_ioc_id = ioc_id; }
-
- // get the IOC ID
- int MBEDEndpoint::getIOCID() { return this->m_ioc_id; }
-
+
// get the IOC <--> MBED resource map
MBEDToIOCResourceMap *MBEDEndpoint::getMap() { return this->m_map; }
@@ -201,11 +194,11 @@
//if (success) this->logger()->log("Saving IOC ID for Light: %s...",light->getName());
// update the IOC ID if found
- if (success) this->saveIOCID(result);
+ if (success) this->saveIOCID(light,result);
// DEBUG
- if (success) this->logger()->log("Light: %s IOC ID=%d sent successfully",light->getName(),this->getIOCID());
- else this->logger()->log("Light: %s IOC ID=%d send FAILED",light->getName(),this->getIOCID());
+ if (success) this->logger()->log("Light: %s IOC ID=%d sent successfully",light->getName(),light->getIOCID());
+ else this->logger()->log("Light: %s send FAILED",light->getName());
// DEBUG
if (!success) this->logger()->log("Loading Light: %s FAILED",light->getName());
@@ -241,7 +234,7 @@
char *data = this->buildIOCPayload(payload,IOC_PAYLOAD_LEN,light);
// issue the request
- success = this->m_transports[LOAD_TRANSPORT]->updateEndpoint(this->getIOCID(),(char *)payload,strlen(payload),(char *)result,IOC_RESULT_LEN);
+ success = this->m_transports[LOAD_TRANSPORT]->updateEndpoint(light->getIOCID(),(char *)payload,strlen(payload),(char *)result,IOC_RESULT_LEN);
// DEBUG
if (success) this->logger()->log("Update of Endpoint to IOC successful");
@@ -276,6 +269,11 @@
// IOC expects "Point(X,Y)" for LOCATION, but in reverse from MBED
str_json += "\"" + std::string(name) + "\":\"Point(" + std::string(value) + ")\",";
}
+
+ // Handle /dev/addldata
+ if (strcmp(name,this->getMap()->endpointNameToIOCName("/dev/addldata")) == 0 && light->getIOCID() > 0) {
+ str_json += "\"" + std::string(name) + "\":\"id:" + std::string("" + light->getIOCID()) + "\",";
+ }
}
// Special Case: STARTDATETIME
@@ -289,7 +287,7 @@
// Special Case: TIMEZONEOFFSET
str_json += "\"TIMEZONEOFFSET\":\"+2:00\"";
-
+
// close
str_json += "}";
@@ -304,7 +302,7 @@
}
// save the IOC ID
- void MBEDEndpoint::saveIOCID(char *json) {
+ void MBEDEndpoint::saveIOCID(Light *light,char *json) {
if (json != NULL) {
std::string str_json(json);
@@ -325,7 +323,7 @@
sscanf(str_ioc_id.c_str(),"%d",&ioc_id);
// save the IOC ID
- if (ioc_id > 0) this->setIOCID(ioc_id);
+ if (ioc_id > 0) light->setIOCID(ioc_id);
}
else {
// cannot find the ID tag in the result JSON