2020-09-12 16:04:38 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
|
|
|
|
#if CONFIG_HAL_BOARD == HAL_BOARD_SITL && defined(HAL_BUILD_AP_PERIPH)
|
|
|
|
|
|
|
|
#include "AP_HAL_SITL.h"
|
|
|
|
#include "AP_HAL_SITL_Namespace.h"
|
|
|
|
#include "HAL_SITL_Class.h"
|
|
|
|
#include "UARTDriver.h"
|
|
|
|
#include "Scheduler.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <SITL/SIM_JSBSim.h>
|
|
|
|
#include <AP_HAL/utility/Socket.h>
|
2020-12-28 10:33:56 -04:00
|
|
|
#include <AP_HAL/utility/getopt_cpp.h>
|
2020-09-12 16:04:38 -03:00
|
|
|
|
|
|
|
extern const AP_HAL::HAL& hal;
|
|
|
|
|
|
|
|
using namespace HALSITL;
|
|
|
|
|
|
|
|
void SITL_State::init(int argc, char * const argv[]) {
|
2020-12-28 10:33:56 -04:00
|
|
|
int opt;
|
|
|
|
const struct GetOptLong::option options[] = {
|
|
|
|
{"help", false, 0, 'h'},
|
|
|
|
{"instance", true, 0, 'I'},
|
2022-04-29 08:48:37 -03:00
|
|
|
{"maintenance", false, 0, 'M'},
|
2020-12-28 10:33:56 -04:00
|
|
|
};
|
2020-09-12 16:04:38 -03:00
|
|
|
|
2020-12-28 10:33:56 -04:00
|
|
|
setvbuf(stdout, (char *)0, _IONBF, 0);
|
|
|
|
setvbuf(stderr, (char *)0, _IONBF, 0);
|
|
|
|
|
2022-04-29 08:48:37 -03:00
|
|
|
GetOptLong gopt(argc, argv, "hI:M",
|
2020-12-28 10:33:56 -04:00
|
|
|
options);
|
|
|
|
|
|
|
|
while((opt = gopt.getoption()) != -1) {
|
|
|
|
switch (opt) {
|
|
|
|
case 'I':
|
|
|
|
_instance = atoi(gopt.optarg);
|
|
|
|
break;
|
2022-04-29 08:48:37 -03:00
|
|
|
case 'M':
|
|
|
|
printf("Running in Maintenance Mode\n");
|
|
|
|
_maintenance = true;
|
|
|
|
break;
|
2020-12-28 10:33:56 -04:00
|
|
|
default:
|
|
|
|
printf("Options:\n"
|
|
|
|
"\t--help|-h display this help information\n"
|
2022-04-29 08:48:37 -03:00
|
|
|
"\t--instance|-I N set instance of SITL Periph\n"
|
|
|
|
"\t--maintenance|-M run in maintenance mode\n");
|
2020-12-28 10:33:56 -04:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
2021-10-16 00:10:40 -03:00
|
|
|
|
2020-12-28 10:33:56 -04:00
|
|
|
printf("Running Instance: %d\n", _instance);
|
2020-09-12 16:04:38 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
void SITL_State::wait_clock(uint64_t wait_time_usec) {
|
|
|
|
while (AP_HAL::native_micros64() < wait_time_usec) {
|
|
|
|
usleep(1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-26 09:31:22 -03:00
|
|
|
// when Periph can use SITL simulated devices we should remove these
|
|
|
|
// stubs:
|
|
|
|
ssize_t SITL::SerialDevice::read_from_device(char*, unsigned int) const { return -1; }
|
2020-09-12 16:04:38 -03:00
|
|
|
|
2021-10-26 09:31:22 -03:00
|
|
|
ssize_t SITL::SerialDevice::write_to_device(char const*, unsigned int) const { return -1; }
|
2020-09-12 16:04:38 -03:00
|
|
|
|
|
|
|
#endif //CONFIG_HAL_BOARD == HAL_BOARD_SITL && defined(HAL_BUILD_AP_PERIPH)
|