From cc7ffb4c07590392461db99b676452eb7782a208 Mon Sep 17 00:00:00 2001 From: Gregg Date: Mon, 1 Jan 2024 09:39:54 -0600 Subject: [PATCH] Moved prettyPrint into HapOut This completes re-work of all JSON buffer memory management to use HAPOut. Next up: Stress test with Max Accessories to see how many Accessories we can now handle. --- src/HAP.cpp | 42 ++++++++++++++++++++++++- src/HAP.h | 2 ++ src/HomeSpan.cpp | 56 +++------------------------------ src/HomeSpan.h | 1 - src/Streamer.cpp | 80 ------------------------------------------------ 5 files changed, 47 insertions(+), 134 deletions(-) delete mode 100644 src/Streamer.cpp diff --git a/src/HAP.cpp b/src/HAP.cpp index b002c82..d83a412 100644 --- a/src/HAP.cpp +++ b/src/HAP.cpp @@ -1633,7 +1633,10 @@ void HapOut::HapStreamBuffer::flushBuffer(){ if(logLevel<=homeSpan.getLogLevel()){ buffer[num]='\0'; // add null terminator but DO NOT increment num (we don't want terminator considered as part of buffer) - Serial.print(buffer); + if(enablePrettyPrint) // if pretty print needed, use formatted method + printFormatted(buffer,num,2); + else // if not, just print + Serial.print(buffer); } if(hapClient!=NULL){ @@ -1680,12 +1683,49 @@ int HapOut::HapStreamBuffer::sync(){ hapClient=NULL; enablePrettyPrint=false; byteCount=0; + indent=0; mbedtls_sha512_finish_ret(ctx,hash); // finish SHA-384 and store hash mbedtls_sha512_starts_ret(ctx,1); // re-start hash for next time return(0); } + +////////////////////////////////////// + +void HapOut::HapStreamBuffer::printFormatted(char *buf, size_t nChars, size_t nsp){ + + for(int i=0;iwrite(buffer,num); -// delay(1); -// -// pbump(-num); -// return num; -//} -// -//////////////////////////////////////// -// -//StreamBuffer::int_type StreamBuffer::overflow(StreamBuffer::int_type c){ -// -// if(c!=EOF){ -// *pptr() = c; -// pbump(1); -// } -// -// if(flushBuffer()==EOF) -// return EOF; -// return c; -//} -// -//////////////////////////////////////// -// -//int StreamBuffer::sync(){ -// -// if(flushBuffer()==EOF) -// return -1; -// return 0; -//} -// -////////////////////////////////////////