completed update to checkEvent()
checkEvents() now allows for multiple characteristics to be updated by service->notify(). This change included the use of vector<SpanBuf> to dynamically create the the temporary storage needed. To do: re-work similar routines to use vector<SpanBuf> instead of needing to perform two passes each time to gauge size of SpanBuf array needed.
This commit is contained in:
parent
6ad063a2b2
commit
4f6f249357
|
|
@ -18,7 +18,7 @@ struct DEV_TempSensor : Service::TemperatureSensor { // A standalone Tempera
|
||||||
|
|
||||||
void event(){
|
void event(){
|
||||||
|
|
||||||
temp->setVal(22.0);
|
temp->setVal((double)random(15,25));
|
||||||
|
|
||||||
} // event
|
} // event
|
||||||
};
|
};
|
||||||
|
|
@ -48,11 +48,11 @@ struct DEV_AirQualitySensor : Service::AirQualitySensor { // A standalone Ai
|
||||||
|
|
||||||
void event(){
|
void event(){
|
||||||
|
|
||||||
airQuality->setVal(1);
|
airQuality->setVal((int)random(1,6));
|
||||||
o3Density->setVal(10.8);
|
o3Density->setVal((double)random(200,500));
|
||||||
if(!random(2)){
|
if(!random(2)){
|
||||||
Serial.println("HERE\n");
|
Serial.println("HERE\n");
|
||||||
no2Density->setVal(50.3);
|
no2Density->setVal((double)random(600,800));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // event
|
} // event
|
||||||
|
|
|
||||||
38
src/HAP.cpp
38
src/HAP.cpp
|
|
@ -1093,8 +1093,7 @@ int HAPClient::putCharacteristicsURL(char *json){
|
||||||
void HAPClient::checkEvents(){
|
void HAPClient::checkEvents(){
|
||||||
|
|
||||||
unsigned long cTime=millis(); // current time
|
unsigned long cTime=millis(); // current time
|
||||||
int nObj=0;
|
vector<SpanBuf> spanBuf; // vector to SpanBuf objects
|
||||||
SpanBuf pObj[homeSpan.Events.size()]; // maximum number of objects needed if every Event is triggered and each requires a Notification
|
|
||||||
|
|
||||||
for(int i=0;i<homeSpan.Events.size();i++){ // loop over all defined Events
|
for(int i=0;i<homeSpan.Events.size();i++){ // loop over all defined Events
|
||||||
if(cTime>homeSpan.Events[i]->alarmTime){ // if alarm time has passed
|
if(cTime>homeSpan.Events[i]->alarmTime){ // if alarm time has passed
|
||||||
|
|
@ -1104,7 +1103,14 @@ void HAPClient::checkEvents(){
|
||||||
|
|
||||||
for(int j=0;j<homeSpan.Events[i]->service->Characteristics.size();j++){ // loop over all characteristics
|
for(int j=0;j<homeSpan.Events[i]->service->Characteristics.size();j++){ // loop over all characteristics
|
||||||
if(homeSpan.Events[i]->service->Characteristics[j]->isUpdated){ // if characteristic is updated
|
if(homeSpan.Events[i]->service->Characteristics[j]->isUpdated){ // if characteristic is updated
|
||||||
|
|
||||||
|
SpanBuf sb; // create SpanBuf object
|
||||||
|
sb.characteristic=homeSpan.Events[i]->service->Characteristics[j]; // set characteristic
|
||||||
|
sb.status=StatusCode::OK; // set status
|
||||||
|
sb.val=""; // set dummy "val" so that sprintfNotify knows to consider this "update"
|
||||||
|
|
||||||
|
spanBuf.push_back(sb);
|
||||||
|
|
||||||
Serial.print("Event for aid=");
|
Serial.print("Event for aid=");
|
||||||
Serial.print(homeSpan.Events[i]->service->Characteristics[j]->aid);
|
Serial.print(homeSpan.Events[i]->service->Characteristics[j]->aid);
|
||||||
Serial.print(" iid=");
|
Serial.print(" iid=");
|
||||||
|
|
@ -1112,29 +1118,17 @@ void HAPClient::checkEvents(){
|
||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
|
|
||||||
homeSpan.Events[i]->service->Characteristics[j]->isUpdated=false; // reset isUpdated flag
|
homeSpan.Events[i]->service->Characteristics[j]->isUpdated=false; // reset isUpdated flag
|
||||||
}
|
|
||||||
}
|
} // if characteristic is updated
|
||||||
}
|
} // characteristic loop
|
||||||
}
|
} // alarm triggered
|
||||||
}
|
} // events loop
|
||||||
|
|
||||||
/*
|
if(spanBuf.size()>0) // if updated items are found
|
||||||
if(characteristic){ // if the service has responded with a characteristic to update
|
eventNotify(&spanBuf[0],spanBuf.size()); // transmit EVENT Notifications
|
||||||
pObj[nObj].status=StatusCode::OK; // populate pObj
|
|
||||||
pObj[nObj].characteristic=characteristic;
|
|
||||||
pObj[nObj].val=""; // dummy object needed to ensure sprintfNotify knows to consider this "update"
|
|
||||||
nObj++; // increment number of characteristics found that need to be turned off
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(nObj>0)
|
|
||||||
eventNotify(pObj,nObj); // transmit EVENT Notification for "n" pObj objects
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
void HAPClient::checkTimedResets(){
|
void HAPClient::checkTimedResets(){
|
||||||
|
|
|
||||||
|
|
@ -114,7 +114,6 @@ struct HAPClient {
|
||||||
static void checkTimedResets(); // checks for Timed Resets and reports to controllers as needed (HAP Section 6.8)
|
static void checkTimedResets(); // checks for Timed Resets and reports to controllers as needed (HAP Section 6.8)
|
||||||
static void checkEvents(); // checks for Event Notifications and reports to controllers as needed (HAP Section 6.8)
|
static void checkEvents(); // checks for Event Notifications and reports to controllers as needed (HAP Section 6.8)
|
||||||
static void eventNotify(SpanBuf *pObj, int nObj, int ignoreClient=-1); // transmits EVENT Notifications for nObj SpanBuf objects, pObj, with optional flag to ignore a specific client
|
static void eventNotify(SpanBuf *pObj, int nObj, int ignoreClient=-1); // transmits EVENT Notifications for nObj SpanBuf objects, pObj, with optional flag to ignore a specific client
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////
|
/////////////////////////////////////////////////
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue