1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-26 01:35:41 +03:00

Limit MSP ports to 2 for normal usage scenarios.

This commit is contained in:
Dominic Clifton 2014-08-14 00:50:17 +01:00
parent 7453e98b3b
commit 0b353341f8
3 changed files with 13 additions and 4 deletions

View file

@ -449,12 +449,18 @@ bool isSerialConfigValid(serialConfig_t *serialConfigToCheck)
uint8_t functionIndex; uint8_t functionIndex;
uint8_t cliPortCount = 0; uint8_t cliPortCount = 0;
uint8_t mspPortCount = 0;
for (functionIndex = 0; functionIndex < SERIAL_PORT_COUNT; functionIndex++) { for (functionIndex = 0; functionIndex < SERIAL_PORT_COUNT; functionIndex++) {
if (serialPortFunctions[functionIndex].scenario & FUNCTION_CLI) { if (serialPortFunctions[functionIndex].scenario & FUNCTION_CLI) {
if (++cliPortCount > 1) { if (++cliPortCount > 1) {
return false; return false;
} }
} }
if (serialPortFunctions[functionIndex].scenario & FUNCTION_MSP) {
if (++mspPortCount > MAX_MSP_PORT_COUNT) {
return false;
}
}
} }
return true; return true;
} }

View file

@ -206,7 +206,7 @@ typedef struct mspPort_s {
uint8_t cmdMSP; uint8_t cmdMSP;
} mspPort_t; } mspPort_t;
static mspPort_t mspPorts[SERIAL_PORT_COUNT]; static mspPort_t mspPorts[MAX_MSP_PORT_COUNT];
static mspPort_t *currentPort; static mspPort_t *currentPort;
@ -353,7 +353,7 @@ static void openAllMSPSerialPorts(serialConfig_t *serialConfig)
} }
} while (!port); } while (!port);
if (port) { if (port && portIndex < MAX_MSP_PORT_COUNT) {
mspPorts[portIndex++].port = port; mspPorts[portIndex++].port = port;
} }
@ -909,7 +909,7 @@ static void mspProcessPort(void)
void mspProcess(void) { void mspProcess(void) {
uint8_t portIndex; uint8_t portIndex;
for (portIndex = 0; portIndex < SERIAL_PORT_COUNT; portIndex++) { for (portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
currentPort = &mspPorts[portIndex]; currentPort = &mspPorts[portIndex];
if (!currentPort->port) { if (!currentPort->port) {
continue; continue;
@ -939,7 +939,7 @@ void sendMspTelemetry(void)
static uint32_t sequenceIndex = 0; static uint32_t sequenceIndex = 0;
uint8_t portIndex; uint8_t portIndex;
for (portIndex = 0; portIndex < SERIAL_PORT_COUNT; portIndex++) { for (portIndex = 0; portIndex < MAX_MSP_PORT_COUNT; portIndex++) {
currentPort = &mspPorts[portIndex]; currentPort = &mspPorts[portIndex];
if (!currentPort->port) { if (!currentPort->port) {
continue; continue;

View file

@ -17,5 +17,8 @@
#pragma once #pragma once
// Each MSP port requires state and a receive buffer, revisit this default if someone needs more than 2 MSP ports.
#define MAX_MSP_PORT_COUNT 2
void mspProcess(void); void mspProcess(void);
void sendMspTelemetry(void); void sendMspTelemetry(void);