This commit is contained in:
gym487 2017-04-23 01:08:48 +08:00
parent f69e5eb283
commit f7fbba877e
9 changed files with 8600 additions and 13 deletions

View File

@ -11,6 +11,7 @@
#include <unistd.h>
#endif
#include "gpssim.h"
#include "socket.c"
int sinTable512[] = {
2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 32, 35, 38, 41, 44, 47,
@ -1726,6 +1727,10 @@ int main(int argc, char *argv[])
int timeoverwrite = FALSE; // Overwirte the TOC and TOE in the RINEX file
ionoutc_t ionoutc;
int usesocket=false;
int sockc=0;
////////////////////////////////////////////////////////////
// Read options
@ -1749,7 +1754,7 @@ int main(int argc, char *argv[])
exit(1);
}
while ((result=getopt(argc,argv,"e:u:g:l:o:s:b:T:t:d:iv"))!=-1)
while ((result=getopt(argc,argv,"e:u:g:l:o:s:b:T:t:d:iv:n"))!=-1)
{
switch (result)
{
@ -1836,6 +1841,9 @@ int main(int argc, char *argv[])
case '?':
usage();
exit(1);
case 'n':
sockc=sockinit();
usesocket=true;
default:
break;
}
@ -2075,14 +2083,14 @@ int main(int argc, char *argv[])
exit(1);
}
}
if(usesocket==false){
// Open output file
if (NULL==(fp=fopen(outfile,"wb")))
{
printf("ERROR: Failed to open output file.\n");
exit(1);
if (NULL==(fp=fopen(outfile,"wb")))
{
printf("ERROR: Failed to open output file.\n");
exit(1);
}
}
////////////////////////////////////////////////////////////
// Initialize channels
////////////////////////////////////////////////////////////
@ -2223,7 +2231,7 @@ int main(int argc, char *argv[])
iq_buff[isamp*2+1] = (short)q_acc;
}
if (data_format==SC01)
if (data_format==SC01&&usesocket==false)
{
for (isamp=0; isamp<2*iq_buff_size; isamp++)
{
@ -2235,17 +2243,26 @@ int main(int argc, char *argv[])
fwrite(iq8_buff, 1, iq_buff_size/4, fp);
}
else if (data_format==SC08)
else if (data_format==SC08&&usesocket==false)
{
for (isamp=0; isamp<2*iq_buff_size; isamp++)
iq8_buff[isamp] = iq_buff[isamp]>>4; // 12-bit bladeRF -> 8-bit HackRF
fwrite(iq8_buff, 1, 2*iq_buff_size, fp);
}
else // data_format==SC16
else if(data_format==SC16&&usesocket==false)
{
fwrite(iq_buff, 2, 2*iq_buff_size, fp);
}
if(usesocket==true){
float *datap=(float*)calloc(iq_buff_size*2,sizeof(float));
int l=0;
for(l=0;l<iq_buff_size*2;l++){
datap[l]=(float)iq_buff[l];
}
socksend(sockc,datap,iq_buff_size*2*sizeof(float));
free(datap);
}
//
// Update navigation message and channel allocation every 30 seconds
@ -2303,7 +2320,9 @@ int main(int argc, char *argv[])
}
}
}
if(subGpsTime(grx, g0)-(double)(clock()-tstart)/CLOCKS_PER_SEC>0.2&&usesocket==true){
sleep(0.2);
}
// Update receiver time
grx = incGpsTime(grx, 0.1);
@ -2320,8 +2339,9 @@ int main(int argc, char *argv[])
free(iq_buff);
// Close file
if(usesocket==false)
fclose(fp);
else sockclose(sockc);
// Process time
printf("Process time = %.1f [sec]\n", (double)(tend-tstart)/CLOCKS_PER_SEC);

2349
gpssim.c~ Normal file

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,8 @@
#define TRUE (1)
#define FALSE (0)
#define true (1)
#define false (0)
/*! \brief Maximum length of a line in a text file (RINEX, motion) */
#define MAX_CHAR (100)

177
gpssim.h~ Normal file
View File

