Renamed SpanPut to SpanBuf
This commit is contained in:
parent
471d62f3c2
commit
e7c2fc46f7
35
src/HAP.cpp
35
src/HAP.cpp
|
|
@ -2,7 +2,6 @@
|
|||
#include <ESPmDNS.h>
|
||||
#include <sodium.h>
|
||||
|
||||
//#include "HomeSpan.h"
|
||||
#include "HAP.h"
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
@ -1041,7 +1040,7 @@ int HAPClient::putCharacteristicsURL(char *json){
|
|||
if(n==0) // if no objects found, return
|
||||
return(0);
|
||||
|
||||
SpanPut pObj[n]; // reserve space for objects
|
||||
SpanBuf pObj[n]; // reserve space for objects
|
||||
if(!homeSpan.updateCharacteristics(json, pObj)) // perform update
|
||||
return(0); // return if failed to update (error message will have been printed in update)
|
||||
|
||||
|
|
@ -1085,34 +1084,6 @@ int HAPClient::putCharacteristicsURL(char *json){
|
|||
// Create and send Event Notifications if needed
|
||||
|
||||
eventNotify(pObj,n,HAPClient::conNum); // transmit EVENT Notification for "n" pObj objects, except DO NOT notify client making request
|
||||
|
||||
/*
|
||||
for(int i=0;i<MAX_CONNECTIONS;i++){ // loop over all connection slots
|
||||
if(hap[i].client && i!=HAPClient::conNum){ // if there is a client connected to this slot and it is NOT the current client requesting this update
|
||||
|
||||
int nBytes=homeSpan.sprintfNotify(pObj,n,NULL,i); // get JSON response - includes terminating null (will be recast to uint8_t* below)
|
||||
|
||||
if(nBytes>0){
|
||||
char jsonBuf[nBytes+1];
|
||||
homeSpan.sprintfNotify(pObj,n,jsonBuf,i);
|
||||
|
||||
int nChars=snprintf(NULL,0,"EVENT/1.0 200 OK\r\nContent-Type: application/hap+json\r\nContent-Length: %d\r\n\r\n",nBytes); // create Body with Content Length = size of JSON Buf
|
||||
char body[nChars+1];
|
||||
sprintf(body,"EVENT/1.0 200 OK\r\nContent-Type: application/hap+json\r\nContent-Length: %d\r\n\r\n",nBytes);
|
||||
|
||||
LOG2("\n>>>>>>>>>> ");
|
||||
LOG2(hap[i].client.remoteIP());
|
||||
LOG2(" >>>>>>>>>>\n");
|
||||
LOG2(body);
|
||||
LOG2(jsonBuf);
|
||||
LOG2("\n");
|
||||
|
||||
hap[i].sendEncrypted(body,(uint8_t *)jsonBuf,nBytes); // note recasting of jsonBuf into uint8_t*
|
||||
|
||||
} // if there are characteristic updates to notify
|
||||
} // if client exists
|
||||
}
|
||||
*/
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
|
@ -1143,7 +1114,7 @@ void HAPClient::checkNotifications(){
|
|||
if(!n) // nothing to do (either no Timed Reset characteristics, or none that need to be turned off)
|
||||
return;
|
||||
|
||||
SpanPut pObj[n]; // use a SpanPut object (for convenience) to load characteristics to be updated
|
||||
SpanBuf pObj[n]; // use a SpanBuf object to load characteristics to be updated
|
||||
n=0; // reset number of tResets found that need to be turned off
|
||||
|
||||
for(int i=0;i<homeSpan.TimedResets.size();i++){ // PASS 2: loop through all defined Timed Resets
|
||||
|
|
@ -1171,7 +1142,7 @@ void HAPClient::checkNotifications(){
|
|||
|
||||
//////////////////////////////////////
|
||||
|
||||
void HAPClient::eventNotify(SpanPut *pObj, int nObj, int ignoreClient){
|
||||
void HAPClient::eventNotify(SpanBuf *pObj, int nObj, int ignoreClient){
|
||||
|
||||
for(int cNum=0;cNum<MAX_CONNECTIONS;cNum++){ // loop over all connection slots
|
||||
if(hap[cNum].client && cNum!=ignoreClient){ // if there is a client connected to this slot and it is NOT flagged to be ignored (in cases where it is the client making a PUT request
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ struct HAPClient {
|
|||
static void removeController(uint8_t *id); // removes specific Controller. If no remaining admin Controllers, remove all others (if any) as per HAP requirements.
|
||||
static void printControllers(); // prints IDs of all allocated (paired) Controller
|
||||
static void checkNotifications(); // checks for notifications and reports to controllers as needed (HAP Section 6.8)
|
||||
static void eventNotify(SpanPut *pObj, int nObj, int ignoreClient=-1); // transmits EVENT Notifications for nObj SpanPut 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
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
#include "Utils.h"
|
||||
#include "HAP.h"
|
||||
//#include "HomeSpan.h"
|
||||
|
||||
using namespace Utils;
|
||||
|
||||
|
|
@ -504,7 +503,7 @@ int Span::countCharacteristics(char *buf){
|
|||
|
||||
///////////////////////////////
|
||||
|
||||
int Span::updateCharacteristics(char *buf, SpanPut *pObj){
|
||||
int Span::updateCharacteristics(char *buf, SpanBuf *pObj){
|
||||
|
||||
int nObj=0;
|
||||
char *p1;
|
||||
|
|
@ -620,7 +619,7 @@ void Span::clearNotify(int slotNum){
|
|||
|
||||
///////////////////////////////
|
||||
|
||||
int Span::sprintfNotify(SpanPut *pObj, int nObj, char *cBuf, int conNum){
|
||||
int Span::sprintfNotify(SpanBuf *pObj, int nObj, char *cBuf, int conNum){
|
||||
|
||||
int nChars=0;
|
||||
boolean notifyFlag=false;
|
||||
|
|
@ -650,7 +649,7 @@ int Span::sprintfNotify(SpanPut *pObj, int nObj, char *cBuf, int conNum){
|
|||
|
||||
///////////////////////////////
|
||||
|
||||
int Span::sprintfAttributes(SpanPut *pObj, int nObj, char *cBuf){
|
||||
int Span::sprintfAttributes(SpanBuf *pObj, int nObj, char *cBuf){
|
||||
|
||||
int nChars=0;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ struct SpanAccessory;
|
|||
struct SpanService;
|
||||
struct SpanCharacteristic;
|
||||
struct SpanRange;
|
||||
struct SpanPut;
|
||||
struct SpanBuf;
|
||||
struct SpanTimedReset;
|
||||
|
||||
///////////////////////////////
|
||||
|
|
@ -62,12 +62,12 @@ struct Span{
|
|||
SpanCharacteristic *find(int aid, int iid); // return Characteristic with matching aid and iid (else NULL if not found)
|
||||
|
||||
int countCharacteristics(char *buf); // return number of characteristic objects referenced in PUT /characteristics JSON request
|
||||
int updateCharacteristics(char *buf, SpanPut *pObj); // parses PUT /characteristics JSON request 'buf into 'pObj' and updates referenced characteristics; returns 1 on success, 0 on fail
|
||||
int sprintfAttributes(SpanPut *pObj, int nObj, char *cBuf); // prints SpanPut object into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
||||
int updateCharacteristics(char *buf, SpanBuf *pObj); // parses PUT /characteristics JSON request 'buf into 'pObj' and updates referenced characteristics; returns 1 on success, 0 on fail
|
||||
int sprintfAttributes(SpanBuf *pObj, int nObj, char *cBuf); // prints SpanBuf object into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
||||
int sprintfAttributes(char **ids, int numIDs, int flags, char *cBuf); // prints accessory.characteristic ids into buf, unless buf=NULL; return number of characters printed, excluding null terminator, even if buf=NULL
|
||||
|
||||
void clearNotify(int slotNum); // set ev notification flags for connection 'slotNum' to false across all characteristics
|
||||
int sprintfNotify(SpanPut *pObj, int nObj, char *cBuf, int conNum); // prints notification JSON into buf based on SpanPut objects and specified connection number
|
||||
int sprintfNotify(SpanBuf *pObj, int nObj, char *cBuf, int conNum); // prints notification JSON into buf based on SpanBuf objects and specified connection number
|
||||
|
||||
void setResetPin(int pin){resetPin=pin;} // sets new pin to be used for factory reset
|
||||
|
||||
|
|
@ -211,9 +211,9 @@ struct SpanRange{
|
|||
|
||||
///////////////////////////////
|
||||
|
||||
struct SpanPut{ // storage to process PUT /characteristics request
|
||||
int aid; // aid to update
|
||||
int iid; // iid to update
|
||||
struct SpanBuf{ // temporary storage buffer for use with putCharacteristicsURL() and checkNotifications()
|
||||
int aid; // updated aid
|
||||
int iid; // updated iid
|
||||
char *val=NULL; // updated value (optional, though either at least 'val' or 'ev' must be specified)
|
||||
char *ev=NULL; // updated event notification flag (optional, though either at least 'val' or 'ev' must be specified)
|
||||
StatusCode status; // return status (HAP Table 6-11)
|
||||
|
|
|
|||
Loading…
Reference in New Issue