From 6c88f8a1a996df7d899a39ed664600ce410fe37b Mon Sep 17 00:00:00 2001 From: Arnaud ZANETTI Date: Mon, 30 Oct 2017 14:00:26 +0100 Subject: [PATCH] Allow to use stdout as output file. --- README.md | 2 +- gpssim.c | 79 +++++++++++++++++++++++++++++-------------------------- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 14b0af6..b80e960 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,7 @@ Options: -t Scenario start time YYYY/MM/DD,hh:mm:ss -T Overwrite TOC and TOE to scenario start time -d Duration [sec] (dynamic mode max: 300 static mode max: 86400) - -o I/Q sampling data file (default: gpssim.bin) + -o I/Q sampling data file (default: gpssim.bin ; use - for stdout) -s Sampling frequency [Hz] (default: 2600000) -b I/Q data format [1/8/16] (default: 16) -i Disable ionospheric delay for spacecraft scenario diff --git a/gpssim.c b/gpssim.c index 5916511..827cd55 100644 --- a/gpssim.c +++ b/gpssim.c @@ -1512,7 +1512,7 @@ int generateNavMsg(gpstime_t g, channel_t *chan, int init) // Sanity check if (((chan->dwrd[1])&(0x1FFFFUL<<13)) != ((tow&0x1FFFFUL)<<13)) { - printf("\nWARNING: Invalid TOW in subframe 5.\n"); + fprintf(stderr, "\nWARNING: Invalid TOW in subframe 5.\n"); return(0); } */ @@ -1646,7 +1646,7 @@ int allocateChannel(channel_t *chan, ephem_t *eph, ionoutc_t ionoutc, gpstime_t void usage(void) { - printf("Usage: gps-sdr-sim [options]\n" + fprintf(stderr, "Usage: gps-sdr-sim [options]\n" "Options:\n" " -e RINEX navigation file for GPS ephemerides (required)\n" " -u User motion file (dynamic mode)\n" @@ -1779,7 +1779,7 @@ int main(int argc, char *argv[]) samp_freq = atof(optarg); if (samp_freq<1.0e6) { - printf("ERROR: Invalid sampling frequency.\n"); + fprintf(stderr, "ERROR: Invalid sampling frequency.\n"); exit(1); } break; @@ -1787,7 +1787,7 @@ int main(int argc, char *argv[]) data_format = atoi(optarg); if (data_format!=SC01 && data_format!=SC08 && data_format!=SC16) { - printf("ERROR: Invalid I/Q data format.\n"); + fprintf(stderr, "ERROR: Invalid I/Q data format.\n"); exit(1); } break; @@ -1817,7 +1817,7 @@ int main(int argc, char *argv[]) if (t0.y<=1980 || t0.m<1 || t0.m>12 || t0.d<1 || t0.d>31 || t0.hh<0 || t0.hh>23 || t0.mm<0 || t0.mm>59 || t0.sec<0.0 || t0.sec>=60.0) { - printf("ERROR: Invalid date and time.\n"); + fprintf(stderr, "ERROR: Invalid date and time.\n"); exit(1); } t0.sec = floor(t0.sec); @@ -1843,7 +1843,7 @@ int main(int argc, char *argv[]) if (navfile[0]==0) { - printf("ERROR: GPS ephemeris file is not specified.\n"); + fprintf(stderr, "ERROR: GPS ephemeris file is not specified.\n"); exit(1); } @@ -1858,7 +1858,7 @@ int main(int argc, char *argv[]) if (duration<0.0 || (duration>((double)USER_MOTION_SIZE)/10.0 && !staticLocationMode) || (duration>STATIC_MAX_DURATION && staticLocationMode)) { - printf("ERROR: Invalid duration.\n"); + fprintf(stderr, "ERROR: Invalid duration.\n"); exit(1); } iduration = (int)(duration*10.0 + 0.5); @@ -1884,12 +1884,12 @@ int main(int argc, char *argv[]) if (numd==-1) { - printf("ERROR: Failed to open user motion / NMEA GGA file.\n"); + fprintf(stderr, "ERROR: Failed to open user motion / NMEA GGA file.\n"); exit(1); } else if (numd==0) { - printf("ERROR: Failed to read user motion / NMEA GGA data.\n"); + fprintf(stderr, "ERROR: Failed to read user motion / NMEA GGA data.\n"); exit(1); } @@ -1901,14 +1901,14 @@ int main(int argc, char *argv[]) { // Static geodetic coordinates input mode: "-l" // Added by scateu@gmail.com - printf("Using static location mode.\n"); + fprintf(stderr, "Using static location mode.\n"); llh2xyz(llh,xyz[0]); // Convert llh to xyz numd = iduration; } /* - printf("xyz = %11.1f, %11.1f, %11.1f\n", xyz[0][0], xyz[0][1], xyz[0][2]); - printf("llh = %11.6f, %11.6f, %11.1f\n", llh[0]*R2D, llh[1]*R2D, llh[2]); + fprintf(stderr, "xyz = %11.1f, %11.1f, %11.1f\n", xyz[0][0], xyz[0][1], xyz[0][2]); + fprintf(stderr, "llh = %11.6f, %11.6f, %11.1f\n", llh[0]*R2D, llh[1]*R2D, llh[2]); */ //////////////////////////////////////////////////////////// // Read ephemeris @@ -1918,19 +1918,19 @@ int main(int argc, char *argv[]) if (neph==0) { - printf("ERROR: No ephemeris available.\n"); + fprintf(stderr, "ERROR: No ephemeris available.\n"); exit(1); } if ((verb==TRUE)&&(ionoutc.vflg==TRUE)) { - printf(" %12.3e %12.3e %12.3e %12.3e\n", + fprintf(stderr, " %12.3e %12.3e %12.3e %12.3e\n", ionoutc.alpha0, ionoutc.alpha1, ionoutc.alpha2, ionoutc.alpha3); - printf(" %12.3e %12.3e %12.3e %12.3e\n", + fprintf(stderr, " %12.3e %12.3e %12.3e %12.3e\n", ionoutc.beta0, ionoutc.beta1, ionoutc.beta2, ionoutc.beta3); - printf(" %19.11e %19.11e %9d %9d\n", + fprintf(stderr, " %19.11e %19.11e %9d %9d\n", ionoutc.A0, ionoutc.A1, ionoutc.tot, ionoutc.wnt); - printf("%6d\n", ionoutc.dtls); + fprintf(stderr, "%6d\n", ionoutc.dtls); } for (sv=0; sv0) - printf("%02d %6.1f %5.1f %11.1f %5.1f\n", chan[i].prn, + fprintf(stderr, "%02d %6.1f %5.1f %11.1f %5.1f\n", chan[i].prn, chan[i].azel[0]*R2D, chan[i].azel[1]*R2D, chan[i].rho0.d, chan[i].rho0.iono_delay); } @@ -2205,7 +2210,7 @@ int main(int argc, char *argv[]) chan[i].iword++; /* if (chan[i].iword>=N_DWRD) - printf("\nWARNING: Subframe word buffer overflow.\n"); + fprintf(stderr, "\nWARNING: Subframe word buffer overflow.\n"); */ } @@ -2302,11 +2307,11 @@ int main(int argc, char *argv[]) // Show ditails about simulated channels if (verb==TRUE) { - printf("\n"); + fprintf(stderr, "\n"); for (i=0; i0) - printf("%02d %6.1f %5.1f %11.1f %5.1f\n", chan[i].prn, + fprintf(stderr, "%02d %6.1f %5.1f %11.1f %5.1f\n", chan[i].prn, chan[i].azel[0]*R2D, chan[i].azel[1]*R2D, chan[i].rho0.d, chan[i].rho0.iono_delay); } } @@ -2316,13 +2321,13 @@ int main(int argc, char *argv[]) grx = incGpsTime(grx, 0.1); // Update time counter - printf("\rTime into run = %4.1f", subGpsTime(grx, g0)); + fprintf(stderr, "\rTime into run = %4.1f", subGpsTime(grx, g0)); fflush(stdout); } tend = clock(); - printf("\nDone!\n"); + fprintf(stderr, "\nDone!\n"); // Free I/Q buffer free(iq_buff); @@ -2331,7 +2336,7 @@ int main(int argc, char *argv[]) fclose(fp); // Process time - printf("Process time = %.1f [sec]\n", (double)(tend-tstart)/CLOCKS_PER_SEC); + fprintf(stderr, "Process time = %.1f [sec]\n", (double)(tend-tstart)/CLOCKS_PER_SEC); return(0); }