21 uint8_t tmp1 = *ptr++;
22 uint8_t tmp2 = *ptr++;
23 uint8_t tmp3 = *ptr++;
34 uint8_t* ptr = (uint8_t*)&val;
35 uint8_t* ptr2 = (uint8_t*)&flippedFloat;
36 uint8_t tmp1 = *ptr++;
37 uint8_t tmp2 = *ptr++;
38 uint8_t tmp3 = *ptr++;
49 const uint32_t* w = (
const uint32_t*)(ptr);
76 if (dataLength & 0x00000003)
81 uint32_t* dataPtr = (
void*)data;
82 uint32_t* dataPtrEnd = (
void*)(data + dataLength);
84 while (dataPtr < dataPtrEnd)
91 void flipDoubles(uint8_t*
data,
int dataLength,
int offset, uint16_t* offsets, uint16_t offsetsLength)
93 uint16_t* doubleOffsetsEnd = offsets + offsetsLength;
95 int maxDoubleOffset = dataLength - 8;
97 while (offsets < doubleOffsetsEnd)
99 offsetToDouble = (*offsets++);
100 isDouble = ((offsetToDouble & 0x8000) == 0);
101 offsetToDouble = (offsetToDouble & 0x7FFF) - offset;
102 if (offsetToDouble >= 0 && offsetToDouble <= maxDoubleOffset)
110 uint64_t* ptr = (
void*)(data + offsetToDouble);
117 void flipStrings(uint8_t*
data,
int dataLength,
int offset, uint16_t* offsets, uint16_t offsetsLength)
119 uint16_t* stringOffsetsEnd = offsets + offsetsLength;
124 while (offsets < stringOffsetsEnd)
126 offsetToString = (*offsets++) - offset;
127 lengthOfString = (*offsets++);
128 maxStringOffset = dataLength - lengthOfString;
129 if (offsetToString >= 0 && offsetToString <= maxStringOffset)
137 #pragma warning(push) 138 #pragma warning(disable: 4267) 152 static uint16_t offsetsIns1[] =
161 static uint16_t offsetsIns2[] =
170 static uint16_t offsetsIns3[] =
179 static uint16_t offsetsIns4[] =
188 static uint16_t offsetsSysParams[] =
194 static uint16_t offsetsPreImuMag[] =
202 static uint16_t offsetsDualImuMag[] =
210 static uint16_t offsetsGps[] =
222 static uint16_t offsetsRmc[] =
226 offsetof(
rmc_t, bits) | 0x8000
229 static uint16_t offsetsInl2States[] =
234 static uint16_t offsetsRtkNav[] =
242 static uint16_t offsetsFlashConfig[] =
253 static uint16_t offsetsOnlyTimeFirst[] = { 1, 0 };
254 static uint16_t offsetsDebugArray[] = { 3, 72, 80, 88 };
255 static uint16_t offsetsSurveyIn[] =
263 static uint16_t* s_doubleOffsets[] =
268 offsetsOnlyTimeFirst,
276 offsetsOnlyTimeFirst,
293 offsetsOnlyTimeFirst,
310 offsetsOnlyTimeFirst,
311 offsetsOnlyTimeFirst,
317 offsetsOnlyTimeFirst,
318 offsetsOnlyTimeFirst,
320 offsetsOnlyTimeFirst,
322 offsetsOnlyTimeFirst,
323 offsetsOnlyTimeFirst,
336 offsetsOnlyTimeFirst,
369 if ((offsets = s_doubleOffsets[dataId]))
371 *offsetsLength = (*offsets++);
392 static uint16_t debugStringOffsets[] = { 2, 0, 80 };
394 static uint16_t rtosTaskOffsets[] =
402 160, MAX_TASK_NAME_LEN
405 static uint16_t manufInfoOffsets[] =
411 static uint16_t diagMsgOffsets[] =
417 static uint16_t* s_stringOffsets[] =
522 if ((offsets = s_stringOffsets[dataId]))
524 *offsetsLength = (*offsets++);
533 if (count < 1 || count % 4 != 0)
538 uint32_t checksum = 0;
539 uint32_t* dataPtr = (uint32_t*)data;
540 uint32_t* dataEnd = dataPtr + (count / 4);
542 while (dataPtr < dataEnd)
544 checksum ^= *dataPtr++;
553 return checksum32((
const uint8_t*)data + 4, size - 4);
559 return checksum32((
const uint8_t*)data + 8, size - 8);
603 default:
return defaultRmcBits;
607 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)
609 double j1, j2, j3, j4, j5;
610 double intgr = floor(julian);
611 double frac = julian - intgr;
612 double gregjd = 2299161.0;
616 double tmp = floor(((intgr - 1867216.0) - 0.25) / 36524.25);
617 j1 = intgr + 1.0 + tmp - floor(0.25 * tmp);
625 double dayfrac = frac + 0.5;
633 j3 = floor(6680.0 + ((j2 - 2439870.0) - 122.1) / 365.25);
634 j4 = floor(j3 * 365.25);
635 j5 = floor((j2 - j4) / 30.6001);
637 double d = floor(j2 - j4 - floor(j5 * 30.6001));
638 double m = floor(j5 - 1);
643 double y = floor(j3 - 4715.0);
656 double hr = floor(dayfrac * 24.0);
657 double mn = floor((dayfrac * 24.0 - hr) * 60.0);
658 double f = ((dayfrac * 24.0 - hr) * 60.0 - mn) * 60.0;
687 *minute = (int32_t)mn;
691 *second = (int32_t)sc;
695 *millisecond = (int32_t)((sc - floor(sc)) * 1000.0);
702 gpsSeconds += (gpsTimeofWeekMS / 1000);
710 double gpsDays = (double)gpsWeek * 7.0;
711 gpsDays += ((((double)gpsMilliseconds / 1000.0) - (double)leapSeconds) / 86400.0);
712 return (2444244.500000) + gpsDays;
717 unsigned int millisecondsToday = gps->
timeOfWeekMs % 86400000;
718 unsigned int hours = millisecondsToday / 1000 / 60 / 60;
719 unsigned int minutes = (millisecondsToday / (1000 * 60)) % 60;
720 unsigned int seconds = (millisecondsToday / 1000) % 60;
721 int written =
SNPRINTF(*buffer, *bufferLength,
",%02u%02u%02u", hours, minutes, seconds);
722 *bufferLength -= written;
729 int degrees = (int)(v);
730 double minutes = (v - ((double)degrees)) * 60.0;
732 int written =
SNPRINTF(*buffer, *bufferLength, degreesFormat, abs(degrees));
733 *bufferLength -= written;
736 written =
SNPRINTF(*buffer, *bufferLength,
"%07.4f,", fabs(minutes));
737 *bufferLength -= written;
740 written =
SNPRINTF(*buffer, *bufferLength,
"%c", (degrees >= 0 ? posC : negC));
741 *bufferLength -= written;
772 if (bufferLength < 128)
777 unsigned int checkSum = 0;
817 char* bufferStart = buffer;
820 written =
SNPRINTF(buffer, bufferLength,
"%s",
"GPGGA");
822 bufferLength -= written;
828 written =
SNPRINTF(buffer, bufferLength,
",%u,%02u,%.2f,%.2f,M,%.2f,M,,",
829 (
unsigned)fixQuality,
835 bufferLength -= written;
838 for (
char* ptr = bufferStart + 1; ptr < buffer; ptr++)
843 written =
SNPRINTF(buffer, bufferLength,
"*%.2x\r\n", checkSum);
845 return (
int)(buffer - bufferStart);
870 if (prn <= 0)
return 0;
910 int prn = svID + (sys ==
SYS_QZS ? 192 : 0);
911 return satNo(sys, prn);
uint16_t * getDoubleOffsets(eDataIDs dataId, uint16_t *offsetsLength)
#define RMC_BITS_INL2_NED_SIGMA
#define _MEMBER_ARRAY_ELEMENT_COUNT(type, member)
#define RMC_BITS_GPS1_POS
#define RMC_BITS_PREINTEGRATED_IMU_MAG
#define RMC_BITS_GPS1_RTK_POS
#define RMC_BITS_GPS1_UBX_POS
static void appendGPSTimeOfLastFix(const gps_pos_t *gps, char **buffer, int *bufferLength)
int satNumCalc(int gnssID, int svID)
#define RMC_BITS_GPS1_RTK_POS_REL
uint32_t serialNumChecksum32(const void *data, int size)
#define RMC_BITS_GPS2_RAW
#define RMC_BITS_GPS1_RAW
#define RMC_BITS_GPS2_POS
#define RMC_BITS_DUAL_IMU_MAG_RAW
#define RMC_BITS_GPS1_RTK_HDG_REL
#define RMC_BITS_GPS2_VEL
#define RMC_BITS_MAGNETOMETER2
#define RMC_BITS_GPS1_RTK_HDG_MISC
#define DID_GPS2_RTK_CMP_REL
uint16_t * getStringOffsetsLengths(eDataIDs dataId, uint16_t *offsetsLength)
void flipFloat(uint8_t *ptr)
size_t count(InputIterator first, InputIterator last, T const &item)
#define RMC_BITS_GPS_BASE_RAW
#define DID_PREINTEGRATED_IMU
static void appendGPSCoord(const gps_pos_t *gps, char **buffer, int *bufferLength, double v, const char *degreesFormat, char posC, char negC)
#define DID_PREINTEGRATED_IMU_MAG
int satNo(int sys, int prn)
void flipDoubles(uint8_t *data, int dataLength, int offset, uint16_t *offsets, uint16_t offsetsLength)
uint64_t didToRmcBit(uint32_t dataId, uint64_t defaultRmcBits)
void flipEndianess32(uint8_t *data, int dataLength)
void flipDouble(void *ptr)
#define DID_MAGNETOMETER_2
#define RMC_BITS_DUAL_IMU_RAW
#define RMC_BITS_GPS1_VEL
#define RMC_BITS_MAGNETOMETER1
float flipFloatCopy(float val)
double gpsToJulian(int32_t gpsWeek, int32_t gpsMilliseconds, int32_t leapSeconds)
#define RMC_BITS_WHEEL_CONFIG
#define GPS_TO_UNIX_OFFSET
#define RMC_BITS_RTK_STATE
#define DID_GPS2_RTK_CMP_MISC
#define RMC_BITS_BAROMETER
#define DID_DIAGNOSTIC_MESSAGE
#define RMC_BITS_WHEEL_ENCODER
uint32_t flashChecksum32(const void *data, int size)
#define RMC_BITS_GPS2_SAT
void flipStrings(uint8_t *data, int dataLength, int offset, uint16_t *offsets, uint16_t offsetsLength)
int gpsToNmeaGGA(const gps_pos_t *gps, char *buffer, int bufferLength)
#define DID_MAGNETOMETER_1
#define DID_RTK_CODE_RESIDUAL
#define RMC_BITS_GPS1_SAT
USBInterfaceDescriptor data
#define DID_DUAL_IMU_RAW_MAG
#define RMC_BITS_DUAL_IMU
#define RMC_BITS_GPS1_RTK_POS_MISC
#define RMC_BITS_RTK_PHASE_RESIDUAL
double gpsToUnix(uint32_t gpsWeek, uint32_t gpsTimeofWeekMS, uint8_t leapSeconds)
#define MAX_TASK_NAME_LEN
#define RMC_BITS_DUAL_IMU_MAG
#define STATIC_ASSERT(exp)
#define DID_WHEEL_ENCODER
#define RMC_BITS_STROBE_IN_TIME
#define DID_STROBE_IN_TIME
#define RMC_BITS_PREINTEGRATED_IMU
#define DID_INL2_NED_SIGMA
uint32_t checksum32(const void *data, int count)
double flipDoubleCopy(double val)
#define DID_GPS1_RTK_POS_REL
#define _ARRAY_ELEMENT_COUNT(a)
#define RMC_BITS_RTK_CODE_RESIDUAL
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)
#define RMC_BITS_DIAGNOSTIC_MESSAGE
#define DID_RTK_PHASE_RESIDUAL
#define DID_GPS1_RTK_POS_MISC