50 for (uint8_t dx = 0; dx < msg->
length; dx++) {
55 for (uint16_t dx = 0; dx < msg->
length; dx++) {
86 if ((msg->
csumA == a) && (msg->
csumB == b)) {
return true; }
101 size_t asize = 8 + msg->
length;
102 uint8_t *outarray = calloc(asize, 1);
104 outarray[ix++] = msg->
sync1;
105 outarray[ix++] = msg->
sync2;
107 outarray[ix++] = msg->
msgID;
108 outarray[ix++] = (uint8_t)(msg->
length & 0xFF);
109 outarray[ix++] = (uint8_t)(msg->
length >> 8);
112 memcpy(outarray + ix, msg->
data, msg->
length);
118 outarray[ix++] = msg->
csumA;
119 outarray[ix++] = msg->
csumB;
135 int strlength = 24 + 3 * msg->
length;
136 char *str = calloc(strlength, 1);
138 sprintf(str + 12,
"%02x %02x ", (uint8_t)(msg->
length & 0xFF), (uint8_t)(msg->
length >> 8));
140 for (uint8_t ix = 0; ix < msg->
length; ix++) {
141 sprintf(str + 18 + 3 * ix,
"%02x ", msg->
data[ix]);
144 for (uint16_t ix = 0; ix < msg->
length; ix++) {
145 sprintf(str + 18 + 3 * ix,
"%02x ", msg->
extdata[ix]);
176 if (out == NULL || msg == NULL) {
return false; }
178 if (msg->
msgClass != UBXNAV || msg->
msgID != 0x07) {
return false; }
180 const uint8_t *d = msg->
data;
181 out->
tow = d[0] + (d[1] << 8) + (d[2] << 16) + (d[3] << 24);
182 out->
year = d[4] + (d[5] << 8);
191 out->
accuracy = d[12] + (d[13] << 8) + (d[14] << 16) + (d[15] << 24);
192 out->
nanosecond = (int32_t)(d[16] + (d[17] << 8) + (d[18] << 16) + (d[19] << 24));
197 out->
longitude = ((int32_t)(d[24] + (d[25] << 8) + (d[26] << 16) + (d[27] << 24))) * 1E-7;
198 out->
latitude = ((int32_t)(d[28] + (d[29] << 8) + (d[30] << 16) + (d[31] << 24))) * 1E-7;
199 out->
height = (int32_t)(d[32] + (d[33] << 8) + (d[34] << 16) + (d[35] << 24));
200 out->
ASL = (int32_t)(d[36] + (d[37] << 8) + (d[38] << 16) + (d[39] << 24));
201 out->
horizAcc = d[40] + (d[41] << 8) + (d[42] << 16) + (d[43] << 24);
202 out->
vertAcc = d[44] + (d[45] << 8) + (d[46] << 16) + (d[47] << 24);
203 out->
northV = (int32_t)(d[48] + (d[49] << 8) + (d[50] << 16) + (d[51] << 24));
204 out->
eastV = (int32_t)(d[52] + (d[53] << 8) + (d[54] << 16) + (d[55] << 24));
205 out->
downV = (int32_t)(d[56] + (d[57] << 8) + (d[58] << 16) + (d[59] << 24));
206 out->
groundSpeed = (int32_t)(d[60] + (d[61] << 8) + (d[62] << 16) + (d[63] << 24));
207 out->
heading = ((int32_t)(d[64] + (d[65] << 8) + (d[66] << 16) + (d[67] << 24))) * 1E-5;
208 out->
speedAcc = (int32_t)(d[68] + (d[69] << 8) + (d[70] << 16) + (d[71] << 24));
209 out->
headingAcc = ((int32_t)(d[72] + (d[73] << 8) + (d[74] << 16) + (d[75] << 24))) * 1E-5;
210 out->
pDOP = d[76] + (d[77] << 8);
213 out->
vehicleHeading = ((int32_t)(d[84] + (d[85] << 8) + (d[86] << 16) + (d[87] << 24))) * 1E-5;
215 out->
magDecAcc = ((int32_t)(d[90] + (d[91] << 8) + (d[92] << 16) + (d[93] << 24))) * 1E-2;
bool ubx_check_checksum(const ubx_message *msg)
Verify checksum bytes of UBX message.
bool ubx_decode_nav_pvt(const ubx_message *msg, ubx_nav_pvt *out)
Decode UBX NAV-PVT message.
void ubx_print_hex(const ubx_message *msg)
Print UBX message in hexadecimal form.
void ubx_set_checksum(ubx_message *msg)
Set checksum bytes for UBX message.
void ubx_calc_checksum(const ubx_message *msg, uint8_t *csA, uint8_t *csB)
Calculate checksum for UBX message.
size_t ubx_flat_array(const ubx_message *msg, uint8_t **out)
Convert UBX message to flat array of bytes.
char * ubx_string_hex(const ubx_message *msg)
Return UBX message as string of hexadecimal pairs.
Internal representation of a UBX message.
uint8_t csumB
Checksum part B.
uint8_t sync1
Should always be 0xB5.
uint8_t sync2
Should always be 0x62.
uint8_t data[256]
Data if length <= 256.
uint8_t msgClass
A value from ubx_class.
uint8_t msgID
Message ID byte.
uint16_t length
Message length.
uint8_t csumA
Checksum part A.
Represent decoded NAV-PVT message.
int32_t downV
Velocity (Down, mm/s)
uint8_t second
Second (UTC)
uint32_t tow
GPS Time of Week.
uint8_t minute
Minute (UTC)
uint8_t numSV
Number of satellites used for current solution.
int32_t ASL
Height above mean sea level (?datum)
uint32_t accuracy
Estimated time accuracy (ns)
float magneticDeclination
Local magnetic field declination.
float latitude
WGS84 Latitude.
uint32_t vertAcc
Vertical accuracy estimate.
int32_t headingAcc
Heading accuracy estimate.
bool validTime
Time data valid.
uint8_t fixType
Navigation Fix type.
int32_t speedAcc
Speed/velocity accuracy estimate.
uint16_t year
Calendar year.
int32_t groundSpeed
Ground Speed (mm/s)
int32_t northV
Velocity (North, mm/s)
int32_t height
WGS84 Height.
uint8_t pvtFlags
More flags.
uint32_t horizAcc
Horizontal accuracy estimate (mm)
bool validMagDec
Magnetic declination data valid.
float heading
Motion heading.
int32_t eastV
Velocity (East, mm/s)
uint8_t fixFlags
Navigation status flags.
uint16_t pDOP
Position dilution.
uint8_t fixFlags2
Expanded navigation status flags.
int32_t nanosecond
+/- nanosecond (UTC)
uint8_t month
Calendar month.
float magDecAcc
Estimated accuracty of magnetic field declination.
float longitude
WGS84 Longitude.
float vehicleHeading
Vehicle orientation.
bool validDate
Date data valid.