AP_HAL_SITL: add ability to simulate more than 2 GPSs

This commit is contained in:
Peter Barker 2024-11-12 08:49:12 +11:00 committed by Peter Barker
parent 42b3bec595
commit 4b679dfb1a
3 changed files with 5 additions and 9 deletions

View File

@ -304,13 +304,9 @@ SITL::SerialDevice *SITL_State_Common::create_serial_sim(const char *name, const
return ais;
#endif
} else if (strncmp(name, "gps", 3) == 0) {
const char *p = strchr(name, ':');
if (p == nullptr) {
AP_HAL::panic("Need a GPS number (e.g. sim:gps:1)");
}
uint8_t x = atoi(p+1);
uint8_t x = atoi(arg);
if (x <= 0 || x > ARRAY_SIZE(gps)) {
AP_HAL::panic("Bad GPS number %u", x);
AP_HAL::panic("Bad GPS number %u (%s)", x, arg);
}
gps[x-1] = NEW_NOTHROW SITL::GPS(x-1);
return gps[x-1];

View File

@ -231,7 +231,7 @@ public:
const char *defaults_path = HAL_PARAM_DEFAULTS_PATH;
// simulated GPS devices
SITL::GPS *gps[2]; // constrained by # of parameter sets
SITL::GPS *gps[AP_SIM_MAX_GPS_SENSORS]; // constrained by # of parameter sets
// Simulated ELRS radio
SITL::ELRS *elrs;

View File

@ -77,11 +77,11 @@ void UARTDriver::_begin(uint32_t baud, uint16_t rxSpace, uint16_t txSpace)
if (strcmp(path, "GPS1") == 0) {
/* gps */
_connected = true;
_sim_serial_device = _sitlState->create_serial_sim("gps:1", "", _portNumber);
_sim_serial_device = _sitlState->create_serial_sim("gps", "1", _portNumber);
} else if (strcmp(path, "GPS2") == 0) {
/* 2nd gps */
_connected = true;
_sim_serial_device = _sitlState->create_serial_sim("gps:2", "", _portNumber);
_sim_serial_device = _sitlState->create_serial_sim("gps", "2", _portNumber);
} else {
/* parse type:args:flags string for path.
For example: