Created checkNotifications()
This will replace older checkEvents() after testing validates new and improved methodology.
This commit is contained in:
parent
53f51cc11b
commit
1efeb2880b
10
src/HAP.cpp
10
src/HAP.cpp
|
|
@ -1175,6 +1175,16 @@ void HAPClient::callServiceLoops(){
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
|
void HAPClient::checkNotifications(){
|
||||||
|
|
||||||
|
if(!homeSpan.Notifications.empty()){ // if there are Notifications to process
|
||||||
|
eventNotify(&homeSpan.Notifications[0],homeSpan.Notifications.size()); // transmit EVENT Notifications
|
||||||
|
homeSpan.Notifications.clear(); // clear Notifications vector
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////
|
||||||
|
|
||||||
void HAPClient::checkEvents(){
|
void HAPClient::checkEvents(){
|
||||||
|
|
||||||
unsigned long cTime=millis(); // current time
|
unsigned long cTime=millis(); // current time
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,7 @@ 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 callServiceLoops(); // call the loop() method for any Service with that over-rode the default method
|
static void callServiceLoops(); // call the loop() method for any Service with that over-rode the default method
|
||||||
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 checkNotifications(); // checks for Event Notifications and reports to controllers as needed (HAP Section 6.8)
|
||||||
static void checkTimedWrites(); // checks for expired Timed Write PIDs, and clears any found (HAP Section 6.7.2.4)
|
static void checkTimedWrites(); // checks for expired Timed Write PIDs, and clears any found (HAP Section 6.7.2.4)
|
||||||
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
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -149,7 +149,7 @@ void Span::poll() {
|
||||||
|
|
||||||
HAPClient::checkTimedResets();
|
HAPClient::checkTimedResets();
|
||||||
HAPClient::callServiceLoops();
|
HAPClient::callServiceLoops();
|
||||||
HAPClient::checkEvents();
|
HAPClient::checkNotifications();
|
||||||
HAPClient::checkTimedWrites();
|
HAPClient::checkTimedWrites();
|
||||||
|
|
||||||
} // poll
|
} // poll
|
||||||
|
|
@ -575,6 +575,8 @@ int Span::updateCharacteristics(char *buf, SpanBuf *pObj){
|
||||||
|
|
||||||
} // parse objects
|
} // parse objects
|
||||||
|
|
||||||
|
snapTime=millis(); // timestamp for this series of updates, assigned to each characteristic in loadUpdate()
|
||||||
|
|
||||||
for(int i=0;i<nObj;i++){ // PASS 1: loop over all objects, identify characteristics, and initialize update for those found
|
for(int i=0;i<nObj;i++){ // PASS 1: loop over all objects, identify characteristics, and initialize update for those found
|
||||||
|
|
||||||
if(twFail){ // this is a timed-write request that has either expired or for which there was no PID
|
if(twFail){ // this is a timed-write request that has either expired or for which there was no PID
|
||||||
|
|
@ -1069,6 +1071,7 @@ StatusCode SpanCharacteristic::loadUpdate(char *val, char *ev){
|
||||||
} // switch
|
} // switch
|
||||||
|
|
||||||
isUpdated=true;
|
isUpdated=true;
|
||||||
|
updateTime=homeSpan.snapTime;
|
||||||
return(StatusCode::TBD);
|
return(StatusCode::TBD);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1103,8 +1106,13 @@ void SpanCharacteristic::setVal(int val){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
isUpdated=true;
|
updateTime=homeSpan.snapTime;
|
||||||
|
|
||||||
|
SpanBuf sb; // create SpanBuf object
|
||||||
|
sb.characteristic=this; // set characteristic
|
||||||
|
sb.status=StatusCode::OK; // set status
|
||||||
|
sb.val=""; // set dummy "val" so that sprintfNotify knows to consider this "update"
|
||||||
|
homeSpan.Notifications.push_back(sb); // store SpanBuf in Notifications vector
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
@ -1112,7 +1120,20 @@ void SpanCharacteristic::setVal(int val){
|
||||||
void SpanCharacteristic::setVal(double val){
|
void SpanCharacteristic::setVal(double val){
|
||||||
|
|
||||||
value.FLOAT=(double)val;
|
value.FLOAT=(double)val;
|
||||||
isUpdated=true;
|
updateTime=homeSpan.snapTime;
|
||||||
|
|
||||||
|
SpanBuf sb; // create SpanBuf object
|
||||||
|
sb.characteristic=this; // set characteristic
|
||||||
|
sb.status=StatusCode::OK; // set status
|
||||||
|
sb.val=""; // set dummy "val" so that sprintfNotify knows to consider this "update"
|
||||||
|
homeSpan.Notifications.push_back(sb); // store SpanBuf in Notifications vector
|
||||||
|
}
|
||||||
|
|
||||||
|
///////////////////////////////
|
||||||
|
|
||||||
|
int SpanCharacteristic::timeVal(){
|
||||||
|
|
||||||
|
return(homeSpan.snapTime-updateTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
|
|
||||||
|
|
@ -52,6 +52,7 @@ struct Span{
|
||||||
vector<SpanTimedReset *> TimedResets; // vector of pointers to all TimedResets
|
vector<SpanTimedReset *> TimedResets; // vector of pointers to all TimedResets
|
||||||
vector<SpanEvent *> Events; // vector of pointer to all Events
|
vector<SpanEvent *> Events; // vector of pointer to all Events
|
||||||
vector<SpanService *> Loops; // vector of pointer to all Services that have over-ridden loop() methods
|
vector<SpanService *> Loops; // vector of pointer to all Services that have over-ridden loop() methods
|
||||||
|
vector<SpanBuf> Notifications; // vector of SpanBuf objects that store info for Characteristics that are updated with setVal() and require a Notification Event
|
||||||
unordered_map<uint64_t, uint32_t> TimedWrites; // map of timed-write PIDs and Alarm Times (based on TTLs)
|
unordered_map<uint64_t, uint32_t> TimedWrites; // map of timed-write PIDs and Alarm Times (based on TTLs)
|
||||||
|
|
||||||
void begin(Category catID,
|
void begin(Category catID,
|
||||||
|
|
@ -157,7 +158,8 @@ struct SpanCharacteristic{
|
||||||
boolean ev[MAX_CONNECTIONS]={false}; // Characteristic Event Notify Enable (per-connection)
|
boolean ev[MAX_CONNECTIONS]={false}; // Characteristic Event Notify Enable (per-connection)
|
||||||
|
|
||||||
int aid=0; // Accessory ID - passed through from Service containing this Characteristic
|
int aid=0; // Accessory ID - passed through from Service containing this Characteristic
|
||||||
boolean isUpdated=false; // set to true when new value has been requested by PUT /characteristic, or when value is updated with setVal()
|
boolean isUpdated=false; // set to true when new value has been requested by PUT /characteristic
|
||||||
|
unsigned long updateTime; // last time value was updated (in millis) either by PUT /characteristic OR by setVal()
|
||||||
UVal newValue; // the updated value requested by PUT /characteristic
|
UVal newValue; // the updated value requested by PUT /characteristic
|
||||||
SpanService *service=NULL; // pointer to Service containing this Characteristic
|
SpanService *service=NULL; // pointer to Service containing this Characteristic
|
||||||
|
|
||||||
|
|
@ -182,6 +184,7 @@ struct SpanCharacteristic{
|
||||||
void setVal(double value); // sets value of UVal value for FLOAT Characteristic type
|
void setVal(double value); // sets value of UVal value for FLOAT Characteristic type
|
||||||
|
|
||||||
boolean updated(){return(isUpdated);} // returns isUpdated
|
boolean updated(){return(isUpdated);} // returns isUpdated
|
||||||
|
int timeVal(); // returns time elapsed (in millis) since value was last updated
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue