Buffered writes to telnetClient

This commit is contained in:
fvanroie 2021-05-23 12:20:59 +02:00
parent a80de01d0e
commit 372c51a9e6
3 changed files with 14 additions and 3 deletions

View File

@ -279,7 +279,7 @@ void debugPrintSuffix(uint8_t tag, int level, Print* _logOutput)
if(_logOutput == &Serial) { if(_logOutput == &Serial) {
console_update_prompt(); console_update_prompt();
} else { } else {
_logOutput->print("hasp > "); telnet_update_prompt();
} }
} }

View File

@ -6,6 +6,7 @@
#if HASP_USE_TELNET > 0 #if HASP_USE_TELNET > 0
#include "ConsoleInput.h" #include "ConsoleInput.h"
#include <StreamUtils.h>
#include "hasp_debug.h" #include "hasp_debug.h"
#include "hasp_config.h" #include "hasp_config.h"
@ -32,12 +33,21 @@ static EthernetServer telnetServer(23);
extern hasp_http_config_t http_config; extern hasp_http_config_t http_config;
#endif #endif
// Create a new Stream that buffers all writes to telnetClient
WriteBufferingStream bufferedtelnetBufferedClientClient{telnetClient, 200};
uint8_t telnetLoginState = TELNET_UNAUTHENTICATED; uint8_t telnetLoginState = TELNET_UNAUTHENTICATED;
uint16_t telnetPort = 23; uint16_t telnetPort = 23;
uint8_t telnetEnabled = true; // Enable telnet debug output uint8_t telnetEnabled = true; // Enable telnet debug output
uint8_t telnetLoginAttempt = 0; // Initial attempt uint8_t telnetLoginAttempt = 0; // Initial attempt
ConsoleInput* telnetConsole; ConsoleInput* telnetConsole;
void telnet_update_prompt()
{
bufferedtelnetBufferedClientClient.print("hasp > ");
bufferedtelnetBufferedClientClient.flush();
}
void telnetClientDisconnect() void telnetClientDisconnect()
{ {
Log.unregisterOutput(1); // telnetClient Log.unregisterOutput(1); // telnetClient
@ -52,12 +62,12 @@ void telnetClientDisconnect()
void telnetClientLogon() void telnetClientLogon()
{ {
telnetClient.println(); telnetClient.println();
debugPrintHaspHeader(&telnetClient); debugPrintHaspHeader(&bufferedtelnetBufferedClientClient);
telnetLoginState = TELNET_AUTHENTICATED; // User and Pass are correct telnetLoginState = TELNET_AUTHENTICATED; // User and Pass are correct
telnetLoginAttempt = 0; // Reset attempt counter telnetLoginAttempt = 0; // Reset attempt counter
/* Now register logger for telnet */ /* Now register logger for telnet */
Log.registerOutput(1, &telnetClient, LOG_LEVEL_VERBOSE, true); Log.registerOutput(1, &bufferedtelnetBufferedClientClient, LOG_LEVEL_VERBOSE, true);
telnetClient.flush(); telnetClient.flush();
// telnetClient.setTimeout(10); // telnetClient.setTimeout(10);

View File

@ -17,6 +17,7 @@ void telnetStart(void);
void telnetStop(void); void telnetStop(void);
/* ===== Special Event Processors ===== */ /* ===== Special Event Processors ===== */
void telnet_update_prompt();
/* ===== Getter and Setter Functions ===== */ /* ===== Getter and Setter Functions ===== */