Skip to content

Commit

Permalink
Merge time mark functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
egorf committed Aug 10, 2016
2 parents bae7dac + ab056f9 commit 5cd909c
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 13 deletions.
13 changes: 10 additions & 3 deletions app/rtkrcv/rtkrcv.c
Expand Up @@ -572,9 +572,9 @@ static void prstatus(vt_t *vt)
};
const char *freq[]={"-","L1","L1+L2","L1+L2+L5","","",""};
rtcm_t rtcm[3];
int i,j,n,thread,cycle,state,rtkstat,nsat0,nsat1,prcout;
int i,j,n,thread,cycle,state,rtkstat,nsat0,nsat1,prcout,rcvcount,tmcount,timevalid;
int cputime,nb[3]={0},nmsg[3][10]={{0}};
char tstr[64],s[1024],*p;
char tstr[64],tmstr[64],s[1024],*p;
double runtime,rt[3]={0},dop[4]={0},rr[3],bl1=0.0,bl2=0.0;
double azel[MAXSAT*2],pos[3],vel[3],*del;

Expand All @@ -588,6 +588,9 @@ static void prstatus(vt_t *vt)
rtkstat=svr.rtk.sol.stat;
nsat0=svr.obs[0][0].n;
nsat1=svr.obs[1][0].n;
rcvcount = svr.raw[0].obs.rcvcount;
tmcount = svr.raw[0].obs.tmcount;
timevalid = svr.raw[0].obs.data[0].timevalid;
cputime=svr.cputime;
prcout=svr.prcout;
for (i=0;i<3;i++) nb[i]=svr.nb[i];
Expand All @@ -600,6 +603,7 @@ static void prstatus(vt_t *vt)
rt[1]=floor(runtime/60.0); rt[2]=runtime-rt[1]*60.0;
}
for (i=0;i<3;i++) rtcm[i]=svr.rtcm[i];
time2str(svr.raw[0].obs.data[0].eventime,tmstr,9);
rtksvrunlock(&svr);

for (i=n=0;i<MAXSAT;i++) {
Expand All @@ -612,7 +616,7 @@ static void prstatus(vt_t *vt)
dops(n,azel,0.0,dop);

vt_printf(vt,"\n%s%-28s: %s%s\n",ESC_BOLD,"Parameter","Value",ESC_RESET);
vt_printf(vt,"%-28s: %s\n","rtklib version",VER_RTKLIB);
vt_printf(vt,"%-28s: %s %s\n","rtklib version",VER_RTKLIB,"by Emlid");
vt_printf(vt,"%-28s: %d\n","rtk server thread",thread);
vt_printf(vt,"%-28s: %s\n","rtk server state",svrstate[state]);
vt_printf(vt,"%-28s: %d\n","processing cycle (ms)",cycle);
Expand Down Expand Up @@ -697,6 +701,9 @@ static void prstatus(vt_t *vt)
vt_printf(vt,"%-28s: %.3f\n","baseline length float (m)",bl1);
vt_printf(vt,"%-28s: %.3f\n","baseline length fixed (m)",bl2);
vt_printf(vt,"%-28s: %d\n","monitor port",moniport);
vt_printf(vt,"%-28s: %s\n","last time mark",tmcount ? tmstr : "-");
vt_printf(vt,"%-28s: %d\n","receiver time mark count",rcvcount);
vt_printf(vt,"%-28s: %d\n","rtklib time mark count",tmcount);
}
/* print satellite -----------------------------------------------------------*/
static void prsatellite(vt_t *vt, int nf)
Expand Down
15 changes: 10 additions & 5 deletions src/convrnx.c
Expand Up @@ -751,7 +751,11 @@ static void convobs(FILE **ofp, rnxopt_t *opt, strfile_t *str, int *n,
restslips(slips,str->obs->data,str->obs->n);

/* output rinex obs */
outrnxobsb(ofp[0],opt,str->obs->data,str->obs->n,0);
outrnxobsb(ofp[0],opt,str->obs->data,str->obs->n,str->obs->flag);
/* n[8] - count of events converted to rinex */
if (str->obs->flag == 5) n[8]++;
/* set to zero flag for the next iteration (initialization) */
str->obs->flag = 0;

if (opt->tstart.time==0) opt->tstart=time;
opt->tend=time;
Expand Down Expand Up @@ -950,7 +954,7 @@ static void setapppos(strfile_t *str, rnxopt_t *opt)
/* show status message -------------------------------------------------------*/
static int showstat(int sess, gtime_t ts, gtime_t te, int *n)
{
const char type[]="ONGHQLSE";
const char type[]="ONGHQLSET";
char msg[1024]="",*p=msg,s[64];
int i;

Expand All @@ -967,9 +971,10 @@ static int showstat(int sess, gtime_t ts, gtime_t te, int *n)
}
p+=sprintf(p,": ");

for (i=0;i<NOUTFILE+1;i++) {
/* +2 to NOUTFILE for counters of errors and events */
for (i=0;i<NOUTFILE+2;i++) {
if (n[i]==0) continue;
p+=sprintf(p,"%c=%d%s",type[i],n[i],i<NOUTFILE?" ":"");
p+=sprintf(p,"%c=%d%s",type[i],n[i],i<NOUTFILE+1?" ":"");
}
return showmsg(msg);
}
Expand All @@ -981,7 +986,7 @@ static int convrnx_s(int sess, int format, rnxopt_t *opt, const char *file,
strfile_t *str;
gtime_t ts={0},te={0},tend={0},time={0};
unsigned char slips[MAXSAT][NFREQ+NEXOBS]={{0}};
int i,j,nf,type,n[NOUTFILE+1]={0},abort=0;
int i,j,nf,type,n[NOUTFILE+2]={0},abort=0;
char path[1024],*paths[NOUTFILE],s[NOUTFILE][1024];
char *epath[MAXEXFILE]={0},*staid=*opt->staid?opt->staid:"0000";

Expand Down
49 changes: 49 additions & 0 deletions src/rcv/ublox.c
Expand Up @@ -49,6 +49,7 @@
* crc24q() -> rtk_crc24q()
* check week number zero for ubx-rxm-raw and rawx
*-----------------------------------------------------------------------------*/
#include <stdint.h>
#include "rtklib.h"

#define UBXSYNC1 0xB5 /* ubx message sync code 1 */
Expand All @@ -64,6 +65,7 @@
#define ID_TRKD5 0x030A /* ubx message id: trace mesurement data */
#define ID_TRKMEAS 0x0310 /* ubx message id: trace mesurement data */
#define ID_TRKSFRBX 0x030F /* ubx message id: trace subframe buffer */
#define ID_TIMTM2 0x0D03 /* ubx message id: time mark data */

#define FU1 1 /* ubx message field types */
#define FU2 2
Expand Down Expand Up @@ -982,6 +984,52 @@ static int decode_trksfrbx(raw_t *raw)
}
return 0;
}
/* decode ubx-tim-tm2: time mark data ----------------------------------------*/
static int decode_timtm2(raw_t *raw)
{
gtime_t eventime;
uint8_t ch, flags;
uint16_t count, wnR, wnF;
uint32_t towMsR, towSubMsR, towMsF, towSubMsF, accEst;
int time, timeBase, newRisingEdge, newFallingEdge;
unsigned char *p=raw->buff+6;

trace(4, "decode_timtm2: len=%d\n", raw->len);

if (raw->outtype) {
sprintf(raw->msgtype, "UBX TIM-TM2 (%4d)", raw->len);
}
ch = U1(p);
flags = *(p+1);
count = U2(p+2);
wnR = U2(p+4);
wnF = U2(p+6);
towMsR = U4(p+8);
towSubMsR = U4(p+12);
towMsF = U4(p+16);
towSubMsF = U4(p+20);
accEst = U4(p+24);

/* extract flags to variables */
newFallingEdge = ((flags >> 2) & 0x01);
timeBase = ((flags >> 3) & 0x03);
time = ((flags >> 6) & 0x01);
newRisingEdge = ((flags >> 7) & 0x01);

if (newFallingEdge)
{
eventime = gpst2time(wnF,towMsF*1E-3+towSubMsF*1E-9);
raw->obs.flag = 5; /* Event flag */
raw->obs.data[0].eventime = eventime;
raw->obs.rcvcount = count;
raw->obs.tmcount++;
raw->obs.data[0].timevalid = time;
} else {
raw->obs.flag = 0;
}
return 0;
}

