mirror of
https://github.com/iNavFlight/inav.git
synced 2025-07-17 13:25:27 +03:00
Merge pull request #10271 from MUSTARDTIGERFPV/serialpassthrough-modes
Allow serialpassthrough to set parity & stop bits
This commit is contained in:
commit
3cc11ce397
11 changed files with 109 additions and 3 deletions
|
@ -107,7 +107,7 @@ While connected to the CLI, all Logical Switches are temporarily disabled (5.1.0
|
|||
| `save` | Save and reboot |
|
||||
| `sd_info` | Sdcard info |
|
||||
| `serial` | Configure serial ports. [Usage](Serial.md) |
|
||||
| `serialpassthrough` | Passthrough serial data to port, with `<id> <baud> <mode>`, where `id` is the zero based port index, `baud` is a standard baud rate, and mode is `rx`, `tx`, or both (`rxtx`) |
|
||||
| `serialpassthrough` | Passthrough serial data to port, with `<id> <baud> <mode> <options>`, where `id` is the zero based port index, `baud` is a standard baud rate, mode is `rx`, `tx`, or both (`rxtx`), and options is a short string like `8N1` or `8E2` |
|
||||
| `servo` | Configure servos |
|
||||
| `set` | Change setting with name=value or blank or * for list |
|
||||
| `smix` | Custom servo mixer |
|
||||
|
|
|
@ -86,6 +86,11 @@ void serialSetMode(serialPort_t *instance, portMode_t mode)
|
|||
instance->vTable->setMode(instance, mode);
|
||||
}
|
||||
|
||||
void serialSetOptions(serialPort_t *instance, portOptions_t options)
|
||||
{
|
||||
instance->vTable->setOptions(instance, options);
|
||||
}
|
||||
|
||||
void serialWriteBufShim(void *instance, const uint8_t *data, int count)
|
||||
{
|
||||
serialWriteBuf((serialPort_t *)instance, data, count);
|
||||
|
|
|
@ -95,6 +95,8 @@ struct serialPortVTable {
|
|||
|
||||
void (*setMode)(serialPort_t *instance, portMode_t mode);
|
||||
|
||||
void (*setOptions)(serialPort_t *instance, portOptions_t options);
|
||||
|
||||
void (*writeBuf)(serialPort_t *instance, const void *data, int count);
|
||||
|
||||
bool (*isConnected)(const serialPort_t *instance);
|
||||
|
@ -113,6 +115,7 @@ void serialWriteBuf(serialPort_t *instance, const uint8_t *data, int count);
|
|||
uint8_t serialRead(serialPort_t *instance);
|
||||
void serialSetBaudRate(serialPort_t *instance, uint32_t baudRate);
|
||||
void serialSetMode(serialPort_t *instance, portMode_t mode);
|
||||
void serialSetOptions(serialPort_t *instance, portOptions_t options);
|
||||
bool isSerialTransmitBufferEmpty(const serialPort_t *instance);
|
||||
void serialPrint(serialPort_t *instance, const char *str);
|
||||
uint32_t serialGetBaudRate(serialPort_t *instance);
|
||||
|
|
|
@ -623,6 +623,11 @@ void softSerialSetMode(serialPort_t *instance, portMode_t mode)
|
|||
instance->mode = mode;
|
||||
}
|
||||
|
||||
void softSerialSetOptions(serialPort_t *instance, portOptions_t options)
|
||||
{
|
||||
instance->options = options;
|
||||
}
|
||||
|
||||
bool isSoftSerialTransmitBufferEmpty(const serialPort_t *instance)
|
||||
{
|
||||
return instance->txBufferHead == instance->txBufferTail;
|
||||
|
@ -636,6 +641,7 @@ static const struct serialPortVTable softSerialVTable = {
|
|||
.serialSetBaudRate = softSerialSetBaudRate,
|
||||
.isSerialTransmitBufferEmpty = isSoftSerialTransmitBufferEmpty,
|
||||
.setMode = softSerialSetMode,
|
||||
.setOptions = softSerialSetOptions,
|
||||
.isConnected = NULL,
|
||||
.writeBuf = NULL,
|
||||
.beginWrite = NULL,
|
||||
|
|
|
@ -317,6 +317,12 @@ void tcpSetMode(serialPort_t *instance, portMode_t mode)
|
|||
UNUSED(mode);
|
||||
}
|
||||
|
||||
void tcpSetOptions(serialPort_t *instance, portOptions_t options)
|
||||
{
|
||||
UNUSED(instance);
|
||||
UNUSED(options);
|
||||
}
|
||||
|
||||
static const struct serialPortVTable tcpVTable[] = {
|
||||
{
|
||||
.serialWrite = tcpWrite,
|
||||
|
@ -326,6 +332,7 @@ static const struct serialPortVTable tcpVTable[] = {
|
|||
.serialSetBaudRate = tcpSetBaudRate,
|
||||
.isSerialTransmitBufferEmpty = isTcpTransmitBufferEmpty,
|
||||
.setMode = tcpSetMode,
|
||||
.setOptions = tcpSetOptions,
|
||||
.isConnected = tcpIsConnected,
|
||||
.writeBuf = tcpWritBuf,
|
||||
.beginWrite = NULL,
|
||||
|
|
|
@ -175,6 +175,13 @@ void uartSetMode(serialPort_t *instance, portMode_t mode)
|
|||
uartReconfigure(uartPort);
|
||||
}
|
||||
|
||||
void uartSetOptions(serialPort_t *instance, portOptions_t options)
|
||||
{
|
||||
uartPort_t *uartPort = (uartPort_t *)instance;
|
||||
uartPort->port.options = options;
|
||||
uartReconfigure(uartPort);
|
||||
}
|
||||
|
||||
uint32_t uartTotalRxBytesWaiting(const serialPort_t *instance)
|
||||
{
|
||||
const uartPort_t *s = (const uartPort_t*)instance;
|
||||
|
@ -255,6 +262,7 @@ const struct serialPortVTable uartVTable[] = {
|
|||
.serialSetBaudRate = uartSetBaudRate,
|
||||
.isSerialTransmitBufferEmpty = isUartTransmitBufferEmpty,
|
||||
.setMode = uartSetMode,
|
||||
.setOptions = uartSetOptions,
|
||||
.isConnected = NULL,
|
||||
.writeBuf = NULL,
|
||||
.beginWrite = NULL,
|
||||
|
|
|
@ -185,6 +185,13 @@ void uartSetMode(serialPort_t *instance, portMode_t mode)
|
|||
uartReconfigure(uartPort);
|
||||
}
|
||||
|
||||
void uartSetOptions(serialPort_t *instance, portOptions_t options)
|
||||
{
|
||||
uartPort_t *uartPort = (uartPort_t *)instance;
|
||||
uartPort->port.options = options;
|
||||
uartReconfigure(uartPort);
|
||||
}
|
||||
|
||||
uint32_t uartTotalRxBytesWaiting(const serialPort_t *instance)
|
||||
{
|
||||
uartPort_t *s = (uartPort_t*)instance;
|
||||
|
@ -266,6 +273,7 @@ const struct serialPortVTable uartVTable[] = {
|
|||
.serialSetBaudRate = uartSetBaudRate,
|
||||
.isSerialTransmitBufferEmpty = isUartTransmitBufferEmpty,
|
||||
.setMode = uartSetMode,
|
||||
.setOptions = uartSetOptions,
|
||||
.isConnected = NULL,
|
||||
.writeBuf = NULL,
|
||||
.beginWrite = NULL,
|
||||
|
|
|
@ -178,6 +178,13 @@ void uartSetMode(serialPort_t *instance, portMode_t mode)
|
|||
uartReconfigure(uartPort);
|
||||
}
|
||||
|
||||
void uartSetOptions(serialPort_t *instance, portOptions_t options)
|
||||
{
|
||||
uartPort_t *uartPort = (uartPort_t *)instance;
|
||||
uartPort->port.options = options;
|
||||
uartReconfigure(uartPort);
|
||||
}
|
||||
|
||||
uint32_t uartTotalRxBytesWaiting(const serialPort_t *instance)
|
||||
{
|
||||
const uartPort_t *s = (const uartPort_t*)instance;
|
||||
|
@ -260,6 +267,7 @@ const struct serialPortVTable uartVTable[] = {
|
|||
.serialSetBaudRate = uartSetBaudRate,
|
||||
.isSerialTransmitBufferEmpty = isUartTransmitBufferEmpty,
|
||||
.setMode = uartSetMode,
|
||||
.setOptions = uartSetOptions,
|
||||
.isConnected = NULL,
|
||||
.writeBuf = NULL,
|
||||
.beginWrite = NULL,
|
||||
|
|
|
@ -67,6 +67,14 @@ static void usbVcpSetMode(serialPort_t *instance, portMode_t mode)
|
|||
// TODO implement
|
||||
}
|
||||
|
||||
static void usbVcpSetOptions(serialPort_t *instance, portOptions_t options)
|
||||
{
|
||||
UNUSED(instance);
|
||||
UNUSED(options);
|
||||
|
||||
// TODO implement
|
||||
}
|
||||
|
||||
static bool isUsbVcpTransmitBufferEmpty(const serialPort_t *instance)
|
||||
{
|
||||
UNUSED(instance);
|
||||
|
@ -184,6 +192,7 @@ static const struct serialPortVTable usbVTable[] = {
|
|||
.serialSetBaudRate = usbVcpSetBaudRate,
|
||||
.isSerialTransmitBufferEmpty = isUsbVcpTransmitBufferEmpty,
|
||||
.setMode = usbVcpSetMode,
|
||||
.setOptions = usbVcpSetOptions,
|
||||
.isConnected = usbVcpIsConnected,
|
||||
.writeBuf = usbVcpWriteBuf,
|
||||
.beginWrite = usbVcpBeginWrite,
|
||||
|
|
|
@ -308,6 +308,12 @@ static void usbVcpSetMode(serialPort_t *instance, portMode_t mode)
|
|||
UNUSED(mode);
|
||||
}
|
||||
|
||||
static void usbVcpSetOptions(serialPort_t *instance, portOptions_t options)
|
||||
{
|
||||
UNUSED(instance);
|
||||
UNUSED(options);
|
||||
}
|
||||
|
||||
static bool isUsbVcpTransmitBufferEmpty(const serialPort_t *instance)
|
||||
{
|
||||
UNUSED(instance);
|
||||
|
@ -434,6 +440,7 @@ static const struct serialPortVTable usbVTable[] = {
|
|||
.serialSetBaudRate = usbVcpSetBaudRate,
|
||||
.isSerialTransmitBufferEmpty = isUsbVcpTransmitBufferEmpty,
|
||||
.setMode = usbVcpSetMode,
|
||||
.setOptions = usbVcpSetOptions,
|
||||
.isConnected = usbVcpIsConnected,
|
||||
.writeBuf = usbVcpWriteBuf,
|
||||
.beginWrite = usbVcpBeginWrite,
|
||||
|
|
|
@ -914,6 +914,42 @@ static void cliSerial(char *cmdline)
|
|||
}
|
||||
|
||||
#ifdef USE_SERIAL_PASSTHROUGH
|
||||
|
||||
portOptions_t constructPortOptions(char *options) {
|
||||
if (strlen(options) != 3 || options[0] != '8') {
|
||||
// Invalid format
|
||||
return -1;
|
||||
}
|
||||
|
||||
portOptions_t result = 0;
|
||||
|
||||
switch (options[1]) {
|
||||
case 'N':
|
||||
result |= SERIAL_PARITY_NO;
|
||||
break;
|
||||
case 'E':
|
||||
result |= SERIAL_PARITY_EVEN;
|
||||
break;
|
||||
default:
|
||||
// Invalid format
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (options[2]) {
|
||||
case '1':
|
||||
result |= SERIAL_STOPBITS_1;
|
||||
break;
|
||||
case '2':
|
||||
result |= SERIAL_STOPBITS_2;
|
||||
break;
|
||||
default:
|
||||
// Invalid format
|
||||
return -1;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void cliSerialPassthrough(char *cmdline)
|
||||
{
|
||||
char * saveptr;
|
||||
|
@ -926,6 +962,7 @@ static void cliSerialPassthrough(char *cmdline)
|
|||
int id = -1;
|
||||
uint32_t baud = 0;
|
||||
unsigned mode = 0;
|
||||
portOptions_t options = SERIAL_NOT_INVERTED;
|
||||
char* tok = strtok_r(cmdline, " ", &saveptr);
|
||||
int index = 0;
|
||||
|
||||
|
@ -943,6 +980,9 @@ static void cliSerialPassthrough(char *cmdline)
|
|||
if (strstr(tok, "tx") || strstr(tok, "TX"))
|
||||
mode |= MODE_TX;
|
||||
break;
|
||||
case 3:
|
||||
options |= constructPortOptions(tok);
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
tok = strtok_r(NULL, " ", &saveptr);
|
||||
|
@ -960,7 +1000,7 @@ static void cliSerialPassthrough(char *cmdline)
|
|||
|
||||
passThroughPort = openSerialPort(id, FUNCTION_NONE, NULL, NULL,
|
||||
baud, mode,
|
||||
SERIAL_NOT_INVERTED);
|
||||
options);
|
||||
if (!passThroughPort) {
|
||||
tfp_printf("Port %d could not be opened.\r\n", id);
|
||||
return;
|
||||
|
@ -976,6 +1016,11 @@ static void cliSerialPassthrough(char *cmdline)
|
|||
passThroughPort->mode, mode);
|
||||
serialSetMode(passThroughPort, mode);
|
||||
}
|
||||
if (options && passThroughPort->options != options) {
|
||||
tfp_printf("Adjusting options from %d to %d.\r\n",
|
||||
passThroughPort->options, options);
|
||||
serialSetOptions(passThroughPort, options);
|
||||
}
|
||||
// If this port has a rx callback associated we need to remove it now.
|
||||
// Otherwise no data will be pushed in the serial port buffer!
|
||||
if (passThroughPort->rxCallback) {
|
||||
|
@ -4515,7 +4560,7 @@ const clicmd_t cmdTable[] = {
|
|||
CLI_COMMAND_DEF("save", "save and reboot", NULL, cliSave),
|
||||
CLI_COMMAND_DEF("serial", "configure serial ports", NULL, cliSerial),
|
||||
#ifdef USE_SERIAL_PASSTHROUGH
|
||||
CLI_COMMAND_DEF("serialpassthrough", "passthrough serial data to port", "<id> [baud] [mode] : passthrough to serial", cliSerialPassthrough),
|
||||
CLI_COMMAND_DEF("serialpassthrough", "passthrough serial data to port", "<id> [baud] [mode] [options]: passthrough to serial", cliSerialPassthrough),
|
||||
#endif
|
||||
CLI_COMMAND_DEF("servo", "configure servos", NULL, cliServo),
|
||||
#ifdef USE_PROGRAMMING_FRAMEWORK
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue