From 7bc885dd266f2e24901bf19fcc6abe4c138a3d34 Mon Sep 17 00:00:00 2001 From: Gregg Date: Wed, 10 May 2023 22:12:21 -0500 Subject: [PATCH] Completed initial migration of Serial.print to LOG0 Finished all applicable cases in main source code. TO DO: apply LOG0 to extras --- src/HAP.cpp | 63 +++++++++++++++++++++++++++--------------------- src/HAP.h | 8 +++--- src/HomeSpan.cpp | 24 ++++++++++-------- src/HomeSpan.h | 4 +-- src/SRP.cpp | 10 +++++--- src/SRP.h | 2 +- src/TLV.h | 22 +++++++---------- src/Utils.cpp | 5 ++-- 8 files changed, 74 insertions(+), 64 deletions(-) diff --git a/src/HAP.cpp b/src/HAP.cpp index 6e27e36..39bed60 100644 --- a/src/HAP.cpp +++ b/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.logLevelLTPK,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.logLevelMAX) 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::buf(tagType tag, int len){ // TLV print() template -void TLV::print(){ - - char buf[3]; +void TLV::print(int minLogLevel){ + if(homeSpan.getLogLevel()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;j0 } // loop over all TLVs diff --git a/src/Utils.cpp b/src/Utils.cpp index 94dd131..7645405 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -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