Allow to use stdout as output file.

This commit is contained in:
Arnaud ZANETTI 2017-10-30 14:00:26 +01:00
parent b0c2b5500c
commit 6c88f8a1a9
2 changed files with 43 additions and 38 deletions

View File

@ -64,7 +64,7 @@ Options:
-t <date,time> Scenario start time YYYY/MM/DD,hh:mm:ss
-T <date,time> Overwrite TOC and TOE to scenario start time
-d <duration> Duration [sec] (dynamic mode max: 300 static mode max: 86400)
-o <output> I/Q sampling data file (default: gpssim.bin)
-o <output> I/Q sampling data file (default: gpssim.bin ; use - for stdout)
-s <frequency> Sampling frequency [Hz] (default: 2600000)
-b <iq_bits> I/Q data format [1/8/16] (default: 16)
-i Disable ionospheric delay for spacecraft scenario

View File

@ -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 <gps_nav> RINEX navigation file for GPS ephemerides (required)\n"
" -u <user_motion> 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; sv<MAX_SAT; sv++)
@ -2003,11 +2003,11 @@ int main(int argc, char *argv[])
{
if (subGpsTime(g0, gmin)<0.0 || subGpsTime(gmax, g0)<0.0)
{
printf("ERROR: Invalid start time.\n");
printf("tmin = %4d/%02d/%02d,%02d:%02d:%02.0f (%d:%.0f)\n",
fprintf(stderr, "ERROR: Invalid start time.\n");
fprintf(stderr, "tmin = %4d/%02d/%02d,%02d:%02d:%02.0f (%d:%.0f)\n",
tmin.y, tmin.m, tmin.d, tmin.hh, tmin.mm, tmin.sec,
gmin.week, gmin.sec);
printf("tmax = %4d/%02d/%02d,%02d:%02d:%02.0f (%d:%.0f)\n",
fprintf(stderr, "tmax = %4d/%02d/%02d,%02d:%02d:%02.0f (%d:%.0f)\n",
tmax.y, tmax.m, tmax.d, tmax.hh, tmax.mm, tmax.sec,
gmax.week, gmax.sec);
exit(1);
@ -2020,9 +2020,9 @@ int main(int argc, char *argv[])
t0 = tmin;
}
printf("Start time = %4d/%02d/%02d,%02d:%02d:%02.0f (%d:%.0f)\n",
fprintf(stderr, "Start time = %4d/%02d/%02d,%02d:%02d:%02.0f (%d:%.0f)\n",
t0.y, t0.m, t0.d, t0.hh, t0.mm, t0.sec, g0.week, g0.sec);
printf("Duration = %.1f [sec]\n", ((double)numd)/10.0);
fprintf(stderr, "Duration = %.1f [sec]\n", ((double)numd)/10.0);
// Select the current set of ephemerides
ieph = -1;
@ -2048,7 +2048,7 @@ int main(int argc, char *argv[])
if (ieph == -1)
{
printf("ERROR: No current set of ephemerides has been found.\n");
fprintf(stderr, "ERROR: No current set of ephemerides has been found.\n");
exit(1);
}
@ -2061,7 +2061,7 @@ int main(int argc, char *argv[])
if (iq_buff==NULL)
{
printf("ERROR: Faild to allocate 16-bit I/Q buffer.\n");
fprintf(stderr, "ERROR: Faild to allocate 16-bit I/Q buffer.\n");
exit(1);
}
@ -2070,7 +2070,7 @@ int main(int argc, char *argv[])
iq8_buff = calloc(2*iq_buff_size, 1);
if (iq8_buff==NULL)
{
printf("ERROR: Faild to allocate 8-bit I/Q buffer.\n");
fprintf(stderr, "ERROR: Faild to allocate 8-bit I/Q buffer.\n");
exit(1);
}
}
@ -2079,16 +2079,21 @@ int main(int argc, char *argv[])
iq8_buff = calloc(iq_buff_size/4, 1); // byte = {I0, Q0, I1, Q1, I2, Q2, I3, Q3}
if (iq8_buff==NULL)
{
printf("ERROR: Faild to allocate compressed 1-bit I/Q buffer.\n");
fprintf(stderr, "ERROR: Faild to allocate compressed 1-bit I/Q buffer.\n");
exit(1);
}
}
// Open output file
if (NULL==(fp=fopen(outfile,"wb")))
{
printf("ERROR: Failed to open output file.\n");
exit(1);
// "-" can be used as name for stdout
if(strcmp("-", outfile)){
if (NULL==(fp=fopen(outfile,"wb")))
{
fprintf(stderr, "ERROR: Failed to open output file.\n");
exit(1);
}
}else{
fp = stdout;
}
////////////////////////////////////////////////////////////
@ -2112,7 +2117,7 @@ int main(int argc, char *argv[])
for(i=0; i<MAX_CHAN; i++)
{
if (chan[i].prn>0)
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; i<MAX_CHAN; i++)
{
if (chan[i].prn>0)
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);
}