mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-19 22:35:23 +03:00
Update serial_cli.c
This commit is contained in:
parent
c31fd202c5
commit
fde0075296
1 changed files with 78 additions and 0 deletions
|
@ -116,6 +116,9 @@ static void cliProfile(char *cmdline);
|
||||||
static void cliReboot(void);
|
static void cliReboot(void);
|
||||||
static void cliSave(char *cmdline);
|
static void cliSave(char *cmdline);
|
||||||
static void cliSerial(char *cmdline);
|
static void cliSerial(char *cmdline);
|
||||||
|
#ifndef SKIP_SERIAL_PASSTHROUGH
|
||||||
|
static void cliSerialPassthrough(char *cmdline);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef USE_SERVOS
|
#ifdef USE_SERVOS
|
||||||
static void cliServo(char *cmdline);
|
static void cliServo(char *cmdline);
|
||||||
|
@ -283,6 +286,11 @@ const clicmd_t cmdTable[] = {
|
||||||
CLI_COMMAND_DEF("rxfail", "show/set rx failsafe settings", NULL, cliRxFail),
|
CLI_COMMAND_DEF("rxfail", "show/set rx failsafe settings", NULL, cliRxFail),
|
||||||
CLI_COMMAND_DEF("save", "save and reboot", NULL, cliSave),
|
CLI_COMMAND_DEF("save", "save and reboot", NULL, cliSave),
|
||||||
CLI_COMMAND_DEF("serial", "configure serial ports", NULL, cliSerial),
|
CLI_COMMAND_DEF("serial", "configure serial ports", NULL, cliSerial),
|
||||||
|
#ifndef SKIP_SERIAL_PASSTHROUGH
|
||||||
|
CLI_COMMAND_DEF("serialpassthrough", "passthrough serial data to port",
|
||||||
|
"<id> [baud] [mode] : passthrough to serial",
|
||||||
|
cliSerialPassthrough),
|
||||||
|
#endif
|
||||||
#ifdef USE_SERVOS
|
#ifdef USE_SERVOS
|
||||||
CLI_COMMAND_DEF("servo", "configure servos", NULL, cliServo),
|
CLI_COMMAND_DEF("servo", "configure servos", NULL, cliServo),
|
||||||
#endif
|
#endif
|
||||||
|
@ -1021,6 +1029,76 @@ static void cliSerial(char *cmdline)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef SKIP_SERIAL_PASSTHROUGH
|
||||||
|
static void cliSerialPassthrough(char *cmdline)
|
||||||
|
{
|
||||||
|
if (isEmpty(cmdline)) {
|
||||||
|
cliShowParseError();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int id = -1;
|
||||||
|
uint32_t baud = 0;
|
||||||
|
unsigned mode = 0;
|
||||||
|
char* tok = strtok(cmdline, " ");
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
while (tok != NULL) {
|
||||||
|
switch(index) {
|
||||||
|
case 0:
|
||||||
|
id = atoi(tok);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
baud = atoi(tok);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
if (strstr(tok, "rx") || strstr(tok, "RX"))
|
||||||
|
mode |= MODE_RX;
|
||||||
|
if (strstr(tok, "tx") || strstr(tok, "TX"))
|
||||||
|
mode |= MODE_TX;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
index++;
|
||||||
|
tok = strtok(NULL, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
serialPort_t *passThroughPort;
|
||||||
|
serialPortUsage_t *passThroughPortUsage = findSerialPortUsageByIdentifier(id);
|
||||||
|
if (!passThroughPortUsage || passThroughPortUsage->serialPort == NULL) {
|
||||||
|
if (!baud) {
|
||||||
|
printf("Port %d is not open, you must specify baud\r\n", id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!mode)
|
||||||
|
mode = MODE_RXTX;
|
||||||
|
|
||||||
|
passThroughPort = openSerialPort(id, FUNCTION_PASSTHROUGH, NULL,
|
||||||
|
baud, mode,
|
||||||
|
SERIAL_NOT_INVERTED);
|
||||||
|
if (!passThroughPort) {
|
||||||
|
printf("Port %d could not be opened\r\n", id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
printf("Port %d opened, baud=%d\r\n", id, baud);
|
||||||
|
} else {
|
||||||
|
passThroughPort = passThroughPortUsage->serialPort;
|
||||||
|
// If the user supplied a mode, override the port's mode, otherwise
|
||||||
|
// leave the mode unchanged. serialPassthrough() handles one-way ports.
|
||||||
|
printf("Port %d already open\r\n", id);
|
||||||
|
if (mode && passThroughPort->mode != mode) {
|
||||||
|
printf("Adjusting mode from configured value %d to %d\r\n",
|
||||||
|
passThroughPort->mode, mode);
|
||||||
|
serialSetMode(passThroughPort, mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Relaying data to device on port %d, Reset your board to exit "
|
||||||
|
"serial passthrough mode.\r\n");
|
||||||
|
|
||||||
|
serialPassthrough(cliPort, passThroughPort, NULL, NULL);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void cliAdjustmentRange(char *cmdline)
|
static void cliAdjustmentRange(char *cmdline)
|
||||||
{
|
{
|
||||||
int i, val = 0;
|
int i, val = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue