Skip to content

Commit eb34933

Browse files
committedOct 17, 2023
Fix ubx message receive
1 parent 5697fb5 commit eb34933

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed
 

‎gps.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ void gps_parse_ubx_pvt(gps_ubx_pvt_t *data, uint8_t *buffer) {
318318

319319
void gps_parse_ubx_hpposecef(gps_ubx_hpposecef_t *data, uint8_t *buffer) {
320320
buffer += 4; // align to start of payload
321-
#define FIELD( byte_offset, original_type, struct_type, formatter, scale, offset, unit, name) \
321+
#define FIELD(byte_offset, original_type, struct_type, formatter, scale, offset, unit, name) \
322322
data->name = ((struct_type)(*(original_type *)(buffer + byte_offset))) * scale + offset;
323323
GPS_UBX_HPPOSECEF_FIELDS
324324
#undef FIELD
@@ -329,7 +329,7 @@ void gps_parse_ubx_hpposecef(gps_ubx_hpposecef_t *data, uint8_t *buffer) {
329329

330330
void gps_parse_ubx_hpposllh(gps_ubx_hpposllh_t *data, uint8_t *buffer) {
331331
buffer += 4; // align to start of payload
332-
#define FIELD( byte_offset, original_type, struct_type, formatter, scale, offset, unit, name) \
332+
#define FIELD(byte_offset, original_type, struct_type, formatter, scale, offset, unit, name) \
333333
data->name = ((struct_type)(*(original_type *)(buffer + byte_offset))) * scale + offset;
334334
GPS_UBX_HPPOSLLH_FIELDS
335335
#undef FIELD

‎gps_interface.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ void gps_interface_close(gps_serial_port *serial_port) {
136136
serial_port->open = 0;
137137
}
138138

139-
gps_protocol_type gps_interface_get_line(gps_serial_port *port, unsigned char start_sequence[GPS_MAX_START_SEQUENCE_SIZE],
139+
gps_protocol_type gps_interface_get_line(gps_serial_port *port,
140+
unsigned char start_sequence[GPS_MAX_START_SEQUENCE_SIZE],
140141
int *start_sequence_size, char line[GPS_MAX_LINE_SIZE], int *line_size,
141142
bool sleep) {
142143
uint8_t c;
@@ -178,9 +179,9 @@ gps_protocol_type gps_interface_get_line(gps_serial_port *port, unsigned char st
178179
start_sequence[1] = GPS_UBX_SYNC_SECOND_BYTE;
179180
start_sequence[2] = 0x00;
180181
*start_sequence_size = 2;
182+
ubx_message_size = 0;
181183
} else {
182184
size = -1;
183-
continue;
184185
}
185186
break;
186187
// first sync byte for nmea message
@@ -203,7 +204,6 @@ gps_protocol_type gps_interface_get_line(gps_serial_port *port, unsigned char st
203204
ubx_message_size = 0;
204205
} else {
205206
size = -1;
206-
continue;
207207
}
208208
break;
209209
}
@@ -236,7 +236,7 @@ gps_protocol_type gps_interface_get_line(gps_serial_port *port, unsigned char st
236236
line[size] = c;
237237

238238
// check if the size matches the ubx_message_size
239-
if (size >= 3 && size - 6 == ubx_message_size)
239+
if (size > 2 && size - 5 == ubx_message_size)
240240
break;
241241
}
242242

‎test/test.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ int main(void) {
4848
continue;
4949
}
5050

51-
printf("UBX %s: ", gps_ubx_message_type_string((gps_ubx_message_type)prot_and_msg.message));
51+
if(prot_and_msg.protocol == GPS_PROTOCOL_TYPE_NMEA)
52+
printf("NMEA %s: ", gps_nmea_message_type_string((gps_nmea_message_type)prot_and_msg.message));
53+
else if(prot_and_msg.protocol == GPS_PROTOCOL_TYPE_UBX)
54+
printf("UBX %s: ", gps_ubx_message_type_string((gps_ubx_message_type)prot_and_msg.message));
5255
gps_to_file(&gps_files, &data, &prot_and_msg);
5356
}
5457

0 commit comments

Comments
 (0)