Completed initial migration of Serial.print to LOG0
Finished all applicable cases in main source code. TO DO: apply LOG0 to extras
This commit is contained in:
parent
66bb13af03
commit
7bc885dd26
63
src/HAP.cpp
63
src/HAP.cpp
|
|
@ -220,7 +220,7 @@ void HAPClient::processRequest(){
|
|||
if(!strncmp(body,"POST /pair-setup ",17) && // POST PAIR-SETUP
|
||||
strstr(body,"Content-Type: application/pairing+tlv8") && // check that content is TLV8
|
||||
tlv8.unpack(content,cLen)){ // read TLV content
|
||||
if(homeSpan.logLevel>1) tlv8.print(); // print TLV records in form "TAG(INT) LENGTH(INT) VALUES(HEX)"
|
||||
tlv8.print(2); // print TLV records in form "TAG(INT) LENGTH(INT) VALUES(HEX)"
|
||||
LOG2("------------ END TLVS! ------------\n");
|
||||
|
||||
postPairSetupURL(); // process URL
|
||||
|
|
@ -230,7 +230,7 @@ void HAPClient::processRequest(){
|
|||
if(!strncmp(body,"POST /pair-verify ",18) && // POST PAIR-VERIFY
|
||||
strstr(body,"Content-Type: application/pairing+tlv8") && // check that content is TLV8
|
||||
tlv8.unpack(content,cLen)){ // read TLV content
|
||||
if(homeSpan.logLevel>1) tlv8.print(); // print TLV records in form "TAG(INT) LENGTH(INT) VALUES(HEX)"
|
||||
tlv8.print(2); // print TLV records in form "TAG(INT) LENGTH(INT) VALUES(HEX)"
|
||||
LOG2("------------ END TLVS! ------------\n");
|
||||
|
||||
postPairVerifyURL(); // process URL
|
||||
|
|
@ -240,7 +240,7 @@ void HAPClient::processRequest(){
|
|||
if(!strncmp(body,"POST /pairings ",15) && // POST PAIRINGS
|
||||
strstr(body,"Content-Type: application/pairing+tlv8") && // check that content is TLV8
|
||||
tlv8.unpack(content,cLen)){ // read TLV content
|
||||
if(homeSpan.logLevel>1) tlv8.print(); // print TLV records in form "TAG(INT) LENGTH(INT) VALUES(HEX)"
|
||||
tlv8.print(2); // print TLV records in form "TAG(INT) LENGTH(INT) VALUES(HEX)"
|
||||
LOG2("------------ END TLVS! ------------\n");
|
||||
|
||||
postPairingsURL(); // process URL
|
||||
|
|
@ -250,7 +250,7 @@ void HAPClient::processRequest(){
|
|||
if(!strncmp(body,"POST /pairings ",15) && // POST PAIRINGS
|
||||
strstr(body,"Content-Type: application/pairing+tlv8") && // check that content is TLV8
|
||||
tlv8.unpack(content,cLen)){ // read TLV content
|
||||
if(homeSpan.logLevel>1) tlv8.print(); // print TLV records in form "TAG(INT) LENGTH(INT) VALUES(HEX)"
|
||||
tlv8.print(2); // print TLV records in form "TAG(INT) LENGTH(INT) VALUES(HEX)"
|
||||
LOG2("------------ END TLVS! ------------\n");
|
||||
|
||||
postPairingsURL(); // process URL
|
||||
|
|
@ -529,7 +529,7 @@ int HAPClient::postPairSetupURL(){
|
|||
return(0);
|
||||
}
|
||||
|
||||
if(homeSpan.logLevel>1) tlv8.print(); // print decrypted TLV data
|
||||
tlv8.print(2); // print decrypted TLV data
|
||||
LOG2("------- END DECRYPTED TLVS! -------\n");
|
||||
|
||||
if(!tlv8.buf(kTLVType_Identifier) || !tlv8.buf(kTLVType_PublicKey) || !tlv8.buf(kTLVType_Signature)){
|
||||
|
|
@ -609,7 +609,7 @@ int HAPClient::postPairSetupURL(){
|
|||
|
||||
LOG2("------- ENCRYPTING SUB-TLVS -------\n");
|
||||
|
||||
if(homeSpan.logLevel>1) tlv8.print();
|
||||
tlv8.print(2);
|
||||
|
||||
size_t subTLVLen=tlv8.pack(NULL); // get size of buffer needed to store sub-TLV
|
||||
uint8_t subTLV[subTLVLen];
|
||||
|
|
@ -721,7 +721,7 @@ int HAPClient::postPairVerifyURL(){
|
|||
|
||||
LOG2("------- ENCRYPTING SUB-TLVS -------\n");
|
||||
|
||||
if(homeSpan.logLevel>1) tlv8.print();
|
||||
tlv8.print(2);
|
||||
|
||||
size_t subTLVLen=tlv8.pack(NULL); // get size of buffer needed to store sub-TLV
|
||||
uint8_t subTLV[subTLVLen];
|
||||
|
|
@ -785,7 +785,7 @@ int HAPClient::postPairVerifyURL(){
|
|||
return(0);
|
||||
}
|
||||
|
||||
if(homeSpan.logLevel>1) tlv8.print(); // print decrypted TLV data
|
||||
tlv8.print(2); // print decrypted TLV data
|
||||
LOG2("------- END DECRYPTED TLVS! -------\n");
|
||||
|
||||
if(!tlv8.buf(kTLVType_Identifier) || !tlv8.buf(kTLVType_Signature)){
|
||||
|
|
@ -1429,7 +1429,7 @@ void HAPClient::tlvRespond(){
|
|||
LOG2(client.remoteIP());
|
||||
LOG2(" >>>>>>>>>>\n");
|
||||
LOG2(body);
|
||||
if(homeSpan.logLevel>1) tlv8.print();
|
||||
tlv8.print(2);
|
||||
|
||||
if(!cPair){ // unverified, unencrypted session
|
||||
client.print(body);
|
||||
|
|
@ -1531,26 +1531,35 @@ void HAPClient::sendEncrypted(char *body, uint8_t *dataBuf, int dataLen){
|
|||
/////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void HAPClient::hexPrintColumn(uint8_t *buf, int n){
|
||||
void HAPClient::hexPrintColumn(uint8_t *buf, int n, int minLogLevel){
|
||||
|
||||
if(homeSpan.logLevel<minLogLevel)
|
||||
return;
|
||||
|
||||
for(int i=0;i<n;i++)
|
||||
LOG0("%d) %02X\n",i,buf[i]);
|
||||
Serial.printf("%d) %02X\n",i,buf[i]);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void HAPClient::hexPrintRow(uint8_t *buf, int n){
|
||||
|
||||
void HAPClient::hexPrintRow(uint8_t *buf, int n, int minLogLevel){
|
||||
|
||||
if(homeSpan.logLevel<minLogLevel)
|
||||
return;
|
||||
|
||||
for(int i=0;i<n;i++)
|
||||
LOG0("%02X",buf[i]);
|
||||
Serial.printf("%02X",buf[i]);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
||||
void HAPClient::charPrintRow(uint8_t *buf, int n){
|
||||
void HAPClient::charPrintRow(uint8_t *buf, int n, int minLogLevel){
|
||||
|
||||
if(homeSpan.logLevel<minLogLevel)
|
||||
return;
|
||||
|
||||
for(int i=0;i<n;i++)
|
||||
LOG0("%c",buf[i]);
|
||||
Serial.printf("%c",buf[i]);
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
@ -1587,8 +1596,7 @@ Controller *HAPClient::addController(uint8_t *id, uint8_t *ltpk, boolean admin){
|
|||
memcpy(slot->LTPK,ltpk,32);
|
||||
slot->admin=admin;
|
||||
LOG2("\n*** Updated Controller: ");
|
||||
if(homeSpan.logLevel>1)
|
||||
charPrintRow(id,36);
|
||||
charPrintRow(id,36,2);
|
||||
LOG2(slot->admin?" (admin)\n\n":" (regular)\n\n");
|
||||
return(slot);
|
||||
}
|
||||
|
|
@ -1599,8 +1607,7 @@ Controller *HAPClient::addController(uint8_t *id, uint8_t *ltpk, boolean admin){
|
|||
memcpy(slot->LTPK,ltpk,32);
|
||||
slot->admin=admin;
|
||||
LOG2("\n*** Added Controller: ");
|
||||
if(homeSpan.logLevel>1)
|
||||
charPrintRow(id,36);
|
||||
charPrintRow(id,36,2);
|
||||
LOG2(slot->admin?" (admin)\n\n":" (regular)\n\n");
|
||||
return(slot);
|
||||
}
|
||||
|
|
@ -1637,8 +1644,7 @@ void HAPClient::removeController(uint8_t *id){
|
|||
|
||||
if((slot=findController(id))){ // remove controller if found
|
||||
LOG2("\n***Removed Controller: ");
|
||||
if(homeSpan.logLevel>1)
|
||||
charPrintRow(id,36);
|
||||
charPrintRow(id,36,2);
|
||||
LOG2(slot->admin?" (admin)\n":" (regular)\n");
|
||||
slot->allocated=false;
|
||||
|
||||
|
|
@ -1660,23 +1666,26 @@ void HAPClient::removeController(uint8_t *id){
|
|||
|
||||
//////////////////////////////////////
|
||||
|
||||
void HAPClient::printControllers(){
|
||||
void HAPClient::printControllers(int minLogLevel){
|
||||
|
||||
if(homeSpan.logLevel<minLogLevel)
|
||||
return;
|
||||
|
||||
int n=0;
|
||||
|
||||
for(int i=0;i<MAX_CONTROLLERS;i++){ // loop over all controller slots
|
||||
if(controllers[i].allocated){
|
||||
LOG0("Paired Controller: ");
|
||||
Serial.printf("Paired Controller: ");
|
||||
charPrintRow(controllers[i].ID,36);
|
||||
LOG0("%s LTPK: ",controllers[i].admin?" (admin)":" (regular)");
|
||||
Serial.printf("%s LTPK: ",controllers[i].admin?" (admin)":" (regular)");
|
||||
hexPrintRow(controllers[i].LTPK,32);
|
||||
LOG0("\n");
|
||||
Serial.printf("\n");
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
if(n==0)
|
||||
LOG0("No Paired Controllers\n");
|
||||
Serial.printf("No Paired Controllers\n");
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -131,9 +131,9 @@ struct HAPClient {
|
|||
|
||||
static void init(); // initialize HAP after start-up
|
||||
|
||||
static void hexPrintColumn(uint8_t *buf, int n); // prints 'n' bytes of *buf as HEX, one byte per row. For diagnostics/debugging only
|
||||
static void hexPrintRow(uint8_t *buf, int n); // prints 'n' bytes of *buf as HEX, all on one row
|
||||
static void charPrintRow(uint8_t *buf, int n); // prints 'n' bytes of *buf as CHAR, all on one row
|
||||
static void hexPrintColumn(uint8_t *buf, int n, int minLogLevel=0); // prints 'n' bytes of *buf as HEX, one byte per row, subject to specified minimum log level
|
||||
static void hexPrintRow(uint8_t *buf, int n, int minLogLevel=0); // prints 'n' bytes of *buf as HEX, all on one row, subject to specified minimum log level
|
||||
static void charPrintRow(uint8_t *buf, int n, int minLogLevel=0); // prints 'n' bytes of *buf as CHAR, all on one row, subject to specified minimum log level
|
||||
|
||||
static Controller *findController(uint8_t *id); // returns pointer to controller with mathching ID (or NULL if no match)
|
||||
static Controller *getFreeController(); // return pointer to next free controller slot (or NULL if no free slots)
|
||||
|
|
@ -141,7 +141,7 @@ struct HAPClient {
|
|||
static int nAdminControllers(); // returns number of admin Controllers stored
|
||||
static void removeControllers(); // removes all Controllers (sets allocated flags to false for all slots)
|
||||
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 printControllers(int minLogLevel=0); // prints IDs of all allocated (paired) Controller, subject to specified minimum log level
|
||||
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 eventNotify(SpanBuf *pObj, int nObj, int ignoreClient=-1); // transmits EVENT Notifications for nObj SpanBuf objects, pObj, with optional flag to ignore a specific client
|
||||
|
|
|
|||
|
|
@ -1218,7 +1218,11 @@ int Span::sprintfAttributes(char *cBuf, int flags){
|
|||
|
||||
///////////////////////////////
|
||||
|
||||
void Span::prettyPrint(char *buf, int nsp){
|
||||
void Span::prettyPrint(char *buf, int nsp, int minLogLevel){
|
||||
|
||||
if(logLevel<minLogLevel)
|
||||
return;
|
||||
|
||||
int s=strlen(buf);
|
||||
int indent=0;
|
||||
|
||||
|
|
@ -1227,34 +1231,34 @@ void Span::prettyPrint(char *buf, int nsp){
|
|||
|
||||
case '{':
|
||||
case '[':
|
||||
LOG0("%c\n",buf[i]);
|
||||
Serial.printf("%c\n",buf[i]);
|
||||
indent+=nsp;
|
||||
for(int j=0;j<indent;j++)
|
||||
LOG0(" ");
|
||||
Serial.printf(" ");
|
||||
break;
|
||||
|
||||
case '}':
|
||||
case ']':
|
||||
LOG0("\n");
|
||||
Serial.printf("\n");
|
||||
indent-=nsp;
|
||||
for(int j=0;j<indent;j++)
|
||||
LOG0(" ");
|
||||
LOG0("%c",buf[i]);
|
||||
Serial.printf(" ");
|
||||
Serial.printf("%c",buf[i]);
|
||||
break;
|
||||
|
||||
case ',':
|
||||
LOG0("%c\n",buf[i]);
|
||||
Serial.printf("%c\n",buf[i]);
|
||||
for(int j=0;j<indent;j++)
|
||||
LOG0(" ");
|
||||
Serial.printf(" ");
|
||||
break;
|
||||
|
||||
default:
|
||||
LOG0("%c",buf[i]);
|
||||
Serial.printf("%c",buf[i]);
|
||||
|
||||
} // switch
|
||||
} // loop over all characters
|
||||
|
||||
LOG0("\n");
|
||||
Serial.printf("\n");
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -110,8 +110,6 @@ struct SpanUserCommand;
|
|||
|
||||
extern Span homeSpan;
|
||||
|
||||
#include "HAP.h"
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// INTERNAL HOMESPAN STRUCTURES - NOT FOR USER ACCESS //
|
||||
////////////////////////////////////////////////////////
|
||||
|
|
@ -264,7 +262,7 @@ class Span{
|
|||
|
||||
int sprintfAttributes(char *cBuf, int flags=GET_VALUE|GET_META|GET_PERMS|GET_TYPE|GET_DESC); // prints Attributes JSON database into buf, unless buf=NULL; return number of characters printed, excluding null terminator
|
||||
|
||||
void prettyPrint(char *buf, int nsp=2); // print arbitrary JSON from buf to serial monitor, formatted with indentions of 'nsp' spaces
|
||||
void prettyPrint(char *buf, int nsp=2, int minLogLevel=0); // print arbitrary JSON from buf to serial monitor, formatted with indentions of 'nsp' spaces, subject to specified minimum log level
|
||||
SpanCharacteristic *find(uint32_t 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, SpanBuf *pObj); // parses PUT /characteristics JSON request 'buf into 'pObj' and updates referenced characteristics; returns 1 on success, 0 on fail
|
||||
|
|
|
|||
10
src/SRP.cpp
10
src/SRP.cpp
|
|
@ -266,15 +266,17 @@ int SRP6A::writeTLV(kTLVType tag, mbedtls_mpi *mpi){
|
|||
|
||||
//////////////////////////////////////
|
||||
|
||||
void SRP6A::print(mbedtls_mpi *mpi){
|
||||
|
||||
void SRP6A::print(mbedtls_mpi *mpi, int minLogLevel){
|
||||
|
||||
if(homeSpan.getLogLevel()<minLogLevel)
|
||||
return;
|
||||
|
||||
char sBuf[2000];
|
||||
size_t sLen;
|
||||
|
||||
mbedtls_mpi_write_string(mpi,16,sBuf,2000,&sLen);
|
||||
|
||||
LOG0("%d ",(sLen-1)/2); // subtract 1 for null-terminator, and then divide by 2 to get number of bytes (e.g. 4F = 2 characters, but represents just one mpi byte)
|
||||
LOG0("%s\n",sBuf);
|
||||
Serial.printf("%d %s\n",(sLen-1)/2,sBuf); // subtract 1 for null-terminator, and then divide by 2 to get number of bytes (e.g. 4F = 2 characters, but represents just one mpi byte)
|
||||
}
|
||||
|
||||
//////////////////////////////////////
|
||||
|
|
|
|||
|
|
@ -87,6 +87,6 @@ struct SRP6A {
|
|||
int verifyProof(); // verify M1 SRP6A Proof received from HAP client (return 1 on success, 0 on failure)
|
||||
void createProof(); // create M2 server-side SRP6A Proof based on M1 as received from HAP Client
|
||||
|
||||
void print(mbedtls_mpi *mpi); // prints size of mpi (in bytes), followed by the mpi itself (as a hex charcter string) - for diagnostic purposes only
|
||||
void print(mbedtls_mpi *mpi, int minLogLevel=0); // prints size of mpi (in bytes), followed by the mpi itself (as a hex charcter string), subject to specified minimum log level
|
||||
|
||||
};
|
||||
|
|
|
|||
22
src/TLV.h
22
src/TLV.h
|
|
@ -56,7 +56,7 @@ public:
|
|||
uint8_t *buf(tagType tag); // returns VAL Buffer for TLV with matching TAG (or NULL if no match)
|
||||
uint8_t *buf(tagType tag, int len); // set length and returns VAL Buffer for TLV with matching TAG (or NULL if no match or if LEN>MAX)
|
||||
int len(tagType tag); // returns LEN for TLV matching TAG (or 0 if TAG is found but LEN not yet set; -1 if no match at all)
|
||||
void print(); // prints all defined TLVs (those with length>0). For diagnostics/debugging only
|
||||
void print(int minLogLevel=0); // prints all defined TLVs (those with length>0), subject to specified minimum log level
|
||||
int unpack(uint8_t *tlvBuf, int nBytes); // unpacks nBytes of TLV content from single byte buffer into individual TLV records (return 1 on success, 0 if fail)
|
||||
int pack(uint8_t *tlvBuf); // if tlvBuf!=NULL, packs all defined TLV records (LEN>0) into a single byte buffer, spitting large TLVs into separate 255-byte chunks. Returns number of bytes (that would be) stored in buffer
|
||||
int pack_old(uint8_t *buf); // packs all defined TLV records (LEN>0) into a single byte buffer, spitting large TLVs into separate 255-byte records. Returns number of bytes stored in buffer
|
||||
|
|
@ -192,24 +192,20 @@ uint8_t *TLV<tagType, maxTags>::buf(tagType tag, int len){
|
|||
// TLV print()
|
||||
|
||||
template<class tagType, int maxTags>
|
||||
void TLV<tagType, maxTags>::print(){
|
||||
|
||||
char buf[3];
|
||||
void TLV<tagType, maxTags>::print(int minLogLevel){
|
||||
|
||||
if(homeSpan.getLogLevel()<minLogLevel)
|
||||
return;
|
||||
|
||||
for(int i=0;i<numTags;i++){
|
||||
|
||||
if(tlv[i].len>0){
|
||||
Serial.print(tlv[i].name);
|
||||
Serial.print("(");
|
||||
Serial.print(tlv[i].len);
|
||||
Serial.print(") ");
|
||||
Serial.printf("%s(%d) ",tlv[i].name,tlv[i].len);
|
||||
|
||||
for(int j=0;j<tlv[i].len;j++){
|
||||
sprintf(buf,"%02X",tlv[i].val[j]);
|
||||
Serial.print(buf);
|
||||
}
|
||||
for(int j=0;j<tlv[i].len;j++)
|
||||
Serial.printf("%02X",tlv[i].val[j]);
|
||||
|
||||
Serial.print("\n");
|
||||
Serial.printf("\n");
|
||||
|
||||
} // len>0
|
||||
} // loop over all TLVs
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
********************************************************************************/
|
||||
|
||||
#include "Utils.h"
|
||||
#include "HomeSpan.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
|
|
@ -104,10 +105,10 @@ PushButton::PushButton(int pin, triggerType_t triggerType){
|
|||
threshold/=calibCount;
|
||||
#if SOC_TOUCH_VERSION_1
|
||||
threshold/=2;
|
||||
Serial.printf("Touch Sensor at pin=%d used for calibration. Triggers when sensor reading < %d.\n",pin,threshold);
|
||||
LOG0("Touch Sensor at pin=%d used for calibration. Triggers when sensor reading < %d.\n",pin,threshold);
|
||||
#elif SOC_TOUCH_VERSION_2
|
||||
threshold*=2;
|
||||
Serial.printf("Touch Sensor at pin=%d used for calibration. Triggers when sensor reading > %d.\n",pin,threshold);
|
||||
LOG0("Touch Sensor at pin=%d used for calibration. Triggers when sensor reading > %d.\n",pin,threshold);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Reference in New Issue