Enable command console on PC build

This commit is contained in:
Kuba Szczodrzyński 2024-02-10 15:05:01 +01:00
parent 2738bff96a
commit 4fff3d79c5
No known key found for this signature in database
GPG Key ID: 43037AC62A600562
11 changed files with 53 additions and 11 deletions

View File

@ -123,7 +123,7 @@
#endif #endif
#ifndef HASP_USE_CONSOLE #ifndef HASP_USE_CONSOLE
#define HASP_USE_CONSOLE HASP_TARGET_ARDUINO #define HASP_USE_CONSOLE 1
#endif #endif
/* Filesystem */ /* Filesystem */

View File

@ -139,13 +139,11 @@ void debugStart(void)
LOG_INFO(TAG_DEBG, F("Console started")); LOG_INFO(TAG_DEBG, F("Console started"));
debug_flush(); debug_flush();
#else #endif
#if HASP_USE_CONSOLE > 0 #if HASP_USE_CONSOLE > 0
consoleSetup(); consoleSetup();
#endif #endif
#endif
} }
void debugStop() void debugStop()

View File

@ -5,8 +5,10 @@
#if HASP_USE_CONSOLE > 0 #if HASP_USE_CONSOLE > 0
#if HASP_TARGET_ARDUINO
#include "ConsoleInput.h" #include "ConsoleInput.h"
#include <StreamUtils.h> #include <StreamUtils.h>
#endif
#include "hasp_debug.h" #include "hasp_debug.h"
#include "hasp_console.h" #include "hasp_console.h"
@ -17,15 +19,18 @@
extern hasp_http_config_t http_config; extern hasp_http_config_t http_config;
#endif #endif
#if HASP_TARGET_ARDUINO
// Create a new Stream that buffers all writes to serialClient // Create a new Stream that buffers all writes to serialClient
HardwareSerial* bufferedSerialClient = (HardwareSerial*)&HASP_SERIAL; HardwareSerial* bufferedSerialClient = (HardwareSerial*)&HASP_SERIAL;
ConsoleInput* console;
#endif
uint8_t consoleLoginState = CONSOLE_UNAUTHENTICATED; uint8_t consoleLoginState = CONSOLE_UNAUTHENTICATED;
uint16_t serialPort = 0; uint16_t serialPort = 0;
uint8_t consoleEnabled = true; // Enable serial debug output uint8_t consoleEnabled = true; // Enable serial debug output
uint8_t consoleLoginAttempt = 0; // Initial attempt uint8_t consoleLoginAttempt = 0; // Initial attempt
ConsoleInput* console;
#if HASP_TARGET_ARDUINO
void console_update_prompt() void console_update_prompt()
{ {
if(console) console->update(__LINE__); if(console) console->update(__LINE__);
@ -101,9 +106,21 @@ static void console_process_line(const char* input)
} }
} }
} }
#elif HASP_TARGET_PC
static bool console_running = true;
static int console_thread(void* arg)
{
while(console_running) {
std::string input;
std::getline(std::cin, input);
dispatch_text_line(input.c_str(), TAG_CONS);
}
}
#endif
void consoleStart() void consoleStart()
{ {
#if HASP_TARGET_ARDUINO
LOG_TRACE(TAG_MSGR, F(D_SERVICE_STARTING)); LOG_TRACE(TAG_MSGR, F(D_SERVICE_STARTING));
console = new ConsoleInput(bufferedSerialClient, HASP_CONSOLE_BUFFER); console = new ConsoleInput(bufferedSerialClient, HASP_CONSOLE_BUFFER);
if(console) { if(console) {
@ -126,16 +143,32 @@ void consoleStart()
console_logoff(); console_logoff();
LOG_ERROR(TAG_CONS, F(D_SERVICE_START_FAILED)); LOG_ERROR(TAG_CONS, F(D_SERVICE_START_FAILED));
} }
#elif HASP_TARGET_PC
LOG_TRACE(TAG_MSGR, F(D_SERVICE_STARTING));
#if defined(WINDOWS)
CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)console_thread, NULL, 0, NULL);
#elif defined(POSIX)
pthread_t thread;
pthread_create(&thread, NULL, (void* (*)(void*))console_thread, NULL);
#endif
#endif
} }
void consoleStop() void consoleStop()
{ {
#if HASP_TARGET_ARDUINO
console_logoff(); console_logoff();
Log.unregisterOutput(0); // serialClient Log.unregisterOutput(0); // serialClient
HASP_SERIAL.end(); HASP_SERIAL.end();
delete console; delete console;
console = NULL; console = NULL;
#elif HASP_TARGET_PC
#if defined(WINDOWS)
#elif defined(POSIX)
#endif
#endif
} }
void consoleSetup() void consoleSetup()
@ -147,6 +180,7 @@ void consoleSetup()
IRAM_ATTR void consoleLoop() IRAM_ATTR void consoleLoop()
{ {
#if HASP_TARGET_ARDUINO
if(!console) return; if(!console) return;
bool update = false; bool update = false;
@ -175,6 +209,7 @@ IRAM_ATTR void consoleLoop()
} }
} }
if(update) console_update_prompt(); if(update) console_update_prompt();
#endif
} }
#if HASP_USE_CONFIG > 0 #if HASP_USE_CONFIG > 0
@ -201,4 +236,4 @@ bool consoleSetConfig(const JsonObject& settings)
} }
#endif // HASP_USE_CONFIG #endif // HASP_USE_CONFIG
#endif #endif

View File

@ -4,10 +4,10 @@
#ifndef HASP_CONSOLE_H #ifndef HASP_CONSOLE_H
#define HASP_CONSOLE_H #define HASP_CONSOLE_H
#if HASP_USE_CONSOLE > 0
#include "hasplib.h" #include "hasplib.h"
#if HASP_USE_CONSOLE > 0
/* ===== Default Event Processors ===== */ /* ===== Default Event Processors ===== */
void consoleSetup(); void consoleSetup();
IRAM_ATTR void consoleLoop(void); IRAM_ATTR void consoleLoop(void);

View File

@ -2,6 +2,9 @@
For full license information read the LICENSE file in the project folder */ For full license information read the LICENSE file in the project folder */
#include "hasplib.h" #include "hasplib.h"
#if HASP_USE_HTTP > 0
#include "ArduinoLog.h" #include "ArduinoLog.h"
#define HTTP_LEGACY #define HTTP_LEGACY
@ -21,7 +24,6 @@
#include "hasp_gui.h" #include "hasp_gui.h"
#include "hasp_debug.h" #include "hasp_debug.h"
#if HASP_USE_HTTP > 0
#include "sys/net/hasp_network.h" #include "sys/net/hasp_network.h"
#include "sys/net/hasp_time.h" #include "sys/net/hasp_time.h"

View File

@ -3,6 +3,9 @@
//#include "webServer.h" //#include "webServer.h"
#include "hasplib.h" #include "hasplib.h"
#if HASP_USE_HTTP_ASYNC > 0
#include "ArduinoLog.h" #include "ArduinoLog.h"
#if defined(ARDUINO_ARCH_ESP32) #if defined(ARDUINO_ARCH_ESP32)
@ -16,7 +19,6 @@
#include "hasp_gui.h" #include "hasp_gui.h"
#include "hasp_debug.h" #include "hasp_debug.h"
#if HASP_USE_HTTP_ASYNC > 0
#include "sys/net/hasp_network.h" #include "sys/net/hasp_network.h"
/* clang-format off */ /* clang-format off */

View File

@ -99,6 +99,7 @@ build_src_filter =
-<SSLSocket.c> -<SSLSocket.c>
-<sys/> -<sys/>
+<sys/gpio/> +<sys/gpio/>
+<sys/svc/>
-<hal/> -<hal/>
+<drv/> +<drv/>
-<drv/touch> -<drv/touch>

View File

@ -84,6 +84,7 @@ build_src_filter =
-<SSLSocket.c> -<SSLSocket.c>
-<sys/> -<sys/>
+<sys/gpio/> +<sys/gpio/>
+<sys/svc/>
-<hal/> -<hal/>
+<drv/> +<drv/>
-<drv/touch> -<drv/touch>

View File

@ -89,6 +89,7 @@ build_src_filter =
-<SSLSocket.c> -<SSLSocket.c>
-<sys/> -<sys/>
+<sys/gpio/> +<sys/gpio/>
+<sys/svc/>
-<hal/> -<hal/>
+<drv/> +<drv/>
-<drv/touch> -<drv/touch>

View File

@ -113,6 +113,7 @@ build_src_filter =
-<SSLSocket.c> -<SSLSocket.c>
-<sys/> -<sys/>
+<sys/gpio/> +<sys/gpio/>
+<sys/svc/>
-<hal/> -<hal/>
+<drv/> +<drv/>
-<drv/touch> -<drv/touch>

View File

@ -119,6 +119,7 @@ build_src_filter =
-<SSLSocket.c> -<SSLSocket.c>
-<sys/> -<sys/>
+<sys/gpio/> +<sys/gpio/>
+<sys/svc/>
-<hal/> -<hal/>
+<drv/> +<drv/>
-<drv/touch> -<drv/touch>