started work on TLV streaming with << operator
Goal - eliminate sendEncrypted() completely by using hapOut in tlvRepond(). Next up: use function call instead of << operator so logic can be moved into TLV.h
This commit is contained in:
parent
96e6f55c72
commit
73f761adc9
42
src/HAP.cpp
42
src/HAP.cpp
|
|
@ -34,6 +34,33 @@
|
||||||
|
|
||||||
//////////////////////////////////////
|
//////////////////////////////////////
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, tlv8_t &tlv){
|
||||||
|
|
||||||
|
uint8_t *p=tlv.val.get(); // starting pointer
|
||||||
|
uint8_t *pend=p+tlv.len; // ending pointer (may equal starting if len=0)
|
||||||
|
|
||||||
|
do{
|
||||||
|
uint8_t nBytes=(pend-p)>255?255:(pend-p); // max is 255 bytes per TLV record
|
||||||
|
os.write((char *)&tlv.tag,1);
|
||||||
|
os.write((char *)&nBytes,1);
|
||||||
|
os.write((char *)p,nBytes);
|
||||||
|
p+=nBytes;
|
||||||
|
} while(p<pend);
|
||||||
|
|
||||||
|
return(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, TLV8 &tlv){
|
||||||
|
|
||||||
|
for(auto it=tlv.begin();it!=tlv.end();it++)
|
||||||
|
os << (*it);
|
||||||
|
return(os);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////
|
||||||
|
|
||||||
void HAPClient::init(){
|
void HAPClient::init(){
|
||||||
|
|
||||||
size_t len; // not used but required to read blobs from NVS
|
size_t len; // not used but required to read blobs from NVS
|
||||||
|
|
@ -1222,6 +1249,19 @@ void HAPClient::getStatusURL(HAPClient *hapClient, void (*callBack)(const char *
|
||||||
}
|
}
|
||||||
hapOut << "</table>\n";
|
hapOut << "</table>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HAPTLV tlv;
|
||||||
|
|
||||||
|
uint8_t x[400];
|
||||||
|
tlv.add(58);
|
||||||
|
memset(x,'A',400);
|
||||||
|
tlv.add(48,49,x);
|
||||||
|
memset(x,'B',400);
|
||||||
|
tlv.add(50,'B');
|
||||||
|
memset(x,'C',400);
|
||||||
|
tlv.add(52,256,x);
|
||||||
|
|
||||||
|
hapOut << tlv;
|
||||||
|
|
||||||
hapOut << "</body></html>\n";
|
hapOut << "</body></html>\n";
|
||||||
hapOut.flush();
|
hapOut.flush();
|
||||||
|
|
@ -1740,7 +1780,7 @@ void HapOut::HapStreamBuffer::printFormatted(char *buf, size_t nChars, size_t ns
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -352,9 +352,8 @@ class Span{
|
||||||
Span& setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
Span& setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
||||||
Span& setStatusCallback(void (*f)(HS_STATUS status)){statusCallback=f;return(*this);} // sets an optional user-defined function to call when HomeSpan status changes
|
Span& setStatusCallback(void (*f)(HS_STATUS status)){statusCallback=f;return(*this);} // sets an optional user-defined function to call when HomeSpan status changes
|
||||||
const char* statusString(HS_STATUS s); // returns char string for HomeSpan status change messages
|
const char* statusString(HS_STATUS s); // returns char string for HomeSpan status change messages
|
||||||
|
Span& setPairingCode(const char *s); // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
|
||||||
Span& setPairingCode(const char *s); // {sprintf(pairingCodeCommand,"S %9s",s);return(*this);} // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
|
void deleteStoredValues(){processSerialCommand("V");} // deletes stored Characteristic values from NVS
|
||||||
void deleteStoredValues(){processSerialCommand("V");} // deletes stored Characteristic values from NVS
|
|
||||||
|
|
||||||
int enableOTA(boolean auth=true, boolean safeLoad=true){return(spanOTA.init(auth, safeLoad, NULL));} // enables Over-the-Air updates, with (auth=true) or without (auth=false) authorization password
|
int enableOTA(boolean auth=true, boolean safeLoad=true){return(spanOTA.init(auth, safeLoad, NULL));} // enables Over-the-Air updates, with (auth=true) or without (auth=false) authorization password
|
||||||
int enableOTA(const char *pwd, boolean safeLoad=true){return(spanOTA.init(true, safeLoad, pwd));} // enables Over-the-Air updates, with custom authorization password (overrides any password stored with the 'O' command)
|
int enableOTA(const char *pwd, boolean safeLoad=true){return(spanOTA.init(true, safeLoad, pwd));} // enables Over-the-Air updates, with custom authorization password (overrides any password stored with the 'O' command)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue