13 uint32_t checksum = 0;
15 uint8_t *
end = str + size;
16 for(uint8_t *ptr=str; ptr<
end; ptr++)
27 while(*str != 0 && *str !=
',')
38 double deg = (int)ddmm / 100 ;
40 return deg + (ddmm / 60) ;
46 *status |= state & mask;
57 const int doy[]={1,32,60,91,121,152,182,213,244,274,305,335};
59 int days,sec,year=(int)ep[0],mon=(
int)ep[1],day=(int)ep[2];
61 if (year<1970||2099<year||mon<1||12<mon)
return time;
64 days=(year-1970)*365+(year-1969)/4+doy[mon-1]+day-2+(year%4==0&&mon>=3?1:0);
65 sec=(int)floor(ep[5]);
66 time.
time=(time_t)days*86400+(
int)ep[3]*3600+(int)ep[4]*60+sec;
71 static const double gpst0[]={1980,1, 6,0,0,0};
83 time_t w=(time_t)(sec/(86400*7));
85 if (week) *week=(int)w;
86 return (
double)(sec-(double)w*86400*7)+t.
sec;
134 ",%02d:%02d:02%d.02%d" 148 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
154 int n =
SNPRINTF(a, aSize,
"$PTOW");
155 n +=
SNPRINTF(a+n, aSize-n,
",%.6lf", imuTow);
156 n +=
SNPRINTF(a+n, aSize-n,
",%.6lf", insTow);
157 n +=
SNPRINTF(a+n, aSize-n,
",%u", gpsWeek);
160 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
166 int n =
SNPRINTF(a, aSize,
"$PIMU");
186 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
192 int n =
SNPRINTF(a, aSize,
"$PPIMU");
211 n +=
SNPRINTF(a+n, aSize-n,
",%.3f", pimu.
dt);
214 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
220 int n =
SNPRINTF(a, aSize,
"$PINS1");
223 n +=
SNPRINTF(a+n, aSize-n,
",%u", (
unsigned int)ins1.
week);
235 n +=
SNPRINTF(a+n, aSize-n,
",%.8lf", ins1.
lla[0]);
236 n +=
SNPRINTF(a+n, aSize-n,
",%.8lf", ins1.
lla[1]);
237 n +=
SNPRINTF(a+n, aSize-n,
",%.3lf", ins1.
lla[2]);
244 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
250 int n =
SNPRINTF(a, aSize,
"$PINS2");
253 n +=
SNPRINTF(a+n, aSize-n,
",%u", (
unsigned int)ins2.
week);
266 n +=
SNPRINTF(a+n, aSize-n,
",%.8lf", ins2.
lla[0]);
267 n +=
SNPRINTF(a+n, aSize-n,
",%.8lf", ins2.
lla[1]);
268 n +=
SNPRINTF(a+n, aSize-n,
",%.3lf", ins2.
lla[2]);
271 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
277 int n =
SNPRINTF(a, aSize,
"$PSTRB");
278 n +=
SNPRINTF(a+n, aSize-n,
",%u", (
unsigned int)strobe.
week);
280 n +=
SNPRINTF(a+n, aSize-n,
",%u", (
unsigned int)strobe.
pin);
281 n +=
SNPRINTF(a+n, aSize-n,
",%u", (
unsigned int)strobe.
count);
284 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
290 int n =
SNPRINTF(a, aSize,
"$PGPSP");
292 n +=
SNPRINTF(a+n, aSize-n,
",%u", (
unsigned int)pos.
week);
314 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
320 int degrees = (int)(v);
321 double minutes = (v-((double)degrees))*60.0;
323 return SNPRINTF(a, aSize,
",%02d%07.4lf,%c", abs(degrees), fabs(minutes), (degrees >= 0 ?
'N' :
'S'));
328 int degrees = (int)(v);
329 double minutes = (v-((double)degrees))*60.0;
331 return SNPRINTF(a, aSize,
",%03d%07.4lf,%c", abs(degrees), fabs(minutes), (degrees >= 0 ?
'E' :
'W'));
336 unsigned int millisecondsToday = timeOfWeekMs % 86400000;
337 unsigned int hours = millisecondsToday / 1000 / 60 / 60;
338 unsigned int minutes = (millisecondsToday / (1000 * 60)) % 60;
339 unsigned int seconds = (millisecondsToday / 1000) % 60;
341 return SNPRINTF(a, aSize,
",%02u%02u%02u", hours, minutes, seconds);
346 unsigned int millisecondsToday = timeOfWeekMs % 86400000;
347 unsigned int hours = millisecondsToday / 1000 / 60 / 60;
348 unsigned int minutes = (millisecondsToday / (1000 * 60)) % 60;
349 unsigned int seconds = (millisecondsToday / 1000) % 60;
350 unsigned int milliseconds = millisecondsToday % 1000;
352 return SNPRINTF(a, aSize,
",%02u%02u%02u.%03u", hours, minutes, seconds, milliseconds);
358 int32_t year, month, day, hours, minutes, seconds, milliseconds;
359 julianToDate(julian, &year, &month, &day, &hours, &minutes, &seconds, &milliseconds);
361 return SNPRINTF(a, aSize,
",%02u%02u%02u", (
unsigned int)day, (
unsigned int)month, (
unsigned int)(year-2000));
367 int32_t year, month, day, hours, minutes, seconds, milliseconds;
368 julianToDate(julian, &year, &month, &day, &hours, &minutes, &seconds, &milliseconds);
370 return SNPRINTF(a, aSize,
",%02u,%02u,%04u", (
unsigned int)day, (
unsigned int)month, (
unsigned int)year);
431 int n =
SNPRINTF(a, aSize,
"$GPGGA");
442 (
unsigned int)fixQuality,
449 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
474 int n =
SNPRINTF(a, aSize,
"$GPGLL");
481 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
491 fixQuality = 0;
break;
493 fixQuality = 2;
break;
501 fixQuality = 3;
break;
546 (
unsigned int)fixQuality);
548 for (uint32_t i = 0; i < 12; i++)
569 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
609 int n =
SNPRINTF(a, aSize,
"$GPRMC");
624 float courseMadeTrue = 0.0f;
635 bool positive = (magDec >= 0.0);
641 (positive ?
"E" :
"W"));
644 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
659 int n =
SNPRINTF(a, aSize,
"$GPZDA");
662 n +=
SNPRINTF(a+n, aSize-n,
",00,00");
665 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
687 int n =
SNPRINTF(a, aSize,
"$PASHR");
694 n +=
SNPRINTF(a+n, aSize-n,
",%+.2f", heave);
709 n +=
SNPRINTF(a+n, aSize-n,
",%d", fix);
713 n +=
SNPRINTF(a+n, aSize-n,
"*%.2x\r\n", checkSum);
724 if(pHandle >= NUM_COM_PORTS)
728 char *ptr = (
char *)msg;
735 if(*ptr!=
','){ options = atoi(ptr); }
737 if(*ptr!=
','){ tmp.
pimu = atoi(ptr); }
739 if(*ptr!=
','){ tmp.
ppimu = atoi(ptr); }
741 if(*ptr!=
','){ tmp.
pins1 = atoi(ptr); }
743 if(*ptr!=
','){ tmp.
pins2 = atoi(ptr); }
745 if(*ptr!=
','){ tmp.
pgpsp = atoi(ptr); }
749 if(*ptr!=
','){ tmp.
gpgga = atoi(ptr); }
751 if(*ptr!=
','){ tmp.
gpgll = atoi(ptr); }
753 if(*ptr!=
','){ tmp.
gpgsa = atoi(ptr); }
755 if(*ptr!=
','){ tmp.
gprmc = atoi(ptr); }
757 if(*ptr!=
','){ tmp.
gpzda = atoi(ptr); }
759 if(*ptr!=
','){ tmp.
pashr = atoi(ptr); }
767 asciiPeriod[i] = tmp;
785 int parse_nmea_zda(
const char msg[],
int msgSize,
double &day,
double &month,
double &year)
787 char *ptr = (
char *)&msg[7];
817 char *ptr = (
char *)&msg[7];
821 double UTCtime = atof(ptr);
825 datetime[3] = ((int)UTCtime / 10000) % 100;
826 datetime[4] = ((int)UTCtime / 100) % 100;
827 double subSec = UTCtime - (int)UTCtime;
828 datetime[5] = (double)((
int)UTCtime % 100) + subSec + gpsPos->
leapS;
833 uint32_t iTOW = (uint32_t)((iTOWd + 0.00001) * 1000.0);
851 char pMode[4] = {0,0,0,0};
864 int differential = 0;
865 if(pMode[0] ==
'R' || pMode[1] ==
'R' || pMode[2] ==
'R' || pMode[3] ==
'R')
867 else if(pMode[0] ==
'F' || pMode[1] ==
'F' || pMode[2] ==
'F' || pMode[3] ==
'F')
869 else if(pMode[0] ==
'D' || pMode[1] ==
'D' || pMode[2] ==
'D' || pMode[3] ==
'D')
874 else if(pMode[0] ==
'A' || pMode[1] ==
'A' || pMode[2] ==
'A' || pMode[3] ==
'A')
876 else if(pMode[0] ==
'E' || pMode[1] ==
'E' || pMode[2] ==
'E' || pMode[3] ==
'E')
880 if(fixType == 2 && navMode == 3)
884 *satsUsed = atoi(ptr);
892 gpsPos->
hMSL = (float)lla[2];
896 double sep = atof(ptr);
904 gpsPos->
lla[0] = lla[0];
905 gpsPos->
lla[1] = lla[1];
906 gpsPos->
lla[2] = lla[2] + sep;
911 lla[2] = gpsPos->
lla[2];
919 gpsPos->
ecef[0] = ecef[0];
920 gpsPos->
ecef[1] = ecef[1];
921 gpsPos->
ecef[2] = ecef[2];
941 char *ptr = (
char *)&msg[7];
945 double UTCtime = atof(ptr);
949 datetime[3] = ((int)UTCtime / 10000) % 100;
950 datetime[4] = ((int)UTCtime / 100) % 100;
951 double subSec = UTCtime - (int)UTCtime;
952 datetime[5] = (double)((
int)UTCtime % 100) + subSec + gpsPos->
leapS;
957 uint32_t iTOW = (uint32_t)((iTOWd + 0.00001) * 1000.0);
975 int quality = atoi(ptr);
980 int differential = 0;
998 if(fixType == 2 && navMode == 3)
1002 *satsUsed = atoi(ptr);
1010 gpsPos->
hMSL = (float)lla[2];
1017 double sep = atof(ptr);
1025 gpsPos->
lla[0] = lla[0];
1026 gpsPos->
lla[1] = lla[1];
1027 gpsPos->
lla[2] = lla[2] + sep;
1032 lla[2] = gpsPos->
lla[2];
1039 gpsPos->
week = week;
1040 gpsPos->
ecef[0] = ecef[0];
1041 gpsPos->
ecef[1] = ecef[1];
1042 gpsPos->
ecef[2] = ecef[2];
1057 char *ptr = (
char *)&msg[7];
1061 double UTCtime = atof(ptr);
1065 for(
int i=0;i<5;++i)
1073 float cogRad =
DEG2RAD((
float)atof(ptr));
1076 datetime[3] = ((int)UTCtime / 10000) % 100;
1077 datetime[4] = ((int)UTCtime / 100) % 100;
1078 double subSec = UTCtime - (int)UTCtime;
1079 datetime[5] = (double)((
int)UTCtime % 100) + subSec;
1083 gpsVel->
timeOfWeekMs = (uint32_t)((iTOWd + 0.00001) * 1000.0);
1086 gpsVel->
vel[0] = spdm_s * cosf(cogRad);
1087 gpsVel->
vel[1] = spdm_s * sinf(cogRad);
1102 char *ptr = (
char *)&msg[7];
1109 *navMode = atoi(ptr);
1112 for(
int i=0;i<13;++i)
1118 gpsPos->
pDop = (float)atof(ptr);
1127 int parse_nmea_gsv(
const char msg[],
int msgSize,
gps_sat_t* gpsSat,
int lastGSVmsg[2],
int *satCount, uint32_t *cnoSum, uint32_t *cnoCount)
1129 char *ptr = (
char *)&msg[7];
1137 int msgNum = atoi(ptr);
1141 int numSV = atoi(ptr);
1147 if(lastGSVmsg[0] != msg[2] || lastGSVmsg[1] < msgNum)
1150 lastGSVmsg[0] = msg[2];
1151 lastGSVmsg[1] = msgNum;
1154 int countSat = numSV - (msgNum - 1) * 4;
1158 for(
int i=0;i<countSat;++i)
1161 int svid = atoi(ptr);
1165 int elv = atoi(ptr);
1173 int cno = atoi(ptr);
1179 auto& svDest = gpsSat->
sat[(*satCount)++];
1189 svDest.svId = svid-192;
1197 svDest.svId = svid + 87;
1210 svDest.svId = svid - 64;
int parse_nmea_gns(const char msg[], int msgSize, gps_pos_t *gpsPos, double datetime[6], int *satsUsed, int navMode)
int parse_nmea_gsa(const char msg[], int msgSize, gps_pos_t *gpsPos, int *navMode)
static const double gpst0[]
#define RMC_OPTIONS_PORT_SER1
int gps_to_nmea_gll(char a[], const int aSize, gps_pos_t &pos)
int gps_to_nmea_pashr(char a[], const int aSize, gps_pos_t &pos, ins_1_t &ins1, float heave, inl2_ned_sigma_t &sigma)
void set_gpsPos_status_mask(uint32_t *status, uint32_t state, uint32_t mask)
#define RMC_OPTIONS_PORT_USB
def lla2ecef(lla, metric=True)
static int asciiSnprintfGPSDateOfLastFixCSV(char *a, size_t aSize, gps_pos_t &pos)
static int asciiSnprintfGPSTimeOfLastFixMilliseconds(char *a, size_t aSize, uint32_t timeOfWeekMs)
int parse_nmea_zda(const char msg[], int msgSize, double &day, double &month, double &year)
uint32_t parse_nmea_ascb(int pHandle, const char msg[], int msgSize, ascii_msgs_t asciiPeriod[NUM_COM_PORTS])
int dimu_to_nmea_pimu(char a[], const int aSize, dual_imu_t &dimu)
void quat_ecef2ned(float lat, float lon, float *qe2n)
int tow_to_nmea_ptow(char a[], const int aSize, double imuTow, double insTow, unsigned int gpsWeek)
void quatConjRot(ixVector3 result, const ixQuat q, const ixVector3 v)
#define INS_STATUS_NAV_FIX_STATUS(insStatus)
int gps_to_nmea_pgpsp(char a[], const int aSize, gps_pos_t &pos, gps_vel_t &vel)
static int asciiSnprintfLonToDegMin(char *a, size_t aSize, double v)
int ins1_to_nmea_pins1(char a[], const int aSize, ins_1_t &ins1)
static int asciiSnprintfGPSDateOfLastFix(char *a, size_t aSize, gps_pos_t &pos)
double gpsToJulian(int32_t gpsWeek, int32_t gpsMilliseconds, int32_t leapSeconds)
char * ASCII_find_next_field(char *str)
#define RMC_OPTIONS_PORT_MASK
int gps_to_nmea_gsa(char a[], const int aSize, gps_pos_t &pos, gps_sat_t &sat)
int strobe_to_nmea_pstrb(char a[], const int aSize, strobe_in_time_t &strobe)
char addInfo[DEVINFO_ADDINFO_STRLEN]
static int asciiSnprintfLatToDegMin(char *a, size_t aSize, double v)
uint32_t ASCII_compute_checksum(uint8_t *str, int size)
char manufacturer[DEVINFO_MANUFACTURER_STRLEN]
#define INS_STATUS_SOLUTION(insStatus)
int dev_info_to_nmea_info(char a[], const int aSize, dev_info_t &info)
int parse_nmea_gga(const char msg[], int msgSize, gps_pos_t *gpsPos, double datetime[6], int *satsUsed, int navMode)
#define MAX_NUM_SAT_CHANNELS
double time2gpst(gtime_t t, int *week)
#define RMC_OPTIONS_PORT_CURRENT
int gps_to_nmea_gga(char a[], const int aSize, gps_pos_t &pos)
gps_sat_sv_t sat[MAX_NUM_SAT_CHANNELS]
int gps_to_nmea_zda(char a[], const int aSize, gps_pos_t &pos)
int pimu_to_nmea_ppimu(char a[], const int aSize, preintegrated_imu_t &pimu)
gtime_t epoch2time(const double *ep)
#define RMC_OPTIONS_PORT_SER0
double ddmm2deg(double ddmm)
int ins2_to_nmea_pins2(char a[], const int aSize, ins_2_t &ins2)
void julianToDate(double julian, int32_t *year, int32_t *month, int32_t *day, int32_t *hour, int32_t *minute, int32_t *second, int32_t *millisecond)
static int asciiSnprintfGPSTimeOfLastFix(char *a, size_t aSize, uint32_t timeOfWeekMs)
int gps_to_nmea_rmc(char a[], const int aSize, gps_pos_t &pos, gps_vel_t &vel, float magDeclination)
int parse_nmea_gsv(const char msg[], int msgSize, gps_sat_t *gpsSat, int lastGSVmsg[2], int *satCount, uint32_t *cnoSum, uint32_t *cnoCount)
int parse_nmea_rmc(const char msg[], int msgSize, gps_vel_t *gpsVel, double datetime[6], int *satsUsed, int navMode)