@ -0,0 +1,177 @@
#ifndef GPSSIM_H
#define GPSSIM_H
#define TRUE (1)
#define FALSE (0)
/*! \brief Maximum length of a line in a text file (RINEX, motion) */
#define MAX_CHAR (100)
/*! \brief Maximum number of satellites in RINEX file */
#define MAX_SAT (32)
/*! \brief Maximum number of channels we simulate */
#define MAX_CHAN (16)
/*! \brief Maximum number of user motion points */
#define USER_MOTION_SIZE (3000) // max duration at 10Hz
/*! \brief Maximum duration for static mode*/
#define STATIC_MAX_DURATION (86400) // second
/*! \brief Number of subframes */
#define N_SBF (5) // 5 subframes per frame
/*! \brief Number of words per subframe */
#define N_DWRD_SBF (10) // 10 word per subframe
/*! \brief Number of words */
#define N_DWRD ((N_SBF+1)*N_DWRD_SBF) // Subframe word buffer size
/*! \brief C/A code sequence length */
#define CA_SEQ_LEN (1023)
#define SECONDS_IN_WEEK 604800.0
#define SECONDS_IN_HALF_WEEK 302400.0
#define SECONDS_IN_DAY 86400.0
#define SECONDS_IN_HOUR 3600.0
#define SECONDS_IN_MINUTE 60.0
#define POW2_M5 0.03125
#define POW2_M19 1.907348632812500e-6
#define POW2_M29 1.862645149230957e-9
#define POW2_M31 4.656612873077393e-10
#define POW2_M33 1.164153218269348e-10
#define POW2_M43 1.136868377216160e-13
#define POW2_M55 2.775557561562891e-17
#define POW2_M50 8.881784197001252e-016
#define POW2_M30 9.313225746154785e-010
#define POW2_M27 7.450580596923828e-009
#define POW2_M24 5.960464477539063e-008
// Conventional values employed in GPS ephemeris model (ICD-GPS-200)
#define GM_EARTH 3.986005e14
#define OMEGA_EARTH 7.2921151467e-5
#define PI 3.1415926535898
#define WGS84_RADIUS 6378137.0
#define WGS84_ECCENTRICITY 0.0818191908426
#define R2D 57.2957795131
#define SPEED_OF_LIGHT 2.99792458e8
#define LAMBDA_L1 0.190293672798365
/*! \brief GPS L1 Carrier frequency */
#define CARR_FREQ (1575.42e6)
/*! \brief C/A code frequency */
#define CODE_FREQ (1.023e6)
#define CARR_TO_CODE (1.0/1540.0)
// Sampling data format
#define SC01 (1)
#define SC08 (8)
#define SC16 (16)
#define EPHEM_ARRAY_SIZE (13) // for daily GPS broadcast ephemers file (brdc)
/*! \brief Structure representing GPS time */
typedef struct
{
int week; /*!< GPS week number (since January 1980) */
double sec; /*!< second inside the GPS \a week */
} gpstime_t;
/*! \brief Structure repreenting UTC time */
typedef struct
{
int y; /*!< Calendar year */
int m; /*!< Calendar month */
int d; /*!< Calendar day */
int hh; /*!< Calendar hour */
int mm; /*!< Calendar minutes */
double sec; /*!< Calendar seconds */
} datetime_t;
/*! \brief Structure representing ephemeris of a single satellite */
typedef struct
{
int vflg; /*!< Valid Flag */
datetime_t t;
gpstime_t toc; /*!< Time of Clock */
gpstime_t toe; /*!< Time of Ephemeris */
int iodc; /*!< Issue of Data, Clock */
int iode; /*!< Isuse of Data, Ephemeris */
double deltan; /*!< Delta-N (radians/sec) */
double cuc; /*!< Cuc (radians) */
double cus; /*!< Cus (radians) */
double cic; /*!< Correction to inclination cos (radians) */
double cis; /*!< Correction to inclination sin (radians) */
double crc; /*!< Correction to radius cos (meters) */
double crs; /*!< Correction to radius sin (meters) */
double ecc; /*!< e Eccentricity */
double sqrta; /*!< sqrt(A) (sqrt(m)) */
double m0; /*!< Mean anamoly (radians) */
double omg0; /*!< Longitude of the ascending node (radians) */
double inc0; /*!< Inclination (radians) */
double aop;
double omgdot; /*!< Omega dot (radians/s) */
double idot; /*!< IDOT (radians/s) */
double af0; /*!< Clock offset (seconds) */
double af1; /*!< rate (sec/sec) */
double af2; /*!< acceleration (sec/sec^2) */
double tgd; /*!< Group delay L2 bias */
int svhlth;
int codeL2;
// Working variables follow
double n; /*!< Mean motion (Average angular velocity) */
double sq1e2; /*!< sqrt(1-e^2) */
double A; /*!< Semi-major axis */
double omgkdot; /*!< OmegaDot-OmegaEdot */
} ephem_t;
typedef struct
{
int enable;
int vflg;
double alpha0,alpha1,alpha2,alpha3;
double beta0,beta1,beta2,beta3;
double A0,A1;
int dtls,tot,wnt;
int dtlsf,dn,wnlsf;
} ionoutc_t;
typedef struct
{
gpstime_t g;
double range; // pseudorange
double rate;
double d; // geometric distance
double azel[2];
double iono_delay;
} range_t;
/*! \brief Structure representing a Channel */
typedef struct
{
int prn; /*< PRN Number */
int ca[CA_SEQ_LEN]; /*< C/A Sequence */
double f_carr; /*< Carrier frequency */
double f_code; /*< Code frequency */
unsigned int carr_phase; /*< Carrier phase */
int carr_phasestep; /*< Carrier phasestep */
double code_phase; /*< Code phase */
gpstime_t g0; /*!< GPS time at start */
unsigned long sbf[5][N_DWRD_SBF]; /*!< current subframe */
unsigned long dwrd[N_DWRD]; /*!< Data words of sub-frame */
int iword; /*!< initial word */
int ibit; /*!< initial bit */
int icode; /*!< initial code */
int dataBit; /*!< current data bit */
int codeCA; /*!< current C/A code */
double azel[2];
range_t rho0;
} channel_t;
#endif

3571
rtk/eil41040.17n Normal file

File diff suppressed because it is too large Load Diff

39
socket.c Normal file
View File

@ -0,0 +1,39 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/shm.h>
#define MYPORT 1234
int sockinit()
{
int sock = socket(AF_INET,SOCK_STREAM, 0);
struct sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(MYPORT);
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
if (connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
{
perror("connect");
exit(1);
}
return sock;
}
void sockclose(int s){
close(s);
}
void socksend(int s,void *dataa,int siz){
send(s,dataa,siz,0);
}

39
socket.c~ Normal file
View File

@ -0,0 +1,39 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/shm.h>
#define MYPORT 1234
#define BUFFER_SIZE 1024
int sockinit()
{
int sock = socket(AF_INET,SOCK_STREAM, 0);
struct sockaddr_in servaddr;
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(MYPORT);
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
if (connect(sock, (struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
{
perror("connect");
exit(1);
}
return sock;
}
void sockclose(int s){
close(s);
}
void socksend(int s,void *dataa,int siz){
send(s,dataa,siz,0);
}

1183
tcp.grc Normal file

File diff suppressed because it is too large Load Diff

1208
wslb1110.17n Normal file

File diff suppressed because it is too large Load Diff