Exemplo n.º 1
0
/* main ----------------------------------------------------------------------*/
int main(int argc, char **argv)
{
    gtime_t ts={0},te={0};
    obs_t obs={0};
    nav_t nav={0};
    sta_t sta={{0}};
    double es[6]={0},ee[6]={0},tint=0.0;
    char *infile[16]={0},*outfile="",buff[1024],*p;
    int i,n=0,m=0,type[16],trlevel=0,staid=0,ret=0;
    
    for (i=1;i<argc;i++) {
        if (!strcmp(argv[i],"-ts")&&i+2<argc) {
            sscanf(argv[++i],"%lf/%lf/%lf",es  ,es+1,es+2);
            sscanf(argv[++i],"%lf:%lf:%lf",es+3,es+4,es+6);
        }
        else if (!strcmp(argv[i],"-te")&&i+2<argc) {
            sscanf(argv[++i],"%lf/%lf/%lf",ee  ,ee+1,ee+2);
            sscanf(argv[++i],"%lf:%lf:%lf",ee+3,ee+4,ee+5);
        }
        else if (!strcmp(argv[i],"-ti" )&&i+1<argc) tint =atof(argv[++i]);
        else if (!strcmp(argv[i],"-sta")&&i+1<argc) staid=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-out")&&i+1<argc) outfile=argv[++i];
        else if (!strcmp(argv[i],"-typ")&&i+1<argc) {
            strcpy(buff,argv[++i]);
            for (p=strtok(buff,",");p;p=strtok(NULL,",")) type[m++]=atoi(p);
        }
        else if (!strcmp(argv[i],"-x"  )&&i+1<argc) trlevel=atoi(argv[++i]);
        else if (!strncmp(argv[i],"-",1)) print_help();
        else infile[n++]=argv[i];
    }
    if (trlevel>0) {
        traceopen(TRACEFILE);
        tracelevel(trlevel);
    }
    if (es[0]>0.0) ts=epoch2time(es);
    if (ee[0]>0.0) te=epoch2time(ee);
    
    /* read rinex files */
    for (i=0;i<n;i++) {
        readrnxt(infile[i],0,ts,te,tint,"",&obs,&nav,&sta);
    }
    sortobs(&obs);
    uniqnav(&nav);
    
    /* convert to rtcm messages */
    if (!conv_rtcm(type,m,outfile,&obs,&nav,&sta,staid)) ret=-1;
    
    free(obs.data);
    freenav(&nav,0xFF);
    
    if (trlevel>0) {
        traceclose();
    }
    return ret;
}
Exemplo n.º 2
0
int main(int argc, char ** argv)
{
	ros::init(argc, argv, "rtk_node");

	traceopen("trace");
	tracelevel(5);

	rtksvr_t svr;
	rtksvrinit( &svr );

	while(ros::ok())
	{
		ros::spinOnce();
	}
}
Exemplo n.º 3
0
static jboolean open_trace_file(JNIEnv* env, int trace_level, gtime_t timestamp)
{
   double ep[6];
   char filename[1024];

   if (trace_level <= 0)
      return JNI_FALSE;

   time2epoch(utc2gpst(timestamp),ep);
   sprintf(filename,"rtkgps_%04.0f%02.0f%02.0f%02.0f%02.0f%02.0f.trace",
	 ep[0],ep[1],ep[2],ep[3],ep[4],ep[5]);
   if (!get_path_in_storage_dir(env, filename, sizeof(filename)))
      return JNI_FALSE;

   LOGV("open_trace_file() %s", filename);
   traceopen(filename);
   tracelevel(trace_level);

   return JNI_TRUE;
}
Exemplo n.º 4
0
int loadrosopts(opt_t *opts);

