From ad28bbfc09b4548e4e1bfa08b345c868d6044da4 Mon Sep 17 00:00:00 2001 From: fvanroie Date: Thu, 1 Dec 2022 01:38:21 +0100 Subject: [PATCH] Default to USB Serial console on SC01 Plus #390 --- src/log/hasp_debug.cpp | 17 ++++++++++++----- src/sys/svc/hasp_console.cpp | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/log/hasp_debug.cpp b/src/log/hasp_debug.cpp index fde3675e..1d4e20d1 100644 --- a/src/log/hasp_debug.cpp +++ b/src/log/hasp_debug.cpp @@ -17,6 +17,7 @@ #include "ConsoleInput.h" #include "lvgl.h" //#include "time.h" +#include #if defined(ARDUINO_ARCH_ESP8266) #include // sntp_servermode_dhcp() @@ -70,7 +71,8 @@ uint8_t debugSyslogFacility = 0; uint8_t debugSyslogProtocol = 0; // A UDP instance to let us send and receive packets over UDP -WiFiUDP* syslogClient = NULL; +WiFiUDP* syslogClient = NULL; +WriteBufferingStream* bufferedSyslogClient = NULL; #define SYSLOG_PROTO_IETF 0 // Create a new syslog instance with LOG_KERN facility @@ -130,7 +132,8 @@ void debugStartSyslog() if(syslogClient) { if(syslogClient->beginPacket(debugSyslogHost, debugSyslogPort)) { - Log.registerOutput(2, syslogClient, HASP_LOG_LEVEL, true); + if(!bufferedSyslogClient) bufferedSyslogClient = new WriteBufferingStream(syslogClient, 256); + Log.registerOutput(2, bufferedSyslogClient ? bufferedSyslogClient : syslogClient, HASP_LOG_LEVEL, true); LOG_INFO(TAG_SYSL, F(D_SERVICE_STARTED)); } } else { @@ -345,6 +348,10 @@ void debugPrintSuffix(uint8_t tag, int level, Print* _logOutput) if(syslogClient && _logOutput == syslogClient) { syslogClient->endPacket(); return; + } else if(bufferedSyslogClient && _logOutput == bufferedSyslogClient) { + bufferedSyslogClient.flush(); + syslogClient->endPacket(); + return; } #endif @@ -374,7 +381,7 @@ void debugStartSerial() if(baudrate < 9600) baudrate = SERIAL_SPEED; #if defined(STM32F4xx) || defined(STM32F7xx) -#ifndef STM32_SERIAL1 // Define what Serial port to use for log output +#ifndef STM32_SERIAL1 // Define what Serial port to use for log output HASP_SERIAL.setRx(PA3); // User Serial2 HASP_SERIAL.setTx(PA2); #endif @@ -382,10 +389,10 @@ void debugStartSerial() HASP_SERIAL.begin(baudrate); /* prepare for possible serial debug */ delay(10); - Log.registerOutput(0, &Serial, HASP_LOG_LEVEL, true); // LOG_LEVEL_VERBOSE + Log.registerOutput(0, &HASP_SERIAL, HASP_LOG_LEVEL, true); // LOG_LEVEL_VERBOSE HASP_SERIAL.println(); - debugPrintHaspHeader(&Serial); + debugPrintHaspHeader(&HASP_SERIAL); HASP_SERIAL.flush(); LOG_INFO(TAG_DEBG, F(D_SERVICE_STARTED " @ %u bps"), debugSerialBaud); diff --git a/src/sys/svc/hasp_console.cpp b/src/sys/svc/hasp_console.cpp index 9cb04527..ddd5c372 100644 --- a/src/sys/svc/hasp_console.cpp +++ b/src/sys/svc/hasp_console.cpp @@ -19,7 +19,7 @@ extern hasp_http_config_t http_config; #endif // Create a new Stream that buffers all writes to serialClient -HardwareSerial* bufferedSerialClient = (HardwareSerial*)&Serial; +HardwareSerial* bufferedSerialClient = (HardwareSerial*)&HASP_SERIAL; uint8_t consoleLoginState = CONSOLE_UNAUTHENTICATED; uint16_t serialPort = 0;