[NPS] Add an option to not send NPS Ivy messages during simulation

This commit is contained in:
Michal Podhradsky
2017-11-27 09:53:35 -08:00
parent 8e6406daed
commit 1ccd44c523
3 changed files with 34 additions and 22 deletions
+1
View File
@@ -64,6 +64,7 @@ struct NpsMain {
int rc_script; int rc_script;
bool norc; bool norc;
char *ivy_bus; char *ivy_bus;
bool nodisplay;
}; };
struct NpsMain nps_main; struct NpsMain nps_main;
+29 -22
View File
@@ -158,6 +158,7 @@ bool nps_main_parse_options(int argc, char **argv)
nps_main.ivy_bus = NULL; nps_main.ivy_bus = NULL;
nps_main.host_time_factor = 1.0; nps_main.host_time_factor = 1.0;
nps_main.fg_fdm = 0; nps_main.fg_fdm = 0;
nps_main.nodisplay = false;
static const char *usage = static const char *usage =
"Usage: %s [options]\n" "Usage: %s [options]\n"
@@ -173,6 +174,7 @@ bool nps_main_parse_options(int argc, char **argv)
" --norc e.g. disable RC\n" " --norc e.g. disable RC\n"
" --ivy_bus <ivy bus> e.g. 127.255.255.255\n" " --ivy_bus <ivy bus> e.g. 127.255.255.255\n"
" --time_factor <factor> e.g. 2.5\n" " --time_factor <factor> e.g. 2.5\n"
" --nodisplay e.g. disable NPS ivy messages\n"
" --fg_fdm"; " --fg_fdm";
@@ -190,6 +192,7 @@ bool nps_main_parse_options(int argc, char **argv)
{"time_factor", 1, NULL, 0}, {"time_factor", 1, NULL, 0},
{"fg_fdm", 0, NULL, 0}, {"fg_fdm", 0, NULL, 0},
{"fg_port_in", 1, NULL, 0}, {"fg_port_in", 1, NULL, 0},
{"nodisplay", 0, NULL, 0},
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
int option_index = 0; int option_index = 0;
@@ -226,6 +229,8 @@ bool nps_main_parse_options(int argc, char **argv)
nps_main.fg_fdm = 1; break; nps_main.fg_fdm = 1; break;
case 10: case 10:
nps_main.fg_port_in = atoi(optarg); break; nps_main.fg_port_in = atoi(optarg); break;
case 11:
nps_main.nodisplay = true; break;
default: default:
break; break;
} }
@@ -311,34 +316,36 @@ void *nps_main_display(void *data __attribute__((unused)))
nps_ivy_init(nps_main.ivy_bus); nps_ivy_init(nps_main.ivy_bus);
while (TRUE) { // start the loop only if no_display is false
clock_get_current_time(&requestStart); if (!nps_main.nodisplay) {
while (TRUE) {
clock_get_current_time(&requestStart);
pthread_mutex_lock(&fdm_mutex); pthread_mutex_lock(&fdm_mutex);
memcpy(&fdm_ivy, &fdm, sizeof(fdm)); memcpy(&fdm_ivy, &fdm, sizeof(fdm));
memcpy(&sensors_ivy, &sensors, sizeof(sensors)); memcpy(&sensors_ivy, &sensors, sizeof(sensors));
pthread_mutex_unlock(&fdm_mutex); pthread_mutex_unlock(&fdm_mutex);
nps_ivy_display(&fdm_ivy, &sensors_ivy); nps_ivy_display(&fdm_ivy, &sensors_ivy);
clock_get_current_time(&requestEnd); clock_get_current_time(&requestEnd);
// Calculate time it took // Calculate time it took
task_ns = (requestEnd.tv_sec - requestStart.tv_sec) * 1000000000L + (requestEnd.tv_nsec - requestStart.tv_nsec); task_ns = (requestEnd.tv_sec - requestStart.tv_sec) * 1000000000L + (requestEnd.tv_nsec - requestStart.tv_nsec);
// task took less than one period, sleep for the rest of time // task took less than one period, sleep for the rest of time
if (task_ns < period_ns) { if (task_ns < period_ns) {
waitFor.tv_sec = 0; waitFor.tv_sec = 0;
waitFor.tv_nsec = period_ns - task_ns; waitFor.tv_nsec = period_ns - task_ns;
nanosleep(&waitFor, NULL); nanosleep(&waitFor, NULL);
} else { } else {
// task took longer than the period // task took longer than the period
#ifdef PRINT_TIME #ifdef PRINT_TIME
printf("IVY DISPLAY THREAD: task took longer than one period, exactly %f [ms], but the period is %f [ms]\n", printf("IVY DISPLAY THREAD: task took longer than one period, exactly %f [ms], but the period is %f [ms]\n",
(double)task_ns / 1E6, (double)period_ns / 1E6); (double)task_ns / 1E6, (double)period_ns / 1E6);
#endif #endif
}
} }
} }
return(NULL); return(NULL);
} }
+4
View File
@@ -85,6 +85,8 @@ def main():
help="Time factor (default 1.0)") help="Time factor (default 1.0)")
nps_opts.add_option("--fg_fdm", action="store_true", nps_opts.add_option("--fg_fdm", action="store_true",
help="Use FlightGear native-fdm protocol instead of native-gui") help="Use FlightGear native-fdm protocol instead of native-gui")
nps_opts.add_option("--nodisplay", dest="nodisplay", action="store_true",
help="Don't send NPS Ivy messages")
parser.add_option_group(ocamlsim_opts) parser.add_option_group(ocamlsim_opts)
parser.add_option_group(nps_opts) parser.add_option_group(nps_opts)
@@ -164,6 +166,8 @@ def main():
simargs.append(str(options.time_factor)) simargs.append(str(options.time_factor))
if options.fg_fdm: if options.fg_fdm:
simargs.append("--fg_fdm") simargs.append("--fg_fdm")
if options.nodisplay:
simargs.append("--nodisplay")
else: else:
parser.error("Please specify a valid sim type.") parser.error("Please specify a valid sim type.")