int start_rtkrcv(int argc, char **argv)
{
    int i;

    for (i=1;i<argc;i++) {
        if (!strcmp(argv[i],"-m")&&i+1<argc) moniport=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-r")&&i+1<argc) outstat=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-t")&&i+1<argc) rcv_trace=atoi(argv[++i]);
        else fprintf(stderr,"Unknown option: %s\n",argv[i]);
    }
    if (rcv_trace>0) {
        traceopen(TRACEFILE);
        tracelevel(rcv_trace);
    }
    /* initialize rtk server and monitor port */
    rtksvrinit(&svr);
    strinit(&moni);

    /* load options from ROS */
    resetsysopts();
    loadrosopts(rcvopts);
    loadrosopts(sysopts);
    getsysopts(&prcopt,solopt,&filopt);

    /* read navigation data */
    if (!readnav(NAVIFILE,&svr.nav)) {
        fprintf(stderr,"no navigation data: %s\n",NAVIFILE);
    }
    if (outstat>0) {
        rtkopenstat(STATFILE,outstat);
    }
    /* open monitor port */
    if (moniport>0&&!openmoni(moniport)) {
        fprintf(stderr,"monitor port open error: %d\n",moniport);
        return 0;
    }
    /* start rtk server */
    if (!startsvr(&svr_vt)) return 0;
Exemplo n.º 5
0
/* execute processing session ------------------------------------------------*/
static int execses(gtime_t ts, gtime_t te, double ti, const prcopt_t *popt,
                   const solopt_t *sopt, const filopt_t *fopt, int flag,
                   char **infile, const int *index, int n, char *outfile)
{
    FILE *fp;
    prcopt_t popt_=*popt;
    char tracefile[1024],statfile[1024];
    
    trace(3,"execses : n=%d outfile=%s\n",n,outfile);
    
    /* open debug trace */
    if (flag&&sopt->trace>0) {
        if (*outfile) {
            strcpy(tracefile,outfile);
            strcat(tracefile,".trace");
        }
        else {
            strcpy(tracefile,fopt->trace);
        }
        traceclose();
        traceopen(tracefile);
        tracelevel(sopt->trace);
    }
    /* read obs and nav data */
    if (!readobsnav(ts,te,ti,infile,index,n,&popt_,&obss,&navs,stas)) return 0;
    
    /* set antenna paramters */
    if (popt_.sateph==EPHOPT_PREC||popt_.sateph==EPHOPT_SSRCOM) {
        setpcv(obss.n>0?obss.data[0].time:timeget(),&popt_,&navs,&pcvss,&pcvsr,
               stas);
    }
    /* read ocean tide loading parameters */
    if (popt_.mode>PMODE_SINGLE&&fopt->blq) {
        readotl(&popt_,fopt->blq,stas);
    }
    /* rover/reference fixed position */
    if (popt_.mode==PMODE_FIXED) {
        if (!antpos(&popt_,1,&obss,&navs,stas,fopt->stapos)) {
            freeobsnav(&obss,&navs);
            return 0;
        }
    }
    else if (PMODE_DGPS<=popt_.mode&&popt_.mode<=PMODE_STATIC) {
        if (!antpos(&popt_,2,&obss,&navs,stas,fopt->stapos)) {
            freeobsnav(&obss,&navs);
            return 0;
        }
    }
    /* open solution statistics */
    if (flag&&sopt->sstat>0) {
        strcpy(statfile,outfile);
        strcat(statfile,".stat");
        rtkclosestat();
        rtkopenstat(statfile,sopt->sstat);
    }
    /* write header to output file */
    if (flag&&!outhead(outfile,infile,n,&popt_,sopt)) {
        freeobsnav(&obss,&navs);
        return 0;
    }
    iobsu=iobsr=isbs=ilex=revs=aborts=0;
    
    if (popt_.mode==PMODE_SINGLE||popt_.soltype==0) {
        if ((fp=openfile(outfile))) {
            procpos(fp,&popt_,sopt,0); /* forward */
            fclose(fp);
        }
    }
    else if (popt_.soltype==1) {
        if ((fp=openfile(outfile))) {
            revs=1; iobsu=iobsr=obss.n-1; isbs=sbss.n-1; ilex=lexs.n-1;
            procpos(fp,&popt_,sopt,0); /* backward */
            fclose(fp);
        }
    }
    else { /* combined */
        solf=(sol_t *)malloc(sizeof(sol_t)*nepoch);
        solb=(sol_t *)malloc(sizeof(sol_t)*nepoch);
        rbf=(double *)malloc(sizeof(double)*nepoch*3);
        rbb=(double *)malloc(sizeof(double)*nepoch*3);
        
        if (solf&&solb) {
            isolf=isolb=0;
            procpos(NULL,&popt_,sopt,1); /* forward */
            revs=1; iobsu=iobsr=obss.n-1; isbs=sbss.n-1; ilex=lexs.n-1;
            procpos(NULL,&popt_,sopt,1); /* backward */
            
            /* combine forward/backward solutions */
            if (!aborts&&(fp=openfile(outfile))) {
                combres(fp,&popt_,sopt);
                fclose(fp);
            }
        }
        else showmsg("error : memory allocation");
        free(solf);
        free(solb);
        free(rbf);
        free(rbb);
    }
    /* free obs and nav data */
    freeobsnav(&obss,&navs);
    
    return aborts?1:0;
}
Exemplo n.º 6
0
/* str2str -------------------------------------------------------------------*/
int main(int argc, char **argv)
{
    static char cmd[MAXRCVCMD]="";
    const char ss[]={'E','-','W','C','C'};
    strconv_t *conv[MAXSTR]={NULL};
    double pos[3],stapos[3]={0};
    char *paths[MAXSTR],s[MAXSTR][MAXSTRPATH]={{0}},*cmdfile="";
    char *local="",*proxy="",*msg="1004,1019",*opt="",buff[256],*p;
    char strmsg[MAXSTRMSG]="";
    int i,n=0,dispint=5000,trlevel=0,opts[]={10000,10000,2000,32768,10,0,30};
    int types[MAXSTR]={0},stat[MAXSTR]={0},byte[MAXSTR]={0},bps[MAXSTR]={0};
    int fmts[MAXSTR],sta=0;
    
    for (i=0;i<MAXSTR;i++) paths[i]=s[i];
    
    for (i=1;i<argc;i++) {
        if (!strcmp(argv[i],"-in")&&i+1<argc) {
            if (!decodepath(argv[++i],types,paths[0],fmts)) return -1;
        }
        else if (!strcmp(argv[i],"-out")&&i+1<argc&&n<MAXSTR-1) {
            if (!decodepath(argv[++i],types+n+1,paths[n+1],fmts+n+1)) return -1;
            n++;
        }
        else if (!strcmp(argv[i],"-p")&&i+3<argc) {
            pos[0]=atof(argv[++i])*D2R;
            pos[1]=atof(argv[++i])*D2R;
            pos[2]=atof(argv[++i]);
            pos2ecef(pos,stapos);
        }
        else if (!strcmp(argv[i],"-msg")&&i+1<argc) msg=argv[++i];
        else if (!strcmp(argv[i],"-opt")&&i+1<argc) opt=argv[++i];
        else if (!strcmp(argv[i],"-sta")&&i+1<argc) sta=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-d"  )&&i+1<argc) dispint=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-s"  )&&i+1<argc) opts[0]=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-r"  )&&i+1<argc) opts[1]=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-n"  )&&i+1<argc) opts[5]=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-f"  )&&i+1<argc) opts[6]=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-c"  )&&i+1<argc) cmdfile=argv[++i];
        else if (!strcmp(argv[i],"-l"  )&&i+1<argc) local=argv[++i];
        else if (!strcmp(argv[i],"-x"  )&&i+1<argc) proxy=argv[++i];
        else if (!strcmp(argv[i],"-t"  )&&i+1<argc) trlevel=atoi(argv[++i]);
        else if (*argv[i]=='-') printhelp();
    }
    if (!*paths[0]) {
        fprintf(stderr,"specify input stream\n");
        return -1;
    }
    if (n<=0) {
        fprintf(stderr,"specify output stream(s)\n");
        return -1;
    }
    for (i=0;i<n;i++) {
        if (fmts[i+1]<0) continue;
        if (fmts[i+1]!=STRFMT_RTCM3) {
            fprintf(stderr,"unsupported output format\n");
            return -1;
        }
        if (fmts[0]<0) {
            fprintf(stderr,"specify input format\n");
            return -1;
        }
        if (!(conv[i]=strconvnew(fmts[0],fmts[i+1],msg,sta,sta!=0,opt))) {
            fprintf(stderr,"stream conversion error\n");
            return -1;
        }
    }
    signal(SIGTERM,sigfunc);
    signal(SIGINT ,sigfunc);
    signal(SIGHUP ,SIG_IGN);
    signal(SIGPIPE,SIG_IGN);
    
    strsvrinit(&strsvr,n+1);
    
    if (trlevel>0) {
        traceopen(TRFILE);
        tracelevel(trlevel);
    }
    fprintf(stderr,"stream server start\n");
    
    strsetdir(local);
    strsetproxy(proxy);
    
    if (*cmdfile) readcmd(cmdfile,cmd,0);
    
    /* start stream server */
    if (!strsvrstart(&strsvr,opts,types,paths,conv,*cmd?cmd:NULL,stapos)) {
        fprintf(stderr,"stream server start error\n");
        return -1;
    }
    for (intrflg=0;!intrflg;) {
        
        /* get stream server status */
        strsvrstat(&strsvr,stat,byte,bps,strmsg);
        
        /* show stream server status */
        for (i=0,p=buff;i<MAXSTR;i++) p+=sprintf(p,"%c",ss[stat[i]+1]);
        
        fprintf(stderr,"%s [%s] %10d B %7d bps %s\n",
                time_str(utc2gpst(timeget()),0),buff,byte[0],bps[0],strmsg);
        
        sleepms(dispint);
    }
    if (*cmdfile) readcmd(cmdfile,cmd,1);
    
    /* stop stream server */
    strsvrstop(&strsvr,*cmd?cmd:NULL);
    
    for (i=0;i<n;i++) {
        strconvfree(conv[i]);
    }
    if (trlevel>0) {
        traceclose();
    }
    fprintf(stderr,"stream server stop\n");
    return 0;
}
Exemplo n.º 7
0
// convert file -------------------------------------------------------------
void __fastcall TMainWindow::ConvertFile(void)
{
    rnxopt_t rnxopt={0};
    AnsiString InFile_Text=InFile->Text;
    AnsiString OutFile1_Text=OutFile1->Text,OutFile2_Text=OutFile2->Text;
    AnsiString OutFile3_Text=OutFile3->Text,OutFile4_Text=OutFile4->Text;
    AnsiString OutFile5_Text=OutFile5->Text,OutFile6_Text=OutFile6->Text;
    AnsiString OutFile7_Text=OutFile7->Text;
    int i,format,sat;
    char file[1024]="",*ofile[7],ofile_[7][1024]={""},msg[256],*p;
    char buff[256],tstr[32];
    double RNXVER[]={2.10,2.11,2.12,3.00,3.01,3.02};
    FILE *fp;
    
    // abort conversion
    if (BtnConvert->Caption=="Abort") {
        abortf=1;
        return;
    }
    for (i=0;i<7;i++) ofile[i]=ofile_[i];
    
    // recognize input file format
    strcpy(file,InFile_Text.c_str());
    if (!(p=strrchr(file,'.'))) p=file;
    if (Format->ItemIndex==0) { // auto
        if      (!strcmp(p,".rtcm2")) format=STRFMT_RTCM2;
        else if (!strcmp(p,".rtcm3")) format=STRFMT_RTCM3;
        else if (!strcmp(p,".gps"  )) format=STRFMT_OEM4;
        else if (!strcmp(p,".ubx"  )) format=STRFMT_UBX;
        else if (!strcmp(p,".log"  )) format=STRFMT_SS2;
        else if (!strcmp(p,".bin"  )) format=STRFMT_CRES;
        else if (!strcmp(p,".jps"  )) format=STRFMT_JAVAD;
        else if (!strcmp(p,".bnx"  )) format=STRFMT_BINEX;
        else if (!strcmp(p,".binex")) format=STRFMT_BINEX;
        else if (!strcmp(p,".rt17" )) format=STRFMT_RT17;
        else if (!strcmp(p,".obs"  )) format=STRFMT_RINEX;
        else if (!strcmp(p,".OBS"  )) format=STRFMT_RINEX;
        else if (!strcmp(p,".nav"  )) format=STRFMT_RINEX;
        else if (!strcmp(p,".NAV"  )) format=STRFMT_RINEX;
        else if (!strcmp(p+2,"nav" )) format=STRFMT_RINEX;
        else if (!strcmp(p+2,"NAV" )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"o"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"O"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"n"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"N"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"p"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"P"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"g"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"G"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"h"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"H"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"q"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"Q"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"l"   )) format=STRFMT_RINEX;
        else if (!strcmp(p+3,"L"   )) format=STRFMT_RINEX;
        else {
            showmsg("file format can not be recognized");
            return;
        }
    }
    else {
        for (i=0;formatstrs[i];i++) {
            if (Format->Text==formatstrs[i]) break;
        }
        if (formatstrs[i]) format=i; else return;
    }
    rnxopt.rnxver=RNXVER[RnxVer];
    
    if (format==STRFMT_RTCM2||format==STRFMT_RTCM3||format==STRFMT_RT17) {
        
        // input start date/time for rtcm 2 ro rtcm 3
        if (StartDialog->ShowModal()!=mrOk) return;
        rnxopt.trtcm=StartDialog->Time;
    }
    if (OutFile1->Enabled&&OutFileEna1->Checked) strcpy(ofile[0],OutFile1_Text.c_str());
    if (OutFile2->Enabled&&OutFileEna2->Checked) strcpy(ofile[1],OutFile2_Text.c_str());
    if (OutFile3->Enabled&&OutFileEna3->Checked) strcpy(ofile[2],OutFile3_Text.c_str());
    if (OutFile4->Enabled&&OutFileEna4->Checked) strcpy(ofile[3],OutFile4_Text.c_str());
    if (OutFile5->Enabled&&OutFileEna5->Checked) strcpy(ofile[4],OutFile5_Text.c_str());
    if (OutFile6->Enabled&&OutFileEna6->Checked) strcpy(ofile[5],OutFile6_Text.c_str());
    if (OutFile7->Enabled&&OutFileEna7->Checked) strcpy(ofile[6],OutFile7_Text.c_str());
    
    // check overwrite output file
    for (i=0;i<6;i++) {
        if (!*ofile[i]||!(fp=fopen(ofile[i],"r"))) continue;
        fclose(fp);
        ConfDialog->Label2->Caption=ofile[i];
        if (ConfDialog->ShowModal()!=mrOk) return;
    }
    GetTime(&rnxopt.ts,&rnxopt.te,&rnxopt.tint,&rnxopt.tunit);
    strncpy(rnxopt.staid,RnxCode.c_str(),31);
    sprintf(rnxopt.prog,"%s %s",PRGNAME,VER_RTKLIB);
    strncpy(rnxopt.runby,RunBy.c_str(),31);
    strncpy(rnxopt.marker,Marker.c_str(),63);
    strncpy(rnxopt.markerno,MarkerNo.c_str(),31);
    strncpy(rnxopt.markertype,MarkerType.c_str(),31);
    for (i=0;i<2;i++) strncpy(rnxopt.name[i],Name[i].c_str(),31);
    for (i=0;i<3;i++) strncpy(rnxopt.rec [i],Rec [i].c_str(),31);
    for (i=0;i<3;i++) strncpy(rnxopt.ant [i],Ant [i].c_str(),31);
    if (AutoPos) {
        for (i=0;i<3;i++) rnxopt.apppos[i]=AppPos[i];
    }
    for (i=0;i<3;i++) rnxopt.antdel[i]=AntDel[i];
    strncpy(rnxopt.rcvopt,RcvOption.c_str(),255);
    rnxopt.navsys=NavSys;
    rnxopt.obstype=ObsType;
    rnxopt.freqtype=FreqType;
    p=rnxopt.comment[0];
    sprintf(p,"log: %-53.53s",file);
    p=rnxopt.comment[1];
    p+=sprintf(p,"format: %s",formatstrs[format]);
    if (*rnxopt.rcvopt) sprintf(p,", option: %s",rnxopt.rcvopt);
    for (i=0;i<2;i++) strncpy(rnxopt.comment[i+2],Comment[i].c_str(),63);
    for (i=0;i<6;i++) strcpy(rnxopt.mask[i],CodeMask[i].c_str());
    rnxopt.autopos=AutoPos;
    rnxopt.scanobs=ScanObs;
    rnxopt.outiono=OutIono;
    rnxopt.outtime=OutTime;
    rnxopt.outleaps=OutLeaps;
    
    strcpy(buff,ExSats.c_str());
    for (p=strtok(buff," ");p;p=strtok(NULL," ")) {
        if (!(sat=satid2no(p))) continue;
        rnxopt.exsats[sat-1]=1;
    }
    abortf=0;
    BtnConvert  ->Caption="Abort";
    Panel1      ->Enabled=false;
    Panel2      ->Enabled=false;
    BtnPlot     ->Enabled=false;
    BtnPost     ->Enabled=false;
    BtnOptions  ->Enabled=false;
    BtnExit     ->Enabled=false;
    Format      ->Enabled=false;
    BtnKey      ->Enabled=false;
    LabelInFile ->Enabled=false;
    LabelOutDir ->Enabled=false;
    LabelOutFile->Enabled=false;
    LabelFormat ->Enabled=false;
    Message     ->Caption="";
    
    if (TraceLevel>0) {
        traceopen(TRACEFILE);
        tracelevel(TraceLevel);
    }
    // convert to rinex
    (void)convrnx(format,&rnxopt,file,ofile);
    
    if (TraceLevel>0) {
        traceclose();
    }
    BtnConvert  ->Caption="&Convert";
    Panel1      ->Enabled=true;
    Panel2      ->Enabled=true;
    BtnPlot     ->Enabled=true;
    BtnPost     ->Enabled=true;
    BtnOptions  ->Enabled=true;
    BtnExit     ->Enabled=true;
    Format      ->Enabled=true;
    BtnKey      ->Enabled=true;
    LabelInFile ->Enabled=true;
    LabelOutDir ->Enabled=true;
    LabelOutFile->Enabled=true;
    LabelFormat ->Enabled=true;
    
