2017-05-12 10:17:42 +00:00
|
|
|
/*!
|
|
|
|
* \file rtklib_solution.cc
|
|
|
|
* \brief solution functions
|
|
|
|
* \authors <ul>
|
|
|
|
* <li> 2007-2013, T. Takasu
|
|
|
|
* <li> 2017, Javier Arribas
|
|
|
|
* <li> 2017, Carles Fernandez
|
|
|
|
* </ul>
|
|
|
|
*
|
|
|
|
* This is a derived work from RTKLIB http://www.rtklib.com/
|
|
|
|
* The original source code at https://github.com/tomojitakasu/RTKLIB is
|
|
|
|
* released under the BSD 2-clause license with an additional exclusive clause
|
|
|
|
* that does not apply here. This additional clause is reproduced below:
|
|
|
|
*
|
|
|
|
* " The software package includes some companion executive binaries or shared
|
|
|
|
* libraries necessary to execute APs on Windows. These licenses succeed to the
|
|
|
|
* original ones of these software. "
|
|
|
|
*
|
|
|
|
* Neither the executive binaries nor the shared libraries are required by, used
|
|
|
|
* or included in GNSS-SDR.
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
* Copyright (C) 2007-2013, T. Takasu
|
|
|
|
* Copyright (C) 2017, Javier Arribas
|
|
|
|
* Copyright (C) 2017, Carles Fernandez
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are
|
|
|
|
* met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
#include "rtklib_solution.h"
|
2017-05-12 15:47:09 +00:00
|
|
|
#include "rtklib_rtkcmn.h"
|
|
|
|
#include "rtklib_rtksvr.h"
|
2018-12-09 21:00:09 +00:00
|
|
|
#include <cctype>
|
2019-08-24 15:34:12 +00:00
|
|
|
#include <cmath>
|
2019-02-03 18:24:44 +00:00
|
|
|
#include <cstring>
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* constants and macros ------------------------------------------------------*/
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
#define SQR_SOL(x) ((x) < 0.0 ? -(x) * (x) : (x) * (x))
|
2019-09-13 06:56:37 +00:00
|
|
|
#define SQRT_SOL(x) ((x) < 0.0 ? 0.0 : std::sqrt(x))
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
const int MAXFIELD = 64; /* max number of fields in a record */
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
const double KNOT2M = 0.514444444; /* m/knot */
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
static const int SOLQ_NMEA[] = {/* nmea quality flags to rtklib sol quality */
|
2018-03-03 01:03:39 +00:00
|
|
|
/* nmea 0183 v.2.3 quality flags: */
|
|
|
|
/* 0=invalid, 1=gps fix (sps), 2=dgps fix, 3=pps fix, 4=rtk, 5=float rtk */
|
|
|
|
/* 6=estimated (dead reckoning), 7=manual input, 8=simulation */
|
|
|
|
SOLQ_NONE, SOLQ_SINGLE, SOLQ_DGPS, SOLQ_PPP, SOLQ_FIX,
|
|
|
|
SOLQ_FLOAT, SOLQ_DR, SOLQ_NONE, SOLQ_NONE, SOLQ_NONE};
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* solution option to field separator ----------------------------------------*/
|
|
|
|
const char *opt2sep(const solopt_t *opt)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (!*opt->sep)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
return " ";
|
|
|
|
}
|
2018-12-03 21:08:19 +00:00
|
|
|
if (!strcmp(opt->sep, "\\t"))
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
return "\t";
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
return opt->sep;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* separate fields -----------------------------------------------------------*/
|
|
|
|
int tonum(char *buff, const char *sep, double *v)
|
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
int n;
|
|
|
|
int len = static_cast<int>(strlen(sep));
|
|
|
|
char *p;
|
|
|
|
char *q;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (p = buff, n = 0; n < MAXFIELD; p = q + len)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if ((q = strstr(p, sep)))
|
|
|
|
{
|
|
|
|
*q = '\0';
|
|
|
|
}
|
|
|
|
if (*p)
|
|
|
|
{
|
|
|
|
v[n++] = atof(p);
|
|
|
|
}
|
|
|
|
if (!q)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* sqrt of covariance --------------------------------------------------------*/
|
|
|
|
double sqvar(double covar)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
return covar < 0.0 ? -sqrt(-covar) : sqrt(covar);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* convert ddmm.mm in nmea format to deg -------------------------------------*/
|
|
|
|
double dmm2deg(double dmm)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
return floor(dmm / 100.0) + fmod(dmm, 100.0) / 60.0;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* convert time in nmea format to time ---------------------------------------*/
|
|
|
|
void septime(double t, double *t1, double *t2, double *t3)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
*t1 = floor(t / 10000.0);
|
|
|
|
t -= *t1 * 10000.0;
|
|
|
|
*t2 = floor(t / 100.0);
|
|
|
|
*t3 = t - *t2 * 100.0;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* solution to covariance ----------------------------------------------------*/
|
|
|
|
void soltocov(const sol_t *sol, double *P)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
P[0] = sol->qr[0]; /* xx or ee */
|
|
|
|
P[4] = sol->qr[1]; /* yy or nn */
|
|
|
|
P[8] = sol->qr[2]; /* zz or uu */
|
2017-05-12 15:47:09 +00:00
|
|
|
P[1] = P[3] = sol->qr[3]; /* xy or en */
|
|
|
|
P[5] = P[7] = sol->qr[4]; /* yz or nu */
|
|
|
|
P[2] = P[6] = sol->qr[5]; /* zx or ue */
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* covariance to solution ----------------------------------------------------*/
|
|
|
|
void covtosol(const double *P, sol_t *sol)
|
|
|
|
{
|
2018-12-08 17:49:31 +00:00
|
|
|
sol->qr[0] = static_cast<float>(P[0]); /* xx or ee */
|
|
|
|
sol->qr[1] = static_cast<float>(P[4]); /* yy or nn */
|
|
|
|
sol->qr[2] = static_cast<float>(P[8]); /* zz or uu */
|
|
|
|
sol->qr[3] = static_cast<float>(P[1]); /* xy or en */
|
|
|
|
sol->qr[4] = static_cast<float>(P[5]); /* yz or nu */
|
|
|
|
sol->qr[5] = static_cast<float>(P[2]); /* zx or ue */
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-25 17:47:28 +00:00
|
|
|
/* decode nmea gprmc: recommended minimum data for gps -----------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
int decode_nmearmc(char **val, int n, sol_t *sol)
|
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
double tod = 0.0;
|
|
|
|
double lat = 0.0;
|
|
|
|
double lon = 0.0;
|
|
|
|
double vel = 0.0;
|
|
|
|
double dir = 0.0;
|
|
|
|
double date = 0.0;
|
|
|
|
double ang = 0.0;
|
|
|
|
double ep[6];
|
2017-05-12 15:47:09 +00:00
|
|
|
double pos[3] = {0};
|
2019-08-12 22:19:31 +00:00
|
|
|
char act = ' ';
|
|
|
|
char ns = 'N';
|
|
|
|
char ew = 'E';
|
|
|
|
char mew = 'E';
|
|
|
|
char mode = 'A';
|
2017-05-12 10:17:42 +00:00
|
|
|
int i;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_nmearmc: n=%d\n", n);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = 0; i < n; i++)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-12 17:22:57 +00:00
|
|
|
switch (i)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
tod = atof(val[i]);
|
|
|
|
break; /* time in utc (hhmmss) */
|
|
|
|
case 1:
|
|
|
|
act = *val[i];
|
|
|
|
break; /* A=active,V=void */
|
|
|
|
case 2:
|
|
|
|
lat = atof(val[i]);
|
|
|
|
break; /* latitude (ddmm.mmm) */
|
|
|
|
case 3:
|
|
|
|
ns = *val[i];
|
|
|
|
break; /* N=north,S=south */
|
|
|
|
case 4:
|
|
|
|
lon = atof(val[i]);
|
|
|
|
break; /* longitude (dddmm.mmm) */
|
|
|
|
case 5:
|
|
|
|
ew = *val[i];
|
|
|
|
break; /* E=east,W=west */
|
|
|
|
case 6:
|
|
|
|
vel = atof(val[i]);
|
|
|
|
break; /* speed (knots) */
|
|
|
|
case 7:
|
|
|
|
dir = atof(val[i]);
|
|
|
|
break; /* track angle (deg) */
|
|
|
|
case 8:
|
|
|
|
date = atof(val[i]);
|
|
|
|
break; /* date (ddmmyy) */
|
|
|
|
case 9:
|
|
|
|
ang = atof(val[i]);
|
|
|
|
break; /* magnetic variation */
|
|
|
|
case 10:
|
|
|
|
mew = *val[i];
|
|
|
|
break; /* E=east,W=west */
|
|
|
|
case 11:
|
|
|
|
mode = *val[i];
|
|
|
|
break; /* mode indicator (>nmea 2) */
|
|
|
|
/* A=autonomous,D=differential */
|
|
|
|
/* E=estimated,N=not valid,S=simulator */
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
if ((act != 'A' && act != 'V') || (ns != 'N' && ns != 'S') || (ew != 'E' && ew != 'W'))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(2, "invalid nmea gprmc format\n");
|
2017-05-12 17:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
pos[0] = (ns == 'S' ? -1.0 : 1.0) * dmm2deg(lat) * D2R;
|
|
|
|
pos[1] = (ew == 'W' ? -1.0 : 1.0) * dmm2deg(lon) * D2R;
|
|
|
|
septime(date, ep + 2, ep + 1, ep);
|
|
|
|
septime(tod, ep + 3, ep + 4, ep + 5);
|
|
|
|
ep[0] += ep[0] < 80.0 ? 2000.0 : 1900.0;
|
2017-05-12 15:47:09 +00:00
|
|
|
sol->time = utc2gpst(epoch2time(ep));
|
2018-03-03 01:03:39 +00:00
|
|
|
pos2ecef(pos, sol->rr);
|
|
|
|
sol->stat = mode == 'D' ? SOLQ_DGPS : SOLQ_SINGLE;
|
2017-05-12 15:47:09 +00:00
|
|
|
sol->ns = 0;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-25 17:47:28 +00:00
|
|
|
sol->type = 0; /* position type = xyz */
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(5, "decode_nmearmc: %s rr=%.3f %.3f %.3f stat=%d ns=%d vel=%.2f dir=%.0f ang=%.0f mew=%c mode=%c\n",
|
|
|
|
time_str(sol->time, 0), sol->rr[0], sol->rr[1], sol->rr[2], sol->stat, sol->ns,
|
|
|
|
vel, dir, ang, mew, mode);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode nmea gpgga: fix information ----------------------------------------*/
|
|
|
|
int decode_nmeagga(char **val, int n, sol_t *sol)
|
|
|
|
{
|
|
|
|
gtime_t time;
|
2019-08-12 22:19:31 +00:00
|
|
|
double tod = 0.0;
|
|
|
|
double lat = 0.0;
|
|
|
|
double lon = 0.0;
|
|
|
|
double hdop = 0.0;
|
|
|
|
double alt = 0.0;
|
|
|
|
double msl = 0.0;
|
|
|
|
double ep[6];
|
|
|
|
double tt;
|
2017-05-12 15:47:09 +00:00
|
|
|
double pos[3] = {0};
|
2019-08-12 22:19:31 +00:00
|
|
|
char ns = 'N';
|
|
|
|
char ew = 'E';
|
|
|
|
char ua = ' ';
|
|
|
|
char um = ' ';
|
|
|
|
int i;
|
|
|
|
int solq = 0;
|
|
|
|
int nrcv = 0;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_nmeagga: n=%d\n", n);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = 0; i < n; i++)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-12 17:22:57 +00:00
|
|
|
switch (i)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
tod = atof(val[i]);
|
|
|
|
break; /* time in utc (hhmmss) */
|
|
|
|
case 1:
|
|
|
|
lat = atof(val[i]);
|
|
|
|
break; /* latitude (ddmm.mmm) */
|
|
|
|
case 2:
|
|
|
|
ns = *val[i];
|
|
|
|
break; /* N=north,S=south */
|
|
|
|
case 3:
|
|
|
|
lon = atof(val[i]);
|
|
|
|
break; /* longitude (dddmm.mmm) */
|
|
|
|
case 4:
|
|
|
|
ew = *val[i];
|
|
|
|
break; /* E=east,W=west */
|
|
|
|
case 5:
|
|
|
|
solq = atoi(val[i]);
|
|
|
|
break; /* fix quality */
|
|
|
|
case 6:
|
|
|
|
nrcv = atoi(val[i]);
|
|
|
|
break; /* # of satellite tracked */
|
|
|
|
case 7:
|
|
|
|
hdop = atof(val[i]);
|
|
|
|
break; /* hdop */
|
|
|
|
case 8:
|
|
|
|
alt = atof(val[i]);
|
|
|
|
break; /* altitude in msl */
|
|
|
|
case 9:
|
|
|
|
ua = *val[i];
|
|
|
|
break; /* unit (M) */
|
|
|
|
case 10:
|
|
|
|
msl = atof(val[i]);
|
|
|
|
break; /* height of geoid */
|
|
|
|
case 11:
|
|
|
|
um = *val[i];
|
|
|
|
break; /* unit (M) */
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
if ((ns != 'N' && ns != 'S') || (ew != 'E' && ew != 'W'))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(2, "invalid nmea gpgga format\n");
|
2017-05-12 17:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
if (sol->time.time == 0.0)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(2, "no date info for nmea gpgga\n");
|
2017-05-12 17:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
pos[0] = (ns == 'N' ? 1.0 : -1.0) * dmm2deg(lat) * D2R;
|
|
|
|
pos[1] = (ew == 'E' ? 1.0 : -1.0) * dmm2deg(lon) * D2R;
|
|
|
|
pos[2] = alt + msl;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
time2epoch(sol->time, ep);
|
|
|
|
septime(tod, ep + 3, ep + 4, ep + 5);
|
2017-05-12 15:47:09 +00:00
|
|
|
time = utc2gpst(epoch2time(ep));
|
2018-03-03 01:03:39 +00:00
|
|
|
tt = timediff(time, sol->time);
|
|
|
|
if (tt < -43200.0)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
sol->time = timeadd(time, 86400.0);
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else if (tt > 43200.0)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
sol->time = timeadd(time, -86400.0);
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
sol->time = time;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
pos2ecef(pos, sol->rr);
|
2019-02-22 09:47:24 +00:00
|
|
|
sol->stat = 0 <= solq && solq <= 8 ? SOLQ_NMEA[solq] : SOLQ_NONE;
|
2017-05-12 15:47:09 +00:00
|
|
|
sol->ns = nrcv;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-25 17:47:28 +00:00
|
|
|
sol->type = 0; /* position type = xyz */
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(5, "decode_nmeagga: %s rr=%.3f %.3f %.3f stat=%d ns=%d hdop=%.1f ua=%c um=%c\n",
|
|
|
|
time_str(sol->time, 0), sol->rr[0], sol->rr[1], sol->rr[2], sol->stat, sol->ns,
|
|
|
|
hdop, ua, um);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode nmea ---------------------------------------------------------------*/
|
|
|
|
int decode_nmea(char *buff, sol_t *sol)
|
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
char *p;
|
|
|
|
char *q;
|
|
|
|
char *val[MAXFIELD] = {nullptr};
|
2017-05-12 15:47:09 +00:00
|
|
|
int n = 0;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_nmea: buff=%s\n", buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
/* parse fields */
|
2018-03-03 01:03:39 +00:00
|
|
|
for (p = buff; *p && n < MAXFIELD; p = q + 1)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if ((q = strchr(p, ',')) || (q = strchr(p, '*')))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
val[n++] = p;
|
|
|
|
*q = '\0';
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
/* decode nmea sentence */
|
2019-08-13 11:52:43 +00:00
|
|
|
if (val[0])
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-13 11:52:43 +00:00
|
|
|
if (!strcmp(val[0], "$GPRMC"))
|
|
|
|
{
|
|
|
|
return decode_nmearmc(val + 1, n - 1, sol);
|
|
|
|
}
|
|
|
|
if (!strcmp(val[0], "$GPGGA"))
|
|
|
|
{
|
|
|
|
return decode_nmeagga(val + 1, n - 1, sol);
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode solution time ------------------------------------------------------*/
|
|
|
|
char *decode_soltime(char *buff, const solopt_t *opt, gtime_t *time)
|
|
|
|
{
|
|
|
|
double v[MAXFIELD];
|
2019-08-12 22:19:31 +00:00
|
|
|
char *p;
|
|
|
|
char *q;
|
|
|
|
char s[64] = " ";
|
|
|
|
int n;
|
|
|
|
int len;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_soltime:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if (!strcmp(opt->sep, "\\t"))
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-13 11:10:45 +00:00
|
|
|
std::strncpy(s, "\t", 2);
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else if (*opt->sep)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-13 11:10:45 +00:00
|
|
|
std::strncpy(s, opt->sep, 64);
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2018-12-08 17:49:31 +00:00
|
|
|
len = static_cast<int>(strlen(s));
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
/* yyyy/mm/dd hh:mm:ss or yyyy mm dd hh:mm:ss */
|
2018-03-03 01:03:39 +00:00
|
|
|
if (sscanf(buff, "%lf/%lf/%lf %lf:%lf:%lf", v, v + 1, v + 2, v + 3, v + 4, v + 5) >= 6)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (v[0] < 100.0)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
v[0] += v[0] < 80.0 ? 2000.0 : 1900.0;
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
|
|
|
*time = epoch2time(v);
|
|
|
|
if (opt->times == TIMES_UTC)
|
|
|
|
{
|
|
|
|
*time = utc2gpst(*time);
|
|
|
|
}
|
|
|
|
else if (opt->times == TIMES_JST)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
*time = utc2gpst(timeadd(*time, -9 * 3600.0));
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2019-02-11 20:13:02 +00:00
|
|
|
if (!(p = strchr(buff, ':')) || !(p = strchr(p + 1, ':')))
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for (p++; isdigit(static_cast<int>(*p)) || *p == '.';)
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
return p + len;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
if (opt->posf == SOLF_GSIF)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (sscanf(buff, "%lf %lf %lf %lf:%lf:%lf", v, v + 1, v + 2, v + 3, v + 4, v + 5) < 6)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-12-03 09:05:47 +00:00
|
|
|
return nullptr;
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
*time = timeadd(epoch2time(v), -12.0 * 3600.0);
|
2019-02-11 20:13:02 +00:00
|
|
|
if (!(p = strchr(buff, ':')) || !(p = strchr(p + 1, ':')))
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
for (p++; isdigit(static_cast<int>(*p)) || *p == '.';)
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
return p + len;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
/* wwww ssss */
|
2018-03-03 01:03:39 +00:00
|
|
|
for (p = buff, n = 0; n < 2; p = q + len)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if ((q = strstr(p, s)))
|
|
|
|
{
|
|
|
|
*q = '\0';
|
|
|
|
}
|
|
|
|
if (*p)
|
|
|
|
{
|
|
|
|
v[n++] = atof(p);
|
|
|
|
}
|
|
|
|
if (!q)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (n >= 2 && 0.0 <= v[0] && v[0] <= 3000.0 && 0.0 <= v[1] && v[1] < 604800.0)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-12-08 17:49:31 +00:00
|
|
|
*time = gpst2time(static_cast<int>(v[0]), v[1]);
|
2017-05-12 17:22:57 +00:00
|
|
|
return p;
|
|
|
|
}
|
2018-12-03 09:05:47 +00:00
|
|
|
return nullptr;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode x/y/z-ecef ---------------------------------------------------------*/
|
|
|
|
int decode_solxyz(char *buff, const solopt_t *opt, sol_t *sol)
|
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
double val[MAXFIELD];
|
|
|
|
double P[9] = {0};
|
|
|
|
int i = 0;
|
|
|
|
int j;
|
|
|
|
int n;
|
2017-05-12 15:47:09 +00:00
|
|
|
const char *sep = opt2sep(opt);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_solxyz:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if ((n = tonum(buff, sep, val)) < 3)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
sol->rr[j] = val[i++]; /* xyz */
|
|
|
|
}
|
2019-02-11 20:13:02 +00:00
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->stat = static_cast<unsigned char>(val[i++]);
|
|
|
|
}
|
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->ns = static_cast<unsigned char>(val[i++]);
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (i + 3 < n)
|
|
|
|
{
|
|
|
|
P[0] = val[i] * val[i];
|
|
|
|
i++; /* sdx */
|
|
|
|
P[4] = val[i] * val[i];
|
|
|
|
i++; /* sdy */
|
|
|
|
P[8] = val[i] * val[i];
|
|
|
|
i++; /* sdz */
|
|
|
|
if (i + 3 < n)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
P[1] = P[3] = SQR_SOL(val[i]);
|
|
|
|
i++; /* sdxy */
|
|
|
|
P[5] = P[7] = SQR_SOL(val[i]);
|
|
|
|
i++; /* sdyz */
|
|
|
|
P[2] = P[6] = SQR_SOL(val[i]);
|
|
|
|
i++; /* sdzx */
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
covtosol(P, sol);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2019-02-11 20:13:02 +00:00
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->age = static_cast<float>(val[i++]);
|
|
|
|
}
|
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->ratio = static_cast<float>(val[i]);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-25 17:47:28 +00:00
|
|
|
sol->type = 0; /* position type = xyz */
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if (MAXSOLQ < sol->stat)
|
|
|
|
{
|
|
|
|
sol->stat = SOLQ_NONE;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode lat/lon/height -----------------------------------------------------*/
|
|
|
|
int decode_solllh(char *buff, const solopt_t *opt, sol_t *sol)
|
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
double val[MAXFIELD];
|
|
|
|
double pos[3];
|
|
|
|
double Q[9] = {0};
|
|
|
|
double P[9];
|
|
|
|
int i = 0;
|
|
|
|
int n;
|
2017-05-12 15:47:09 +00:00
|
|
|
const char *sep = opt2sep(opt);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_solllh:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
n = tonum(buff, sep, val);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
if (!opt->degf)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (n < 3)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
pos[0] = val[i++] * D2R; /* lat/lon/hgt (ddd.ddd) */
|
|
|
|
pos[1] = val[i++] * D2R;
|
2017-05-12 17:22:57 +00:00
|
|
|
pos[2] = val[i++];
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
else
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (n < 7)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
pos[0] = dms2deg(val) * D2R; /* lat/lon/hgt (ddd mm ss) */
|
|
|
|
pos[1] = dms2deg(val + 3) * D2R;
|
2017-05-12 17:22:57 +00:00
|
|
|
pos[2] = val[6];
|
2018-03-03 01:03:39 +00:00
|
|
|
i += 7;
|
|
|
|
}
|
|
|
|
pos2ecef(pos, sol->rr);
|
2019-02-11 20:13:02 +00:00
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->stat = static_cast<unsigned char>(val[i++]);
|
|
|
|
}
|
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->ns = static_cast<unsigned char>(val[i++]);
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (i + 3 < n)
|
|
|
|
{
|
|
|
|
Q[4] = val[i] * val[i];
|
|
|
|
i++; /* sdn */
|
|
|
|
Q[0] = val[i] * val[i];
|
|
|
|
i++; /* sde */
|
|
|
|
Q[8] = val[i] * val[i];
|
|
|
|
i++; /* sdu */
|
|
|
|
if (i + 3 < n)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
Q[1] = Q[3] = SQR_SOL(val[i]);
|
|
|
|
i++; /* sdne */
|
|
|
|
Q[2] = Q[6] = SQR_SOL(val[i]);
|
|
|
|
i++; /* sdeu */
|
|
|
|
Q[5] = Q[7] = SQR_SOL(val[i]);
|
|
|
|
i++; /* sdun */
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
covecef(pos, Q, P);
|
|
|
|
covtosol(P, sol);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2019-02-11 20:13:02 +00:00
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->age = static_cast<float>(val[i++]);
|
|
|
|
}
|
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->ratio = static_cast<float>(val[i]);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-25 17:47:28 +00:00
|
|
|
sol->type = 0; /* position type = xyz */
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if (MAXSOLQ < sol->stat)
|
|
|
|
{
|
|
|
|
sol->stat = SOLQ_NONE;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode e/n/u-baseline -----------------------------------------------------*/
|
|
|
|
int decode_solenu(char *buff, const solopt_t *opt, sol_t *sol)
|
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
double val[MAXFIELD];
|
|
|
|
double Q[9] = {0};
|
|
|
|
int i = 0;
|
|
|
|
int j;
|
|
|
|
int n;
|
2017-05-12 15:47:09 +00:00
|
|
|
const char *sep = opt2sep(opt);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_solenu:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if ((n = tonum(buff, sep, val)) < 3)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
sol->rr[j] = val[i++]; /* enu */
|
|
|
|
}
|
2019-02-11 20:13:02 +00:00
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->stat = static_cast<unsigned char>(val[i++]);
|
|
|
|
}
|
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->ns = static_cast<unsigned char>(val[i++]);
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (i + 3 < n)
|
|
|
|
{
|
|
|
|
Q[0] = val[i] * val[i];
|
|
|
|
i++; /* sde */
|
|
|
|
Q[4] = val[i] * val[i];
|
|
|
|
i++; /* sdn */
|
|
|
|
Q[8] = val[i] * val[i];
|
|
|
|
i++; /* sdu */
|
|
|
|
if (i + 3 < n)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
Q[1] = Q[3] = SQR_SOL(val[i]);
|
|
|
|
i++; /* sden */
|
|
|
|
Q[5] = Q[7] = SQR_SOL(val[i]);
|
|
|
|
i++; /* sdnu */
|
|
|
|
Q[2] = Q[6] = SQR_SOL(val[i]);
|
|
|
|
i++; /* sdue */
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
covtosol(Q, sol);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2019-02-11 20:13:02 +00:00
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->age = static_cast<float>(val[i++]);
|
|
|
|
}
|
|
|
|
if (i < n)
|
|
|
|
{
|
|
|
|
sol->ratio = static_cast<float>(val[i]);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-25 17:47:28 +00:00
|
|
|
sol->type = 1; /* position type = enu */
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if (MAXSOLQ < sol->stat)
|
|
|
|
{
|
|
|
|
sol->stat = SOLQ_NONE;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode gsi f solution -----------------------------------------------------*/
|
2017-05-13 17:35:20 +00:00
|
|
|
int decode_solgsi(char *buff, const solopt_t *opt __attribute((unused)), sol_t *sol)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
|
|
|
double val[MAXFIELD];
|
2019-08-12 22:19:31 +00:00
|
|
|
int i = 0;
|
|
|
|
int j;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_solgsi:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if (tonum(buff, " ", val) < 3)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (j = 0; j < 3; j++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
sol->rr[j] = val[i++]; /* xyz */
|
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
sol->stat = SOLQ_FIX;
|
2017-05-12 10:17:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode solution position --------------------------------------------------*/
|
|
|
|
int decode_solpos(char *buff, const solopt_t *opt, sol_t *sol)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
sol_t sol0 = {{0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, '0', '0', '0', 0, 0, 0};
|
2017-05-12 15:47:09 +00:00
|
|
|
char *p = buff;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_solpos: buff=%s\n", buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
*sol = sol0;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
/* decode solution time */
|
2018-03-03 01:03:39 +00:00
|
|
|
if (!(p = decode_soltime(p, opt, &sol->time)))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
/* decode solution position */
|
|
|
|
switch (opt->posf)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
case SOLF_XYZ:
|
|
|
|
return decode_solxyz(p, opt, sol);
|
|
|
|
case SOLF_LLH:
|
|
|
|
return decode_solllh(p, opt, sol);
|
|
|
|
case SOLF_ENU:
|
|
|
|
return decode_solenu(p, opt, sol);
|
|
|
|
case SOLF_GSIF:
|
|
|
|
return decode_solgsi(p, opt, sol);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode reference position -------------------------------------------------*/
|
|
|
|
void decode_refpos(char *buff, const solopt_t *opt, double *rb)
|
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
double val[MAXFIELD];
|
|
|
|
double pos[3];
|
|
|
|
int i;
|
|
|
|
int n;
|
2017-05-12 15:47:09 +00:00
|
|
|
const char *sep = opt2sep(opt);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "decode_refpos: buff=%s\n", buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if ((n = tonum(buff, sep, val)) < 3)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (opt->posf == SOLF_XYZ)
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* xyz */
|
2019-02-11 20:13:02 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
rb[i] = val[i];
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
else if (opt->degf == 0)
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* lat/lon/hgt (ddd.ddd) */
|
2018-03-03 01:03:39 +00:00
|
|
|
pos[0] = val[0] * D2R;
|
|
|
|
pos[1] = val[1] * D2R;
|
2017-05-12 17:22:57 +00:00
|
|
|
pos[2] = val[2];
|
2018-03-03 01:03:39 +00:00
|
|
|
pos2ecef(pos, rb);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
else if (opt->degf == 1 && n >= 7)
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* lat/lon/hgt (ddd mm ss) */
|
2018-03-03 01:03:39 +00:00
|
|
|
pos[0] = dms2deg(val) * D2R;
|
|
|
|
pos[1] = dms2deg(val + 3) * D2R;
|
2017-05-12 17:22:57 +00:00
|
|
|
pos[2] = val[6];
|
2018-03-03 01:03:39 +00:00
|
|
|
pos2ecef(pos, rb);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode solution -----------------------------------------------------------*/
|
|
|
|
int decode_sol(char *buff, const solopt_t *opt, sol_t *sol, double *rb)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_sol: buff=%s\n", buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if (!strncmp(buff, COMMENTH, 1))
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* reference position */
|
2019-02-11 20:13:02 +00:00
|
|
|
if (!strstr(buff, "ref pos") && !strstr(buff, "slave pos"))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!(p = strchr(buff, ':')))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
decode_refpos(p + 1, opt, rb);
|
2017-05-12 17:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (!strncmp(buff, "$GP", 3))
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* decode nmea */
|
2019-02-11 20:13:02 +00:00
|
|
|
if (!decode_nmea(buff, sol))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 17:22:57 +00:00
|
|
|
/* for time update only */
|
2019-02-11 20:13:02 +00:00
|
|
|
if (opt->posf != SOLF_NMEA && !strncmp(buff, "$GPRMC", 6))
|
|
|
|
{
|
|
|
|
return 2;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
else
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* decode position record */
|
2019-02-11 20:13:02 +00:00
|
|
|
if (!decode_solpos(buff, opt, sol))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode solution options ---------------------------------------------------*/
|
|
|
|
void decode_solopt(char *buff, solopt_t *opt)
|
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_solhead: buff=%s\n", buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if (strncmp(buff, COMMENTH, 1) != 0 && strncmp(buff, "+", 1) != 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if (strstr(buff, "GPST"))
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
opt->times = TIMES_GPST;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else if (strstr(buff, "UTC"))
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
opt->times = TIMES_UTC;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else if (strstr(buff, "JST"))
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
opt->times = TIMES_JST;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if ((p = strstr(buff, "x-ecef(m)")))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
opt->posf = SOLF_XYZ;
|
|
|
|
opt->degf = 0;
|
2018-03-03 01:03:39 +00:00
|
|
|
strncpy(opt->sep, p + 9, 1);
|
2017-05-12 17:22:57 +00:00
|
|
|
opt->sep[1] = '\0';
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else if ((p = strstr(buff, "latitude(d'\")")))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
opt->posf = SOLF_LLH;
|
|
|
|
opt->degf = 1;
|
2018-03-03 01:03:39 +00:00
|
|
|
strncpy(opt->sep, p + 14, 1);
|
2017-05-12 17:22:57 +00:00
|
|
|
opt->sep[1] = '\0';
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else if ((p = strstr(buff, "latitude(deg)")))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
opt->posf = SOLF_LLH;
|
|
|
|
opt->degf = 0;
|
2018-03-03 01:03:39 +00:00
|
|
|
strncpy(opt->sep, p + 13, 1);
|
2017-05-12 17:22:57 +00:00
|
|
|
opt->sep[1] = '\0';
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else if ((p = strstr(buff, "e-baseline(m)")))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
opt->posf = SOLF_ENU;
|
|
|
|
opt->degf = 0;
|
2018-03-03 01:03:39 +00:00
|
|
|
strncpy(opt->sep, p + 13, 1);
|
2017-05-12 17:22:57 +00:00
|
|
|
opt->sep[1] = '\0';
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else if ((p = strstr(buff, "+SITE/INF")))
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* gsi f2/f3 solution */
|
|
|
|
opt->times = TIMES_GPST;
|
|
|
|
opt->posf = SOLF_GSIF;
|
|
|
|
opt->degf = 0;
|
2019-08-13 11:10:45 +00:00
|
|
|
std::strncpy(opt->sep, " ", 2);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read solution option ------------------------------------------------------*/
|
|
|
|
void readsolopt(FILE *fp, solopt_t *opt)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
char buff[MAXSOLMSG + 1];
|
2017-05-12 10:17:42 +00:00
|
|
|
int i;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "readsolopt:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = 0; fgets(buff, sizeof(buff), fp) && i < 100; i++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* only 100 lines */
|
|
|
|
/* decode solution options */
|
2018-03-03 01:03:39 +00:00
|
|
|
decode_solopt(buff, opt);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* input solution data from stream ---------------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* input solution data from stream
|
|
|
|
* args : unsigned char data I stream data
|
|
|
|
* gtime_t ts I start time (ts.time == 0: from start)
|
|
|
|
* gtime_t te I end time (te.time == 0: to end)
|
|
|
|
* double tint I time interval (0: all)
|
|
|
|
* int qflag I quality flag (0: all)
|
|
|
|
* solbuf_t *solbuf IO solution buffer
|
|
|
|
* return : status (1:solution received,0:no solution,-1:disconnect received)
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
int inputsol(unsigned char data, gtime_t ts, gtime_t te, double tint,
|
2018-03-03 01:03:39 +00:00
|
|
|
int qflag, const solopt_t *opt, solbuf_t *solbuf)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
sol_t sol = {{0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, '0', '0', '0', 0, 0, 0};
|
2017-05-12 10:17:42 +00:00
|
|
|
int stat;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "inputsol: data=0x%02x\n", data);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
sol.time = solbuf->time;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (data == '$' || (!isprint(data) && data != '\r' && data != '\n'))
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* sync header */
|
|
|
|
solbuf->nb = 0;
|
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
solbuf->buff[solbuf->nb++] = data;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (data != '\n' && solbuf->nb < MAXSOLMSG)
|
|
|
|
{
|
|
|
|
return 0; /* sync trailer */
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
solbuf->buff[solbuf->nb] = '\0';
|
|
|
|
solbuf->nb = 0;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
/* check disconnect message */
|
2018-12-08 17:49:31 +00:00
|
|
|
if (!strcmp(reinterpret_cast<char *>(solbuf->buff), MSG_DISCONN))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "disconnect received\n");
|
2017-05-12 17:22:57 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
/* decode solution */
|
2018-12-08 17:49:31 +00:00
|
|
|
if ((stat = decode_sol(reinterpret_cast<char *>(solbuf->buff), opt, &sol, solbuf->rb)) > 0)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
solbuf->time = sol.time; /* update current time */
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (stat != 1 || !screent(sol.time, ts, te, tint) || (qflag && sol.stat != qflag))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
/* add solution to solution buffer */
|
2018-03-03 01:03:39 +00:00
|
|
|
return addsol(solbuf, &sol);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read solution data --------------------------------------------------------*/
|
|
|
|
int readsoldata(FILE *fp, gtime_t ts, gtime_t te, double tint, int qflag,
|
2018-03-03 01:03:39 +00:00
|
|
|
const solopt_t *opt, solbuf_t *solbuf)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "readsoldata:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
while ((c = fgetc(fp)) != EOF)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
/* input solution */
|
2018-12-08 17:49:31 +00:00
|
|
|
inputsol(static_cast<unsigned char>(c), ts, te, tint, qflag, opt, solbuf);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
return solbuf->n > 0;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* compare solution data -----------------------------------------------------*/
|
|
|
|
int cmpsol(const void *p1, const void *p2)
|
|
|
|
{
|
2019-08-16 13:19:31 +00:00
|
|
|
auto *q1 = static_cast<const sol_t *>(p1);
|
|
|
|
auto *q2 = static_cast<const sol_t *>(p2);
|
2018-03-03 01:03:39 +00:00
|
|
|
double tt = timediff(q1->time, q2->time);
|
|
|
|
return tt < -0.0 ? -1 : (tt > 0.0 ? 1 : 0);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* sort solution data --------------------------------------------------------*/
|
|
|
|
int sort_solbuf(solbuf_t *solbuf)
|
|
|
|
{
|
|
|
|
sol_t *solbuf_data;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "sort_solbuf: n=%d\n", solbuf->n);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if (solbuf->n <= 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
if (!(solbuf_data = static_cast<sol_t *>(realloc(solbuf->data, sizeof(sol_t) * solbuf->n))))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(1, "sort_solbuf: memory allocation error\n");
|
|
|
|
free(solbuf->data);
|
2018-12-03 09:05:47 +00:00
|
|
|
solbuf->data = nullptr;
|
2018-03-03 01:03:39 +00:00
|
|
|
solbuf->n = solbuf->nmax = 0;
|
2017-05-12 17:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
solbuf->data = solbuf_data;
|
2018-03-03 01:03:39 +00:00
|
|
|
qsort(solbuf->data, solbuf->n, sizeof(sol_t), cmpsol);
|
2017-05-12 15:47:09 +00:00
|
|
|
solbuf->nmax = solbuf->n;
|
|
|
|
solbuf->start = 0;
|
2018-03-03 01:03:39 +00:00
|
|
|
solbuf->end = solbuf->n - 1;
|
2017-05-12 10:17:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read solutions data from solution files -------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* read solution data from soluiton files
|
|
|
|
* args : char *files[] I solution files
|
|
|
|
* int nfile I number of files
|
|
|
|
* (gtime_t ts) I start time (ts.time == 0: from start)
|
|
|
|
* (gtime_t te) I end time (te.time == 0: to end)
|
|
|
|
* (double tint) I time interval (0: all)
|
|
|
|
* (int qflag) I quality flag (0: all)
|
|
|
|
* solbuf_t *solbuf O solution buffer
|
|
|
|
* return : status (1:ok,0:no data or error)
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
int readsolt(char *files[], int nfile, gtime_t ts, gtime_t te,
|
2018-03-03 01:03:39 +00:00
|
|
|
double tint, int qflag, solbuf_t *solbuf)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
2019-02-22 09:47:24 +00:00
|
|
|
solopt_t opt = SOLOPT_DEFAULT;
|
2017-05-12 10:17:42 +00:00
|
|
|
int i;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "readsolt: nfile=%d\n", nfile);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
initsolbuf(solbuf, 0, 0);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = 0; i < nfile; i++)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2018-12-08 17:49:31 +00:00
|
|
|
if (!(fp = fopen(files[i], "rbe")))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(1, "readsolt: file open error %s\n", files[i]);
|
2017-05-12 17:22:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* read solution options in header */
|
2018-03-03 01:03:39 +00:00
|
|
|
readsolopt(fp, &opt);
|
2017-05-12 17:22:57 +00:00
|
|
|
rewind(fp);
|
|
|
|
|
|
|
|
/* read solution data */
|
2018-03-03 01:03:39 +00:00
|
|
|
if (!readsoldata(fp, ts, te, tint, qflag, &opt, solbuf))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(1, "readsolt: no solution in %s\n", files[i]);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
|
|
|
fclose(fp);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
return sort_solbuf(solbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int readsol(char *files[], int nfile, solbuf_t *sol)
|
|
|
|
{
|
2017-05-13 08:41:35 +00:00
|
|
|
gtime_t time = {0, 0.0};
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "readsol: nfile=%d\n", nfile);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
return readsolt(files, nfile, time, time, 0.0, 0, sol);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* add solution data to solution buffer ----------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* add solution data to solution buffer
|
|
|
|
* args : solbuf_t *solbuf IO solution buffer
|
|
|
|
* sol_t *sol I solution data
|
|
|
|
* return : status (1:ok,0:error)
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
int addsol(solbuf_t *solbuf, const sol_t *sol)
|
|
|
|
{
|
|
|
|
sol_t *solbuf_data;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "addsol:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
if (solbuf->cyclic)
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* ring buffer */
|
2019-02-11 20:13:02 +00:00
|
|
|
if (solbuf->nmax <= 1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
solbuf->data[solbuf->end] = *sol;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (++solbuf->end >= solbuf->nmax)
|
|
|
|
{
|
|
|
|
solbuf->end = 0;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
if (solbuf->start == solbuf->end)
|
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (++solbuf->start >= solbuf->nmax)
|
|
|
|
{
|
|
|
|
solbuf->start = 0;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
solbuf->n++;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
|
|
|
|
return 1;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (solbuf->n >= solbuf->nmax)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
solbuf->nmax = solbuf->nmax == 0 ? 8192 : solbuf->nmax * 2;
|
2018-12-08 17:49:31 +00:00
|
|
|
if (!(solbuf_data = static_cast<sol_t *>(realloc(solbuf->data, sizeof(sol_t) * solbuf->nmax))))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(1, "addsol: memory allocation error\n");
|
|
|
|
free(solbuf->data);
|
2018-12-03 09:05:47 +00:00
|
|
|
solbuf->data = nullptr;
|
2018-03-03 01:03:39 +00:00
|
|
|
solbuf->n = solbuf->nmax = 0;
|
2017-05-12 17:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
solbuf->data = solbuf_data;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
solbuf->data[solbuf->n++] = *sol;
|
2017-05-12 10:17:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get solution data from solution buffer --------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* get solution data by index from solution buffer
|
|
|
|
* args : solbuf_t *solbuf I solution buffer
|
|
|
|
* int index I index of solution (0...)
|
|
|
|
* return : solution data pointer (NULL: no solution, out of range)
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
sol_t *getsol(solbuf_t *solbuf, int index)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "getsol: index=%d\n", index);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if (index < 0 || solbuf->n <= index)
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if ((index = solbuf->start + index) >= solbuf->nmax)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
index -= solbuf->nmax;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
return solbuf->data + index;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* initialize solution buffer --------------------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* initialize position solutions
|
|
|
|
* args : solbuf_t *solbuf I solution buffer
|
|
|
|
* int cyclic I solution data buffer type (0:linear,1:cyclic)
|
|
|
|
* int nmax I initial number of solution data
|
|
|
|
* return : status (1:ok,0:error)
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
void initsolbuf(solbuf_t *solbuf, int cyclic, int nmax)
|
|
|
|
{
|
2017-05-13 08:41:35 +00:00
|
|
|
gtime_t time0 = {0, 0.0};
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "initsolbuf: cyclic=%d nmax=%d\n", cyclic, nmax);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
solbuf->n = solbuf->nmax = solbuf->start = solbuf->end = 0;
|
|
|
|
solbuf->cyclic = cyclic;
|
|
|
|
solbuf->time = time0;
|
2018-12-03 09:05:47 +00:00
|
|
|
solbuf->data = nullptr;
|
2017-05-12 10:17:42 +00:00
|
|
|
if (cyclic)
|
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (nmax <= 2)
|
|
|
|
{
|
|
|
|
nmax = 2;
|
|
|
|
}
|
2018-12-08 17:49:31 +00:00
|
|
|
if (!(solbuf->data = static_cast<sol_t *>(malloc(sizeof(sol_t) * nmax))))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(1, "initsolbuf: memory allocation error\n");
|
2017-05-12 17:22:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
solbuf->nmax = nmax;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* free solution ---------------------------------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* free memory for solution buffer
|
|
|
|
* args : solbuf_t *solbuf I solution buffer
|
|
|
|
* return : none
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
void freesolbuf(solbuf_t *solbuf)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "freesolbuf: n=%d\n", solbuf->n);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
free(solbuf->data);
|
2017-05-12 15:47:09 +00:00
|
|
|
solbuf->n = solbuf->nmax = solbuf->start = solbuf->end = 0;
|
2018-12-03 09:05:47 +00:00
|
|
|
solbuf->data = nullptr;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void freesolstatbuf(solstatbuf_t *solstatbuf)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "freesolstatbuf: n=%d\n", solstatbuf->n);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
solstatbuf->n = solstatbuf->nmax = 0;
|
2017-05-12 10:17:42 +00:00
|
|
|
free(solstatbuf->data);
|
2018-12-03 09:05:47 +00:00
|
|
|
solstatbuf->data = nullptr;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* compare solution status ---------------------------------------------------*/
|
|
|
|
int cmpsolstat(const void *p1, const void *p2)
|
|
|
|
{
|
2019-08-16 13:19:31 +00:00
|
|
|
auto *q1 = static_cast<const solstat_t *>(p1);
|
|
|
|
auto *q2 = static_cast<const solstat_t *>(p2);
|
2018-03-03 01:03:39 +00:00
|
|
|
double tt = timediff(q1->time, q2->time);
|
|
|
|
return tt < -0.0 ? -1 : (tt > 0.0 ? 1 : 0);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* sort solution data --------------------------------------------------------*/
|
|
|
|
int sort_solstat(solstatbuf_t *statbuf)
|
|
|
|
{
|
|
|
|
solstat_t *statbuf_data;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "sort_solstat: n=%d\n", statbuf->n);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if (statbuf->n <= 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
if (!(statbuf_data = static_cast<solstat_t *>(realloc(statbuf->data, sizeof(solstat_t) * statbuf->n))))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(1, "sort_solstat: memory allocation error\n");
|
|
|
|
free(statbuf->data);
|
2018-12-03 09:05:47 +00:00
|
|
|
statbuf->data = nullptr;
|
2018-03-03 01:03:39 +00:00
|
|
|
statbuf->n = statbuf->nmax = 0;
|
2017-05-12 17:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
statbuf->data = statbuf_data;
|
2018-03-03 01:03:39 +00:00
|
|
|
qsort(statbuf->data, statbuf->n, sizeof(solstat_t), cmpsolstat);
|
2017-05-12 15:47:09 +00:00
|
|
|
statbuf->nmax = statbuf->n;
|
2017-05-12 10:17:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* decode solution status ----------------------------------------------------*/
|
|
|
|
int decode_solstat(char *buff, solstat_t *stat)
|
|
|
|
{
|
2017-05-13 08:41:35 +00:00
|
|
|
static const solstat_t stat0 = {{0, 0.0}, '0', '0', 0, 0, 0, 0, '0', '0', 0, 0, 0, 0};
|
2019-08-12 22:19:31 +00:00
|
|
|
double tow;
|
|
|
|
double az;
|
|
|
|
double el;
|
|
|
|
double resp;
|
|
|
|
double resc;
|
|
|
|
int n;
|
|
|
|
int week;
|
|
|
|
int sat;
|
|
|
|
int frq;
|
|
|
|
int vsat;
|
|
|
|
int snr;
|
|
|
|
int fix;
|
|
|
|
int slip;
|
|
|
|
int lock;
|
|
|
|
int outc;
|
|
|
|
int slipc;
|
|
|
|
int rejc;
|
|
|
|
char id[32] = "";
|
|
|
|
char *p;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "decode_solstat: buff=%s\n", buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if (strstr(buff, "$SAT") != buff)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (p = buff; *p; p++)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
if (*p == ',')
|
|
|
|
{
|
|
|
|
*p = ' ';
|
|
|
|
}
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
n = sscanf(buff, "$SAT%d%lf%s%d%lf%lf%lf%lf%d%d%d%d%d%d%d%d",
|
|
|
|
&week, &tow, id, &frq, &az, &el, &resp, &resc, &vsat, &snr, &fix, &slip,
|
|
|
|
&lock, &outc, &slipc, &rejc);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if (n < 15)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(2, "invalid format of solution status: %s\n", buff);
|
2017-05-12 17:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
if ((sat = satid2no(id)) <= 0)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(2, "invalid satellite in solution status: %s\n", id);
|
2017-05-12 17:22:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
*stat = stat0;
|
2018-03-03 01:03:39 +00:00
|
|
|
stat->time = gpst2time(week, tow);
|
2018-12-08 17:49:31 +00:00
|
|
|
stat->sat = static_cast<unsigned char>(sat);
|
|
|
|
stat->frq = static_cast<unsigned char>(frq);
|
|
|
|
stat->az = static_cast<float>(az * D2R);
|
|
|
|
stat->el = static_cast<float>(el * D2R);
|
|
|
|
stat->resp = static_cast<float>(resp);
|
|
|
|
stat->resc = static_cast<float>(resc);
|
|
|
|
stat->flag = static_cast<unsigned char>((vsat << 5) + (slip << 3) + fix);
|
2019-08-24 15:34:12 +00:00
|
|
|
stat->snr = static_cast<unsigned char>(std::lround(snr * 4.0));
|
2018-12-08 17:49:31 +00:00
|
|
|
stat->lock = static_cast<uint16_t>(lock);
|
|
|
|
stat->outc = static_cast<uint16_t>(outc);
|
|
|
|
stat->slipc = static_cast<uint16_t>(slipc);
|
|
|
|
stat->rejc = static_cast<uint16_t>(rejc);
|
2017-05-12 10:17:42 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2017-05-13 08:41:35 +00:00
|
|
|
|
2017-05-12 10:17:42 +00:00
|
|
|
/* add solution status data --------------------------------------------------*/
|
|
|
|
void addsolstat(solstatbuf_t *statbuf, const solstat_t *stat)
|
|
|
|
{
|
|
|
|
solstat_t *statbuf_data;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(4, "addsolstat:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (statbuf->n >= statbuf->nmax)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
statbuf->nmax = statbuf->nmax == 0 ? 8192 : statbuf->nmax * 2;
|
2018-12-08 17:49:31 +00:00
|
|
|
if (!(statbuf_data = static_cast<solstat_t *>(realloc(statbuf->data, sizeof(solstat_t) *
|
2018-12-09 21:00:09 +00:00
|
|
|
statbuf->nmax))))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(1, "addsolstat: memory allocation error\n");
|
|
|
|
free(statbuf->data);
|
2018-12-03 09:05:47 +00:00
|
|
|
statbuf->data = nullptr;
|
2018-03-03 01:03:39 +00:00
|
|
|
statbuf->n = statbuf->nmax = 0;
|
2017-05-12 17:22:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
statbuf->data = statbuf_data;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
statbuf->data[statbuf->n++] = *stat;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read solution status data -------------------------------------------------*/
|
|
|
|
int readsolstatdata(FILE *fp, gtime_t ts, gtime_t te, double tint,
|
2018-03-03 01:03:39 +00:00
|
|
|
solstatbuf_t *statbuf)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-13 08:41:35 +00:00
|
|
|
solstat_t stat = {{0, 0.0}, '0', '0', 0, 0, 0, 0, '0', '0', 0, 0, 0, 0};
|
2018-03-03 01:03:39 +00:00
|
|
|
char buff[MAXSOLMSG + 1];
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "readsolstatdata:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
while (fgets(buff, sizeof(buff), fp))
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-12 17:22:57 +00:00
|
|
|
/* decode solution status */
|
2019-02-11 20:13:02 +00:00
|
|
|
if (!decode_solstat(buff, &stat))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
|
|
|
|
/* add solution to solution buffer */
|
2018-03-03 01:03:39 +00:00
|
|
|
if (screent(stat.time, ts, te, tint))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
addsolstat(statbuf, &stat);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
return statbuf->n > 0;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* read solution status --------------------------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* read solution status from solution status files
|
|
|
|
* args : char *files[] I solution status files
|
|
|
|
* int nfile I number of files
|
|
|
|
* (gtime_t ts) I start time (ts.time == 0: from start)
|
|
|
|
* (gtime_t te) I end time (te.time == 0: to end)
|
|
|
|
* (double tint) I time interval (0: all)
|
|
|
|
* solstatbuf_t *statbuf O solution status buffer
|
|
|
|
* return : status (1:ok,0:no data or error)
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
int readsolstatt(char *files[], int nfile, gtime_t ts, gtime_t te,
|
2018-03-03 01:03:39 +00:00
|
|
|
double tint, solstatbuf_t *statbuf)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
char path[1024];
|
|
|
|
int i;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "readsolstatt: nfile=%d\n", nfile);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
statbuf->n = statbuf->nmax = 0;
|
2018-12-03 09:05:47 +00:00
|
|
|
statbuf->data = nullptr;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = 0; i < nfile; i++)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2019-08-23 18:48:52 +00:00
|
|
|
std::snprintf(path, sizeof(path), "%s.stat", files[i]);
|
2018-12-08 17:49:31 +00:00
|
|
|
if (!(fp = fopen(path, "re")))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(1, "readsolstatt: file open error %s\n", path);
|
2017-05-12 17:22:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
/* read solution status data */
|
2018-03-03 01:03:39 +00:00
|
|
|
if (!readsolstatdata(fp, ts, te, tint, statbuf))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(1, "readsolt: no solution in %s\n", path);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
|
|
|
fclose(fp);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
return sort_solstat(statbuf);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int readsolstat(char *files[], int nfile, solstatbuf_t *statbuf)
|
|
|
|
{
|
2017-05-13 08:41:35 +00:00
|
|
|
gtime_t time = {0, 0.0};
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "readsolstat: nfile=%d\n", nfile);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
return readsolstatt(files, nfile, time, time, 0.0, statbuf);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution as the form of x/y/z-ecef ---------------------------------*/
|
|
|
|
int outecef(unsigned char *buff, const char *s, const sol_t *sol,
|
2018-03-03 01:03:39 +00:00
|
|
|
const solopt_t *opt)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-12 15:47:09 +00:00
|
|
|
const char *sep = opt2sep(opt);
|
2018-12-08 17:49:31 +00:00
|
|
|
char *p = reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outecef:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-08-23 18:48:52 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF, "%s%s%14.4f%s%14.4f%s%14.4f%s%3d%s%3d%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%6.2f%s%6.1f\n",
|
2018-03-03 01:03:39 +00:00
|
|
|
s, sep, sol->rr[0], sep, sol->rr[1], sep, sol->rr[2], sep, sol->stat, sep,
|
|
|
|
sol->ns, sep, SQRT_SOL(sol->qr[0]), sep, SQRT_SOL(sol->qr[1]), sep, SQRT_SOL(sol->qr[2]),
|
|
|
|
sep, sqvar(sol->qr[3]), sep, sqvar(sol->qr[4]), sep, sqvar(sol->qr[5]),
|
|
|
|
sep, sol->age, sep, sol->ratio);
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution as the form of lat/lon/height -----------------------------*/
|
|
|
|
int outpos(unsigned char *buff, const char *s, const sol_t *sol,
|
2018-03-03 01:03:39 +00:00
|
|
|
const solopt_t *opt)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
double pos[3];
|
|
|
|
double dms1[3];
|
|
|
|
double dms2[3];
|
|
|
|
double P[9];
|
|
|
|
double Q[9];
|
2017-05-12 15:47:09 +00:00
|
|
|
const char *sep = opt2sep(opt);
|
2018-12-08 17:49:31 +00:00
|
|
|
char *p = reinterpret_cast<char *>(buff);
|
2019-08-25 12:59:17 +00:00
|
|
|
char *start;
|
|
|
|
start = p;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outpos :\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
ecef2pos(sol->rr, pos);
|
|
|
|
soltocov(sol, P);
|
|
|
|
covenu(pos, P, Q);
|
2017-05-12 15:47:09 +00:00
|
|
|
if (opt->height == 1)
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* geodetic height */
|
|
|
|
// pos[2] -= geoidh(pos);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
if (opt->degf)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
deg2dms(pos[0] * R2D, dms1);
|
|
|
|
deg2dms(pos[1] * R2D, dms2);
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - start), "%s%s%4.0f%s%02.0f%s%08.5f%s%4.0f%s%02.0f%s%08.5f", s, sep,
|
2018-03-03 01:03:39 +00:00
|
|
|
dms1[0], sep, dms1[1], sep, dms1[2], sep, dms2[0], sep, dms2[1], sep,
|
|
|
|
dms2[2]);
|
|
|
|
}
|
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - start), "%s%s%14.9f%s%14.9f", s, sep, pos[0] * R2D, sep, pos[1] * R2D);
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - start), "%s%10.4f%s%3d%s%3d%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%6.2f%s%6.1f\n",
|
2018-03-03 01:03:39 +00:00
|
|
|
sep, pos[2], sep, sol->stat, sep, sol->ns, sep, SQRT_SOL(Q[4]), sep,
|
|
|
|
SQRT_SOL(Q[0]), sep, SQRT_SOL(Q[8]), sep, sqvar(Q[1]), sep, sqvar(Q[2]),
|
|
|
|
sep, sqvar(Q[5]), sep, sol->age, sep, sol->ratio);
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution as the form of e/n/u-baseline -----------------------------*/
|
|
|
|
int outenu(unsigned char *buff, const char *s, const sol_t *sol,
|
2018-03-03 01:03:39 +00:00
|
|
|
const double *rb, const solopt_t *opt)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
double pos[3];
|
|
|
|
double rr[3];
|
|
|
|
double enu[3];
|
|
|
|
double P[9];
|
|
|
|
double Q[9];
|
2017-05-12 10:17:42 +00:00
|
|
|
int i;
|
2017-05-12 15:47:09 +00:00
|
|
|
const char *sep = opt2sep(opt);
|
2018-12-08 17:49:31 +00:00
|
|
|
char *p = reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outenu :\n");
|
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
rr[i] = sol->rr[i] - rb[i];
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
ecef2pos(rb, pos);
|
|
|
|
soltocov(sol, P);
|
|
|
|
covenu(pos, P, Q);
|
|
|
|
ecef2enu(pos, rr, enu);
|
2019-08-23 18:48:52 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG, "%s%s%14.4f%s%14.4f%s%14.4f%s%3d%s%3d%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%8.4f%s%6.2f%s%6.1f\n",
|
2018-03-03 01:03:39 +00:00
|
|
|
s, sep, enu[0], sep, enu[1], sep, enu[2], sep, sol->stat, sep, sol->ns, sep,
|
|
|
|
SQRT_SOL(Q[0]), sep, SQRT_SOL(Q[4]), sep, SQRT_SOL(Q[8]), sep, sqvar(Q[1]),
|
|
|
|
sep, sqvar(Q[5]), sep, sqvar(Q[2]), sep, sol->age, sep, sol->ratio);
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution in the form of nmea RMC sentence --------------------------*/
|
|
|
|
int outnmea_rmc(unsigned char *buff, const sol_t *sol)
|
|
|
|
{
|
2017-05-12 15:47:09 +00:00
|
|
|
static double dirp = 0.0;
|
2017-05-12 10:17:42 +00:00
|
|
|
gtime_t time;
|
2019-08-12 22:19:31 +00:00
|
|
|
double ep[6];
|
|
|
|
double pos[3];
|
|
|
|
double enuv[3];
|
|
|
|
double dms1[3];
|
|
|
|
double dms2[3];
|
|
|
|
double vel;
|
|
|
|
double dir;
|
|
|
|
double amag = 0.0;
|
|
|
|
char *p = reinterpret_cast<char *>(buff);
|
|
|
|
char *q;
|
|
|
|
char sum;
|
2019-08-16 13:19:31 +00:00
|
|
|
char *emag = const_cast<char *>("E");
|
2019-08-25 12:59:17 +00:00
|
|
|
const int MSG_TAIL = 6;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outnmea_rmc:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (sol->stat <= SOLQ_NONE)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - MSG_TAIL, "$GPRMC,,,,,,,,,,,,");
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = reinterpret_cast<char *>(buff) + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q;
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
time = gpst2utc(sol->time);
|
2018-03-03 01:03:39 +00:00
|
|
|
if (time.sec >= 0.995)
|
|
|
|
{
|
|
|
|
time.time++;
|
|
|
|
time.sec = 0.0;
|
|
|
|
}
|
|
|
|
time2epoch(time, ep);
|
|
|
|
ecef2pos(sol->rr, pos);
|
|
|
|
ecef2enu(pos, sol->rr + 3, enuv);
|
|
|
|
vel = norm_rtk(enuv, 3);
|
2017-05-12 15:47:09 +00:00
|
|
|
if (vel >= 1.0)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
dir = atan2(enuv[0], enuv[1]) * R2D;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (dir < 0.0)
|
|
|
|
{
|
|
|
|
dir += 360.0;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
dirp = dir;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
dir = dirp;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
deg2dms(fabs(pos[0]) * R2D, dms1);
|
|
|
|
deg2dms(fabs(pos[1]) * R2D, dms2);
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - MSG_TAIL, "$GPRMC,%02.0f%02.0f%05.2f,A,%02.0f%010.7f,%s,%03.0f%010.7f,%s,%4.2f,%4.2f,%02.0f%02.0f%02d,%.1f,%s,%s",
|
2018-03-03 01:03:39 +00:00
|
|
|
ep[3], ep[4], ep[5], dms1[0], dms1[1] + dms1[2] / 60.0, pos[0] >= 0 ? "N" : "S",
|
|
|
|
dms2[0], dms2[1] + dms2[2] / 60.0, pos[1] >= 0 ? "E" : "W", vel / KNOT2M, dir,
|
2018-12-08 17:49:31 +00:00
|
|
|
ep[2], ep[1], static_cast<int>(ep[0]) % 100, amag, emag,
|
2018-03-03 01:03:39 +00:00
|
|
|
sol->stat == SOLQ_DGPS || sol->stat == SOLQ_FLOAT || sol->stat == SOLQ_FIX ? "D" : "A");
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = reinterpret_cast<char *>(buff) + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q; /* check-sum */
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution in the form of nmea GGA sentence --------------------------*/
|
|
|
|
int outnmea_gga(unsigned char *buff, const sol_t *sol)
|
|
|
|
{
|
|
|
|
gtime_t time;
|
2019-08-12 22:19:31 +00:00
|
|
|
double h;
|
|
|
|
double ep[6];
|
|
|
|
double pos[3];
|
|
|
|
double dms1[3];
|
|
|
|
double dms2[3];
|
|
|
|
double dop = 1.0;
|
2017-05-12 10:17:42 +00:00
|
|
|
int solq;
|
2019-08-12 22:19:31 +00:00
|
|
|
char *p = reinterpret_cast<char *>(buff);
|
|
|
|
char *q;
|
|
|
|
char sum;
|
2019-08-25 12:59:17 +00:00
|
|
|
const int MSG_TAIL = 6;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outnmea_gga:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (sol->stat <= SOLQ_NONE)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - MSG_TAIL, "$GPGGA,,,,,,,,,,,,,,");
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = reinterpret_cast<char *>(buff) + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q;
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
for (solq = 0; solq < 8; solq++)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-02-22 09:47:24 +00:00
|
|
|
if (SOLQ_NMEA[solq] == sol->stat)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (solq >= 8)
|
|
|
|
{
|
|
|
|
solq = 0;
|
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
time = gpst2utc(sol->time);
|
2018-03-03 01:03:39 +00:00
|
|
|
if (time.sec >= 0.995)
|
|
|
|
{
|
|
|
|
time.time++;
|
|
|
|
time.sec = 0.0;
|
|
|
|
}
|
|
|
|
time2epoch(time, ep);
|
|
|
|
ecef2pos(sol->rr, pos);
|
2019-08-18 20:16:13 +00:00
|
|
|
h = 0; // geoidh(pos);
|
2018-03-03 01:03:39 +00:00
|
|
|
deg2dms(fabs(pos[0]) * R2D, dms1);
|
|
|
|
deg2dms(fabs(pos[1]) * R2D, dms2);
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - MSG_TAIL, "$GPGGA,%02.0f%02.0f%05.2f,%02.0f%010.7f,%s,%03.0f%010.7f,%s,%d,%02d,%.1f,%.3f,M,%.3f,M,%.1f,",
|
2018-03-03 01:03:39 +00:00
|
|
|
ep[3], ep[4], ep[5], dms1[0], dms1[1] + dms1[2] / 60.0, pos[0] >= 0 ? "N" : "S",
|
|
|
|
dms2[0], dms2[1] + dms2[2] / 60.0, pos[1] >= 0 ? "E" : "W", solq,
|
|
|
|
sol->ns, dop, pos[2] - h, h, sol->age);
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = reinterpret_cast<char *>(buff) + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q; /* check-sum */
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution in the form of nmea GSA sentences -------------------------*/
|
|
|
|
int outnmea_gsa(unsigned char *buff, const sol_t *sol,
|
2018-03-03 01:03:39 +00:00
|
|
|
const ssat_t *ssat)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
double azel[MAXSAT * 2];
|
|
|
|
double dop[4];
|
|
|
|
int i;
|
|
|
|
int sat;
|
|
|
|
int sys;
|
|
|
|
int nsat;
|
|
|
|
int prn[MAXSAT];
|
|
|
|
char *p = reinterpret_cast<char *>(buff);
|
|
|
|
char *q;
|
|
|
|
char *s;
|
|
|
|
char sum;
|
2019-08-25 12:59:17 +00:00
|
|
|
const int MSG_TAIL = 6;
|
|
|
|
const int COMMA_LENGTH = 2;
|
|
|
|
const int MAX_LENGTH_INT = 10;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outnmea_gsa:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (sol->stat <= SOLQ_NONE)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - MSG_TAIL, "$GPGSA,A,1,,,,,,,,,,,,,,,");
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = reinterpret_cast<char *>(buff) + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q;
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
/* GPGSA: gps/sbas */
|
2018-03-03 01:03:39 +00:00
|
|
|
for (sat = 1, nsat = 0; sat <= MAXSAT && nsat < 12; sat++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (!ssat[sat - 1].vs || ssat[sat - 1].azel[1] <= 0.0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
sys = satsys(sat, prn + nsat);
|
2019-02-11 20:13:02 +00:00
|
|
|
if (sys != SYS_GPS && sys != SYS_SBS)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (sys == SYS_SBS)
|
|
|
|
{
|
|
|
|
prn[nsat] += 33 - MINPRNSBS;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
azel[i + nsat * 2] = ssat[sat - 1].azel[i];
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
nsat++;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (nsat > 0)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-12 17:22:57 +00:00
|
|
|
s = p;
|
2019-08-23 18:48:52 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF, "$GPGSA,A,%d", sol->stat <= 0 ? 1 : 3);
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = 0; i < 12; i++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (i < nsat)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAX_LENGTH_INT + 2, ",%02d", prn[i]);
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, COMMA_LENGTH, ",");
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
dops(nsat, azel, 0.0, dop);
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (p - s), ",%3.1f,%3.1f,%3.1f,1", dop[1], dop[2], dop[3]);
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = s + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q; /* check-sum */
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
/* GLGSA: glonass */
|
2018-03-03 01:03:39 +00:00
|
|
|
for (sat = 1, nsat = 0; sat <= MAXSAT && nsat < 12; sat++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (!ssat[sat - 1].vs || ssat[sat - 1].azel[1] <= 0.0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (satsys(sat, prn + nsat) != SYS_GLO)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
azel[i + nsat * 2] = ssat[sat - 1].azel[i];
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
nsat++;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (nsat > 0)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-12 17:22:57 +00:00
|
|
|
s = p;
|
2019-08-25 12:59:17 +00:00
|
|
|
const int GLGSA_LENGTH = 11;
|
|
|
|
p += std::snprintf(p, GLGSA_LENGTH, "$GLGSA,A,%d", sol->stat <= 0 ? 1 : 3);
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = 0; i < 12; i++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (i < nsat)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAX_LENGTH_INT + 2, ",%02d", prn[i] + 64);
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, COMMA_LENGTH, ",");
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
dops(nsat, azel, 0.0, dop);
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (p - s), ",%3.1f,%3.1f,%3.1f,2", dop[1], dop[2], dop[3]);
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = s + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q; /* check-sum */
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
/* GAGSA: galileo */
|
2018-03-03 01:03:39 +00:00
|
|
|
for (sat = 1, nsat = 0; sat <= MAXSAT && nsat < 12; sat++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (!ssat[sat - 1].vs || ssat[sat - 1].azel[1] <= 0.0)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (satsys(sat, prn + nsat) != SYS_GAL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
azel[i + nsat * 2] = ssat[sat - 1].azel[i];
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
nsat++;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (nsat > 0)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-12 17:22:57 +00:00
|
|
|
s = p;
|
2019-08-23 18:48:52 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF, "$GAGSA,A,%d", sol->stat <= 0 ? 1 : 3);
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = 0; i < 12; i++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (i < nsat)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAX_LENGTH_INT + 2, ",%02d", prn[i]);
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, COMMA_LENGTH, ",");
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
dops(nsat, azel, 0.0, dop);
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (p - s), ",%3.1f,%3.1f,%3.1f,3", dop[1], dop[2], dop[3]);
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = s + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q; /* check-sum */
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution in the form of nmea GSV sentence --------------------------*/
|
|
|
|
int outnmea_gsv(unsigned char *buff, const sol_t *sol,
|
2018-03-03 01:03:39 +00:00
|
|
|
const ssat_t *ssat)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
double az;
|
|
|
|
double el;
|
|
|
|
double snr;
|
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
int k;
|
|
|
|
int n;
|
|
|
|
int sat;
|
|
|
|
int prn;
|
|
|
|
int sys;
|
|
|
|
int nmsg;
|
|
|
|
int sats[MAXSAT];
|
|
|
|
char *p = reinterpret_cast<char *>(buff);
|
|
|
|
char *q;
|
|
|
|
char *s;
|
|
|
|
char sum;
|
2019-08-25 12:59:17 +00:00
|
|
|
const int MSG_TAIL = 6;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outnmea_gsv:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (sol->stat <= SOLQ_NONE)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-23 18:48:52 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF, "$GPGSV,1,1,0,,,,,,,,,,,,,,,,");
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = reinterpret_cast<char *>(buff) + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q;
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
/* GPGSV: gps/sbas */
|
2018-03-03 01:03:39 +00:00
|
|
|
for (sat = 1, n = 0; sat < MAXSAT && n < 12; sat++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
sys = satsys(sat, &prn);
|
2019-02-11 20:13:02 +00:00
|
|
|
if (sys != SYS_GPS && sys != SYS_SBS)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ssat[sat - 1].vs && ssat[sat - 1].azel[1] > 0.0)
|
|
|
|
{
|
|
|
|
sats[n++] = sat;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
nmsg = n <= 0 ? 0 : (n - 1) / 4 + 1;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = k = 0; i < nmsg; i++)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-12 17:22:57 +00:00
|
|
|
s = p;
|
2019-08-23 18:48:52 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF, "$GPGSV,%d,%d,%02d", nmsg, i + 1, n);
|
2017-05-12 17:22:57 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (j = 0; j < 4; j++, k++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (k < n)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (satsys(sats[k], &prn) == SYS_SBS)
|
|
|
|
{
|
|
|
|
prn += 33 - MINPRNSBS;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
az = ssat[sats[k] - 1].azel[0] * R2D;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (az < 0.0)
|
|
|
|
{
|
|
|
|
az += 360.0;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
el = ssat[sats[k] - 1].azel[1] * R2D;
|
|
|
|
snr = ssat[sats[k] - 1].snr[0] * 0.25;
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (s - p), ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (s - p), ",,,,");
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (s - p), ",1"); /* L1C/A */
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = s + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q; /* check-sum */
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
/* GLGSV: glonass */
|
2018-03-03 01:03:39 +00:00
|
|
|
for (sat = 1, n = 0; sat < MAXSAT && n < 12; sat++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (satsys(sat, &prn) != SYS_GLO)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ssat[sat - 1].vs && ssat[sat - 1].azel[1] > 0.0)
|
|
|
|
{
|
|
|
|
sats[n++] = sat;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
nmsg = n <= 0 ? 0 : (n - 1) / 4 + 1;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = k = 0; i < nmsg; i++)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-12 17:22:57 +00:00
|
|
|
s = p;
|
2019-08-23 18:48:52 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF, "$GLGSV,%d,%d,%02d", nmsg, i + 1, n);
|
2017-05-12 17:22:57 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (j = 0; j < 4; j++, k++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (k < n)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
satsys(sats[k], &prn);
|
|
|
|
prn += 64; /* 65-99 */
|
|
|
|
az = ssat[sats[k] - 1].azel[0] * R2D;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (az < 0.0)
|
|
|
|
{
|
|
|
|
az += 360.0;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
el = ssat[sats[k] - 1].azel[1] * R2D;
|
|
|
|
snr = ssat[sats[k] - 1].snr[0] * 0.25;
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (s - p), ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (s - p), ",,,,");
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (s - p), ",1"); /* L1C/A */
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = s + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q; /* check-sum */
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
/* GAGSV: galileo */
|
2018-03-03 01:03:39 +00:00
|
|
|
for (sat = 1, n = 0; sat < MAXSAT && n < 12; sat++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (satsys(sat, &prn) != SYS_GAL)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (ssat[sat - 1].vs && ssat[sat - 1].azel[1] > 0.0)
|
|
|
|
{
|
|
|
|
sats[n++] = sat;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
nmsg = n <= 0 ? 0 : (n - 1) / 4 + 1;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = k = 0; i < nmsg; i++)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-12 17:22:57 +00:00
|
|
|
s = p;
|
2019-08-23 18:48:52 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF, "$GAGSV,%d,%d,%02d", nmsg, i + 1, n);
|
2017-05-12 17:22:57 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (j = 0; j < 4; j++, k++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (k < n)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
satsys(sats[k], &prn); /* 1-36 */
|
|
|
|
az = ssat[sats[k] - 1].azel[0] * R2D;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (az < 0.0)
|
|
|
|
{
|
|
|
|
az += 360.0;
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
el = ssat[sats[k] - 1].azel[1] * R2D;
|
|
|
|
snr = ssat[sats[k] - 1].snr[0] * 0.25;
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (s - p), ",%02d,%02.0f,%03.0f,%02.0f", prn, el, az, snr);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (s - p), ",,,,");
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLBUF - (s - p), ",7"); /* L1BC */
|
2019-02-11 20:13:02 +00:00
|
|
|
for (q = s + 1, sum = 0; *q; q++)
|
|
|
|
{
|
|
|
|
sum ^= *q; /* check-sum */
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MSG_TAIL, "*%02X%c%c", sum, 0x0D, 0x0A);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output processing options ---------------------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* output processing options to buffer
|
|
|
|
* args : unsigned char *buff IO output buffer
|
|
|
|
* prcopt_t *opt I processign options
|
|
|
|
* return : number of output bytes
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
int outprcopts(unsigned char *buff, const prcopt_t *opt)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
const int sys[] = {SYS_GPS, SYS_GLO, SYS_GAL, SYS_QZS, SYS_SBS, 0};
|
|
|
|
const char *s1[] = {"single", "dgps", "kinematic", "static", "moving-base", "fixed",
|
|
|
|
"ppp-kinematic", "ppp-static", "ppp-fixed", ""};
|
|
|
|
const char *s2[] = {"L1", "L1+L2", "L1+L2+L5", "L1+L2+L5+L6", "L1+L2+L5+L6+L7",
|
|
|
|
"L1+L2+L5+L6+L7+L8", ""};
|
|
|
|
const char *s3[] = {"forward", "backward", "combined"};
|
|
|
|
const char *s4[] = {"off", "broadcast", "sbas", "iono-free", "estimation",
|
|
|
|
"ionex tec", "qzs", "lex", "vtec_sf", "vtec_ef", "gtec", ""};
|
|
|
|
const char *s5[] = {"off", "saastamoinen", "sbas", "est ztd", "est ztd+grad", ""};
|
|
|
|
const char *s6[] = {"broadcast", "precise", "broadcast+sbas", "broadcast+ssr apc",
|
|
|
|
"broadcast+ssr com", "qzss lex", ""};
|
|
|
|
const char *s7[] = {"gps", "glonass", "galileo", "qzss", "sbas", ""};
|
|
|
|
const char *s8[] = {"off", "continuous", "instantaneous", "fix and hold", ""};
|
|
|
|
const char *s9[] = {"off", "on", "auto calib", "external calib", ""};
|
2017-05-12 10:17:42 +00:00
|
|
|
int i;
|
2018-12-08 17:49:31 +00:00
|
|
|
char *p = reinterpret_cast<char *>(buff);
|
2019-08-25 12:59:17 +00:00
|
|
|
char *s;
|
|
|
|
s = p;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outprcopts:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-08-23 18:48:52 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG, "%s pos mode : %s\n", COMMENTH, s1[opt->mode]);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (PMODE_DGPS <= opt->mode && opt->mode <= PMODE_FIXED)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s freqs : %s\n", COMMENTH, s2[opt->nf - 1]);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (opt->mode > PMODE_SINGLE)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s solution : %s\n", COMMENTH, s3[opt->soltype]);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s elev mask : %.1f deg\n", COMMENTH, opt->elmin * R2D);
|
2018-03-03 01:03:39 +00:00
|
|
|
if (opt->mode > PMODE_SINGLE)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s dynamics : %s\n", COMMENTH, opt->dynamics ? "on" : "off");
|
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s tidecorr : %s\n", COMMENTH, opt->tidecorr ? "on" : "off");
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
if (opt->mode <= PMODE_FIXED)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s ionos opt : %s\n", COMMENTH, s4[opt->ionoopt]);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s tropo opt : %s\n", COMMENTH, s5[opt->tropopt]);
|
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s ephemeris : %s\n", COMMENTH, s6[opt->sateph]);
|
2017-05-12 15:47:09 +00:00
|
|
|
if (opt->navsys != SYS_GPS)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s navi sys :", COMMENTH);
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = 0; sys[i]; i++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (opt->navsys & sys[i])
|
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), " %s", s7[i]);
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
if (PMODE_KINEMA <= opt->mode && opt->mode <= PMODE_FIXED)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s amb res : %s\n", COMMENTH, s8[opt->modear]);
|
2018-03-03 01:03:39 +00:00
|
|
|
if (opt->navsys & SYS_GLO)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s amb glo : %s\n", COMMENTH, s9[opt->glomodear]);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (opt->thresar[0] > 0.0)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s val thres : %.1f\n", COMMENTH, opt->thresar[0]);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (opt->mode == PMODE_MOVEB && opt->baseline[0] > 0.0)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s baseline : %.4f %.4f m\n", COMMENTH,
|
2018-03-03 01:03:39 +00:00
|
|
|
opt->baseline[0], opt->baseline[1]);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
for (i = 0; i < 2; i++)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (opt->mode == PMODE_SINGLE || (i >= 1 && opt->mode > PMODE_FIXED))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s antenna%d : %-21s (%7.4f %7.4f %7.4f)\n", COMMENTH,
|
2018-03-03 01:03:39 +00:00
|
|
|
i + 1, opt->anttype[i], opt->antdel[i][0], opt->antdel[i][1],
|
|
|
|
opt->antdel[i][2]);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution header ------------------------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* output solution header to buffer
|
|
|
|
* args : unsigned char *buff IO output buffer
|
|
|
|
* solopt_t *opt I solution options
|
|
|
|
* return : number of output bytes
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
int outsolheads(unsigned char *buff, const solopt_t *opt)
|
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
const char *s1[] = {"WGS84", "Tokyo"};
|
|
|
|
const char *s2[] = {"ellipsoidal", "geodetic"};
|
|
|
|
const char *s3[] = {"GPST", "UTC ", "JST "};
|
|
|
|
const char *sep = opt2sep(opt);
|
2018-12-08 17:49:31 +00:00
|
|
|
char *p = reinterpret_cast<char *>(buff);
|
2018-03-03 01:03:39 +00:00
|
|
|
int timeu = opt->timeu < 0 ? 0 : (opt->timeu > 20 ? 20 : opt->timeu);
|
2019-08-25 12:59:17 +00:00
|
|
|
char *s;
|
|
|
|
s = p;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outsolheads:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
if (opt->posf == SOLF_NMEA)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
|
|
|
if (opt->outhead)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-08-23 18:48:52 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG, "%s (", COMMENTH);
|
2018-03-03 01:03:39 +00:00
|
|
|
if (opt->posf == SOLF_XYZ)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "x/y/z-ecef=WGS84");
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else if (opt->posf == SOLF_ENU)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "e/n/u-baseline=WGS84");
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
else
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "lat/lon/height=%s/%s", s1[opt->datum], s2[opt->height]);
|
2019-02-11 20:13:02 +00:00
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), ",Q=1:fix,2:float,3:sbas,4:dgps,5:single,6:ppp,ns=# of satellites)\n");
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%s %-*s%s", COMMENTH, (opt->timef ? 16 : 8) + timeu + 1, s3[opt->times], sep);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (opt->posf == SOLF_LLH)
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* lat/lon/hgt */
|
|
|
|
if (opt->degf)
|
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%16s%s%16s%s%10s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n",
|
2018-03-03 01:03:39 +00:00
|
|
|
"latitude(d'\")", sep, "longitude(d'\")", sep, "height(m)", sep,
|
|
|
|
"Q", sep, "ns", sep, "sdn(m)", sep, "sde(m)", sep, "sdu(m)", sep,
|
|
|
|
"sdne(m)", sep, "sdeu(m)", sep, "sdue(m)", sep, "age(s)", sep, "ratio");
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%14s%s%14s%s%10s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n",
|
2018-03-03 01:03:39 +00:00
|
|
|
"latitude(deg)", sep, "longitude(deg)", sep, "height(m)", sep,
|
|
|
|
"Q", sep, "ns", sep, "sdn(m)", sep, "sde(m)", sep, "sdu(m)", sep,
|
|
|
|
"sdne(m)", sep, "sdeu(m)", sep, "sdun(m)", sep, "age(s)", sep, "ratio");
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
else if (opt->posf == SOLF_XYZ)
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* x/y/z-ecef */
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%14s%s%14s%s%14s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n",
|
2018-03-03 01:03:39 +00:00
|
|
|
"x-ecef(m)", sep, "y-ecef(m)", sep, "z-ecef(m)", sep, "Q", sep, "ns", sep,
|
|
|
|
"sdx(m)", sep, "sdy(m)", sep, "sdz(m)", sep, "sdxy(m)", sep,
|
|
|
|
"sdyz(m)", sep, "sdzx(m)", sep, "age(s)", sep, "ratio");
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
else if (opt->posf == SOLF_ENU)
|
2017-05-12 17:22:57 +00:00
|
|
|
{ /* e/n/u-baseline */
|
2019-08-25 12:59:17 +00:00
|
|
|
p += std::snprintf(p, MAXSOLMSG - (p - s), "%14s%s%14s%s%14s%s%3s%s%3s%s%8s%s%8s%s%8s%s%8s%s%8s%s%8s%s%6s%s%6s\n",
|
2018-03-03 01:03:39 +00:00
|
|
|
"e-baseline(m)", sep, "n-baseline(m)", sep, "u-baseline(m)", sep,
|
|
|
|
"Q", sep, "ns", sep, "sde(m)", sep, "sdn(m)", sep, "sdu(m)", sep,
|
|
|
|
"sden(m)", sep, "sdnu(m)", sep, "sdue(m)", sep, "age(s)", sep, "ratio");
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-12-08 17:49:31 +00:00
|
|
|
return p - reinterpret_cast<char *>(buff);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution body --------------------------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* output solution body to buffer
|
|
|
|
* args : unsigned char *buff IO output buffer
|
|
|
|
* sol_t *sol I solution
|
|
|
|
* double *rb I base station position {x,y,z} (ecef) (m)
|
|
|
|
* solopt_t *opt I solution options
|
|
|
|
* return : number of output bytes
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
int outsols(unsigned char *buff, const sol_t *sol, const double *rb,
|
2018-03-03 01:03:39 +00:00
|
|
|
const solopt_t *opt)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2019-08-12 22:19:31 +00:00
|
|
|
gtime_t time;
|
|
|
|
gtime_t ts = {0, 0.0};
|
2017-05-12 10:17:42 +00:00
|
|
|
double gpst;
|
2019-08-12 22:19:31 +00:00
|
|
|
int week;
|
|
|
|
int timeu;
|
2017-05-12 15:47:09 +00:00
|
|
|
const char *sep = opt2sep(opt);
|
2017-08-06 08:32:12 +00:00
|
|
|
char s[255];
|
2017-05-12 15:47:09 +00:00
|
|
|
unsigned char *p = buff;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outsols :\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (opt->posf == SOLF_NMEA)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (opt->nmeaintv[0] < 0.0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!screent(sol->time, ts, ts, opt->nmeaintv[0]))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
if (sol->stat <= SOLQ_NONE || (opt->posf == SOLF_ENU && norm_rtk(rb, 3) <= 0.0))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-08-06 08:26:56 +00:00
|
|
|
timeu = opt->timeu < 0 ? 0 : (opt->timeu > 20 ? 20 : opt->timeu);
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
time = sol->time;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (opt->times >= TIMES_UTC)
|
|
|
|
{
|
|
|
|
time = gpst2utc(time);
|
|
|
|
}
|
|
|
|
if (opt->times == TIMES_JST)
|
|
|
|
{
|
|
|
|
time = timeadd(time, 9 * 3600.0);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if (opt->timef)
|
2019-02-11 20:13:02 +00:00
|
|
|
{
|
|
|
|
time2str(time, s, timeu);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
else
|
|
|
|
{
|
2017-08-06 08:26:56 +00:00
|
|
|
gpst = time2gpst(time, &week);
|
|
|
|
if (86400 * 7 - gpst < 0.5 / pow(10.0, timeu))
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
|
|
|
week++;
|
|
|
|
gpst = 0.0;
|
|
|
|
}
|
2019-08-23 18:48:52 +00:00
|
|
|
std::snprintf(s, sizeof(s), "%4d%s%*.*f", week, sep, 6 + (timeu <= 0 ? 0 : timeu + 1), timeu, gpst);
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
switch (opt->posf)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
case SOLF_LLH:
|
|
|
|
p += outpos(p, s, sol, opt);
|
|
|
|
break;
|
|
|
|
case SOLF_XYZ:
|
|
|
|
p += outecef(p, s, sol, opt);
|
|
|
|
break;
|
|
|
|
case SOLF_ENU:
|
|
|
|
p += outenu(p, s, sol, rb, opt);
|
|
|
|
break;
|
|
|
|
case SOLF_NMEA:
|
|
|
|
p += outnmea_rmc(p, sol);
|
|
|
|
p += outnmea_gga(p, sol);
|
|
|
|
break;
|
|
|
|
}
|
2017-08-06 08:26:56 +00:00
|
|
|
return p - buff;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution extended ----------------------------------------------------
|
2019-07-20 10:55:46 +00:00
|
|
|
* output solution extended information
|
2017-05-12 17:22:57 +00:00
|
|
|
* args : unsigned char *buff IO output buffer
|
|
|
|
* sol_t *sol I solution
|
|
|
|
* ssat_t *ssat I satellite status
|
|
|
|
* solopt_t *opt I solution options
|
|
|
|
* return : number of output bytes
|
|
|
|
* notes : only support nmea
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
int outsolexs(unsigned char *buff, const sol_t *sol, const ssat_t *ssat,
|
2018-03-03 01:03:39 +00:00
|
|
|
const solopt_t *opt)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2017-05-13 08:41:35 +00:00
|
|
|
gtime_t ts = {0, 0.0};
|
2017-05-12 15:47:09 +00:00
|
|
|
unsigned char *p = buff;
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
trace(3, "outsolexs:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 15:47:09 +00:00
|
|
|
if (opt->posf == SOLF_NMEA)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2019-02-11 20:13:02 +00:00
|
|
|
if (opt->nmeaintv[1] < 0.0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (!screent(sol->time, ts, ts, opt->nmeaintv[1]))
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2017-05-12 15:47:09 +00:00
|
|
|
if (opt->posf == SOLF_NMEA)
|
2017-05-12 17:22:57 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
p += outnmea_gsa(p, sol, ssat);
|
|
|
|
p += outnmea_gsv(p, sol, ssat);
|
2017-05-12 17:22:57 +00:00
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
return p - buff;
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output processing option ----------------------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* output processing option to file
|
|
|
|
* args : FILE *fp I output file pointer
|
|
|
|
* prcopt_t *opt I processing options
|
|
|
|
* return : none
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
void outprcopt(FILE *fp, const prcopt_t *opt)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
unsigned char buff[MAXSOLMSG + 1];
|
2017-05-12 10:17:42 +00:00
|
|
|
int n;
|
|
|
|
|
2017-05-12 17:22:57 +00:00
|
|
|
trace(3, "outprcopt:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 17:22:57 +00:00
|
|
|
if ((n = outprcopts(buff, opt)) > 0)
|
|
|
|
{
|
|
|
|
fwrite(buff, n, 1, fp);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution header ------------------------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* output solution heade to file
|
|
|
|
* args : FILE *fp I output file pointer
|
|
|
|
* solopt_t *opt I solution options
|
|
|
|
* return : none
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
void outsolhead(FILE *fp, const solopt_t *opt)
|
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
unsigned char buff[MAXSOLMSG + 1];
|
2017-05-12 10:17:42 +00:00
|
|
|
int n;
|
|
|
|
|
2017-05-12 17:22:57 +00:00
|
|
|
trace(3, "outsolhead:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 17:22:57 +00:00
|
|
|
if ((n = outsolheads(buff, opt)) > 0)
|
|
|
|
{
|
|
|
|
fwrite(buff, n, 1, fp);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution body --------------------------------------------------------
|
2017-05-12 17:22:57 +00:00
|
|
|
* output solution body to file
|
|
|
|
* args : FILE *fp I output file pointer
|
|
|
|
* sol_t *sol I solution
|
|
|
|
* double *rb I base station position {x,y,z} (ecef) (m)
|
|
|
|
* solopt_t *opt I solution options
|
|
|
|
* return : none
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
void outsol(FILE *fp, const sol_t *sol, const double *rb,
|
2018-03-03 01:03:39 +00:00
|
|
|
const solopt_t *opt)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
unsigned char buff[MAXSOLMSG + 1];
|
2017-05-12 10:17:42 +00:00
|
|
|
int n;
|
|
|
|
|
2017-05-12 17:22:57 +00:00
|
|
|
trace(3, "outsol :\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 17:22:57 +00:00
|
|
|
if ((n = outsols(buff, sol, rb, opt)) > 0)
|
|
|
|
{
|
|
|
|
fwrite(buff, n, 1, fp);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* output solution extended ----------------------------------------------------
|
2019-07-20 10:55:46 +00:00
|
|
|
* output solution extended information to file
|
2017-05-12 17:22:57 +00:00
|
|
|
* args : FILE *fp I output file pointer
|
|
|
|
* sol_t *sol I solution
|
|
|
|
* ssat_t *ssat I satellite status
|
|
|
|
* solopt_t *opt I solution options
|
|
|
|
* return : output size (bytes)
|
|
|
|
* notes : only support nmea
|
|
|
|
*-----------------------------------------------------------------------------*/
|
2017-05-12 10:17:42 +00:00
|
|
|
void outsolex(FILE *fp, const sol_t *sol, const ssat_t *ssat,
|
2018-03-03 01:03:39 +00:00
|
|
|
const solopt_t *opt)
|
2017-05-12 10:17:42 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
unsigned char buff[MAXSOLMSG + 1];
|
2017-05-12 10:17:42 +00:00
|
|
|
int n;
|
|
|
|
|
2017-05-12 17:22:57 +00:00
|
|
|
trace(3, "outsolex:\n");
|
2017-05-12 10:17:42 +00:00
|
|
|
|
2017-05-12 17:22:57 +00:00
|
|
|
if ((n = outsolexs(buff, sol, ssat, opt)) > 0)
|
|
|
|
{
|
|
|
|
fwrite(buff, n, 1, fp);
|
|
|
|
}
|
2017-05-12 10:17:42 +00:00
|
|
|
}
|