Fix Companion USB clients and shared-port logging
This commit is contained in:
1 parent
bd30388436
commit
b5440c75c7
14 files changed
+731
-47
No files matched your search
@@ -6850,6 +6850,7 @@ void MyMesh::appendRxPowerSavingAdjustmentNote(char* reply, size_t reply_size,
|
||||
|
||||
#if COMPANION_FEATURE_TEXT_TERMINAL
|
||||
Stream& MyMesh::terminalOutput() {
|
||||
if (isTerminalWaitingForInput()) return mesh::usbTerminalPort(false);
|
||||
return _terminal_output != NULL ? *_terminal_output : Serial;
|
||||
}
|
||||
|
||||
@@ -6887,15 +6888,17 @@ void MyMesh::printTerminalBanner(bool show_binary_stop) {
|
||||
output.print("\r\n> ");
|
||||
}
|
||||
|
||||
void MyMesh::enterTerminalMode() {
|
||||
void MyMesh::enterTerminalMode(bool show_banner) {
|
||||
_terminal_mode = true;
|
||||
_terminal_usb_silent = !show_banner;
|
||||
_terminal_output = &mesh::usbTerminalPort();
|
||||
resetTerminalSession();
|
||||
printTerminalBanner(true);
|
||||
if (show_banner) printTerminalBanner(true);
|
||||
}
|
||||
|
||||
void MyMesh::exitTerminalMode() {
|
||||
_terminal_mode = false;
|
||||
_terminal_usb_silent = false;
|
||||
resetTerminalSession();
|
||||
if (_terminal_output == &mesh::usbTerminalPort()) _terminal_output = NULL;
|
||||
}
|
||||
|
||||
@@ -213,12 +213,15 @@ public:
|
||||
void enterCLIRescue();
|
||||
|
||||
#if COMPANION_FEATURE_TEXT_TERMINAL
|
||||
void enterTerminalMode();
|
||||
void enterTerminalMode(bool show_banner = true);
|
||||
void exitTerminalMode();
|
||||
// Clear state owned by the current text-terminal host without changing the
|
||||
// protocol owner or printing a new banner.
|
||||
void resetTerminalSession();
|
||||
bool isTerminalMode() const { return _terminal_mode; }
|
||||
bool isTerminalWaitingForInput() const {
|
||||
return _terminal_mode && _terminal_usb_silent;
|
||||
}
|
||||
void handleTerminalCommand(char* command);
|
||||
#if COMPANION_FEATURE_NETWORK_TERMINAL || defined(WITH_WEBCONFIG)
|
||||
bool enterNetworkTerminalMode(Stream& output);
|
||||
@@ -525,6 +528,7 @@ private:
|
||||
bool _cli_rescue;
|
||||
#if COMPANION_FEATURE_TEXT_TERMINAL
|
||||
bool _terminal_mode;
|
||||
bool _terminal_usb_silent = false;
|
||||
Stream* _terminal_output;
|
||||
mesh::TerminalDisplayFilter _terminal_display;
|
||||
bool _terminal_recipient_set;
|
||||
|
||||
@@ -528,7 +528,9 @@ static void redrawUsbTerminalInput() {
|
||||
}
|
||||
|
||||
static bool isUsbTerminalDataConnected() {
|
||||
#if defined(RP2040_PLATFORM)
|
||||
#if defined(NRF52_PLATFORM)
|
||||
return mesh::isUsbCompanionClientConnected();
|
||||
#elif defined(RP2040_PLATFORM)
|
||||
return (bool)Serial;
|
||||
#else
|
||||
return board.isUsbDataConnected();
|
||||
@@ -595,7 +597,7 @@ static void cancelUsbSerialOperations() {
|
||||
interface_manager.forgetReplyRouteForDisconnected(&usb_serial_interface);
|
||||
}
|
||||
|
||||
static void enterUsbTerminalMode() {
|
||||
static void enterUsbTerminalMode(bool show_banner = true) {
|
||||
usb_binary_startup_probe.cancel();
|
||||
usb_ascii_session_default.cancel();
|
||||
cancelUsbSerialOperations();
|
||||
@@ -604,7 +606,7 @@ static void enterUsbTerminalMode() {
|
||||
clearUsbTerminalLine();
|
||||
usb_terminal_discard_line = false;
|
||||
usb_logging_terminal_mode = false;
|
||||
the_mesh.enterTerminalMode();
|
||||
the_mesh.enterTerminalMode(show_banner);
|
||||
}
|
||||
|
||||
static void enterUsbLoggingTerminalMode() {
|
||||
@@ -832,7 +834,10 @@ static void serviceUsbAsciiSessionDefault() {
|
||||
false,
|
||||
#endif
|
||||
usb_serial_interface.getCompletedFrameCount())) {
|
||||
enterUsbTerminalMode();
|
||||
// A prompt contains '>', the Binary Companion frame marker. Do not send
|
||||
// text to an unknown host: the first ASCII input reveals the terminal,
|
||||
// while a framed app command switches without poisoning its first reply.
|
||||
enterUsbTerminalMode(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -933,6 +938,9 @@ static void serviceUsbTerminal() {
|
||||
}
|
||||
|
||||
Stream& usb_input = mesh::usbCompanionPort();
|
||||
if (the_mesh.isTerminalWaitingForInput() && usb_input.available() > 0) {
|
||||
enterUsbTerminalMode();
|
||||
}
|
||||
while (usb_input.available()) {
|
||||
int value = usb_input.read();
|
||||
if (value < 0) break;
|
||||
@@ -998,6 +1006,14 @@ static void serviceUsbTerminal() {
|
||||
mesh::cli::shouldMaskTerminalInput(usb_terminal_line) ? '*' : c);
|
||||
|
||||
if (strcmp(usb_terminal_line, USB_TERMINAL_STOP_TOKEN) == 0) {
|
||||
#if MESH_USB_LOGGING_AVAILABLE
|
||||
if (!mesh::hasDedicatedUsbLoggingPort() && mesh::isUsbLoggingEnabled()) {
|
||||
clearUsbTerminalLine();
|
||||
usbTerminalOutput().print(
|
||||
"\r\nERROR: set usb.logging off before Binary mode\r\n> ");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
leaveUsbTerminalMode(true);
|
||||
return;
|
||||
}
|
||||
@@ -2584,8 +2600,12 @@ void setup() {
|
||||
USB_HOST_LOSS_GRACE_MS,
|
||||
the_mesh.hasFiniteDelayedReplyForRoute(&usb_serial_interface));
|
||||
});
|
||||
#elif defined(NRF52_PLATFORM)
|
||||
usb_serial_interface.setConnectedCheck([]() {
|
||||
return mesh::isUsbCompanionClientConnected();
|
||||
});
|
||||
#elif (defined(ESP32) && defined(ARDUINO_USB_CDC_ON_BOOT) && ARDUINO_USB_CDC_ON_BOOT) \
|
||||
|| defined(NRF52_PLATFORM) || defined(RP2040_PLATFORM)
|
||||
|| defined(RP2040_PLATFORM)
|
||||
// native USB-CDC (TinyUSB): (bool)Serial reflects DTR, ie. the host really
|
||||
// has the port open. A classic ESP32 behind a UART bridge has no such
|
||||
// signal and keeps the assume-connected default.
|
||||
|
||||
Reference in new issue
Block a user