2011-10-07 19:18:23 -03:00
|
|
|
#include <stdio.h>
|
2011-10-09 06:41:03 -03:00
|
|
|
#include <unistd.h>
|
2011-10-07 19:18:23 -03:00
|
|
|
#include <time.h>
|
|
|
|
#include <sys/time.h>
|
2011-10-11 03:37:19 -03:00
|
|
|
#include <sched.h>
|
|
|
|
#include <wiring.h>
|
2011-11-07 05:52:12 -04:00
|
|
|
#include <getopt.h>
|
2011-11-09 04:40:34 -04:00
|
|
|
#include <signal.h>
|
2011-11-16 21:49:56 -04:00
|
|
|
#include <string.h>
|
2011-10-29 22:40:54 -03:00
|
|
|
#include "desktop.h"
|
2011-10-07 19:18:23 -03:00
|
|
|
|
|
|
|
void setup(void);
|
|
|
|
void loop(void);
|
|
|
|
|
2011-11-07 05:52:12 -04:00
|
|
|
// the state of the desktop simulation
|
2011-11-16 21:49:56 -04:00
|
|
|
struct desktop_info desktop_state;
|
2011-10-07 19:18:23 -03:00
|
|
|
|
2012-02-14 06:07:08 -04:00
|
|
|
// catch floating point exceptions
|
|
|
|
static void sig_fpe(int signum)
|
|
|
|
{
|
|
|
|
printf("ERROR: Floating point exception\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-11-07 05:52:12 -04:00
|
|
|
static void usage(void)
|
2011-10-07 19:18:23 -03:00
|
|
|
{
|
2011-11-07 05:52:12 -04:00
|
|
|
printf("Options:\n");
|
|
|
|
printf("\t-s enable CLI slider switch\n");
|
2011-11-07 07:26:52 -04:00
|
|
|
printf("\t-w wipe eeprom and dataflash\n");
|
2011-11-25 23:47:06 -04:00
|
|
|
printf("\t-r RATE set SITL framerate\n");
|
|
|
|
printf("\t-H HEIGHT initial barometric height\n");
|
2011-11-07 05:52:12 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char * const argv[])
|
|
|
|
{
|
|
|
|
int opt;
|
|
|
|
// default state
|
|
|
|
desktop_state.slider = false;
|
|
|
|
gettimeofday(&desktop_state.sketch_start_time, NULL);
|
|
|
|
|
2012-02-14 06:07:08 -04:00
|
|
|
signal(SIGFPE, sig_fpe);
|
|
|
|
|
2011-11-25 23:47:06 -04:00
|
|
|
while ((opt = getopt(argc, argv, "swhr:H:")) != -1) {
|
2011-11-07 05:52:12 -04:00
|
|
|
switch (opt) {
|
|
|
|
case 's':
|
|
|
|
desktop_state.slider = true;
|
|
|
|
break;
|
2011-11-07 07:26:52 -04:00
|
|
|
case 'w':
|
|
|
|
unlink("eeprom.bin");
|
|
|
|
unlink("dataflash.bin");
|
|
|
|
break;
|
2011-11-25 23:47:06 -04:00
|
|
|
case 'r':
|
|
|
|
desktop_state.framerate = (unsigned)atoi(optarg);
|
|
|
|
break;
|
|
|
|
case 'H':
|
|
|
|
desktop_state.initial_height = atof(optarg);
|
|
|
|
break;
|
2011-11-07 05:52:12 -04:00
|
|
|
default:
|
|
|
|
usage();
|
2011-11-07 07:26:52 -04:00
|
|
|
exit(1);
|
2011-11-07 05:52:12 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-16 21:49:56 -04:00
|
|
|
if (strcmp(SKETCH, "ArduCopter") == 0) {
|
|
|
|
desktop_state.quadcopter = true;
|
2011-11-25 23:47:06 -04:00
|
|
|
if (desktop_state.framerate == 0) {
|
|
|
|
desktop_state.framerate = 200;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (desktop_state.framerate == 0) {
|
|
|
|
desktop_state.framerate = 50;
|
|
|
|
}
|
2011-11-16 21:49:56 -04:00
|
|
|
}
|
2011-11-09 04:40:34 -04:00
|
|
|
|
2011-11-16 21:49:56 -04:00
|
|
|
sitl_setup();
|
2011-10-07 19:18:23 -03:00
|
|
|
setup();
|
2011-11-07 05:52:12 -04:00
|
|
|
|
2011-10-09 06:41:03 -03:00
|
|
|
while (true) {
|
2011-10-11 03:37:19 -03:00
|
|
|
struct timeval tv;
|
2011-10-29 22:40:54 -03:00
|
|
|
fd_set fds;
|
|
|
|
int fd_high = 0;
|
|
|
|
|
|
|
|
FD_ZERO(&fds);
|
2011-10-09 06:41:03 -03:00
|
|
|
loop();
|
2011-10-29 22:40:54 -03:00
|
|
|
|
|
|
|
desktop_serial_select_setup(&fds, &fd_high);
|
|
|
|
tv.tv_sec = 0;
|
|
|
|
tv.tv_usec = 100;
|
|
|
|
|
2011-11-16 21:49:56 -04:00
|
|
|
select(fd_high+1, &fds, NULL, NULL, &tv);
|
2011-10-09 06:41:03 -03:00
|
|
|
}
|
2011-10-07 19:18:23 -03:00
|
|
|
return 0;
|
|
|
|
}
|