/* decode ublox raw message --------------------------------------------------*/
static int decode_ubx(raw_t *raw)
{
Expand All @@ -1004,6 +1052,7 @@ static int decode_ubx(raw_t *raw)
case ID_TRKMEAS : return decode_trkmeas (raw);
case ID_TRKD5 : return decode_trkd5 (raw);
case ID_TRKSFRBX: return decode_trksfrbx(raw);
case ID_TIMTM2 : return decode_timtm2 (raw);
}
if (raw->outtype) {
sprintf(raw->msgtype,"UBX 0x%02X 0x%02X (%4d)",type>>8,type&0xF,
Expand Down
46 changes: 41 additions & 5 deletions src/rinex.c
Expand Up @@ -1856,11 +1856,13 @@ extern int outrnxobsh(FILE *fp, const rnxopt_t *opt, const nav_t *nav)
const char *glo_codes[]={"C1C","C1P","C2C","C2P"};
double ep[6],pos[3]={0},del[3]={0};
int i,j,k,n,prn[MAXPRNGLO];
char date[32],*sys,*tsys="GPS";
char date[32],prog[20],*sys,*tsys="GPS";

trace(3,"outrnxobsh:\n");

timestr_rnx(date);
strcpy(prog,opt->prog);
strcat(prog," Emlid");

if (opt->rnxver<=2.99) { /* ver.2 */
sys=opt->navsys==SYS_GPS?"G (GPS)":"M (MIXED)";
Expand All @@ -1877,7 +1879,7 @@ extern int outrnxobsh(FILE *fp, const rnxopt_t *opt, const nav_t *nav)
}
fprintf(fp,"%9.2f%-11s%-20s%-20s%-20s\n",opt->rnxver,"","OBSERVATION DATA",
sys,"RINEX VERSION / TYPE");
fprintf(fp,"%-20.20s%-20.20s%-20.20s%-20s\n",opt->prog,opt->runby,date,
fprintf(fp,"%-20.20s%-20.20s%-20.20s%-20s\n",prog,opt->runby,date,
"PGM / RUN BY / DATE");

for (i=0;i<MAXCOMMENT;i++) {
Expand Down Expand Up @@ -2020,6 +2022,27 @@ static int obsindex(double ver, int sys, const unsigned char *code,
}
return -1;
}
/* output rinex event time ---------------------------------------------------*/
static void outrinexevent(FILE *fp, const rnxopt_t *opt, const obsd_t *obs,
const double epdiff)
{
int n;
double epe[6];

time2epoch(obs[0].eventime,epe);
n = obs->timevalid ? 0 : 1;

if (opt->rnxver<=2.99) { /* ver.2 */
if (epdiff < 0) fprintf(fp,"\n");
fprintf(fp," %02d %2.0f %2.0f %2.0f %2.0f%11.7f %d%3d",
(int)epe[0]%100,epe[1],epe[2],epe[3],epe[4],epe[5],5,n);
if (epdiff >= 0) fprintf(fp,"\n");
} else { /* ver.3 */
fprintf(fp,"> %04.0f %2.0f %2.0f %2.0f %2.0f%11.7f %d%3d\n",
epe[0],epe[1],epe[2],epe[3],epe[4],epe[5],5,n);
}
if (n) fprintf(fp,"%-60.60s%-20s\n"," Time mark is not valid","COMMENT");
}
/* output rinex obs body -------------------------------------------------------
* output rinex obs body
* args : FILE *fp I output file pointer
Expand All @@ -2033,7 +2056,7 @@ extern int outrnxobsb(FILE *fp, const rnxopt_t *opt, const obsd_t *obs, int n,
int flag)
{
const char *mask;
double ep[6];
double epdiff,ep[6];
char sats[MAXOBS][4]={""};
int i,j,k,m,ns,sys,ind[MAXOBS],s[MAXOBS]={0};

Expand All @@ -2057,17 +2080,25 @@ extern int outrnxobsb(FILE *fp, const rnxopt_t *opt, const obsd_t *obs, int n,
if (!opt->nobs[opt->rnxver<=2.99?0:s[ns]]) continue;
ind[ns++]=i;
}

/* if epoch of event less than epoch of observation, then first output
time mark, else first output observation record */
epdiff = timediff(obs[0].time,obs[0].eventime);
if (flag == 5 && epdiff >= 0) {
outrinexevent(fp, opt, obs, epdiff);
}

if (opt->rnxver<=2.99) { /* ver.2 */
fprintf(fp," %02d %2.0f %2.0f %2.0f %2.0f%11.7f %d%3d",
(int)ep[0]%100,ep[1],ep[2],ep[3],ep[4],ep[5],flag,ns);
(int)ep[0]%100,ep[1],ep[2],ep[3],ep[4],ep[5],0,ns);
for (i=0;i<ns;i++) {
if (i>0&&i%12==0) fprintf(fp,"\n%32s","");
fprintf(fp,"%-3s",sats[i]);
}
}
else { /* ver.3 */
fprintf(fp,"> %04.0f %2.0f %2.0f %2.0f %2.0f%11.7f %d%3d%21s\n",
ep[0],ep[1],ep[2],ep[3],ep[4],ep[5],flag,ns,"");
ep[0],ep[1],ep[2],ep[3],ep[4],ep[5],0,ns,"");
}
for (i=0;i<ns;i++) {
sys=satsys(obs[ind[i]].sat,NULL);
Expand Down Expand Up @@ -2103,6 +2134,11 @@ extern int outrnxobsb(FILE *fp, const rnxopt_t *opt, const obsd_t *obs, int n,
}
if (opt->rnxver>2.99&&fprintf(fp,"\n")==EOF) return 0;
}

if (flag == 5 && epdiff < 0) {
outrinexevent(fp, opt, obs, epdiff);
}

if (opt->rnxver>2.99) return 1;

return fprintf(fp,"\n")!=EOF;
Expand Down
5 changes: 5 additions & 0 deletions src/rtklib.h
Expand Up @@ -517,6 +517,8 @@ typedef struct { /* time struct */

typedef struct { /* observation data record */
gtime_t time; /* receiver sampling time (GPST) */
gtime_t eventime; /* time of event (GPST) */
int timevalid; /* time is valid (Valid GNSS fix) for time mark */
unsigned char sat,rcv; /* satellite/receiver number */
unsigned char SNR [NFREQ+NEXOBS]; /* signal strength (0.25 dBHz) */
unsigned char LLI [NFREQ+NEXOBS]; /* loss of lock indicator */
Expand All @@ -528,6 +530,9 @@ typedef struct { /* observation data record */

typedef struct { /* observation data */
int n,nmax; /* number of obervation data/allocated */
int flag; /* epoch flag (0:ok,1:power failure,>1:event flag) */
int rcvcount; /* count of rcv event */
int tmcount; /* time mark count */
obsd_t *data; /* observation data records */
} obs_t;

Expand Down

0 comments on commit 5cd909c

Please sign in to comment.