Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions device/src/shell/shell_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,16 @@ static int cmd_uhk_useShellSinks(const struct shell *shell, size_t argc, char *a
return 0;
}

static int cmd_uhk_stripVt100(const struct shell *shell, size_t argc, char *argv[])
{
if (argc == 1) {
shell_fprintf(shell, SHELL_NORMAL, "%i\n", ShellConfig_StripVt100 ? 1 : 0);
} else {
ShellConfig_StripVt100 = argv[1][0] == '1';
}
return 0;
}

static int cmd_uhk_logStatus(const struct shell *shell, size_t argc, char *argv[])
{
uint16_t usbBufferFill, usbBufferSize;
Expand All @@ -393,6 +403,7 @@ static int cmd_uhk_logStatus(const struct shell *shell, size_t argc, char *argv[
printk("Has log: %d\n", UsbLogBuffer_HasLog);
printk("Usb log buffer fill: %d / %d\n", usbBufferFill, usbBufferSize);
printk("UseShellSinks: %d\n", ShellConfig_UseShellSinks ? 1 : 0);
printk("StripVt100: %d\n", ShellConfig_StripVt100 ? 1 : 0);
return 0;
}

Expand Down Expand Up @@ -431,6 +442,7 @@ void InitShellCommands(void)
SHELL_CMD_ARG(snapshot, NULL, "Snap log buffer to status buffer", cmd_uhk_snaplog, 1, 0),
SHELL_CMD_ARG(status, NULL, "print log status overview", cmd_uhk_logStatus, 1, 0),
SHELL_CMD_ARG(useShellSinks, NULL, "get/set shell sinks mode", cmd_uhk_useShellSinks, 1, 1),
SHELL_CMD_ARG(stripVt100, NULL, "get/set vt100 stripping for USB log buffer", cmd_uhk_stripVt100, 1, 1),
SHELL_SUBCMD_SET_END);

#if DEVICE_IS_UHK80_RIGHT
Expand Down
24 changes: 17 additions & 7 deletions device/src/shell/shell_transport_uhk.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,32 @@ static void outputToSinks(const shell_sinks_t *sinks, struct uart_transport_data
return;
}

uint8_t stripped[48];
size_t strippedLen = stripVt100(td, data, length, stripped, sizeof(stripped));
bool stripForUsb = ShellConfig_StripVt100;

if (strippedLen == 0) {
return;
// OLED and status buffer always need stripping; USB buffer is optionally raw.
bool needStripped = sinks->toOled || sinks->toStatusBuffer || (sinks->toUsbBuffer && stripForUsb);

uint8_t stripped[48];
size_t strippedLen = 0;
if (needStripped) {
strippedLen = stripVt100(td, data, length, stripped, sizeof(stripped));
}

if (sinks->toUsbBuffer) {
UsbLogBuffer_Print(stripped, strippedLen);
if (stripForUsb) {
if (strippedLen > 0) {
UsbLogBuffer_Print(stripped, strippedLen);
}
} else {
UsbLogBuffer_Print((uint8_t *)data, length);
}
}

if (sinks->toOled) {
if (sinks->toOled && strippedLen > 0) {
LogO("%.*s", (int)strippedLen, stripped);
}

if (sinks->toStatusBuffer) {
if (sinks->toStatusBuffer && strippedLen > 0) {
Macros_SanitizedPut((const char *)stripped, (const char *)stripped + strippedLen);
}
}
Expand Down
2 changes: 2 additions & 0 deletions device/src/shell/sinks.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ bool ShellConfig_IsInPanicMode = false;

bool ShellConfig_UseShellSinks = true;

bool ShellConfig_StripVt100 = true;

static shell_sinks_t emptyConfig() {
return (shell_sinks_t){
.toUsbBuffer = false,
Expand Down
1 change: 1 addition & 0 deletions device/src/shell/sinks.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

extern bool ShellConfig_IsInPanicMode;
extern bool ShellConfig_UseShellSinks;
extern bool ShellConfig_StripVt100;

// Functions:

Expand Down
Loading