diff --git a/sw/ground_segment/misc/natnet2ivy.c b/sw/ground_segment/misc/natnet2ivy.c index 2ee254ab90..9f03bc123c 100644 --- a/sw/ground_segment/misc/natnet2ivy.c +++ b/sw/ground_segment/misc/natnet2ivy.c @@ -57,6 +57,12 @@ uint16_t natnet_data_port = 1511; uint8_t natnet_major = 2; uint8_t natnet_minor = 7; +/** Logging */ +FILE *fp; +char *nameOfLogfile = "natnet_log.dat"; +bool_t log_exists = 0; +bool_t must_log = 0; + /** Ivy Bus default */ #ifdef __APPLE__ char *ivy_bus = "224.255.255.255"; @@ -587,8 +593,41 @@ gboolean timeout_transmit_callback(gpointer data) (int)(rigidBodies[i].ecef_vel.z * 100.0), //int32 ECEF velocity Z in m/s 0, (int)(heading * 10000000.0)); //int32 Course in rad*1e7 + + if (must_log) { + if (log_exists == 0) { + fp = fopen(nameOfLogfile, "w"); + log_exists = 1; + } + + if (fp == NULL) { + printf("I couldn't open file for writing.\n"); + exit(0); + } else { + struct timeval cur_time; + gettimeofday(&cur_time, NULL); + fprintf(fp, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", aircrafts[rigidBodies[i].id].ac_id, + rigidBodies[i].nMarkers, //uint8 Number of markers (sv_num) + (int)(ecef_pos.x * 100.0), //int32 ECEF X in CM + (int)(ecef_pos.y * 100.0), //int32 ECEF Y in CM + (int)(ecef_pos.z * 100.0), //int32 ECEF Z in CM + (int)(DegOfRad(lla_pos.lat) * 1e7), //int32 LLA latitude in deg*1e7 + (int)(DegOfRad(lla_pos.lon) * 1e7), //int32 LLA longitude in deg*1e7 + (int)(rigidBodies[i].z * 1000.0), //int32 LLA altitude in mm above elipsoid + (int)(rigidBodies[i].z * 1000.0), //int32 HMSL height above mean sea level in mm + (int)(rigidBodies[i].ecef_vel.x * 100.0), //int32 ECEF velocity X in cm/s + (int)(rigidBodies[i].ecef_vel.y * 100.0), //int32 ECEF velocity Y in cm/s + (int)(rigidBodies[i].ecef_vel.z * 100.0), //int32 ECEF velocity Z in cm/s + (int)(heading * 10000000.0), //int32 Course in rad*1e7 + (int)cur_time.tv_sec, + (int)cur_time.tv_usec); + } + } } + + + // Reset the velocity differentiator if we calculated the velocity if (rigidBodies[i].nVelocitySamples >= min_velocity_samples) { rigidBodies[i].vel_x = 0; @@ -634,7 +673,7 @@ void print_help(char *filename) " -v, --verbose Verbosity level 0-2 (0)\n\n" " -ac Use rigid ID for GPS of ac_id (multiple possible)\n\n" - + " -log Log to a file\n\n" " -multicast_addr NatNet server multicast address (239.255.42.99)\n" " -server NatNet server IP address (255.255.255.255)\n" " -version NatNet server version (2.5)\n" @@ -696,6 +735,13 @@ static void parse_options(int argc, char **argv) aircrafts[rigid_id].ac_id = ac_id; count_ac++; } + // See if we want to log to a file + else if (strcmp(argv[i], "-log") == 0) { + check_argcount(argc, argv, i, 1); + + nameOfLogfile = argv[++i]; + must_log = 1; + } // Set the NatNet multicast address else if (strcmp(argv[i], "-multicast_addr") == 0) {