Rtksvrstart

rtksvr.c

````
extern int rtksvrstart(rtksvr_t *svr, int cycle, int buffsize, int *strs,
                      char **paths, int *formats, int navsel, char **cmds,
                      char **rcvopts, int nmeacycle, int nmeareq,
                      const double *nmeapos, prcopt_t *prcopt,
                      solopt_t *solopt, stream_t *moni)
{
   gtime_t time,time0={0};
   int i,j,rw;

   tracet(3,"rtksvrstart: cycle=%d buffsize=%d navsel=%d nmeacycle=%d nmeareq=%d\n",
          cycle,buffsize,navsel,nmeacycle,nmeareq);

   if (svr->state) return 0;

   strinitcom();
   svr->cycle=cycle>1?cycle:1;
   svr->nmeacycle=nmeacycle>1000?nmeacycle:1000;
   svr->nmeareq=nmeareq;
   for (i=0;i<3;i++) svr->nmeapos[i]=nmeapos[i];
   svr->buffsize=buffsize>4096?buffsize:4096;
   for (i=0;i<3;i++) svr->format[i]=formats[i];
   svr->navsel=navsel;
   svr->nsbs=0;
   svr->nsol=0;
   svr->prcout=0;
   rtkfree(&svr->rtk);
   rtkinit(&svr->rtk,prcopt);

   for (i=0;i<3;i++) { /* input/log streams */
       svr->nb[i]=svr->npb[i]=0;
           !(svr->pbuf[i]=(unsigned char *)malloc(buffsize))) {
           tracet(1,"rtksvrstart: malloc error\n");
           return 0;
       }
       for (j=0;j<10;j++) svr->nmsg[i][j]=0;
       for (j=0;j<MAXOBSBUF;j++) svr->obs[i][j].n=0;

       /* initialize receiver raw and rtcm control */
       init_raw (svr->raw +i);
       init_rtcm(svr->rtcm+i);

       /* set receiver and rtcm option */
       strcpy(svr->raw [i].opt,rcvopts[i]);
       strcpy(svr->rtcm[i].opt,rcvopts[i]);

       /* connect dgps corrections */
       svr->rtcm[i].dgps=svr->nav.dgps;
   }
   for (i=0;i<2;i++) { /* output peek buffer */
       if (!(svr->sbuf[i]=(unsigned char *)malloc(buffsize))) {
           tracet(1,"rtksvrstart: malloc error\n");
           return 0;
       }
   }
   /* set solution options */
   for (i=0;i<2;i++) {
       svr->solopt[i]=solopt[i];
   }
   /* set base station position */
   for (i=0;i<6;i++) {
       svr->rtk.rb[i]=i<3?prcopt->rb[i]:0.0;
   }
   /* update navigation data */
   for (i=0;i<MAXSAT *2;i++) svr->nav.eph [i].ttr=time0;
   for (i=0;i<NSATGLO*2;i++) svr->nav.geph[i].tof=time0;
   for (i=0;i<NSATSBS*2;i++) svr->nav.seph[i].tof=time0;
   updatenav(&svr->nav);

   /* set monitor stream */
   svr->moni=moni;

   /* open input streams */
   for (i=0;i<8;i++) {
       rw=i<3?STR_MODE_R:STR_MODE_W;
       if (strs[i]!=STR_FILE) rw|=STR_MODE_W;
       if (!stropen(svr->stream+i,strs[i],rw,paths[i])) {
           for (i--;i>=0;i--) strclose(svr->stream+i);
           return 0;
       }
       /* set initial time for rtcm and raw */
       if (i<3) {
           time=utc2gpst(timeget());
           svr->raw [i].time=strs[i]==STR_FILE?strgettime(svr->stream+i):time;
           svr->rtcm[i].time=strs[i]==STR_FILE?strgettime(svr->stream+i):time;
       }
   }
   /* sync input streams */
   strsync(svr->stream,svr->stream+1);
   strsync(svr->stream,svr->stream+2);

   /* write start commands to input streams */
   for (i=0;i<3;i++) {
       if (cmds[i]) strsendcmd(svr->stream+i,cmds[i]);
   }
   /* write solution header to solution streams */
   for (i=3;i<5;i++) {
       writesolhead(svr->stream+i,svr->solopt+i-3);
   }
   /* create rtk server thread */
#ifdef WIN32
   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);
       return 0;
   }
   return 1;
}

````