1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 12:55:19 +03:00

Merge pull request #197 from chocol4te/betaflight

Ben Timby's Serial Passthough feature
This commit is contained in:
borisbstyle 2016-02-25 11:42:41 +01:00
commit 9e1f78075d
4 changed files with 155 additions and 25 deletions

View file

@ -117,6 +117,9 @@ static void cliRateProfile(char *cmdline);
static void cliReboot(void);
static void cliSave(char *cmdline);
static void cliSerial(char *cmdline);
#ifndef SKIP_SERIAL_PASSTHROUGH
static void cliSerialPassthrough(char *cmdline);
#endif
#ifdef USE_SERVOS
static void cliServo(char *cmdline);
@ -285,6 +288,11 @@ const clicmd_t cmdTable[] = {
CLI_COMMAND_DEF("rxfail", "show/set rx failsafe settings", NULL, cliRxFail),
CLI_COMMAND_DEF("save", "save and reboot", NULL, cliSave),
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
CLI_COMMAND_DEF("servo", "configure servos", NULL, cliServo),
#endif
@ -1029,6 +1037,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)
{
int i, val = 0;