#if 0
    // set time-start/end if time not specified
    if (!TimeStartF->Checked&&rnxopt.tstart.time!=0) {
        time2str(rnxopt.tstart,tstr,0);
        tstr[10]='\0';
        TimeY1->Text=tstr;
        TimeH1->Text=tstr+11;
    }
    if (!TimeEndF->Checked&&rnxopt.tend.time!=0) {
        time2str(rnxopt.tend,tstr,0);
        tstr[10]='\0';
        TimeY2->Text=tstr;
        TimeH2->Text=tstr+11;
    }
#endif
    RnxTime=rnxopt.tstart;
    
    AddHist(InFile);
}
Exemplo n.º 8
0
/* str2str -------------------------------------------------------------------*/
int main(int argc, char **argv)
{
    static char cmd[MAXRCVCMD]="";
    const char ss[]={'E','-','W','C','C'};
    strconv_t *conv[MAXSTR]={NULL};
    double pos[3],stapos[3]={0},off[3]={0};
    char *paths[MAXSTR],s[MAXSTR][MAXSTRPATH]={{0}},*cmdfile="";
    char *local="",*proxy="",*msg="1004,1019",*opt="",buff[256],*p;
    char strmsg[MAXSTRMSG]="",*antinfo="",*rcvinfo="";
    char *ant[]={"","",""},*rcv[]={"","",""};
    int i,j,n=0,dispint=5000,trlevel=0,opts[]={10000,10000,2000,32768,10,0,30};
    int types[MAXSTR]={STR_FILE,STR_FILE},stat[MAXSTR]={0},byte[MAXSTR]={0};
    int bps[MAXSTR]={0},fmts[MAXSTR]={0},sta=0;
    
    int ctl_port=2097;
    char ctl_buffer[256];
    char *nodefile;
    int sockfd;
	char *rip;
	struct sockaddr_in serv_addr;
    rip=ctl_buffer;
    fd_set sockset; 
    roverMsg rmsg;
    
    for (i=0;i<MAXSTR;i++) paths[i]=s[i];
    
    for (i=1;i<argc;i++) {
        if (!strcmp(argv[i],"-in")&&i+1<argc) {
            if (!decodepath(argv[++i],types,paths[0],fmts)) return -1;
        }
        else if (!strcmp(argv[i],"-out")&&i+1<argc&&n<MAXSTR-1) {
            if (!decodepath(argv[++i],types+n+1,paths[n+1],fmts+n+1)) return -1;
            n++;
        }
        else if (!strcmp(argv[i],"-p")&&i+3<argc) {
            pos[0]=atof(argv[++i])*D2R;
            pos[1]=atof(argv[++i])*D2R;
            pos[2]=atof(argv[++i]);
            pos2ecef(pos,stapos);
        }
        else if (!strcmp(argv[i],"-o")&&i+3<argc) {
            off[0]=atof(argv[++i]);
            off[1]=atof(argv[++i]);
            off[2]=atof(argv[++i]);
        }
        else if (!strcmp(argv[i],"-msg")&&i+1<argc) msg=argv[++i];
        else if (!strcmp(argv[i],"-opt")&&i+1<argc) opt=argv[++i];
        else if (!strcmp(argv[i],"-sta")&&i+1<argc) sta=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-d"  )&&i+1<argc) dispint=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-s"  )&&i+1<argc) opts[0]=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-r"  )&&i+1<argc) opts[1]=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-n"  )&&i+1<argc) opts[5]=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-f"  )&&i+1<argc) opts[6]=atoi(argv[++i]);
        else if (!strcmp(argv[i],"-c"  )&&i+1<argc) cmdfile=argv[++i];
        else if (!strcmp(argv[i],"-a"  )&&i+1<argc) antinfo=argv[++i];
        else if (!strcmp(argv[i],"-i"  )&&i+1<argc) rcvinfo=argv[++i];
        else if (!strcmp(argv[i],"-l"  )&&i+1<argc) local=argv[++i];
        else if (!strcmp(argv[i],"-x"  )&&i+1<argc) proxy=argv[++i];
        else if (!strcmp(argv[i],"-t"  )&&i+1<argc) trlevel=atoi(argv[++i]);
        
        else if (!strcmp(argv[i],"-port")&&i+1<argc) ctl_port=atoi(argv[++i]);
        else if (!strcmp(argv[i], "-nodefile")&& i+1<argc) nodefile=argv[++i];
        else if (!strcmp(argv[i], "-rip")&&i+1<argc) rip=argv[++i];
        
        else if (*argv[i]=='-') printhelp();
    }
    if (n<=0) n=1; /* stdout */
    fprintf(stderr,"argv parsed\n");
    if(rip==ctl_buffer)
    {
    	fprintf(stderr, "No rover ip address\n");
    	return(-1);
    }
    
	serv_addr.sin_family=AF_INET;
	inet_aton(rip, &serv_addr.sin_addr);
	serv_addr.sin_port=htons(ctl_port);
	
	sockfd=socket(AF_INET,SOCK_STREAM, 0);
	if (sockfd < 0) 
        fprintf(stderr,"ERROR opening socket\n");
        
    FD_ZERO(&sockset);
    FD_SET(sockfd, &sockset);
    
    
    for (i=0;i<n;i++) {
        if (fmts[i+1]<=0) continue;
        if (fmts[i+1]!=STRFMT_RTCM3) {
            fprintf(stderr,"unsupported output format\n");
            return -1;
        }
        if (fmts[0]<0) {
            fprintf(stderr,"specify input format\n");
            return -1;
        }
        if (!(conv[i]=strconvnew(fmts[0],fmts[i+1],msg,sta,sta!=0,opt))) {
            fprintf(stderr,"stream conversion error\n");
            return -1;
        }
        strcpy(buff,antinfo);
        for (p=strtok(buff,","),j=0;p&&j<3;p=strtok(NULL,",")) ant[j++]=p;
        strcpy(conv[i]->out.sta.antdes,ant[0]);
        strcpy(conv[i]->out.sta.antsno,ant[1]);
        conv[i]->out.sta.antsetup=atoi(ant[2]);
        strcpy(buff,rcvinfo);
        for (p=strtok(buff,","),j=0;p&&j<3;p=strtok(NULL,",")) rcv[j++]=p;
        strcpy(conv[i]->out.sta.rectype,rcv[0]);
        strcpy(conv[i]->out.sta.recver ,rcv[1]);
        strcpy(conv[i]->out.sta.recsno ,rcv[2]);
        matcpy(conv[i]->out.sta.pos,pos,3,1);
        matcpy(conv[i]->out.sta.del,off,3,1);
    }
    signal(SIGTERM,sigfunc);
    signal(SIGINT ,sigfunc);
    signal(SIGHUP ,SIG_IGN);
    signal(SIGPIPE,SIG_IGN);
    
    strsvrinit(&strsvr,n+1);
    
    if (trlevel>0) {
        traceopen(TRFILE);
        tracelevel(trlevel);
    }
    fprintf(stderr,"stream server start\n");
    
    strsetdir(local);
    strsetproxy(proxy);
    
    if (*cmdfile) readcmd(cmdfile,cmd,0);
    
    /* start stream server */
    if (!strsvrstart(&strsvr,opts,types,paths,conv,*cmd?cmd:NULL,stapos)) {
        fprintf(stderr,"stream server start error\n");
        return -1;
    }
    
    // Socket server start
    if(connect(sockfd,(struct sockaddr*)&serv_addr,sizeof(serv_addr))<0)
		fprintf(stderr,"error connecting\n");
	if (bind(sockfd, (struct sockaddr *) &serv_addr,
          sizeof(serv_addr)) < 0) 
          fprintf(stderr,"ERROR on binding");
          
    for (intrflg=0;!intrflg;) {
        
        /* get stream server status */
        strsvrstat(&strsvr,stat,byte,bps,strmsg);
        
        /* show stream server status */
        for (i=0,p=buff;i<MAXSTR;i++) p+=sprintf(p,"%c",ss[stat[i]+1]);
        
        fprintf(stderr,"%s [%s] %10d B %7d bps %s\n",
                time_str(utc2gpst(timeget()),0),buff,byte[0],bps[0],strmsg);
        
        sleepms(dispint);
    }
    if (*cmdfile) readcmd(cmdfile,cmd,1);
    
    /* stop stream server */
    strsvrstop(&strsvr,*cmd?cmd:NULL);
    
    for (i=0;i<n;i++) {
        strconvfree(conv[i]);
    }
    if (trlevel>0) {
        traceclose();
    }
    fprintf(stderr,"stream server stop\n");
    return 0;
}
Exemplo n.º 9
0
/* main ----------------------------------------------------------------------*/
int main(int argc, char **argv)
{
    FILE *fp=NULL;
    nav_t nav={0};
    lex_t lex={0};
    gtime_t t0,time;
    double ep0[]={2000,1,1,0,0,0},tspan=24.0,tint=7200,dpos=1;
    double rpos[]={35,137};
    char *ifile="",*ofile="";
    int i,trl=0,index=0,nlat=45,nlon=45;
    
    t0=epoch2time(ep0);
    
    for (i=1;i<argc;i++) {
       if (!strcmp(argv[i],"-t0")&&i+2<argc) {
           if (sscanf(argv[++i],"%lf/%lf/%lf",ep0  ,ep0+1,ep0+2)<3||
               sscanf(argv[++i],"%lf:%lf:%lf",ep0+3,ep0+4,ep0+5)<1) {
               fprintf(stderr,"invalid time\n");
               return -1;
           }
       }
       else if (!strcmp(argv[i],"-ts")&&i+1<argc) tspan=atof(argv[++i]);
       else if (!strcmp(argv[i],"-ti")&&i+1<argc) tint =atof(argv[++i]);
       else if (!strcmp(argv[i],"-u" )&&i+2<argc) {
           rpos[0]=atof(argv[++i]);
           rpos[1]=atof(argv[++i]);
       }
       else if (!strcmp(argv[i],"-n" )&&i+2<argc) {
           nlat=atoi(argv[++i]);
           nlon=atoi(argv[++i]);
       }
       else if (!strcmp(argv[i],"-d" )&&i+1<argc) dpos =atof(argv[++i]);
       else if (!strcmp(argv[i],"-o" )&&i+1<argc) ofile=argv[++i];
       else if (!strcmp(argv[i],"-x" )&&i+1<argc) trl  =atof(argv[++i]);
       else ifile=argv[i];
    }
    if (trl>0) {
       traceopen("diffeph.trace");
       tracelevel(trl);
    }
    t0=epoch2time(ep0);
    
    if (!lexreadmsg(ifile,0,&lex)) {
        fprintf(stderr,"file read error: %s\n",ifile);
        return -1;
    }
    if (!(fp=fopen(ofile,"w"))) {
        fprintf(stderr,"file open error: %s\n",ofile);
        return -1;
    }
    fprintf(fp,"epoch=[%.0f %.0f %.0f %.0f %.0f %.0f];\n",
            ep0[0],ep0[1],ep0[2],ep0[3],ep0[4],ep0[5]);
    
    for (i=0;i<(int)(tspan*3600.0/tint);i++) {
       time=timeadd(t0,tint*i);
       
       fprintf(stderr,"time=%s\r",time_str(time,0));
       
       index=updatelex(index,time,&lex,&nav);
       
       printtec(i+1,time,tint*i,&nav,rpos,nlat,nlon,dpos,fp);
    }
    fclose(fp);
    if (trl>0) traceclose();
    return 0;
}