Merge pull request #6978 from mikeller/add_serialpassthrough_reset

Added option to reset serial passthrough on drop of DTR.
This commit is contained in:
Michael Keller 2018-10-31 15:20:41 +13:00 committed by GitHub
commit a18d48f533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 42 additions and 19 deletions

View File

@ -1095,14 +1095,20 @@ static void cliSerial(char *cmdline)
} }
#if defined(USE_SERIAL_PASSTHROUGH) #if defined(USE_SERIAL_PASSTHROUGH)
#ifdef USE_PINIO
static void cbCtrlLine(void *context, uint16_t ctrl) static void cbCtrlLine(void *context, uint16_t ctrl)
{ {
int pinioDtr = (int)(long)context; #ifdef USE_PINIO
int contextValue = (int)(long)context;
pinioSet(pinioDtr, !(ctrl & CTRL_LINE_STATE_DTR)); if (contextValue) {
} pinioSet(contextValue - 1, !(ctrl & CTRL_LINE_STATE_DTR));
} else
#endif /* USE_PINIO */ #endif /* USE_PINIO */
UNUSED(context);
if (!(ctrl & CTRL_LINE_STATE_DTR)) {
systemReset();
}
}
static void cliSerialPassthrough(char *cmdline) static void cliSerialPassthrough(char *cmdline)
{ {
@ -1114,9 +1120,8 @@ static void cliSerialPassthrough(char *cmdline)
int id = -1; int id = -1;
uint32_t baud = 0; uint32_t baud = 0;
bool enableBaudCb = false; bool enableBaudCb = false;
#ifdef USE_PINIO
int pinioDtr = 0; int pinioDtr = 0;
#endif /* USE_PINIO */ bool resetOnDtr = false;
unsigned mode = 0; unsigned mode = 0;
char *saveptr; char *saveptr;
char* tok = strtok_r(cmdline, " ", &saveptr); char* tok = strtok_r(cmdline, " ", &saveptr);
@ -1131,17 +1136,24 @@ static void cliSerialPassthrough(char *cmdline)
baud = atoi(tok); baud = atoi(tok);
break; break;
case 2: case 2:
if (strstr(tok, "rx") || strstr(tok, "RX")) if (strcasestr(tok, "rx")) {
mode |= MODE_RX; mode |= MODE_RX;
if (strstr(tok, "tx") || strstr(tok, "TX")) }
if (strcasestr(tok, "tx")) {
mode |= MODE_TX; mode |= MODE_TX;
}
break; break;
#ifdef USE_PINIO
case 3: case 3:
if (strncasecmp(tok, "reset", strlen(tok)) == 0) {
resetOnDtr = true;
#ifdef USE_PINIO
} else {
pinioDtr = atoi(tok); pinioDtr = atoi(tok);
break;
#endif /* USE_PINIO */ #endif /* USE_PINIO */
} }
break;
}
index++; index++;
tok = strtok_r(NULL, " ", &saveptr); tok = strtok_r(NULL, " ", &saveptr);
} }
@ -1209,14 +1221,21 @@ static void cliSerialPassthrough(char *cmdline)
serialSetBaudRateCb(cliPort, serialSetBaudRate, passThroughPort); serialSetBaudRateCb(cliPort, serialSetBaudRate, passThroughPort);
} }
cliPrintLine("Forwarding, power cycle to exit."); char *resetMessage = "";
if (resetOnDtr) {
#ifdef USE_PINIO resetMessage = "or drop DTR ";
// Register control line state callback
if (pinioDtr) {
serialSetCtrlLineStateCb(cliPort, cbCtrlLine, (void *)(intptr_t)(pinioDtr - 1));
} }
cliPrintLinef("Forwarding, power cycle %sto exit.", resetMessage);
if (resetOnDtr
#ifdef USE_PINIO
|| pinioDtr
#endif /* USE_PINIO */ #endif /* USE_PINIO */
) {
// Register control line state callback
serialSetCtrlLineStateCb(cliPort, cbCtrlLine, (void *)(intptr_t)(pinioDtr));
}
serialPassthrough(cliPort, passThroughPort, NULL, NULL); serialPassthrough(cliPort, passThroughPort, NULL, NULL);
} }
@ -4523,7 +4542,11 @@ const clicmd_t cmdTable[] = {
#endif #endif
CLI_COMMAND_DEF("serial", "configure serial ports", NULL, cliSerial), CLI_COMMAND_DEF("serial", "configure serial ports", NULL, cliSerial),
#if defined(USE_SERIAL_PASSTHROUGH) #if defined(USE_SERIAL_PASSTHROUGH)
CLI_COMMAND_DEF("serialpassthrough", "passthrough serial data to port", "<id> [baud] [mode] [DTR PINIO]: passthrough to serial", cliSerialPassthrough), #if defined(USE_PINIO)
CLI_COMMAND_DEF("serialpassthrough", "passthrough serial data to port", "<id> [baud] [mode] [dtr pinio|'reset']", cliSerialPassthrough),
#else
CLI_COMMAND_DEF("serialpassthrough", "passthrough serial data to port", "<id> [baud] [mode] ['reset']", cliSerialPassthrough),
#endif
#endif #endif
#ifdef USE_SERVOS #ifdef USE_SERVOS
CLI_COMMAND_DEF("servo", "configure servos", NULL, cliServo), CLI_COMMAND_DEF("servo", "configure servos", NULL, cliServo),