diff --git a/groundStation/src/backend/backend.c b/groundStation/src/backend/backend.c index ae638696ede50acf700d299a56119b0eb8153fdf..068544d2ed16e68d62989f16ab6274ab6b357c07 100644 --- a/groundStation/src/backend/backend.c +++ b/groundStation/src/backend/backend.c @@ -114,6 +114,7 @@ fd_set rfds_master; int max_fd = 0; static FILE * quadlog_file; +static int quadlog_file_open; static char user_specified_log_name[256] = ""; pthread_mutex_t quadResponseMutex, cliInputMutex ; @@ -211,6 +212,7 @@ int main(int argc, char **argv) printf("Creating log file '%s'...\n",log_file); quadlog_file = fopen(log_file, "a"); + quadlog_file_open = 1; // Tell the quad we are ready to send it vrpn data sendStartPacket(); @@ -795,6 +797,12 @@ static void quad_recv() { switch (m.msg_type) { case LOG_ID: + if (!quadlog_file_open) { + char log_file[256]; + create_log_name(log_file, 256); + printf("New log file created: '%s'\n", log_file); + quadlog_file = fopen(log_file, "a"); + } /* something like this */ printf("(Quad) : Log found\n"); fwrite((char *) data, sizeof(char), m.data_len, quadlog_file); @@ -808,11 +816,10 @@ static void quad_recv() { handleResponse(&m, data); break; case LOG_END_ID: - fclose(quadlog_file); - char log_file[256]; - create_log_name(log_file, 256); - printf("New log file created: '%s'\n", log_file); - quadlog_file = fopen(log_file, "a"); + if (quadlog_file_open) { + fclose(quadlog_file); + quadlog_file_open = 0; + } break; default: printf("(Backend): message type %d ignored from quad\n", m.msg_type);