Merge pull request #8 from sgk/refactoring

Refactoring
This commit is contained in:
OSQZSS 2015-07-02 08:25:56 +09:00
commit 6357120da0
3 changed files with 69 additions and 70 deletions

2
.gitignore vendored
View File

@ -34,7 +34,7 @@ gps-sdr-sim-lut
*.dSYM/ *.dSYM/
# Output # Output
gpssim.bin *.bin
# Temporary files # Temporary files
*.swp *.swp

View File

@ -1,6 +1,6 @@
# Makefile for Linux etc. # Makefile for Linux etc.
.PHONY: all clean .PHONY: all clean test test-lut test-nolut
all: gps-sdr-sim gps-sdr-sim-lut all: gps-sdr-sim gps-sdr-sim-lut
SHELL=/bin/bash SHELL=/bin/bash
@ -18,4 +18,17 @@ gpssim-lut.o: gpssim.c
${CC} -c -D_SINE_LUT ${CFLAGS} $< -o $@ ${CC} -c -D_SINE_LUT ${CFLAGS} $< -o $@
clean: clean:
rm -f gpssim.o gpssim-lut.o gps-sdr-sim gps-sdr-sim-lut rm -f gpssim.o gpssim-lut.o gps-sdr-sim gps-sdr-sim-lut *.bin
test: test-lut
test-lut: gps-sdr-sim-lut
time ./gps-sdr-sim-lut -e brdc3540.14n -u circle.csv -b 8
test "$$(md5sum gpssim.bin | awk '{print $$1}')" == "39a577af659440605c4ebbe178f4c4e3"
time ./gps-sdr-sim-lut -e brdc3540.14n -u circle.csv -b 16
test "$$(md5sum gpssim.bin | awk '{print $$1}')" == "bdd460893ad73b19412fc1757e62ccf9"
test-nolut: gps-sdr-sim
time ./gps-sdr-sim -e brdc3540.14n -u circle.csv -b 8
test "$$(md5sum gpssim.bin | awk '{print $$1}')" == "f4beb0857f82038d0465eb9934009edd"
time ./gps-sdr-sim -e brdc3540.14n -u circle.csv -b 16
test "$$(md5sum gpssim.bin | awk '{print $$1}')" == "10403720cb3483515f470fdea09e02ed"

106
gpssim.c
View File

