Refactor SerialBridge printf

This commit is contained in:
Theo Arends 2022-06-07 10:03:12 +02:00
parent b81c3741b7
commit 41bc8bcd34
4 changed files with 17 additions and 10 deletions

View File

@ -46,7 +46,7 @@ extern "C" void resetPins();
extern "C" int startWaveformClockCycles(uint8_t pin, uint32_t highCcys, uint32_t lowCcys, extern "C" int startWaveformClockCycles(uint8_t pin, uint32_t highCcys, uint32_t lowCcys,
uint32_t runTimeCcys, int8_t alignPhase, uint32_t phaseOffsetCcys, bool autoPwm); uint32_t runTimeCcys, int8_t alignPhase, uint32_t phaseOffsetCcys, bool autoPwm);
#ifdef USE_SERIAL_BRIDGE #ifdef USE_SERIAL_BRIDGE
void SerialBridgeLog(const char *mxtime, const char *log_data = nullptr, const char *log_data_payload = nullptr, const char *log_data_retained = nullptr); void SerialBridgePrintf(PGM_P formatP, ...);
#endif #endif
#ifdef USE_INFLUXDB #ifdef USE_INFLUXDB
void InfluxDbProcess(bool use_copy = false); void InfluxDbProcess(bool use_copy = false);

View File

@ -2593,9 +2593,9 @@ void AddLogData(uint32_t loglevel, const char* log_data, const char* log_data_pa
if ((loglevel <= TasmotaGlobal.seriallog_level) && if ((loglevel <= TasmotaGlobal.seriallog_level) &&
(TasmotaGlobal.masterlog_level <= TasmotaGlobal.seriallog_level)) { (TasmotaGlobal.masterlog_level <= TasmotaGlobal.seriallog_level)) {
TasConsole.printf("%s%s%s%s\r\n", mxtime, log_data, log_data_payload, log_data_retained); TasConsole.printf("%s%s%s%s\n", mxtime, log_data, log_data_payload, log_data_retained);
#ifdef USE_SERIAL_BRIDGE #ifdef USE_SERIAL_BRIDGE
SerialBridgeLog(mxtime, log_data, log_data_payload, log_data_retained); SerialBridgePrintf("%s%s%s%s\n", mxtime, log_data, log_data_payload, log_data_retained);
#endif // USE_SERIAL_BRIDGE #endif // USE_SERIAL_BRIDGE
} }

View File

@ -64,14 +64,17 @@ void SetSSerialConfig(uint32_t serial_config) {
} }
} }
void SerialBridgeLog(const char *mxtime, const char *log_data, const char *log_data_payload, const char *log_data_retained) { void SerialBridgePrintf(PGM_P formatP, ...) {
#ifdef USE_SERIAL_BRIDGE_TEE #ifdef USE_SERIAL_BRIDGE_TEE
if (Settings->sbflag1.serbridge_console && serial_bridge_buffer) { if (Settings->sbflag1.serbridge_console && serial_bridge_buffer) {
char empty[2] = { 0 }; va_list arg;
if (!log_data) { log_data = empty; } va_start(arg, formatP);
if (!log_data_payload) { log_data_payload = empty; } char* data = ext_vsnprintf_malloc_P(formatP, arg);
if (!log_data_retained) { log_data_retained = empty; } va_end(arg);
SerialBridgeSerial->printf("%s%s%s%s\r\n", mxtime, log_data, log_data_payload, log_data_retained); if (data == nullptr) { return; }
SerialBridgeSerial->printf(data);
free(data);
} }
#endif // USE_SERIAL_BRIDGE_TEE #endif // USE_SERIAL_BRIDGE_TEE
} }
@ -182,6 +185,7 @@ void SerialBridgeInit(void) {
serial_bridge_buffer = (char*)(malloc(SERIAL_BRIDGE_BUFFER_SIZE)); serial_bridge_buffer = (char*)(malloc(SERIAL_BRIDGE_BUFFER_SIZE));
} }
SerialBridgeSerial->flush(); SerialBridgeSerial->flush();
SerialBridgePrintf("\n");
} }
} }
} }
@ -236,7 +240,7 @@ void CmndSSerialSend(void) {
#ifdef USE_SERIAL_BRIDGE_TEE #ifdef USE_SERIAL_BRIDGE_TEE
if (9 == XdrvMailbox.index) { if (9 == XdrvMailbox.index) {
if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= 1)) {
Settings->sbflag1.serbridge_console = XdrvMailbox.payload &1; Settings->sbflag1.serbridge_console = XdrvMailbox.payload;
} }
ResponseCmndStateText(Settings->sbflag1.serbridge_console); ResponseCmndStateText(Settings->sbflag1.serbridge_console);
} }

View File

@ -638,6 +638,9 @@ extern "C" {
va_end(arg); va_end(arg);
if (len+3 > LOGSZ) { strcat(log_data, "..."); } // Actual data is more if (len+3 > LOGSZ) { strcat(log_data, "..."); } // Actual data is more
TasConsole.printf(log_data); TasConsole.printf(log_data);
#ifdef USE_SERIAL_BRIDGE
SerialBridgePrintf(log_data);
#endif // USE_SERIAL_BRIDGE
} }
void berry_log_C(const char * berry_buf, ...) { void berry_log_C(const char * berry_buf, ...) {