1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 20:20:35 +00:00

Add work on rtklib functions

This commit is contained in:
Carles Fernandez 2017-05-12 19:22:57 +02:00
parent 9da436ec87
commit c804fb8d6f
7 changed files with 3701 additions and 3530 deletions

View File

@ -60,11 +60,51 @@
#include <cmath> #include <cmath>
#include <time.h> #include <time.h>
#include <ctype.h> #include <ctype.h>
#include <pthread.h>
#include <netinet/in.h>
#include "MATH_CONSTANTS.h" #include "MATH_CONSTANTS.h"
#include "gnss_frequencies.h" #include "gnss_frequencies.h"
#include "gnss_obs_codes.h" #include "gnss_obs_codes.h"
/* macros --------------------------------------------------------------------*/
#define dev_t int
#define socket_t int
#define closesocket close
#define lock_t pthread_mutex_t
#define thread_t pthread_t
#define initlock(f) pthread_mutex_init(f,NULL)
#define rtk_lock(f) pthread_mutex_lock(f)
#define rtk_unlock(f) pthread_mutex_unlock(f)
#define TINTACT 200 /* period for stream active (ms) */
#define SERIBUFFSIZE 4096 /* serial buffer size (bytes) */
#define TIMETAGH_LEN 64 /* time tag file header length */
#define MAXCLI 32 /* max client connection for tcp svr */
#define MAXSTATMSG 32 /* max length of status message */
#define VER_RTKLIB "2.4.2"
#define NTRIP_AGENT "RTKLIB/" VER_RTKLIB
#define NTRIP_CLI_PORT 2101 /* default ntrip-client connection port */
#define NTRIP_SVR_PORT 80 /* default ntrip-server connection port */
#define NTRIP_MAXRSP 32768 /* max size of ntrip response */
#define NTRIP_MAXSTR 256 /* max length of mountpoint string */
#define NTRIP_RSP_OK_CLI "ICY 200 OK\r\n" /* ntrip response: client */
#define NTRIP_RSP_OK_SVR "OK\r\n" /* ntrip response: server */
#define NTRIP_RSP_SRCTBL "SOURCETABLE 200 OK\r\n" /* ntrip response: source table */
#define NTRIP_RSP_TBLEND "ENDSOURCETABLE"
#define NTRIP_RSP_HTTP "HTTP/" /* ntrip response: http */
#define NTRIP_RSP_ERROR "ERROR" /* ntrip response: error */
#define FTP_CMD "wget" /* ftp/http command */
#define FTP_TIMEOUT 30 /* ftp/http timeout (s) */
#define MAXRAWLEN 4096 /* max length of receiver raw message */
#define MAXSOLBUF 256 /* max number of solution buffer */
#define MAXSBSMSG 32 /* max number of SBAS msg in RTK server */
#define MAXOBSBUF 128 /* max number of observation data buffer */
const int FILEPATHSEP = '/'; const int FILEPATHSEP = '/';
const double RE_WGS84 = 6378137.0; //!< earth semimajor axis (WGS84) (m) const double RE_WGS84 = 6378137.0; //!< earth semimajor axis (WGS84) (m)
const double FE_WGS84 = (1.0 / 298.257223563); //!< earth flattening (WGS84) const double FE_WGS84 = (1.0 / 298.257223563); //!< earth flattening (WGS84)
@ -1010,6 +1050,179 @@ typedef struct half_cyc_tag { /* half-cycle correction list type */
} half_cyc_t; } half_cyc_t;
typedef struct { /* stream type */
int type; /* type (STR_???) */
int mode; /* mode (STR_MODE_?) */
int state; /* state (-1:error,0:close,1:open) */
unsigned int inb,inr; /* input bytes/rate */
unsigned int outb,outr; /* output bytes/rate */
unsigned int tick,tact; /* tick/active tick */
unsigned int inbt,outbt; /* input/output bytes at tick */
lock_t lock; /* lock flag */
void *port; /* type dependent port control struct */
char path[MAXSTRPATH]; /* stream path */
char msg [MAXSTRMSG]; /* stream message */
} stream_t;
typedef struct { /* serial control type */
dev_t dev; /* serial device */
int error; /* error state */
} serial_t;
typedef struct { /* file control type */
FILE *fp; /* file pointer */
FILE *fp_tag; /* file pointer of tag file */
FILE *fp_tmp; /* temporary file pointer for swap */
FILE *fp_tag_tmp; /* temporary file pointer of tag file for swap */
char path[MAXSTRPATH]; /* file path */
char openpath[MAXSTRPATH]; /* open file path */
int mode; /* file mode */
int timetag; /* time tag flag (0:off,1:on) */
int repmode; /* replay mode (0:master,1:slave) */
int offset; /* time offset (ms) for slave */
gtime_t time; /* start time */
gtime_t wtime; /* write time */
unsigned int tick; /* start tick */
unsigned int tick_f; /* start tick in file */
unsigned int fpos; /* current file position */
double start; /* start offset (s) */
double speed; /* replay speed (time factor) */
double swapintv; /* swap interval (hr) (0: no swap) */
lock_t lock; /* lock flag */
} file_t;
typedef struct { /* tcp control type */
int state; /* state (0:close,1:wait,2:connect) */
char saddr[256]; /* address string */
int port; /* port */
struct sockaddr_in addr; /* address resolved */
socket_t sock; /* socket descriptor */
int tcon; /* reconnect time (ms) (-1:never,0:now) */
unsigned int tact; /* data active tick */
unsigned int tdis; /* disconnect tick */
} tcp_t;
typedef struct { /* tcp server type */
tcp_t svr; /* tcp server control */
tcp_t cli[MAXCLI]; /* tcp client controls */
} tcpsvr_t;
typedef struct { /* tcp cilent type */
tcp_t svr; /* tcp server control */
int toinact; /* inactive timeout (ms) (0:no timeout) */
int tirecon; /* reconnect interval (ms) (0:no reconnect) */
} tcpcli_t;
typedef struct { /* ntrip control type */
int state; /* state (0:close,1:wait,2:connect) */
int type; /* type (0:server,1:client) */
int nb; /* response buffer size */
char url[256]; /* url for proxy */
char mntpnt[256]; /* mountpoint */
char user[256]; /* user */
char passwd[256]; /* password */
char str[NTRIP_MAXSTR]; /* mountpoint string for server */
unsigned char buff[NTRIP_MAXRSP]; /* response buffer */
tcpcli_t *tcp; /* tcp client */
} ntrip_t;
typedef struct { /* ftp download control type */
int state; /* state (0:close,1:download,2:complete,3:error) */
int proto; /* protocol (0:ftp,1:http) */
int error; /* error code (0:no error,1-10:wget error, */
/* 11:no temp dir,12:uncompact error) */
char addr[1024]; /* download address */
char file[1024]; /* download file path */
char user[256]; /* user for ftp */
char passwd[256]; /* password for ftp */
char local[1024]; /* local file path */
int topts[4]; /* time options {poff,tint,toff,tretry} (s) */
gtime_t tnext; /* next retry time (gpst) */
thread_t thread; /* download thread */
} ftp_t;
typedef struct { /* receiver raw data control type */
gtime_t time; /* message time */
gtime_t tobs; /* observation data time */
obs_t obs; /* observation data */
obs_t obuf; /* observation data buffer */
nav_t nav; /* satellite ephemerides */
sta_t sta; /* station parameters */
int ephsat; /* sat number of update ephemeris (0:no satellite) */
sbsmsg_t sbsmsg; /* SBAS message */
char msgtype[256]; /* last message type */
unsigned char subfrm[MAXSAT][380]; /* subframe buffer */
lexmsg_t lexmsg; /* LEX message */
double lockt[MAXSAT][NFREQ+NEXOBS]; /* lock time (s) */
double icpp[MAXSAT],off[MAXSAT],icpc; /* carrier params for ss2 */
double prCA[MAXSAT],dpCA[MAXSAT]; /* L1/CA pseudrange/doppler for javad */
unsigned char halfc[MAXSAT][NFREQ+NEXOBS]; /* half-cycle add flag */
char freqn[MAXOBS]; /* frequency number for javad */
int nbyte; /* number of bytes in message buffer */
int len; /* message length (bytes) */
int iod; /* issue of data */
int tod; /* time of day (ms) */
int tbase; /* time base (0:gpst,1:utc(usno),2:glonass,3:utc(su) */
int flag; /* general purpose flag */
int outtype; /* output message type */
unsigned char buff[MAXRAWLEN]; /* message buffer */
char opt[256]; /* receiver dependent options */
double receive_time;/* RT17: Reiceve time of week for week rollover detection */
unsigned int plen; /* RT17: Total size of packet to be read */
unsigned int pbyte; /* RT17: How many packet bytes have been read so far */
unsigned int page; /* RT17: Last page number */
unsigned int reply; /* RT17: Current reply number */
int week; /* RT17: week number */
unsigned char pbuff[255+4+2]; /* RT17: Packet buffer */
} raw_t;
typedef struct { /* RTK server type */
int state; /* server state (0:stop,1:running) */
int cycle; /* processing cycle (ms) */
int nmeacycle; /* NMEA request cycle (ms) (0:no req) */
int nmeareq; /* NMEA request (0:no,1:nmeapos,2:single sol) */
double nmeapos[3]; /* NMEA request position (ecef) (m) */
int buffsize; /* input buffer size (bytes) */
int format[3]; /* input format {rov,base,corr} */
solopt_t solopt[2]; /* output solution options {sol1,sol2} */
int navsel; /* ephemeris select (0:all,1:rover,2:base,3:corr) */
int nsbs; /* number of sbas message */
int nsol; /* number of solution buffer */
rtk_t rtk; /* RTK control/result struct */
int nb [3]; /* bytes in input buffers {rov,base} */
int nsb[2]; /* bytes in soulution buffers */
int npb[3]; /* bytes in input peek buffers */
unsigned char *buff[3]; /* input buffers {rov,base,corr} */
unsigned char *sbuf[2]; /* output buffers {sol1,sol2} */
unsigned char *pbuf[3]; /* peek buffers {rov,base,corr} */
sol_t solbuf[MAXSOLBUF]; /* solution buffer */
unsigned int nmsg[3][10]; /* input message counts */
raw_t raw [3]; /* receiver raw control {rov,base,corr} */
rtcm_t rtcm[3]; /* RTCM control {rov,base,corr} */
gtime_t ftime[3]; /* download time {rov,base,corr} */
char files[3][MAXSTRPATH]; /* download paths {rov,base,corr} */
obs_t obs[3][MAXOBSBUF]; /* observation data {rov,base,corr} */
nav_t nav; /* navigation data */
sbsmsg_t sbsmsg[MAXSBSMSG]; /* SBAS message buffer */
stream_t stream[8]; /* streams {rov,base,corr,sol1,sol2,logr,logb,logc} */
stream_t *moni; /* monitor stream */
unsigned int tick; /* start tick */
thread_t thread; /* server thread */
int cputime; /* CPU time (ms) for a processing cycle */
int prcout; /* missing observation data count */
lock_t lock; /* lock flag */
} rtksvr_t;
const double chisqr[100] = { /* chi-sqr(n) (alpha=0.001) */ const double chisqr[100] = { /* chi-sqr(n) (alpha=0.001) */
10.8, 13.8, 16.3, 18.5, 20.5, 22.5, 24.3, 26.1, 27.9, 29.6, 10.8, 13.8, 16.3, 18.5, 20.5, 22.5, 24.3, 26.1, 27.9, 29.6,
31.3, 32.9, 34.5, 36.1, 37.7, 39.3, 40.8, 42.3, 43.8, 45.3, 31.3, 32.9, 34.5, 36.1, 37.7, 39.3, 40.8, 42.3, 43.8, 45.3,

View File

@ -13,8 +13,8 @@ void writesolhead(stream_t *stream, const solopt_t *solopt)
{ {
unsigned char buff[1024]; unsigned char buff[1024];
int n; int n;
n = outsolheads(buff,solopt); n = outsolheads(buff, solopt);
strwrite(stream,buff,n); strwrite(stream, buff, n);
} }
@ -24,7 +24,7 @@ void saveoutbuf(rtksvr_t *svr, unsigned char *buff, int n, int index)
rtksvrlock(svr); rtksvrlock(svr);
n = n<svr->buffsize-svr->nsb[index]?n:svr->buffsize-svr->nsb[index]; n = n<svr->buffsize-svr->nsb[index]?n:svr->buffsize-svr->nsb[index];
memcpy(svr->sbuf[index]+svr->nsb[index],buff,n); memcpy(svr->sbuf[index]+svr->nsb[index], buff, n);
svr->nsb[index] += n; svr->nsb[index] += n;
rtksvrunlock(svr); rtksvrunlock(svr);
@ -36,31 +36,31 @@ void writesol(rtksvr_t *svr, int index)
{ {
solopt_t solopt = solopt_default; solopt_t solopt = solopt_default;
unsigned char buff[1024]; unsigned char buff[1024];
int i,n; int i, n;
tracet(4,"writesol: index=%d\n",index); tracet(4, "writesol: index=%d\n", index);
for (i = 0;i<2;i++) for (i = 0;i<2;i++)
{ {
/* output solution */ /* output solution */
n = outsols(buff,&svr->rtk.sol,svr->rtk.rb,svr->solopt+i); n = outsols(buff, &svr->rtk.sol, svr->rtk.rb, svr->solopt+i);
strwrite(svr->stream+i+3,buff,n); strwrite(svr->stream+i+3, buff, n);
/* save output buffer */ /* save output buffer */
saveoutbuf(svr,buff,n,i); saveoutbuf(svr, buff, n, i);
/* output extended solution */ /* output extended solution */
n = outsolexs(buff,&svr->rtk.sol,svr->rtk.ssat,svr->solopt+i); n = outsolexs(buff, &svr->rtk.sol, svr->rtk.ssat, svr->solopt+i);
strwrite(svr->stream+i+3,buff,n); strwrite(svr->stream+i+3, buff, n);
/* save output buffer */ /* save output buffer */
saveoutbuf(svr,buff,n,i); saveoutbuf(svr, buff, n, i);
} }
/* output solution to monitor port */ /* output solution to monitor port */
if (svr->moni) if (svr->moni)
{ {
n = outsols(buff,&svr->rtk.sol,svr->rtk.rb,&solopt); n = outsols(buff, &svr->rtk.sol, svr->rtk.rb, &solopt);
strwrite(svr->moni,buff,n); strwrite(svr->moni, buff, n);
} }
/* save solution buffer */ /* save solution buffer */
if (svr->nsol<MAXSOLBUF) if (svr->nsol<MAXSOLBUF)
@ -75,10 +75,10 @@ void writesol(rtksvr_t *svr, int index)
/* update navigation data ----------------------------------------------------*/ /* update navigation data ----------------------------------------------------*/
void updatenav(nav_t *nav) void updatenav(nav_t *nav)
{ {
int i,j; int i, j;
for (i = 0;i<MAXSAT;i++) for (j = 0;j<NFREQ;j++) for (i = 0;i<MAXSAT;i++) for (j = 0;j<NFREQ;j++)
{ {
nav->lam[i][j] = satwavelen(i+1,j,nav); nav->lam[i][j] = satwavelen(i+1, j, nav);
} }
} }
@ -86,13 +86,13 @@ void updatenav(nav_t *nav)
/* update glonass frequency channel number in raw data struct ----------------*/ /* update glonass frequency channel number in raw data struct ----------------*/
void updatefcn(rtksvr_t *svr) void updatefcn(rtksvr_t *svr)
{ {
int i,j,sat,frq; int i, j, sat, frq;
for (i = 0;i<MAXPRNGLO;i++) for (i = 0;i<MAXPRNGLO;i++)
{ {
sat = satno(SYS_GLO,i+1); sat = satno(SYS_GLO, i+1);
for (j = 0,frq = -999;j<3;j++) for (j = 0, frq = -999;j<3;j++)
{ {
if (svr->raw[j].nav.geph[i].sat != sat) continue; if (svr->raw[j].nav.geph[i].sat != sat) continue;
frq = svr->raw[j].nav.geph[i].frq; frq = svr->raw[j].nav.geph[i].frq;
@ -113,13 +113,13 @@ void updatefcn(rtksvr_t *svr)
void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat, void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
sbsmsg_t *sbsmsg, int index, int iobs) sbsmsg_t *sbsmsg, int index, int iobs)
{ {
eph_t *eph1,*eph2,*eph3; eph_t *eph1, *eph2, *eph3;
geph_t *geph1,*geph2,*geph3; geph_t *geph1, *geph2, *geph3;
gtime_t tof; gtime_t tof;
double pos[3],del[3] = {0},dr[3]; double pos[3], del[3] = {0}, dr[3];
int i,n = 0,prn,sbssat = svr->rtk.opt.sbassatsel,sys,iode; int i, n = 0, prn, sbssat = svr->rtk.opt.sbassatsel, sys, iode;
tracet(4,"updatesvr: ret=%d sat=%2d index=%d\n",ret,sat,index); tracet(4, "updatesvr: ret=%d sat=%2d index=%d\n", ret, sat, index);
if (ret == 1) if (ret == 1)
{ /* observation data */ { /* observation data */
@ -128,7 +128,7 @@ void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
for (i = 0;i<obs->n;i++) for (i = 0;i<obs->n;i++)
{ {
if (svr->rtk.opt.exsats[obs->data[i].sat-1] == 1 || if (svr->rtk.opt.exsats[obs->data[i].sat-1] == 1 ||
!(satsys(obs->data[i].sat,NULL)&svr->rtk.opt.navsys)) continue; !(satsys(obs->data[i].sat, NULL)&svr->rtk.opt.navsys)) continue;
svr->obs[index][iobs].data[n] = obs->data[i]; svr->obs[index][iobs].data[n] = obs->data[i];
svr->obs[index][iobs].data[n++].rcv = index+1; svr->obs[index][iobs].data[n++].rcv = index+1;
} }
@ -139,7 +139,7 @@ void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
} }
else if (ret == 2) else if (ret == 2)
{ /* ephemeris */ { /* ephemeris */
if (satsys(sat,&prn) != SYS_GLO) if (satsys(sat, &prn) != SYS_GLO)
{ {
if (!svr->navsel || svr->navsel == index+1) if (!svr->navsel || svr->navsel == index+1)
{ {
@ -148,8 +148,8 @@ void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
eph3 = svr->nav.eph+sat-1+MAXSAT; eph3 = svr->nav.eph+sat-1+MAXSAT;
if (eph2->ttr.time == 0 || if (eph2->ttr.time == 0 ||
(eph1->iode != eph3->iode && eph1->iode != eph2->iode) || (eph1->iode != eph3->iode && eph1->iode != eph2->iode) ||
(timediff(eph1->toe,eph3->toe) != 0.0 && (timediff(eph1->toe, eph3->toe) != 0.0 &&
timediff(eph1->toe,eph2->toe) != 0.0)) timediff(eph1->toe, eph2->toe) != 0.0))
{ {
*eph3 = *eph2; *eph3 = *eph2;
*eph2 = *eph1; *eph2 = *eph1;
@ -190,7 +190,7 @@ void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
for (i = 0;i<MAXSBSMSG-1;i++) svr->sbsmsg[i] = svr->sbsmsg[i+1]; for (i = 0;i<MAXSBSMSG-1;i++) svr->sbsmsg[i] = svr->sbsmsg[i+1];
svr->sbsmsg[i] = *sbsmsg; svr->sbsmsg[i] = *sbsmsg;
} }
sbsupdatecorr(sbsmsg,&svr->nav); sbsupdatecorr(sbsmsg, &svr->nav);
} }
svr->nmsg[index][3]++; svr->nmsg[index][3]++;
} }
@ -217,11 +217,11 @@ void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
svr->rtk.rb[i] = svr->rtcm[1].sta.pos[i]; svr->rtk.rb[i] = svr->rtcm[1].sta.pos[i];
} }
/* antenna delta */ /* antenna delta */
ecef2pos(svr->rtk.rb,pos); ecef2pos(svr->rtk.rb, pos);
if (svr->rtcm[1].sta.deltype) if (svr->rtcm[1].sta.deltype)
{ /* xyz */ { /* xyz */
del[2] = svr->rtcm[1].sta.hgt; del[2] = svr->rtcm[1].sta.hgt;
enu2ecef(pos,del,dr); enu2ecef(pos, del, dr);
for (i = 0;i<3;i++) for (i = 0;i<3;i++)
{ {
svr->rtk.rb[i] += svr->rtcm[1].sta.del[i]+dr[i]; svr->rtk.rb[i] += svr->rtcm[1].sta.del[i]+dr[i];
@ -229,7 +229,7 @@ void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
} }
else else
{ /* enu */ { /* enu */
enu2ecef(pos,svr->rtcm[1].sta.del,dr); enu2ecef(pos, svr->rtcm[1].sta.del, dr);
for (i = 0;i<3;i++) for (i = 0;i<3;i++)
{ {
svr->rtk.rb[i] += dr[i]; svr->rtk.rb[i] += dr[i];
@ -250,12 +250,12 @@ void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
svr->rtcm[index].ssr[i].update = 0; svr->rtcm[index].ssr[i].update = 0;
iode = svr->rtcm[index].ssr[i].iode; iode = svr->rtcm[index].ssr[i].iode;
sys = satsys(i+1,&prn); sys = satsys(i+1, &prn);
/* check corresponding ephemeris exists */ /* check corresponding ephemeris exists */
if (sys == SYS_GPS || sys == SYS_GAL || sys == SYS_QZS) if (sys == SYS_GPS || sys == SYS_GAL || sys == SYS_QZS)
{ {
if (svr->nav.eph[i ].iode != iode && if (svr->nav.eph[i].iode != iode &&
svr->nav.eph[i+MAXSAT].iode != iode) svr->nav.eph[i+MAXSAT].iode != iode)
{ {
continue; continue;
@ -263,7 +263,7 @@ void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
} }
else if (sys == SYS_GLO) else if (sys == SYS_GLO)
{ {
if (svr->nav.geph[prn-1 ].iode != iode && if (svr->nav.geph[prn-1].iode != iode &&
svr->nav.geph[prn-1+MAXPRNGLO].iode != iode) svr->nav.geph[prn-1+MAXPRNGLO].iode != iode)
{ {
continue; continue;
@ -275,7 +275,7 @@ void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
} }
else if (ret == 31) else if (ret == 31)
{ /* lex message */ { /* lex message */
// lexupdatecorr(&svr->raw[index].lexmsg,&svr->nav,&tof); // lexupdatecorr(&svr->raw[index].lexmsg, &svr->nav, &tof);
svr->nmsg[index][8]++; svr->nmsg[index][8]++;
} }
else if (ret == -1) else if (ret == -1)
@ -291,9 +291,9 @@ int decoderaw(rtksvr_t *svr, int index)
obs_t *obs; obs_t *obs;
nav_t *nav; nav_t *nav;
sbsmsg_t *sbsmsg = NULL; sbsmsg_t *sbsmsg = NULL;
int i,ret,sat,fobs = 0; int i, ret, sat, fobs = 0;
tracet(4,"decoderaw: index=%d\n",index); tracet(4, "decoderaw: index=%d\n", index);
rtksvrlock(svr); rtksvrlock(svr);
@ -302,14 +302,14 @@ int decoderaw(rtksvr_t *svr, int index)
/* input rtcm/receiver raw data from stream */ /* input rtcm/receiver raw data from stream */
if (svr->format[index] == STRFMT_RTCM2) if (svr->format[index] == STRFMT_RTCM2)
{ {
ret = input_rtcm2(svr->rtcm+index,svr->buff[index][i]); ret = input_rtcm2(svr->rtcm+index, svr->buff[index][i]);
obs = &svr->rtcm[index].obs; obs = &svr->rtcm[index].obs;
nav = &svr->rtcm[index].nav; nav = &svr->rtcm[index].nav;
sat = svr->rtcm[index].ephsat; sat = svr->rtcm[index].ephsat;
} }
else if (svr->format[index] == STRFMT_RTCM3) else if (svr->format[index] == STRFMT_RTCM3)
{ {
ret = input_rtcm3(svr->rtcm+index,svr->buff[index][i]); ret = input_rtcm3(svr->rtcm+index, svr->buff[index][i]);
obs = &svr->rtcm[index].obs; obs = &svr->rtcm[index].obs;
nav = &svr->rtcm[index].nav; nav = &svr->rtcm[index].nav;
sat = svr->rtcm[index].ephsat; sat = svr->rtcm[index].ephsat;
@ -317,7 +317,7 @@ int decoderaw(rtksvr_t *svr, int index)
else else
{ {
// Disabled !! // Disabled !!
//ret = input_raw(svr->raw+index,svr->format[index],svr->buff[index][i]); //ret = input_raw(svr->raw+index, svr->format[index], svr->buff[index][i]);
obs = &svr->raw[index].obs; obs = &svr->raw[index].obs;
nav = &svr->raw[index].nav; nav = &svr->raw[index].nav;
sat = svr->raw[index].ephsat; sat = svr->raw[index].ephsat;
@ -325,12 +325,12 @@ int decoderaw(rtksvr_t *svr, int index)
} }
#if 0 /* record for receiving tick */ #if 0 /* record for receiving tick */
if (ret==1) { if (ret==1) {
trace(0,"%d %10d T=%s NS=%2d\n",index,tickget(), trace(0, "%d %10d T=%s NS=%2d\n", index, tickget(),
time_str(obs->data[0].time,0),obs->n); time_str(obs->data[0].time, 0), obs->n);
} }
#endif #endif
/* update rtk server */ /* update rtk server */
if (ret>0) updatesvr(svr,ret,obs,nav,sat,sbsmsg,index,fobs); if (ret>0) updatesvr(svr, ret, obs, nav, sat, sbsmsg, index, fobs);
/* observation data received */ /* observation data received */
if (ret == 1) { if (ret == 1) {
@ -352,7 +352,7 @@ void decodefile(rtksvr_t *svr, int index)
char file[1024]; char file[1024];
int nb; int nb;
tracet(4,"decodefile: index=%d\n",index); tracet(4, "decodefile: index=%d\n", index);
rtksvrlock(svr); rtksvrlock(svr);
@ -363,7 +363,7 @@ void decodefile(rtksvr_t *svr, int index)
rtksvrunlock(svr); rtksvrunlock(svr);
return; return;
} }
strncpy(file,(char *)svr->buff[index],nb-2); file[nb-2] = '\0'; strncpy(file, (char *)svr->buff[index], nb-2); file[nb-2] = '\0';
svr->nb[index] = 0; svr->nb[index] = 0;
rtksvrunlock(svr); rtksvrunlock(svr);
@ -371,10 +371,10 @@ void decodefile(rtksvr_t *svr, int index)
if (svr->format[index] == STRFMT_SP3) { /* precise ephemeris */ if (svr->format[index] == STRFMT_SP3) { /* precise ephemeris */
/* read sp3 precise ephemeris */ /* read sp3 precise ephemeris */
readsp3(file,&nav,0); readsp3(file, &nav, 0);
if (nav.ne <= 0) if (nav.ne <= 0)
{ {
tracet(1,"sp3 file read error: %s\n",file); tracet(1, "sp3 file read error: %s\n", file);
return; return;
} }
/* update precise ephemeris */ /* update precise ephemeris */
@ -384,15 +384,15 @@ void decodefile(rtksvr_t *svr, int index)
svr->nav.ne = svr->nav.nemax = nav.ne; svr->nav.ne = svr->nav.nemax = nav.ne;
svr->nav.peph = nav.peph; svr->nav.peph = nav.peph;
svr->ftime[index] = utc2gpst(timeget()); svr->ftime[index] = utc2gpst(timeget());
strcpy(svr->files[index],file); strcpy(svr->files[index], file);
rtksvrunlock(svr); rtksvrunlock(svr);
} }
else if (svr->format[index] == STRFMT_RNXCLK) { /* precise clock */ else if (svr->format[index] == STRFMT_RNXCLK) { /* precise clock */
/* read rinex clock */ // Disabled!! /* read rinex clock */ // Disabled!!
if ( 1 /*readrnxc(file,&nav)<=0 */) { if ( 1 /*readrnxc(file, &nav)<=0 */) {
tracet(1,"rinex clock file read error: %s\n",file); tracet(1, "rinex clock file read error: %s\n", file);
return; return;
} }
/* update precise clock */ /* update precise clock */
@ -402,7 +402,7 @@ void decodefile(rtksvr_t *svr, int index)
svr->nav.nc = svr->nav.ncmax = nav.nc; svr->nav.nc = svr->nav.ncmax = nav.nc;
svr->nav.pclk = nav.pclk; svr->nav.pclk = nav.pclk;
svr->ftime[index] = utc2gpst(timeget()); svr->ftime[index] = utc2gpst(timeget());
strcpy(svr->files[index],file); strcpy(svr->files[index], file);
rtksvrunlock(svr); rtksvrunlock(svr);
} }
@ -416,11 +416,11 @@ void *rtksvrthread(void *arg)
obs_t obs; obs_t obs;
obsd_t data[MAXOBS*2]; obsd_t data[MAXOBS*2];
double tt; double tt;
unsigned int tick,ticknmea; unsigned int tick, ticknmea;
unsigned char *p,*q; unsigned char *p, *q;
int i,j,n,fobs[3] = {0},cycle,cputime; int i, j, n, fobs[3] = {0}, cycle, cputime;
tracet(3,"rtksvrthread:\n"); tracet(3, "rtksvrthread:\n");
svr->state = 1; obs.data = data; svr->state = 1; obs.data = data;
svr->tick = tickget(); svr->tick = tickget();
@ -435,18 +435,18 @@ void *rtksvrthread(void *arg)
p = svr->buff[i]+svr->nb[i]; q = svr->buff[i]+svr->buffsize; p = svr->buff[i]+svr->nb[i]; q = svr->buff[i]+svr->buffsize;
/* read receiver raw/rtcm data from input stream */ /* read receiver raw/rtcm data from input stream */
if ((n = strread(svr->stream+i,p,q-p)) <= 0) if ((n = strread(svr->stream+i, p, q-p)) <= 0)
{ {
continue; continue;
} }
/* write receiver raw/rtcm data to log stream */ /* write receiver raw/rtcm data to log stream */
strwrite(svr->stream+i+5,p,n); strwrite(svr->stream+i+5, p, n);
svr->nb[i] += n; svr->nb[i] += n;
/* save peek buffer */ /* save peek buffer */
rtksvrlock(svr); rtksvrlock(svr);
n = n<svr->buffsize-svr->npb[i]?n:svr->buffsize-svr->npb[i]; n = n<svr->buffsize-svr->npb[i]?n:svr->buffsize-svr->npb[i];
memcpy(svr->pbuf[i]+svr->npb[i],p,n); memcpy(svr->pbuf[i]+svr->npb[i], p, n);
svr->npb[i] += n; svr->npb[i] += n;
rtksvrunlock(svr); rtksvrunlock(svr);
} }
@ -455,12 +455,12 @@ void *rtksvrthread(void *arg)
if (svr->format[i] == STRFMT_SP3 || svr->format[i] == STRFMT_RNXCLK) if (svr->format[i] == STRFMT_SP3 || svr->format[i] == STRFMT_RNXCLK)
{ {
/* decode download file */ /* decode download file */
decodefile(svr,i); decodefile(svr, i);
} }
else else
{ {
/* decode receiver raw/rtcm data */ /* decode receiver raw/rtcm data */
fobs[i] = decoderaw(svr,i); fobs[i] = decoderaw(svr, i);
} }
} }
for (i = 0;i<fobs[0];i++) for (i = 0;i<fobs[0];i++)
@ -476,17 +476,17 @@ void *rtksvrthread(void *arg)
} }
/* rtk positioning */ /* rtk positioning */
rtksvrlock(svr); rtksvrlock(svr);
rtkpos(&svr->rtk,obs.data,obs.n,&svr->nav); rtkpos(&svr->rtk, obs.data, obs.n, &svr->nav);
rtksvrunlock(svr); rtksvrunlock(svr);
if (svr->rtk.sol.stat != SOLQ_NONE) if (svr->rtk.sol.stat != SOLQ_NONE)
{ {
/* adjust current time */ /* adjust current time */
tt = (int)(tickget()-tick)/1000.0+DTTOL; tt = (int)(tickget()-tick)/1000.0+DTTOL;
timeset(gpst2utc(timeadd(svr->rtk.sol.time,tt))); timeset(gpst2utc(timeadd(svr->rtk.sol.time, tt)));
/* write solution */ /* write solution */
writesol(svr,i); writesol(svr, i);
} }
/* if cpu overload, inclement obs outage counter and break */ /* if cpu overload, inclement obs outage counter and break */
if ((int)(tickget()-tick) >= svr->cycle) if ((int)(tickget()-tick) >= svr->cycle)
@ -500,7 +500,7 @@ void *rtksvrthread(void *arg)
/* send null solution if no solution (1hz) */ /* send null solution if no solution (1hz) */
if (svr->rtk.sol.stat == SOLQ_NONE && cycle%(1000/svr->cycle) == 0) if (svr->rtk.sol.stat == SOLQ_NONE && cycle%(1000/svr->cycle) == 0)
{ {
writesol(svr,0); writesol(svr, 0);
} }
/* send nmea request to base/nrtk input stream */ /* send nmea request to base/nrtk input stream */
if (svr->nmeacycle>0 && (int)(tick-ticknmea) >= svr->nmeacycle) if (svr->nmeacycle>0 && (int)(tick-ticknmea) >= svr->nmeacycle)
@ -509,11 +509,11 @@ void *rtksvrthread(void *arg)
{ {
if (svr->nmeareq == 1) if (svr->nmeareq == 1)
{ {
strsendnmea(svr->stream+1,svr->nmeapos); strsendnmea(svr->stream+1, svr->nmeapos);
} }
else if (svr->nmeareq == 2 && norm_rtk(svr->rtk.sol.rr,3)>0.0) else if (svr->nmeareq == 2 && norm_rtk(svr->rtk.sol.rr, 3)>0.0)
{ {
strsendnmea(svr->stream+1,svr->rtk.sol.rr); strsendnmea(svr->stream+1, svr->rtk.sol.rr);
} }
} }
ticknmea = tick; ticknmea = tick;
@ -542,20 +542,20 @@ void *rtksvrthread(void *arg)
/* initialize rtk server ------------------------------------------------------- /* initialize rtk server -------------------------------------------------------
* initialize rtk server * initialize rtk server
* args : rtksvr_t *svr IO rtk server * args : rtksvr_t *svr IO rtk server
* return : status (0:error,1:ok) * return : status (0:error, 1:ok)
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int rtksvrinit(rtksvr_t *svr) int rtksvrinit(rtksvr_t *svr)
{ {
gtime_t time0 = {0}; gtime_t time0 = {0};
sol_t sol0 = {{0}}; sol_t sol0 = {{0}};
eph_t eph0 = {0,-1,-1}; eph_t eph0 = {0, -1, -1};
geph_t geph0 = {0,-1}; geph_t geph0 = {0, -1};
seph_t seph0 = {0}; seph_t seph0 = {0};
int i,j; int i, j;
tracet(3,"rtksvrinit:\n"); tracet(3, "rtksvrinit:\n");
svr->state = svr->cycle = svr->nmeacycle = svr->nmeareq = 0; svr->state = svr->cycle = svr->nmeacycle = svr->nmeareq = 0;
for (i = 0;i<3;i++) svr->nmeapos[i] = 0.0; for (i = 0;i<3;i++) svr->nmeapos[i] = 0.0;
@ -563,7 +563,7 @@ void *rtksvrthread(void *arg)
for (i = 0;i<3;i++) svr->format[i] = 0; for (i = 0;i<3;i++) svr->format[i] = 0;
for (i = 0;i<2;i++) svr->solopt[i] = solopt_default; for (i = 0;i<2;i++) svr->solopt[i] = solopt_default;
svr->navsel = svr->nsbs = svr->nsol = 0; svr->navsel = svr->nsbs = svr->nsol = 0;
rtkinit(&svr->rtk,&prcopt_default); rtkinit(&svr->rtk, &prcopt_default);
for (i = 0;i<3;i++) svr->nb[i] = 0; for (i = 0;i<3;i++) svr->nb[i] = 0;
for (i = 0;i<2;i++) svr->nsb[i] = 0; for (i = 0;i<2;i++) svr->nsb[i] = 0;
for (i = 0;i<3;i++) svr->npb[i] = 0; for (i = 0;i<3;i++) svr->npb[i] = 0;
@ -583,7 +583,7 @@ void *rtksvrthread(void *arg)
!(svr->nav.geph = (geph_t *)malloc(sizeof(geph_t)*NSATGLO*2)) || !(svr->nav.geph = (geph_t *)malloc(sizeof(geph_t)*NSATGLO*2)) ||
!(svr->nav.seph = (seph_t *)malloc(sizeof(seph_t)*NSATSBS*2))) !(svr->nav.seph = (seph_t *)malloc(sizeof(seph_t)*NSATSBS*2)))
{ {
tracet(1,"rtksvrinit: malloc error\n"); tracet(1, "rtksvrinit: malloc error\n");
return 0; return 0;
} }
for (i = 0;i<MAXSAT *2;i++) svr->nav.eph [i] = eph0; for (i = 0;i<MAXSAT *2;i++) svr->nav.eph [i] = eph0;
@ -597,14 +597,14 @@ void *rtksvrthread(void *arg)
{ {
if (!(svr->obs[i][j].data = (obsd_t *)malloc(sizeof(obsd_t)*MAXOBS))) if (!(svr->obs[i][j].data = (obsd_t *)malloc(sizeof(obsd_t)*MAXOBS)))
{ {
tracet(1,"rtksvrinit: malloc error\n"); tracet(1, "rtksvrinit: malloc error\n");
return 0; return 0;
} }
} }
for (i = 0;i<3;i++) for (i = 0;i<3;i++)
{ {
memset(svr->raw +i,0,sizeof(raw_t )); memset(svr->raw +i, 0, sizeof(raw_t ));
memset(svr->rtcm+i,0,sizeof(rtcm_t)); memset(svr->rtcm+i, 0, sizeof(rtcm_t));
} }
for (i = 0;i<MAXSTRRTK;i++) strinit(svr->stream+i); for (i = 0;i<MAXSTRRTK;i++) strinit(svr->stream+i);
@ -615,13 +615,13 @@ void *rtksvrthread(void *arg)
/* free rtk server ------------------------------------------------------------- /* free rtk server -------------------------------------------------------------
* free rtk server * free rtk server
* args : rtksvr_t *svr IO rtk server * args : rtksvr_t *svr IO rtk server
* return : none * return : none
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void rtksvrfree(rtksvr_t *svr) void rtksvrfree(rtksvr_t *svr)
{ {
int i,j; int i, j;
free(svr->nav.eph ); free(svr->nav.eph );
free(svr->nav.geph); free(svr->nav.geph);
@ -634,63 +634,66 @@ void *rtksvrthread(void *arg)
/* lock/unlock rtk server ------------------------------------------------------ /* lock/unlock rtk server ------------------------------------------------------
* lock/unlock rtk server * lock/unlock rtk server
* args : rtksvr_t *svr IO rtk server * args : rtksvr_t *svr IO rtk server
* return : status (1:ok 0:error) * return : status (1:ok 0:error)
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void rtksvrlock (rtksvr_t *svr) {rtk_lock (&svr->lock);} void rtksvrlock (rtksvr_t *svr) {rtk_lock (&svr->lock);}
void rtksvrunlock(rtksvr_t *svr) {rtk_unlock(&svr->lock);}
void rtksvrunlock(rtksvr_t *svr) {rtk_unlock(&svr->lock);}
/* start rtk server ------------------------------------------------------------ /* start rtk server ------------------------------------------------------------
* start rtk server thread * start rtk server thread
* args : rtksvr_t *svr IO rtk server * args : rtksvr_t *svr IO rtk server
* int cycle I server cycle (ms) * int cycle I server cycle (ms)
* int buffsize I input buffer size (bytes) * int buffsize I input buffer size (bytes)
* int *strs I stream types (STR_???) * int *strs I stream types (STR_???)
* types[0]=input stream rover * types[0]=input stream rover
* types[1]=input stream base station * types[1]=input stream base station
* types[2]=input stream correction * types[2]=input stream correction
* types[3]=output stream solution 1 * types[3]=output stream solution 1
* types[4]=output stream solution 2 * types[4]=output stream solution 2
* types[5]=log stream rover * types[5]=log stream rover
* types[6]=log stream base station * types[6]=log stream base station
* types[7]=log stream correction * types[7]=log stream correction
* char *paths I input stream paths * char *paths I input stream paths
* int *format I input stream formats (STRFMT_???) * int *format I input stream formats (STRFMT_???)
* format[0]=input stream rover * format[0]=input stream rover
* format[1]=input stream base station * format[1]=input stream base station
* format[2]=input stream correction * format[2]=input stream correction
* int navsel I navigation message select * int navsel I navigation message select
* (0:rover,1:base,2:ephem,3:all) * (0:rover, 1:base, 2:ephem, 3:all)
* char **cmds I input stream start commands * char **cmds I input stream start commands
* cmds[0]=input stream rover (NULL: no command) * cmds[0]=input stream rover (NULL: no command)
* cmds[1]=input stream base (NULL: no command) * cmds[1]=input stream base (NULL: no command)
* cmds[2]=input stream corr (NULL: no command) * cmds[2]=input stream corr (NULL: no command)
* char **rcvopts I receiver options * char **rcvopts I receiver options
* rcvopt[0]=receiver option rover * rcvopt[0]=receiver option rover
* rcvopt[1]=receiver option base * rcvopt[1]=receiver option base
* rcvopt[2]=receiver option corr * rcvopt[2]=receiver option corr
* int nmeacycle I nmea request cycle (ms) (0:no request) * int nmeacycle I nmea request cycle (ms) (0:no request)
* int nmeareq I nmea request type (0:no,1:base pos,2:single sol) * int nmeareq I nmea request type (0:no, 1:base pos, 2:single sol)
* double *nmeapos I transmitted nmea position (ecef) (m) * double *nmeapos I transmitted nmea position (ecef) (m)
* prcopt_t *prcopt I rtk processing options * prcopt_t *prcopt I rtk processing options
* solopt_t *solopt I solution options * solopt_t *solopt I solution options
* solopt[0]=solution 1 options * solopt[0]=solution 1 options
* solopt[1]=solution 2 options * solopt[1]=solution 2 options
* stream_t *moni I monitor stream (NULL: not used) * stream_t *moni I monitor stream (NULL: not used)
* return : status (1:ok 0:error) * return : status (1:ok 0:error)
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int rtksvrstart(rtksvr_t *svr, int cycle, int buffsize, int *strs, int rtksvrstart(rtksvr_t *svr, int cycle, int buffsize, int *strs,
char **paths, int *formats, int navsel, char **cmds, char **paths, int *formats, int navsel, char **cmds,
char **rcvopts, int nmeacycle, int nmeareq, char **rcvopts, int nmeacycle, int nmeareq,
const double *nmeapos, prcopt_t *prcopt, const double *nmeapos, prcopt_t *prcopt,
solopt_t *solopt, stream_t *moni) solopt_t *solopt, stream_t *moni)
{ {
gtime_t time,time0 = {0}; gtime_t time, time0 = {0};
int i,j,rw; int i, j, rw;
tracet(3,"rtksvrstart: cycle=%d buffsize=%d navsel=%d nmeacycle=%d nmeareq=%d\n", tracet(3, "rtksvrstart: cycle=%d buffsize=%d navsel=%d nmeacycle=%d nmeareq=%d\n",
cycle,buffsize,navsel,nmeacycle,nmeareq); cycle, buffsize, navsel, nmeacycle, nmeareq);
if (svr->state) return 0; if (svr->state) return 0;
@ -706,7 +709,7 @@ void *rtksvrthread(void *arg)
svr->nsol = 0; svr->nsol = 0;
svr->prcout = 0; svr->prcout = 0;
rtkfree(&svr->rtk); rtkfree(&svr->rtk);
rtkinit(&svr->rtk,prcopt); rtkinit(&svr->rtk, prcopt);
for (i = 0;i<3;i++) for (i = 0;i<3;i++)
{ /* input/log streams */ { /* input/log streams */
@ -714,7 +717,7 @@ void *rtksvrthread(void *arg)
if (!(svr->buff[i] = (unsigned char *)malloc(buffsize)) || if (!(svr->buff[i] = (unsigned char *)malloc(buffsize)) ||
!(svr->pbuf[i] = (unsigned char *)malloc(buffsize))) !(svr->pbuf[i] = (unsigned char *)malloc(buffsize)))
{ {
tracet(1,"rtksvrstart: malloc error\n"); tracet(1, "rtksvrstart: malloc error\n");
return 0; return 0;
} }
for (j = 0;j<10;j++) svr->nmsg[i][j] = 0; for (j = 0;j<10;j++) svr->nmsg[i][j] = 0;
@ -725,8 +728,8 @@ void *rtksvrthread(void *arg)
init_rtcm(svr->rtcm+i); init_rtcm(svr->rtcm+i);
/* set receiver and rtcm option */ /* set receiver and rtcm option */
strcpy(svr->raw [i].opt,rcvopts[i]); strcpy(svr->raw [i].opt, rcvopts[i]);
strcpy(svr->rtcm[i].opt,rcvopts[i]); strcpy(svr->rtcm[i].opt, rcvopts[i]);
/* connect dgps corrections */ /* connect dgps corrections */
svr->rtcm[i].dgps = svr->nav.dgps; svr->rtcm[i].dgps = svr->nav.dgps;
@ -735,7 +738,7 @@ void *rtksvrthread(void *arg)
{ /* output peek buffer */ { /* output peek buffer */
if (!(svr->sbuf[i] = (unsigned char *)malloc(buffsize))) if (!(svr->sbuf[i] = (unsigned char *)malloc(buffsize)))
{ {
tracet(1,"rtksvrstart: malloc error\n"); tracet(1, "rtksvrstart: malloc error\n");
return 0; return 0;
} }
} }
@ -763,7 +766,7 @@ void *rtksvrthread(void *arg)
{ {
rw = i<3?STR_MODE_R:STR_MODE_W; rw = i<3?STR_MODE_R:STR_MODE_W;
if (strs[i] != STR_FILE) rw |= STR_MODE_W; if (strs[i] != STR_FILE) rw |= STR_MODE_W;
if (!stropen(svr->stream+i,strs[i],rw,paths[i])) if (!stropen(svr->stream+i, strs[i], rw, paths[i]))
{ {
for (i--;i >= 0;i--) strclose(svr->stream+i); for (i--;i >= 0;i--) strclose(svr->stream+i);
return 0; return 0;
@ -777,27 +780,22 @@ void *rtksvrthread(void *arg)
} }
} }
/* sync input streams */ /* sync input streams */
strsync(svr->stream,svr->stream+1); strsync(svr->stream, svr->stream+1);
strsync(svr->stream,svr->stream+2); strsync(svr->stream, svr->stream+2);
/* write start commands to input streams */ /* write start commands to input streams */
for (i = 0;i<3;i++) for (i = 0;i<3;i++)
{ {
if (cmds[i]) strsendcmd(svr->stream+i,cmds[i]); if (cmds[i]) strsendcmd(svr->stream+i, cmds[i]);
} }
/* write solution header to solution streams */ /* write solution header to solution streams */
for (i = 3;i<5;i++) for (i = 3;i<5;i++)
{ {
writesolhead(svr->stream+i,svr->solopt+i-3); writesolhead(svr->stream+i, svr->solopt+i-3);
} }
/* create rtk server thread */ /* create rtk server thread */
#ifdef WIN32 if (pthread_create(&svr->thread, NULL, rtksvrthread, svr))
if (!(svr->thread = CreateThread(NULL,0,rtksvrthread,svr,0,NULL)))
{ {
#else
if (pthread_create(&svr->thread,NULL,rtksvrthread,svr))
{
#endif
for (i = 0;i<MAXSTRRTK;i++) strclose(svr->stream+i); for (i = 0;i<MAXSTRRTK;i++) strclose(svr->stream+i);
return 0; return 0;
} }
@ -806,25 +804,25 @@ void *rtksvrthread(void *arg)
/* stop rtk server ------------------------------------------------------------- /* stop rtk server -------------------------------------------------------------
* start rtk server thread * start rtk server thread
* args : rtksvr_t *svr IO rtk server * args : rtksvr_t *svr IO rtk server
* char **cmds I input stream stop commands * char **cmds I input stream stop commands
* cmds[0]=input stream rover (NULL: no command) * cmds[0]=input stream rover (NULL: no command)
* cmds[1]=input stream base (NULL: no command) * cmds[1]=input stream base (NULL: no command)
* cmds[2]=input stream ephem (NULL: no command) * cmds[2]=input stream ephem (NULL: no command)
* return : none * return : none
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void rtksvrstop(rtksvr_t *svr, char **cmds) void rtksvrstop(rtksvr_t *svr, char **cmds)
{ {
int i; int i;
tracet(3,"rtksvrstop:\n"); tracet(3, "rtksvrstop:\n");
/* write stop commands to input streams */ /* write stop commands to input streams */
rtksvrlock(svr); rtksvrlock(svr);
for (i = 0;i<3;i++) for (i = 0;i<3;i++)
{ {
if (cmds[i]) strsendcmd(svr->stream+i,cmds[i]); if (cmds[i]) strsendcmd(svr->stream+i, cmds[i]);
} }
rtksvrunlock(svr); rtksvrunlock(svr);
@ -832,30 +830,25 @@ void *rtksvrthread(void *arg)
svr->state = 0; svr->state = 0;
/* free rtk server thread */ /* free rtk server thread */
#ifdef WIN32 pthread_join(svr->thread, NULL);
WaitForSingleObject(svr->thread,10000);
CloseHandle(svr->thread);
#else
pthread_join(svr->thread,NULL);
#endif
} }
/* open output/log stream ------------------------------------------------------ /* open output/log stream ------------------------------------------------------
* open output/log stream * open output/log stream
* args : rtksvr_t *svr IO rtk server * args : rtksvr_t *svr IO rtk server
* int index I output/log stream index * int index I output/log stream index
* (3:solution 1,4:solution 2,5:log rover, * (3:solution 1, 4:solution 2, 5:log rover,
* 6:log base station,7:log correction) * 6:log base station, 7:log correction)
* int str I output/log stream types (STR_???) * int str I output/log stream types (STR_???)
* char *path I output/log stream path * char *path I output/log stream path
* solopt_t *solopt I solution options * solopt_t *solopt I solution options
* return : status (1:ok 0:error) * return : status (1:ok 0:error)
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int rtksvropenstr(rtksvr_t *svr, int index, int str, const char *path, int rtksvropenstr(rtksvr_t *svr, int index, int str, const char *path,
const solopt_t *solopt) const solopt_t *solopt)
{ {
tracet(3,"rtksvropenstr: index=%d str=%d path=%s\n",index,str,path); tracet(3, "rtksvropenstr: index=%d str=%d path=%s\n", index, str, path);
if (index<3 || index>7 || !svr->state) return 0; if (index<3 || index>7 || !svr->state) return 0;
@ -866,9 +859,9 @@ void *rtksvrthread(void *arg)
rtksvrunlock(svr); rtksvrunlock(svr);
return 0; return 0;
} }
if (!stropen(svr->stream+index,str,STR_MODE_W,path)) if (!stropen(svr->stream+index, str, STR_MODE_W, path))
{ {
tracet(2,"stream open error: index=%d\n",index); tracet(2, "stream open error: index=%d\n", index);
rtksvrunlock(svr); rtksvrunlock(svr);
return 0; return 0;
} }
@ -877,7 +870,7 @@ void *rtksvrthread(void *arg)
svr->solopt[index-3] = *solopt; svr->solopt[index-3] = *solopt;
/* write solution header to solution stream */ /* write solution header to solution stream */
writesolhead(svr->stream+index,svr->solopt+index-3); writesolhead(svr->stream+index, svr->solopt+index-3);
} }
rtksvrunlock(svr); rtksvrunlock(svr);
return 1; return 1;
@ -885,16 +878,16 @@ void *rtksvrthread(void *arg)
/* close output/log stream ----------------------------------------------------- /* close output/log stream -----------------------------------------------------
* close output/log stream * close output/log stream
* args : rtksvr_t *svr IO rtk server * args : rtksvr_t *svr IO rtk server
* int index I output/log stream index * int index I output/log stream index
* (3:solution 1,4:solution 2,5:log rover, * (3:solution 1, 4:solution 2, 5:log rover,
* 6:log base station,7:log correction) * 6:log base station, 7:log correction)
* return : none * return : none
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void rtksvrclosestr(rtksvr_t *svr, int index) void rtksvrclosestr(rtksvr_t *svr, int index)
{ {
tracet(3,"rtksvrclosestr: index=%d\n",index); tracet(3, "rtksvrclosestr: index=%d\n", index);
if (index<3 || index>7 || !svr->state) return; if (index<3 || index>7 || !svr->state) return;
@ -907,24 +900,24 @@ void *rtksvrthread(void *arg)
/* get observation data status ------------------------------------------------- /* get observation data status -------------------------------------------------
* get current observation data status * get current observation data status
* args : rtksvr_t *svr I rtk server * args : rtksvr_t *svr I rtk server
* int rcv I receiver (0:rover,1:base,2:ephem) * int rcv I receiver (0:rover, 1:base, 2:ephem)
* gtime_t *time O time of observation data * gtime_t *time O time of observation data
* int *sat O satellite prn numbers * int *sat O satellite prn numbers
* double *az O satellite azimuth angles (rad) * double *az O satellite azimuth angles (rad)
* double *el O satellite elevation angles (rad) * double *el O satellite elevation angles (rad)
* int **snr O satellite snr for each freq (dBHz) * int **snr O satellite snr for each freq (dBHz)
* snr[i][j] = sat i freq j snr * snr[i][j] = sat i freq j snr
* int *vsat O valid satellite flag * int *vsat O valid satellite flag
* return : number of satellites * return : number of satellites
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int rtksvrostat(rtksvr_t *svr, int rcv, gtime_t *time, int *sat, int rtksvrostat(rtksvr_t *svr, int rcv, gtime_t *time, int *sat,
double *az, double *el, int **snr, int *vsat) double *az, double *el, int **snr, int *vsat)
{ {
int i,j,ns; int i, j, ns;
tracet(4,"rtksvrostat: rcv=%d\n",rcv); tracet(4, "rtksvrostat: rcv=%d\n", rcv);
if (!svr->state) return 0; if (!svr->state) return 0;
rtksvrlock(svr); rtksvrlock(svr);
@ -957,24 +950,24 @@ void *rtksvrthread(void *arg)
/* get stream status ----------------------------------------------------------- /* get stream status -----------------------------------------------------------
* get current stream status * get current stream status
* args : rtksvr_t *svr I rtk server * args : rtksvr_t *svr I rtk server
* int *sstat O status of streams * int *sstat O status of streams
* char *msg O status messages * char *msg O status messages
* return : none * return : none
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void rtksvrsstat(rtksvr_t *svr, int *sstat, char *msg) void rtksvrsstat(rtksvr_t *svr, int *sstat, char *msg)
{ {
int i; int i;
char s[MAXSTRMSG],*p = msg; char s[MAXSTRMSG], *p = msg;
tracet(4,"rtksvrsstat:\n"); tracet(4, "rtksvrsstat:\n");
rtksvrlock(svr); rtksvrlock(svr);
for (i = 0;i<MAXSTRRTK;i++) for (i = 0;i<MAXSTRRTK;i++)
{ {
sstat[i] = strstat(svr->stream+i,s); sstat[i] = strstat(svr->stream+i, s);
if (*s) p += sprintf(p,"(%d) %s ",i+1,s); if (*s) p += sprintf(p, "(%d) %s ", i+1, s);
} }
rtksvrunlock(svr); rtksvrunlock(svr);
} }

View File

@ -55,12 +55,7 @@
#define GNSS_SDR_RTKLIB_RKTSVR_H_ #define GNSS_SDR_RTKLIB_RKTSVR_H_
#include "rtklib.h" #include "rtklib.h"
#include "rtklib_stream.h"
#define MAXRAWLEN 4096 /* max length of receiver raw message */
#define MAXSOLBUF 256 /* max number of solution buffer */
#define MAXSBSMSG 32 /* max number of SBAS msg in RTK server */
#define MAXOBSBUF 128 /* max number of observation data buffer */
const solopt_t solopt_default = { /* defaults solution output options */ const solopt_t solopt_default = { /* defaults solution output options */
SOLF_LLH, TIMES_GPST, 1, 3, /* posf, times, timef, timeu */ SOLF_LLH, TIMES_GPST, 1, 3, /* posf, times, timef, timeu */
@ -92,105 +87,50 @@ const prcopt_t prcopt_default = { /* defaults processing options */
0, 0, 0, {"",""}, {}, 0, {{},{}}, { {}, {{},{}}, {{},{}}, {}, {} }, 0, {} 0, 0, 0, {"",""}, {}, 0, {{},{}}, { {}, {{},{}}, {{},{}}, {}, {} }, 0, {}
}; };
typedef struct { /* receiver raw data control type */
gtime_t time; /* message time */
gtime_t tobs; /* observation data time */
obs_t obs; /* observation data */
obs_t obuf; /* observation data buffer */
nav_t nav; /* satellite ephemerides */
sta_t sta; /* station parameters */
int ephsat; /* sat number of update ephemeris (0:no satellite) */
sbsmsg_t sbsmsg; /* SBAS message */
char msgtype[256]; /* last message type */
unsigned char subfrm[MAXSAT][380]; /* subframe buffer */
lexmsg_t lexmsg; /* LEX message */
double lockt[MAXSAT][NFREQ+NEXOBS]; /* lock time (s) */
double icpp[MAXSAT],off[MAXSAT],icpc; /* carrier params for ss2 */
double prCA[MAXSAT],dpCA[MAXSAT]; /* L1/CA pseudrange/doppler for javad */
unsigned char halfc[MAXSAT][NFREQ+NEXOBS]; /* half-cycle add flag */
char freqn[MAXOBS]; /* frequency number for javad */
int nbyte; /* number of bytes in message buffer */
int len; /* message length (bytes) */
int iod; /* issue of data */
int tod; /* time of day (ms) */
int tbase; /* time base (0:gpst,1:utc(usno),2:glonass,3:utc(su) */
int flag; /* general purpose flag */
int outtype; /* output message type */
unsigned char buff[MAXRAWLEN]; /* message buffer */
char opt[256]; /* receiver dependent options */
double receive_time;/* RT17: Reiceve time of week for week rollover detection */
unsigned int plen; /* RT17: Total size of packet to be read */
unsigned int pbyte; /* RT17: How many packet bytes have been read so far */
unsigned int page; /* RT17: Last page number */
unsigned int reply; /* RT17: Current reply number */
int week; /* RT17: week number */
unsigned char pbuff[255+4+2]; /* RT17: Packet buffer */
} raw_t;
typedef struct { /* RTK server type */
int state; /* server state (0:stop,1:running) */
int cycle; /* processing cycle (ms) */
int nmeacycle; /* NMEA request cycle (ms) (0:no req) */
int nmeareq; /* NMEA request (0:no,1:nmeapos,2:single sol) */
double nmeapos[3]; /* NMEA request position (ecef) (m) */
int buffsize; /* input buffer size (bytes) */
int format[3]; /* input format {rov,base,corr} */
solopt_t solopt[2]; /* output solution options {sol1,sol2} */
int navsel; /* ephemeris select (0:all,1:rover,2:base,3:corr) */
int nsbs; /* number of sbas message */
int nsol; /* number of solution buffer */
rtk_t rtk; /* RTK control/result struct */
int nb [3]; /* bytes in input buffers {rov,base} */
int nsb[2]; /* bytes in soulution buffers */
int npb[3]; /* bytes in input peek buffers */
unsigned char *buff[3]; /* input buffers {rov,base,corr} */
unsigned char *sbuf[2]; /* output buffers {sol1,sol2} */
unsigned char *pbuf[3]; /* peek buffers {rov,base,corr} */
sol_t solbuf[MAXSOLBUF]; /* solution buffer */
unsigned int nmsg[3][10]; /* input message counts */
raw_t raw [3]; /* receiver raw control {rov,base,corr} */
rtcm_t rtcm[3]; /* RTCM control {rov,base,corr} */
gtime_t ftime[3]; /* download time {rov,base,corr} */
char files[3][MAXSTRPATH]; /* download paths {rov,base,corr} */
obs_t obs[3][MAXOBSBUF]; /* observation data {rov,base,corr} */
nav_t nav; /* navigation data */
sbsmsg_t sbsmsg[MAXSBSMSG]; /* SBAS message buffer */
stream_t stream[8]; /* streams {rov,base,corr,sol1,sol2,logr,logb,logc} */
stream_t *moni; /* monitor stream */
unsigned int tick; /* start tick */
thread_t thread; /* server thread */
int cputime; /* CPU time (ms) for a processing cycle */
int prcout; /* missing observation data count */
lock_t lock; /* lock flag */
} rtksvr_t;
void writesolhead(stream_t *stream, const solopt_t *solopt); void writesolhead(stream_t *stream, const solopt_t *solopt);
void saveoutbuf(rtksvr_t *svr, unsigned char *buff, int n, int index); void saveoutbuf(rtksvr_t *svr, unsigned char *buff, int n, int index);
void writesol(rtksvr_t *svr, int index); void writesol(rtksvr_t *svr, int index);
void updatenav(nav_t *nav); void updatenav(nav_t *nav);
void updatefcn(rtksvr_t *svr); void updatefcn(rtksvr_t *svr);
void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat, void updatesvr(rtksvr_t *svr, int ret, obs_t *obs, nav_t *nav, int sat,
sbsmsg_t *sbsmsg, int index, int iobs); sbsmsg_t *sbsmsg, int index, int iobs);
int decoderaw(rtksvr_t *svr, int index); int decoderaw(rtksvr_t *svr, int index);
void decodefile(rtksvr_t *svr, int index); void decodefile(rtksvr_t *svr, int index);
void *rtksvrthread(void *arg); void *rtksvrthread(void *arg);
int rtksvrinit(rtksvr_t *svr); int rtksvrinit(rtksvr_t *svr);
void rtksvrfree(rtksvr_t *svr); void rtksvrfree(rtksvr_t *svr);
void rtksvrlock (rtksvr_t *svr); void rtksvrlock (rtksvr_t *svr);
void rtksvrunlock(rtksvr_t *svr); void rtksvrunlock(rtksvr_t *svr);
int rtksvrstart(rtksvr_t *svr, int cycle, int buffsize, int *strs, int rtksvrstart(rtksvr_t *svr, int cycle, int buffsize, int *strs,
char **paths, int *formats, int navsel, char **cmds, char **paths, int *formats, int navsel, char **cmds,
char **rcvopts, int nmeacycle, int nmeareq, char **rcvopts, int nmeacycle, int nmeareq,
const double *nmeapos, prcopt_t *prcopt, const double *nmeapos, prcopt_t *prcopt,
solopt_t *solopt, stream_t *moni); solopt_t *solopt, stream_t *moni);
void rtksvrstop(rtksvr_t *svr, char **cmds); void rtksvrstop(rtksvr_t *svr, char **cmds);
int rtksvropenstr(rtksvr_t *svr, int index, int str, const char *path, int rtksvropenstr(rtksvr_t *svr, int index, int str, const char *path,
const solopt_t *solopt); const solopt_t *solopt);
void rtksvrclosestr(rtksvr_t *svr, int index); void rtksvrclosestr(rtksvr_t *svr, int index);
int rtksvrostat(rtksvr_t *svr, int rcv, gtime_t *time, int *sat, int rtksvrostat(rtksvr_t *svr, int rcv, gtime_t *time, int *sat,
double *az, double *el, int **snr, int *vsat); double *az, double *el, int **snr, int *vsat);
void rtksvrsstat(rtksvr_t *svr, int *sstat, char *msg); void rtksvrsstat(rtksvr_t *svr, int *sstat, char *msg);

View File

@ -666,15 +666,15 @@ void readsolopt(FILE *fp, solopt_t *opt)
/* input solution data from stream --------------------------------------------- /* input solution data from stream ---------------------------------------------
* input solution data from stream * input solution data from stream
* args : unsigned char data I stream data * args : unsigned char data I stream data
* gtime_t ts I start time (ts.time == 0: from start) * gtime_t ts I start time (ts.time == 0: from start)
* gtime_t te I end time (te.time == 0: to end) * gtime_t te I end time (te.time == 0: to end)
* double tint I time interval (0: all) * double tint I time interval (0: all)
* int qflag I quality flag (0: all) * int qflag I quality flag (0: all)
* solbuf_t *solbuf IO solution buffer * solbuf_t *solbuf IO solution buffer
* return : status (1:solution received,0:no solution,-1:disconnect received) * return : status (1:solution received,0:no solution,-1:disconnect received)
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int inputsol(unsigned char data, gtime_t ts, gtime_t te, double tint, int inputsol(unsigned char data, gtime_t ts, gtime_t te, double tint,
int qflag, const solopt_t *opt, solbuf_t *solbuf) int qflag, const solopt_t *opt, solbuf_t *solbuf)
{ {
@ -766,16 +766,16 @@ int sort_solbuf(solbuf_t *solbuf)
/* read solutions data from solution files ------------------------------------- /* read solutions data from solution files -------------------------------------
* read solution data from soluiton files * read solution data from soluiton files
* args : char *files[] I solution files * args : char *files[] I solution files
* int nfile I number of files * int nfile I number of files
* (gtime_t ts) I start time (ts.time == 0: from start) * (gtime_t ts) I start time (ts.time == 0: from start)
* (gtime_t te) I end time (te.time == 0: to end) * (gtime_t te) I end time (te.time == 0: to end)
* (double tint) I time interval (0: all) * (double tint) I time interval (0: all)
* (int qflag) I quality flag (0: all) * (int qflag) I quality flag (0: all)
* solbuf_t *solbuf O solution buffer * solbuf_t *solbuf O solution buffer
* return : status (1:ok,0:no data or error) * return : status (1:ok,0:no data or error)
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int readsolt(char *files[], int nfile, gtime_t ts, gtime_t te, int readsolt(char *files[], int nfile, gtime_t ts, gtime_t te,
double tint, int qflag, solbuf_t *solbuf) double tint, int qflag, solbuf_t *solbuf)
{ {
@ -820,11 +820,11 @@ int readsol(char *files[], int nfile, solbuf_t *sol)
/* add solution data to solution buffer ---------------------------------------- /* add solution data to solution buffer ----------------------------------------
* add solution data to solution buffer * add solution data to solution buffer
* args : solbuf_t *solbuf IO solution buffer * args : solbuf_t *solbuf IO solution buffer
* sol_t *sol I solution data * sol_t *sol I solution data
* return : status (1:ok,0:error) * return : status (1:ok,0:error)
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int addsol(solbuf_t *solbuf, const sol_t *sol) int addsol(solbuf_t *solbuf, const sol_t *sol)
{ {
sol_t *solbuf_data; sol_t *solbuf_data;
@ -862,11 +862,11 @@ int addsol(solbuf_t *solbuf, const sol_t *sol)
/* get solution data from solution buffer -------------------------------------- /* get solution data from solution buffer --------------------------------------
* get solution data by index from solution buffer * get solution data by index from solution buffer
* args : solbuf_t *solbuf I solution buffer * args : solbuf_t *solbuf I solution buffer
* int index I index of solution (0...) * int index I index of solution (0...)
* return : solution data pointer (NULL: no solution, out of range) * return : solution data pointer (NULL: no solution, out of range)
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
sol_t *getsol(solbuf_t *solbuf, int index) sol_t *getsol(solbuf_t *solbuf, int index)
{ {
trace(4,"getsol: index=%d\n",index); trace(4,"getsol: index=%d\n",index);
@ -881,12 +881,12 @@ sol_t *getsol(solbuf_t *solbuf, int index)
/* initialize solution buffer -------------------------------------------------- /* initialize solution buffer --------------------------------------------------
* initialize position solutions * initialize position solutions
* args : solbuf_t *solbuf I solution buffer * args : solbuf_t *solbuf I solution buffer
* int cyclic I solution data buffer type (0:linear,1:cyclic) * int cyclic I solution data buffer type (0:linear,1:cyclic)
* int nmax I initial number of solution data * int nmax I initial number of solution data
* return : status (1:ok,0:error) * return : status (1:ok,0:error)
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void initsolbuf(solbuf_t *solbuf, int cyclic, int nmax) void initsolbuf(solbuf_t *solbuf, int cyclic, int nmax)
{ {
gtime_t time0 = {0}; gtime_t time0 = {0};
@ -911,10 +911,10 @@ void initsolbuf(solbuf_t *solbuf, int cyclic, int nmax)
/* free solution --------------------------------------------------------------- /* free solution ---------------------------------------------------------------
* free memory for solution buffer * free memory for solution buffer
* args : solbuf_t *solbuf I solution buffer * args : solbuf_t *solbuf I solution buffer
* return : none * return : none
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void freesolbuf(solbuf_t *solbuf) void freesolbuf(solbuf_t *solbuf)
{ {
trace(3,"freesolbuf: n=%d\n",solbuf->n); trace(3,"freesolbuf: n=%d\n",solbuf->n);
@ -1059,15 +1059,15 @@ int readsolstatdata(FILE *fp, gtime_t ts, gtime_t te, double tint,
/* read solution status -------------------------------------------------------- /* read solution status --------------------------------------------------------
* read solution status from solution status files * read solution status from solution status files
* args : char *files[] I solution status files * args : char *files[] I solution status files
* int nfile I number of files * int nfile I number of files
* (gtime_t ts) I start time (ts.time == 0: from start) * (gtime_t ts) I start time (ts.time == 0: from start)
* (gtime_t te) I end time (te.time == 0: to end) * (gtime_t te) I end time (te.time == 0: to end)
* (double tint) I time interval (0: all) * (double tint) I time interval (0: all)
* solstatbuf_t *statbuf O solution status buffer * solstatbuf_t *statbuf O solution status buffer
* return : status (1:ok,0:no data or error) * return : status (1:ok,0:no data or error)
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int readsolstatt(char *files[], int nfile, gtime_t ts, gtime_t te, int readsolstatt(char *files[], int nfile, gtime_t ts, gtime_t te,
double tint, solstatbuf_t *statbuf) double tint, solstatbuf_t *statbuf)
{ {
@ -1191,7 +1191,7 @@ int outnmea_rmc(unsigned char *buff, const sol_t *sol)
static double dirp = 0.0; static double dirp = 0.0;
gtime_t time; gtime_t time;
double ep[6],pos[3],enuv[3],dms1[3],dms2[3],vel,dir,amag = 0.0; double ep[6],pos[3],enuv[3],dms1[3],dms2[3],vel,dir,amag = 0.0;
char *p = (char *)buff,*q,sum,*emag = "E"; char *p = (char *)buff,*q,sum,*emag = (char*)"E";
trace(3,"outnmea_rmc:\n"); trace(3,"outnmea_rmc:\n");
@ -1464,11 +1464,11 @@ int outnmea_gsv(unsigned char *buff, const sol_t *sol,
/* output processing options --------------------------------------------------- /* output processing options ---------------------------------------------------
* output processing options to buffer * output processing options to buffer
* args : unsigned char *buff IO output buffer * args : unsigned char *buff IO output buffer
* prcopt_t *opt I processign options * prcopt_t *opt I processign options
* return : number of output bytes * return : number of output bytes
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int outprcopts(unsigned char *buff, const prcopt_t *opt) int outprcopts(unsigned char *buff, const prcopt_t *opt)
{ {
const int sys[] = {SYS_GPS,SYS_GLO,SYS_GAL,SYS_QZS,SYS_SBS,0}; const int sys[] = {SYS_GPS,SYS_GLO,SYS_GAL,SYS_QZS,SYS_SBS,0};
@ -1550,11 +1550,11 @@ int outprcopts(unsigned char *buff, const prcopt_t *opt)
/* output solution header ------------------------------------------------------ /* output solution header ------------------------------------------------------
* output solution header to buffer * output solution header to buffer
* args : unsigned char *buff IO output buffer * args : unsigned char *buff IO output buffer
* solopt_t *opt I solution options * solopt_t *opt I solution options
* return : number of output bytes * return : number of output bytes
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int outsolheads(unsigned char *buff, const solopt_t *opt) int outsolheads(unsigned char *buff, const solopt_t *opt)
{ {
const char *s1[] = {"WGS84","Tokyo"},*s2[] = {"ellipsoidal","geodetic"}; const char *s1[] = {"WGS84","Tokyo"},*s2[] = {"ellipsoidal","geodetic"};
@ -1612,13 +1612,13 @@ int outsolheads(unsigned char *buff, const solopt_t *opt)
/* output solution body -------------------------------------------------------- /* output solution body --------------------------------------------------------
* output solution body to buffer * output solution body to buffer
* args : unsigned char *buff IO output buffer * args : unsigned char *buff IO output buffer
* sol_t *sol I solution * sol_t *sol I solution
* double *rb I base station position {x,y,z} (ecef) (m) * double *rb I base station position {x,y,z} (ecef) (m)
* solopt_t *opt I solution options * solopt_t *opt I solution options
* return : number of output bytes * return : number of output bytes
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int outsols(unsigned char *buff, const sol_t *sol, const double *rb, int outsols(unsigned char *buff, const sol_t *sol, const double *rb,
const solopt_t *opt) const solopt_t *opt)
{ {
@ -1670,14 +1670,14 @@ int outsols(unsigned char *buff, const sol_t *sol, const double *rb,
/* output solution extended ---------------------------------------------------- /* output solution extended ----------------------------------------------------
* output solution exteneded infomation * output solution exteneded infomation
* args : unsigned char *buff IO output buffer * args : unsigned char *buff IO output buffer
* sol_t *sol I solution * sol_t *sol I solution
* ssat_t *ssat I satellite status * ssat_t *ssat I satellite status
* solopt_t *opt I solution options * solopt_t *opt I solution options
* return : number of output bytes * return : number of output bytes
* notes : only support nmea * notes : only support nmea
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
int outsolexs(unsigned char *buff, const sol_t *sol, const ssat_t *ssat, int outsolexs(unsigned char *buff, const sol_t *sol, const ssat_t *ssat,
const solopt_t *opt) const solopt_t *opt)
{ {
@ -1701,87 +1701,87 @@ int outsolexs(unsigned char *buff, const sol_t *sol, const ssat_t *ssat,
/* output processing option ---------------------------------------------------- /* output processing option ----------------------------------------------------
* output processing option to file * output processing option to file
* args : FILE *fp I output file pointer * args : FILE *fp I output file pointer
* prcopt_t *opt I processing options * prcopt_t *opt I processing options
* return : none * return : none
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void outprcopt(FILE *fp, const prcopt_t *opt) void outprcopt(FILE *fp, const prcopt_t *opt)
{ {
unsigned char buff[MAXSOLMSG+1]; unsigned char buff[MAXSOLMSG+1];
int n; int n;
trace(3,"outprcopt:\n"); trace(3, "outprcopt:\n");
if ((n = outprcopts(buff,opt))>0) if ((n = outprcopts(buff, opt)) > 0)
{ {
fwrite(buff,n,1,fp); fwrite(buff, n, 1, fp);
} }
} }
/* output solution header ------------------------------------------------------ /* output solution header ------------------------------------------------------
* output solution heade to file * output solution heade to file
* args : FILE *fp I output file pointer * args : FILE *fp I output file pointer
* solopt_t *opt I solution options * solopt_t *opt I solution options
* return : none * return : none
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void outsolhead(FILE *fp, const solopt_t *opt) void outsolhead(FILE *fp, const solopt_t *opt)
{ {
unsigned char buff[MAXSOLMSG+1]; unsigned char buff[MAXSOLMSG+1];
int n; int n;
trace(3,"outsolhead:\n"); trace(3, "outsolhead:\n");
if ((n = outsolheads(buff,opt))>0) if ((n = outsolheads(buff, opt)) > 0)
{ {
fwrite(buff,n,1,fp); fwrite(buff, n, 1, fp);
} }
} }
/* output solution body -------------------------------------------------------- /* output solution body --------------------------------------------------------
* output solution body to file * output solution body to file
* args : FILE *fp I output file pointer * args : FILE *fp I output file pointer
* sol_t *sol I solution * sol_t *sol I solution
* double *rb I base station position {x,y,z} (ecef) (m) * double *rb I base station position {x,y,z} (ecef) (m)
* solopt_t *opt I solution options * solopt_t *opt I solution options
* return : none * return : none
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void outsol(FILE *fp, const sol_t *sol, const double *rb, void outsol(FILE *fp, const sol_t *sol, const double *rb,
const solopt_t *opt) const solopt_t *opt)
{ {
unsigned char buff[MAXSOLMSG+1]; unsigned char buff[MAXSOLMSG+1];
int n; int n;
trace(3,"outsol :\n"); trace(3, "outsol :\n");
if ((n = outsols(buff,sol,rb,opt))>0) if ((n = outsols(buff, sol, rb, opt)) > 0)
{ {
fwrite(buff,n,1,fp); fwrite(buff, n, 1, fp);
} }
} }
/* output solution extended ---------------------------------------------------- /* output solution extended ----------------------------------------------------
* output solution exteneded infomation to file * output solution exteneded infomation to file
* args : FILE *fp I output file pointer * args : FILE *fp I output file pointer
* sol_t *sol I solution * sol_t *sol I solution
* ssat_t *ssat I satellite status * ssat_t *ssat I satellite status
* solopt_t *opt I solution options * solopt_t *opt I solution options
* return : output size (bytes) * return : output size (bytes)
* notes : only support nmea * notes : only support nmea
*-----------------------------------------------------------------------------*/ *-----------------------------------------------------------------------------*/
void outsolex(FILE *fp, const sol_t *sol, const ssat_t *ssat, void outsolex(FILE *fp, const sol_t *sol, const ssat_t *ssat,
const solopt_t *opt) const solopt_t *opt)
{ {
unsigned char buff[MAXSOLMSG+1]; unsigned char buff[MAXSOLMSG+1];
int n; int n;
trace(3,"outsolex:\n"); trace(3, "outsolex:\n");
if ((n = outsolexs(buff,sol,ssat,opt))>0) if ((n = outsolexs(buff, sol, ssat, opt)) > 0)
{ {
fwrite(buff,n,1,fp); fwrite(buff, n, 1, fp);
} }
} }

View File

@ -59,69 +59,121 @@
#define MSG_DISCONN "$_DISCONNECT\r\n" /* disconnect message */ #define MSG_DISCONN "$_DISCONNECT\r\n" /* disconnect message */
const char *opt2sep(const solopt_t *opt); const char *opt2sep(const solopt_t *opt);
int tonum(char *buff, const char *sep, double *v); int tonum(char *buff, const char *sep, double *v);
double sqvar(double covar); double sqvar(double covar);
double dmm2deg(double dmm); double dmm2deg(double dmm);
void septime(double t, double *t1, double *t2, double *t3); void septime(double t, double *t1, double *t2, double *t3);
void soltocov(const sol_t *sol, double *P); void soltocov(const sol_t *sol, double *P);
void covtosol(const double *P, sol_t *sol); void covtosol(const double *P, sol_t *sol);
int decode_nmearmc(char **val, int n, sol_t *sol); int decode_nmearmc(char **val, int n, sol_t *sol);
int decode_nmeagga(char **val, int n, sol_t *sol); int decode_nmeagga(char **val, int n, sol_t *sol);
int decode_nmea(char *buff, sol_t *sol); int decode_nmea(char *buff, sol_t *sol);
char *decode_soltime(char *buff, const solopt_t *opt, gtime_t *time); char *decode_soltime(char *buff, const solopt_t *opt, gtime_t *time);
int decode_solxyz(char *buff, const solopt_t *opt, sol_t *sol); int decode_solxyz(char *buff, const solopt_t *opt, sol_t *sol);
int decode_solllh(char *buff, const solopt_t *opt, sol_t *sol); int decode_solllh(char *buff, const solopt_t *opt, sol_t *sol);
int decode_solenu(char *buff, const solopt_t *opt, sol_t *sol); int decode_solenu(char *buff, const solopt_t *opt, sol_t *sol);
int decode_solgsi(char *buff, const solopt_t *opt, sol_t *sol); int decode_solgsi(char *buff, const solopt_t *opt, sol_t *sol);
int decode_solpos(char *buff, const solopt_t *opt, sol_t *sol); int decode_solpos(char *buff, const solopt_t *opt, sol_t *sol);
void decode_refpos(char *buff, const solopt_t *opt, double *rb); void decode_refpos(char *buff, const solopt_t *opt, double *rb);
int decode_sol(char *buff, const solopt_t *opt, sol_t *sol, double *rb); int decode_sol(char *buff, const solopt_t *opt, sol_t *sol, double *rb);
void decode_solopt(char *buff, solopt_t *opt); void decode_solopt(char *buff, solopt_t *opt);
void readsolopt(FILE *fp, solopt_t *opt); void readsolopt(FILE *fp, solopt_t *opt);
int inputsol(unsigned char data, gtime_t ts, gtime_t te, double tint, int inputsol(unsigned char data, gtime_t ts, gtime_t te, double tint,
int qflag, const solopt_t *opt, solbuf_t *solbuf); int qflag, const solopt_t *opt, solbuf_t *solbuf);
int readsoldata(FILE *fp, gtime_t ts, gtime_t te, double tint, int qflag, int readsoldata(FILE *fp, gtime_t ts, gtime_t te, double tint, int qflag,
const solopt_t *opt, solbuf_t *solbuf); const solopt_t *opt, solbuf_t *solbuf);
int cmpsol(const void *p1, const void *p2); int cmpsol(const void *p1, const void *p2);
int sort_solbuf(solbuf_t *solbuf); int sort_solbuf(solbuf_t *solbuf);
int readsolt(char *files[], int nfile, gtime_t ts, gtime_t te, int readsolt(char *files[], int nfile, gtime_t ts, gtime_t te,
double tint, int qflag, solbuf_t *solbuf); double tint, int qflag, solbuf_t *solbuf);
int readsol(char *files[], int nfile, solbuf_t *sol); int readsol(char *files[], int nfile, solbuf_t *sol);
int addsol(solbuf_t *solbuf, const sol_t *sol); int addsol(solbuf_t *solbuf, const sol_t *sol);
sol_t *getsol(solbuf_t *solbuf, int index); sol_t *getsol(solbuf_t *solbuf, int index);
void initsolbuf(solbuf_t *solbuf, int cyclic, int nmax); void initsolbuf(solbuf_t *solbuf, int cyclic, int nmax);
void freesolbuf(solbuf_t *solbuf); void freesolbuf(solbuf_t *solbuf);
void freesolstatbuf(solstatbuf_t *solstatbuf); void freesolstatbuf(solstatbuf_t *solstatbuf);
int cmpsolstat(const void *p1, const void *p2); int cmpsolstat(const void *p1, const void *p2);
int sort_solstat(solstatbuf_t *statbuf); int sort_solstat(solstatbuf_t *statbuf);
int decode_solstat(char *buff, solstat_t *stat); int decode_solstat(char *buff, solstat_t *stat);
void addsolstat(solstatbuf_t *statbuf, const solstat_t *stat); void addsolstat(solstatbuf_t *statbuf, const solstat_t *stat);
int readsolstatdata(FILE *fp, gtime_t ts, gtime_t te, double tint, int readsolstatdata(FILE *fp, gtime_t ts, gtime_t te, double tint,
solstatbuf_t *statbuf); solstatbuf_t *statbuf);
int readsolstatt(char *files[], int nfile, gtime_t ts, gtime_t te, int readsolstatt(char *files[], int nfile, gtime_t ts, gtime_t te,
double tint, solstatbuf_t *statbuf); double tint, solstatbuf_t *statbuf);
int readsolstat(char *files[], int nfile, solstatbuf_t *statbuf); int readsolstat(char *files[], int nfile, solstatbuf_t *statbuf);
int outecef(unsigned char *buff, const char *s, const sol_t *sol, int outecef(unsigned char *buff, const char *s, const sol_t *sol,
const solopt_t *opt); const solopt_t *opt);
int outpos(unsigned char *buff, const char *s, const sol_t *sol, const solopt_t *opt); int outpos(unsigned char *buff, const char *s, const sol_t *sol, const solopt_t *opt);
int outenu(unsigned char *buff, const char *s, const sol_t *sol, int outenu(unsigned char *buff, const char *s, const sol_t *sol,
const double *rb, const solopt_t *opt); const double *rb, const solopt_t *opt);
int outnmea_rmc(unsigned char *buff, const sol_t *sol); int outnmea_rmc(unsigned char *buff, const sol_t *sol);
int outnmea_gga(unsigned char *buff, const sol_t *sol); int outnmea_gga(unsigned char *buff, const sol_t *sol);
int outnmea_gsa(unsigned char *buff, const sol_t *sol, int outnmea_gsa(unsigned char *buff, const sol_t *sol,
const ssat_t *ssat); const ssat_t *ssat);
int outnmea_gsv(unsigned char *buff, const sol_t *sol, int outnmea_gsv(unsigned char *buff, const sol_t *sol,
const ssat_t *ssat); const ssat_t *ssat);
int outprcopts(unsigned char *buff, const prcopt_t *opt); int outprcopts(unsigned char *buff, const prcopt_t *opt);
int outsolheads(unsigned char *buff, const solopt_t *opt); int outsolheads(unsigned char *buff, const solopt_t *opt);
int outsols(unsigned char *buff, const sol_t *sol, const double *rb, int outsols(unsigned char *buff, const sol_t *sol, const double *rb,
const solopt_t *opt); const solopt_t *opt);
int outsolexs(unsigned char *buff, const sol_t *sol, const ssat_t *ssat, int outsolexs(unsigned char *buff, const sol_t *sol, const ssat_t *ssat,
const solopt_t *opt); const solopt_t *opt);
void outprcopt(FILE *fp, const prcopt_t *opt); void outprcopt(FILE *fp, const prcopt_t *opt);
void outsolhead(FILE *fp, const solopt_t *opt); void outsolhead(FILE *fp, const solopt_t *opt);
void outsol(FILE *fp, const sol_t *sol, const double *rb, void outsol(FILE *fp, const sol_t *sol, const double *rb,
const solopt_t *opt); const solopt_t *opt);
void outsolex(FILE *fp, const sol_t *sol, const ssat_t *ssat, void outsolex(FILE *fp, const sol_t *sol, const ssat_t *ssat,
const solopt_t *opt); const solopt_t *opt);

File diff suppressed because it is too large Load Diff

View File

@ -54,16 +54,14 @@
#define GNSS_SDR_RTKLIB_STREAM_H_ #define GNSS_SDR_RTKLIB_STREAM_H_
#include "rtklib.h" #include "rtklib.h"
#include <pthread.h>
#include <netinet/in.h>
/* constants -----------------------------------------------------------------*/ /* constants -----------------------------------------------------------------*/
#define TINTACT 200 /* period for stream active (ms) */ #define TINTACT 200 /* period for stream active (ms) */
#define SERIBUFFSIZE 4096 /* serial buffer size (bytes) */ #define SERIBUFFSIZE 4096 /* serial buffer size (bytes) */
#define TIMETAGH_LEN 64 /* time tag file header length */ #define TIMETAGH_LEN 64 /* time tag file header length */
#define MAXCLI 32 /* max client connection for tcp svr */ #define MAXCLI 32 /* max client connection for tcp svr */
#define MAXSTATMSG 32 /* max length of status message */ #define MAXSTATMSG 32 /* max length of status message */
#define VER_RTKLIB "2.4.2" #define VER_RTKLIB "2.4.2"
#define NTRIP_AGENT "RTKLIB/" VER_RTKLIB #define NTRIP_AGENT "RTKLIB/" VER_RTKLIB
@ -71,199 +69,169 @@
#define NTRIP_SVR_PORT 80 /* default ntrip-server connection port */ #define NTRIP_SVR_PORT 80 /* default ntrip-server connection port */
#define NTRIP_MAXRSP 32768 /* max size of ntrip response */ #define NTRIP_MAXRSP 32768 /* max size of ntrip response */
#define NTRIP_MAXSTR 256 /* max length of mountpoint string */ #define NTRIP_MAXSTR 256 /* max length of mountpoint string */
#define NTRIP_RSP_OK_CLI "ICY 200 OK\r\n" /* ntrip response: client */ #define NTRIP_RSP_OK_CLI "ICY 200 OK\r\n" /* ntrip response: client */
#define NTRIP_RSP_OK_SVR "OK\r\n" /* ntrip response: server */ #define NTRIP_RSP_OK_SVR "OK\r\n" /* ntrip response: server */
#define NTRIP_RSP_SRCTBL "SOURCETABLE 200 OK\r\n" /* ntrip response: source table */ #define NTRIP_RSP_SRCTBL "SOURCETABLE 200 OK\r\n" /* ntrip response: source table */
#define NTRIP_RSP_TBLEND "ENDSOURCETABLE" #define NTRIP_RSP_TBLEND "ENDSOURCETABLE"
#define NTRIP_RSP_HTTP "HTTP/" /* ntrip response: http */ #define NTRIP_RSP_HTTP "HTTP/" /* ntrip response: http */
#define NTRIP_RSP_ERROR "ERROR" /* ntrip response: error */ #define NTRIP_RSP_ERROR "ERROR" /* ntrip response: error */
#define FTP_CMD "wget" /* ftp/http command */ #define FTP_CMD "wget" /* ftp/http command */
#define FTP_TIMEOUT 30 /* ftp/http timeout (s) */ #define FTP_TIMEOUT 30 /* ftp/http timeout (s) */
/* macros --------------------------------------------------------------------*/
#define dev_t int
#define socket_t int
#define closesocket close
#define lock_t pthread_mutex_t
#define thread_t pthread_t
#define initlock(f) pthread_mutex_init(f,NULL)
#define rtk_lock(f) pthread_mutex_lock(f)
#define rtk_unlock(f) pthread_mutex_unlock(f)
typedef struct { /* stream type */
int type; /* type (STR_???) */
int mode; /* mode (STR_MODE_?) */
int state; /* state (-1:error,0:close,1:open) */
unsigned int inb,inr; /* input bytes/rate */
unsigned int outb,outr; /* output bytes/rate */
unsigned int tick,tact; /* tick/active tick */
unsigned int inbt,outbt; /* input/output bytes at tick */
lock_t lock; /* lock flag */
void *port; /* type dependent port control struct */
char path[MAXSTRPATH]; /* stream path */
char msg [MAXSTRMSG]; /* stream message */
} stream_t;
/* type definition -----------------------------------------------------------*/
typedef struct { /* serial control type */
dev_t dev; /* serial device */
int error; /* error state */
} serial_t;
typedef struct { /* file control type */
FILE *fp; /* file pointer */
FILE *fp_tag; /* file pointer of tag file */
FILE *fp_tmp; /* temporary file pointer for swap */
FILE *fp_tag_tmp; /* temporary file pointer of tag file for swap */
char path[MAXSTRPATH]; /* file path */
char openpath[MAXSTRPATH]; /* open file path */
int mode; /* file mode */
int timetag; /* time tag flag (0:off,1:on) */
int repmode; /* replay mode (0:master,1:slave) */
int offset; /* time offset (ms) for slave */
gtime_t time; /* start time */
gtime_t wtime; /* write time */
unsigned int tick; /* start tick */
unsigned int tick_f; /* start tick in file */
unsigned int fpos; /* current file position */
double start; /* start offset (s) */
double speed; /* replay speed (time factor) */
double swapintv; /* swap interval (hr) (0: no swap) */
lock_t lock; /* lock flag */
} file_t;
typedef struct { /* tcp control type */
int state; /* state (0:close,1:wait,2:connect) */
char saddr[256]; /* address string */
int port; /* port */
struct sockaddr_in addr; /* address resolved */
socket_t sock; /* socket descriptor */
int tcon; /* reconnect time (ms) (-1:never,0:now) */
unsigned int tact; /* data active tick */
unsigned int tdis; /* disconnect tick */
} tcp_t;
typedef struct { /* tcp server type */
tcp_t svr; /* tcp server control */
tcp_t cli[MAXCLI]; /* tcp client controls */
} tcpsvr_t;
typedef struct { /* tcp cilent type */
tcp_t svr; /* tcp server control */
int toinact; /* inactive timeout (ms) (0:no timeout) */
int tirecon; /* reconnect interval (ms) (0:no reconnect) */
} tcpcli_t;
typedef struct { /* ntrip control type */
int state; /* state (0:close,1:wait,2:connect) */
int type; /* type (0:server,1:client) */
int nb; /* response buffer size */
char url[256]; /* url for proxy */
char mntpnt[256]; /* mountpoint */
char user[256]; /* user */
char passwd[256]; /* password */
char str[NTRIP_MAXSTR]; /* mountpoint string for server */
unsigned char buff[NTRIP_MAXRSP]; /* response buffer */
tcpcli_t *tcp; /* tcp client */
} ntrip_t;
typedef struct { /* ftp download control type */
int state; /* state (0:close,1:download,2:complete,3:error) */
int proto; /* protocol (0:ftp,1:http) */
int error; /* error code (0:no error,1-10:wget error, */
/* 11:no temp dir,12:uncompact error) */
char addr[1024]; /* download address */
char file[1024]; /* download file path */
char user[256]; /* user for ftp */
char passwd[256]; /* password for ftp */
char local[1024]; /* local file path */
int topts[4]; /* time options {poff,tint,toff,tretry} (s) */
gtime_t tnext; /* next retry time (gpst) */
thread_t thread; /* download thread */
} ftp_t;
serial_t *openserial(const char *path, int mode, char *msg); serial_t *openserial(const char *path, int mode, char *msg);
void closeserial(serial_t *serial); void closeserial(serial_t *serial);
int readserial(serial_t *serial, unsigned char *buff, int n, char *msg); int readserial(serial_t *serial, unsigned char *buff, int n, char *msg);
int writeserial(serial_t *serial, unsigned char *buff, int n, char *msg); int writeserial(serial_t *serial, unsigned char *buff, int n, char *msg);
int stateserial(serial_t *serial); int stateserial(serial_t *serial);
int openfile_(file_t *file, gtime_t time, char *msg); int openfile_(file_t *file, gtime_t time, char *msg);
void closefile_(file_t *file); void closefile_(file_t *file);
file_t *openfile(const char *path, int mode, char *msg); file_t *openfile(const char *path, int mode, char *msg);
void closefile(file_t *file); void closefile(file_t *file);
void swapfile(file_t *file, gtime_t time, char *msg); void swapfile(file_t *file, gtime_t time, char *msg);
void swapclose(file_t *file); void swapclose(file_t *file);
int statefile(file_t *file); int statefile(file_t *file);
int readfile(file_t *file, unsigned char *buff, int nmax, char *msg); int readfile(file_t *file, unsigned char *buff, int nmax, char *msg);
int writefile(file_t *file, unsigned char *buff, int n, char *msg); int writefile(file_t *file, unsigned char *buff, int n, char *msg);
void syncfile(file_t *file1, file_t *file2); void syncfile(file_t *file1, file_t *file2);
void decodetcppath(const char *path, char *addr, char *port, char *user, void decodetcppath(const char *path, char *addr, char *port, char *user,
char *passwd, char *mntpnt, char *str); char *passwd, char *mntpnt, char *str);
int errsock(void); int errsock(void);
int setsock(socket_t sock, char *msg); int setsock(socket_t sock, char *msg);
socket_t accept_nb(socket_t sock, struct sockaddr *addr, socklen_t *len); socket_t accept_nb(socket_t sock, struct sockaddr *addr, socklen_t *len);
int connect_nb(socket_t sock, struct sockaddr *addr, socklen_t len); int connect_nb(socket_t sock, struct sockaddr *addr, socklen_t len);
int recv_nb(socket_t sock, unsigned char *buff, int n); int recv_nb(socket_t sock, unsigned char *buff, int n);
int send_nb(socket_t sock, unsigned char *buff, int n); int send_nb(socket_t sock, unsigned char *buff, int n);
int gentcp(tcp_t *tcp, int type, char *msg); int gentcp(tcp_t *tcp, int type, char *msg);
void discontcp(tcp_t *tcp, int tcon); void discontcp(tcp_t *tcp, int tcon);
tcpsvr_t *opentcpsvr(const char *path, char *msg); tcpsvr_t *opentcpsvr(const char *path, char *msg);
void closetcpsvr(tcpsvr_t *tcpsvr); void closetcpsvr(tcpsvr_t *tcpsvr);
void updatetcpsvr(tcpsvr_t *tcpsvr, char *msg); void updatetcpsvr(tcpsvr_t *tcpsvr, char *msg);
int accsock(tcpsvr_t *tcpsvr, char *msg); int accsock(tcpsvr_t *tcpsvr, char *msg);
int waittcpsvr(tcpsvr_t *tcpsvr, char *msg); int waittcpsvr(tcpsvr_t *tcpsvr, char *msg);
int readtcpsvr(tcpsvr_t *tcpsvr, unsigned char *buff, int n, char *msg); int readtcpsvr(tcpsvr_t *tcpsvr, unsigned char *buff, int n, char *msg);
int writetcpsvr(tcpsvr_t *tcpsvr, unsigned char *buff, int n, char *msg); int writetcpsvr(tcpsvr_t *tcpsvr, unsigned char *buff, int n, char *msg);
int statetcpsvr(tcpsvr_t *tcpsvr); int statetcpsvr(tcpsvr_t *tcpsvr);
int consock(tcpcli_t *tcpcli, char *msg); int consock(tcpcli_t *tcpcli, char *msg);
tcpcli_t *opentcpcli(const char *path, char *msg); tcpcli_t *opentcpcli(const char *path, char *msg);
void closetcpcli(tcpcli_t *tcpcli); void closetcpcli(tcpcli_t *tcpcli);
int waittcpcli(tcpcli_t *tcpcli, char *msg); int waittcpcli(tcpcli_t *tcpcli, char *msg);
int readtcpcli(tcpcli_t *tcpcli, unsigned char *buff, int n, char *msg); int readtcpcli(tcpcli_t *tcpcli, unsigned char *buff, int n, char *msg);
int writetcpcli(tcpcli_t *tcpcli, unsigned char *buff, int n, char *msg); int writetcpcli(tcpcli_t *tcpcli, unsigned char *buff, int n, char *msg);
int statetcpcli(tcpcli_t *tcpcli); int statetcpcli(tcpcli_t *tcpcli);
int encbase64(char *str, const unsigned char *byte, int n); int encbase64(char *str, const unsigned char *byte, int n);
int reqntrip_s(ntrip_t *ntrip, char *msg); int reqntrip_s(ntrip_t *ntrip, char *msg);
int reqntrip_c(ntrip_t *ntrip, char *msg); int reqntrip_c(ntrip_t *ntrip, char *msg);
int rspntrip_s(ntrip_t *ntrip, char *msg); int rspntrip_s(ntrip_t *ntrip, char *msg);
int rspntrip_c(ntrip_t *ntrip, char *msg); int rspntrip_c(ntrip_t *ntrip, char *msg);
int waitntrip(ntrip_t *ntrip, char *msg); int waitntrip(ntrip_t *ntrip, char *msg);
ntrip_t *openntrip(const char *path, int type, char *msg); ntrip_t *openntrip(const char *path, int type, char *msg);
void closentrip(ntrip_t *ntrip); void closentrip(ntrip_t *ntrip);
int readntrip(ntrip_t *ntrip, unsigned char *buff, int n, char *msg); int readntrip(ntrip_t *ntrip, unsigned char *buff, int n, char *msg);
int writentrip(ntrip_t *ntrip, unsigned char *buff, int n, char *msg); int writentrip(ntrip_t *ntrip, unsigned char *buff, int n, char *msg);
int statentrip(ntrip_t *ntrip); int statentrip(ntrip_t *ntrip);
void decodeftppath(const char *path, char *addr, char *file, char *user, void decodeftppath(const char *path, char *addr, char *file, char *user,
char *passwd, int *topts); char *passwd, int *topts);
gtime_t nextdltime(const int *topts, int stat); gtime_t nextdltime(const int *topts, int stat);
void *ftpthread(void *arg); void *ftpthread(void *arg);
ftp_t *openftp(const char *path, int type, char *msg); ftp_t *openftp(const char *path, int type, char *msg);
void closeftp(ftp_t *ftp); void closeftp(ftp_t *ftp);
int readftp(ftp_t *ftp, unsigned char *buff, int n, char *msg); int readftp(ftp_t *ftp, unsigned char *buff, int n, char *msg);
int stateftp(ftp_t *ftp); int stateftp(ftp_t *ftp);
void strinitcom(void); void strinitcom(void);
void strinit(stream_t *stream); void strinit(stream_t *stream);
int stropen(stream_t *stream, int type, int mode, const char *path); int stropen(stream_t *stream, int type, int mode, const char *path);
void strclose(stream_t *stream); void strclose(stream_t *stream);
void strsync(stream_t *stream1, stream_t *stream2); void strsync(stream_t *stream1, stream_t *stream2);
void strlock(stream_t *stream); void strlock(stream_t *stream);
void strunlock(stream_t *stream); void strunlock(stream_t *stream);
int strread(stream_t *stream, unsigned char *buff, int n); int strread(stream_t *stream, unsigned char *buff, int n);
int strwrite(stream_t *stream, unsigned char *buff, int n); int strwrite(stream_t *stream, unsigned char *buff, int n);
int strstat(stream_t *stream, char *msg); int strstat(stream_t *stream, char *msg);
void strsum(stream_t *stream, int *inb, int *inr, int *outb, int *outr); void strsum(stream_t *stream, int *inb, int *inr, int *outb, int *outr);
void strsetopt(const int *opt); void strsetopt(const int *opt);
void strsettimeout(stream_t *stream, int toinact, int tirecon); void strsettimeout(stream_t *stream, int toinact, int tirecon);
void strsetdir(const char *dir); void strsetdir(const char *dir);
void strsetproxy(const char *addr); void strsetproxy(const char *addr);
gtime_t strgettime(stream_t *stream); gtime_t strgettime(stream_t *stream);
void strsendnmea(stream_t *stream, const double *pos); void strsendnmea(stream_t *stream, const double *pos);
int gen_hex(const char *msg, unsigned char *buff); int gen_hex(const char *msg, unsigned char *buff);
void strsendcmd(stream_t *str, const char *cmd); void strsendcmd(stream_t *str, const char *cmd);