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:
Gregg 2020-08-11 20:57:40 -05:00
parent 6ad063a2b2
commit 4f6f249357
3 changed files with 20 additions and 27 deletions

View File

@ -18,7 +18,7 @@ struct DEV_TempSensor : Service::TemperatureSensor { // A standalone Tempera
void event(){
temp->setVal(22.0);
temp->setVal((double)random(15,25));
} // event
};
@ -48,11 +48,11 @@ struct DEV_AirQualitySensor : Service::AirQualitySensor { // A standalone Ai
void event(){
airQuality->setVal(1);
o3Density->setVal(10.8);
airQuality->setVal((int)random(1,6));
o3Density->setVal((double)random(200,500));
if(!random(2)){
Serial.println("HERE\n");
no2Density->setVal(50.3);
no2Density->setVal((double)random(600,800));
}
} // event

View File

@ -1093,8 +1093,7 @@ int HAPClient::putCharacteristicsURL(char *json){
void HAPClient::checkEvents(){
unsigned long cTime=millis(); // current time
int nObj=0;
SpanBuf pObj[homeSpan.Events.size()]; // maximum number of objects needed if every Event is triggered and each requires a Notification
vector<SpanBuf> spanBuf; // vector to SpanBuf objects
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
@ -1105,6 +1104,13 @@ void HAPClient::checkEvents(){
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
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(homeSpan.Events[i]->service->Characteristics[j]->aid);
Serial.print(" iid=");
@ -1112,29 +1118,17 @@ void HAPClient::checkEvents(){
Serial.print("\n");
homeSpan.Events[i]->service->Characteristics[j]->isUpdated=false; // reset isUpdated flag
}
}
}
}
}
/*
if(characteristic){ // if the service has responded with a characteristic to update
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 characteristic is updated
} // characteristic loop
} // alarm triggered
} // events loop
if(nObj>0)
eventNotify(pObj,nObj); // transmit EVENT Notification for "n" pObj objects
if(spanBuf.size()>0) // if updated items are found
eventNotify(&spanBuf[0],spanBuf.size()); // transmit EVENT Notifications
}
*/
//////////////////////////////////////
void HAPClient::checkTimedResets(){

View File

@ -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 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
};
/////////////////////////////////////////////////