@ -244,7 +244,6 @@ void codegen(int *ca, int prn)
int g1[1023],g2[1023],r1[10],r2[10],c1,c2; int g1[1023],g2[1023],r1[10],r2[10],c1,c2;
int i,j; int i,j;
int sv = prn-1;
if (prn<1 || prn>32) if (prn<1 || prn>32)
return; return;
@ -1128,7 +1127,7 @@ int main(int argc, char *argv[])
ephem_t eph[MAX_SAT]; ephem_t eph[MAX_SAT];
gpstime_t g0; gpstime_t g0;
double llh[3],xyz[3]; double llh[3];
double pos[3],vel[3],clk[2]; double pos[3],vel[3],clk[2];
double tmat[3][3]; double tmat[3][3];
double los[3]; double los[3];
@ -1155,8 +1154,8 @@ int main(int argc, char *argv[])
#endif #endif
void *iq_buff = NULL; void *iq_buff = NULL;
gpstime_t grx0,grx1; gpstime_t grx;
range_t rho0,rho1; range_t rho_backup[MAX_SAT];
double delt; // = 1.0/SAMP_FREQ; double delt; // = 1.0/SAMP_FREQ;
int isamp; int isamp;
@ -1269,15 +1268,10 @@ int main(int argc, char *argv[])
printf("User motion data = %d\n", numd); printf("User motion data = %d\n", numd);
// Initial location // Initial location in Geodetic coordinate system
xyz[0] = umd[0][0]; xyz2llh(umd[0], llh);
xyz[1] = umd[0][1];
xyz[2] = umd[0][2];
// Geodetic coordinate system printf("xyz = %11.1f, %11.1f, %11.1f\n", umd[0][0], umd[0][1], umd[0][2]);
xyz2llh(xyz, llh);
printf("xyz = %11.1f, %11.1f, %11.1f\n", xyz[0], xyz[1], xyz[2]);
printf("llh = %11.6f, %11.6f, %11.1f\n", llh[0]*R2D, llh[1]*R2D, llh[2]); printf("llh = %11.6f, %11.6f, %11.1f\n", llh[0]*R2D, llh[1]*R2D, llh[2]);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -1326,11 +1320,7 @@ int main(int argc, char *argv[])
if (eph[sv].vflg==1) if (eph[sv].vflg==1)
{ {
satpos(eph[sv], g0, pos, vel, clk); satpos(eph[sv], g0, pos, vel, clk);
subVect(los, pos, umd[0]);
los[0] = pos[0] - xyz[0];
los[1] = pos[1] - xyz[1];
los[2] = pos[2] - xyz[2];
ecef2neu(los, tmat, neu); ecef2neu(los, tmat, neu);
neu2azel(azel, neu); neu2azel(azel, neu);
@ -1374,7 +1364,7 @@ int main(int argc, char *argv[])
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Initial reception time // Initial reception time
grx0 = g0; grx = g0;
for (i=0; i<nsat; i++) for (i=0; i<nsat; i++)
{ {
@ -1442,42 +1432,38 @@ int main(int argc, char *argv[])
printf("Generating baseband signals...\n"); printf("Generating baseband signals...\n");
printf("\rTime = %4.1f", grx0.sec-g0.sec); printf("\rTime = %4.1f", grx.sec-g0.sec);
fflush(stdout); fflush(stdout);
//
// Generate I/Q samples for every user motion data // Generate I/Q samples for every user motion data
for (iumd=0; iumd<(numd-1); iumd++) //
{
// Refresh code phase and data bit counters // Initial pseudorange
for (i=0; i<nsat; i++) for (i=0; i<nsat; i++)
{ {
// Current pseudorange
sv = chan[i].prn-1; sv = chan[i].prn-1;
computeRange(&rho_backup[sv], eph[sv], grx, umd[0]);
xyz[0] = umd[iumd][0];
xyz[1] = umd[iumd][1];
xyz[2] = umd[iumd][2];
computeRange(&rho0, eph[sv], grx0, xyz);
// Pseudorange at next time step
grx1 = grx0;
grx1.sec += 0.1;
xyz[0] = umd[iumd+1][0];
xyz[1] = umd[iumd+1][1];
xyz[2] = umd[iumd+1][2];
computeRange(&rho1, eph[sv], grx1, xyz);
// Update code phase and data bit counters
computeCodePhase(&chan[i], rho0, rho1, 0.1);
} }
grx.sec += 0.1;
for (iumd=1; iumd<numd; iumd++)
{
#pragma omp parallel for private(isamp) #pragma omp parallel for private(isamp)
// Properties -> Configuration Properties -> C/C++ -> Language -> Open MP Support -> Yes (/openmp) // Properties -> Configuration Properties -> C/C++ -> Language -> Open MP Support -> Yes (/openmp)
for (i=0; i<nsat; i++) for (i=0; i<nsat; i++)
{ {
// Refresh code phase and data bit counters
int sv = chan[i].prn-1;
range_t rho;
// Current pseudorange
computeRange(&rho, eph[sv], grx, umd[iumd]);
// Update code phase and data bit counters
computeCodePhase(&chan[i], rho_backup[sv], rho, 0.1);
rho_backup[sv] = rho;
for (isamp=0; isamp<iq_buff_size; isamp++) for (isamp=0; isamp<iq_buff_size; isamp++)
{ {
#ifdef _SINE_LUT #ifdef _SINE_LUT
@ -1486,14 +1472,14 @@ int main(int argc, char *argv[])
ip = chan[i].dataBit * chan[i].codeCA * cosTable512[iTable]; ip = chan[i].dataBit * chan[i].codeCA * cosTable512[iTable];
qp = chan[i].dataBit * chan[i].codeCA * sinTable512[iTable]; qp = chan[i].dataBit * chan[i].codeCA * sinTable512[iTable];
// Sotre I/Q samples into buffer // Store I/Q samples into buffer
chan[i].iq_buff[isamp*2] = (short)(ip>>1); chan[i].iq_buff[isamp*2] = (short)(ip>>1);
chan[i].iq_buff[isamp*2+1] = (short)(qp>>1); chan[i].iq_buff[isamp*2+1] = (short)(qp>>1);
#else #else
ip = chan[i].dataBit * chan[i].codeCA * cos(2.0*PI*chan[i].carr_phase); ip = chan[i].dataBit * chan[i].codeCA * cos(2.0*PI*chan[i].carr_phase);
qp = chan[i].dataBit * chan[i].codeCA * sin(2.0*PI*chan[i].carr_phase); qp = chan[i].dataBit * chan[i].codeCA * sin(2.0*PI*chan[i].carr_phase);
// Sotre I/Q samples into buffer // Store I/Q samples into buffer
chan[i].iq_buff[isamp*2] = (short)(ADC_GAIN*ip); chan[i].iq_buff[isamp*2] = (short)(ADC_GAIN*ip);
chan[i].iq_buff[isamp*2+1] = (short)(ADC_GAIN*qp); chan[i].iq_buff[isamp*2+1] = (short)(ADC_GAIN*qp);
#endif #endif
@ -1535,32 +1521,32 @@ int main(int argc, char *argv[])
} }
} // End of omp parallel for } // End of omp parallel for
if (data_format==SC08)
{
for (isamp=0; isamp<2*iq_buff_size; isamp++) for (isamp=0; isamp<2*iq_buff_size; isamp++)
{ {
if (data_format==SC08) char sample = 0;
((signed char*)iq_buff)[isamp] = 0;
else
((short*)iq_buff)[isamp] = 0;
for (i=0; i<nsat; i++) for (i=0; i<nsat; i++)
{ sample += (signed char)(chan[i].iq_buff[isamp]>>4); // 12-bit bladeRF -> 8-bit HackRF
if (data_format==SC08) ((signed char*)iq_buff)[isamp] = sample;
((signed char*)iq_buff)[isamp] += (signed char)(chan[i].iq_buff[isamp]>>4); // 12-bit bladeRF -> 8-bit HackRF
else
((short*)iq_buff)[isamp] += chan[i].iq_buff[isamp];
} }
}
if (data_format==SC08)
fwrite(iq_buff, 1, 2*iq_buff_size, fp); fwrite(iq_buff, 1, 2*iq_buff_size, fp);
else } else {
for (isamp=0; isamp<2*iq_buff_size; isamp++)
{
short sample = 0;
for (i=0; i<nsat; i++)
sample += chan[i].iq_buff[isamp];
((short*)iq_buff)[isamp] = sample;
}
fwrite(iq_buff, 2, 2*iq_buff_size, fp); fwrite(iq_buff, 2, 2*iq_buff_size, fp);
}
// Next second // Next second
grx0.sec += 0.1; grx.sec += 0.1;
// Update time counter // Update time counter
printf("\rTime = %4.1f", grx0.sec-g0.sec); printf("\rTime = %4.1f", grx.sec-g0.sec);
fflush(stdout); fflush(stdout);
} }