Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions sensors/common/gps/receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,18 +176,18 @@ int gps_updateEvt(nmea_t *message, sensor_event_t *evtGps, float posStdev, float
evtGps->gps.utc = message->msg.gga.utc * 1000000;

gettime(&evtGps->timestamp, NULL);
break;
return 1;

case nmea_gsa:
evtGps->gps.hdop = (unsigned int)(message->msg.gsa.hdop * 1e2);
evtGps->gps.vdop = (unsigned int)(message->msg.gsa.vdop * 1e2);

evtGps->gps.eph = evtGps->gps.hdop * posStdev;
evtGps->gps.epv = evtGps->gps.vdop * posStdev;
break;
return 0;

case nmea_rmc:
break;
return 0;

case nmea_vtg:
evtGps->gps.heading = message->msg.vtg.track * DEG2MILIRAD; /* degrees -> milliradians */
Expand All @@ -197,13 +197,11 @@ int gps_updateEvt(nmea_t *message, sensor_event_t *evtGps, float posStdev, float

/* This is not 100% correct error estimation but the only we have */
evtGps->gps.evel = evtGps->gps.hdop * velStdev;
break;
return 0;

default:
return 0;
}

return 1;
}


Expand Down
4 changes: 3 additions & 1 deletion sensors/gps/ubx.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#define UBX_VEL_ACCURACY 0.0849f

#define REC_BUF_SZ 1024
#define INBOX_SIZE 3
#define INBOX_SIZE 8

#ifndef UBX_DEFAULT_BAUDRATE
#define UBX_DEFAULT_BAUDRATE B9600
Expand Down Expand Up @@ -215,6 +215,8 @@ static int ubx_alloc(sensor_info_t *info, const char *args)
write(ctx->filedes, UBX_PREMADE_FIX_10HZ, sizeof(UBX_PREMADE_FIX_10HZ));
usleep(100 * 1000);

write(ctx->filedes, UBX_PREMADE_UART1_OUT_NMEA_ONLY_115200, sizeof(UBX_PREMADE_UART1_OUT_NMEA_ONLY_115200));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using sizeof() on a string literal includes the implicit null terminator (\0). Since UBX is a binary protocol, sending an extra 0x00 byte after the message is incorrect and may be misinterpreted by the receiver. It is recommended to use sizeof(...) - 1 to send only the actual message bytes.

write(ctx->filedes, UBX_PREMADE_UART1_OUT_NMEA_ONLY_115200, sizeof(UBX_PREMADE_UART1_OUT_NMEA_ONLY_115200) - 1);


info->ctx = ctx;

return EOK;
Expand Down
3 changes: 3 additions & 0 deletions sensors/gps/ubx.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,7 @@
/* Premade command that sets baudrate to 115200 */
#define UBX_PREMADE_BAUD_115200 "\xb5\x62\x06\x00\x14\x00\x01\x00\x00\x00\xd0\x08\x00\x00\x00\xc2\x01\x00\x07\x00\x07\x00\x00\x00\x00\x00\xc4\x96\xb5\x62\x06\x00\x01"

/* UART1, 115200, 8N1, input: UBX/NMEA/RTCM, output: NMEA only */
#define UBX_PREMADE_UART1_OUT_NMEA_ONLY_115200 "\xb5\x62\x06\x00\x14\x00\x01\x00\x00\x00\xd0\x08\x00\x00\x00\xc2\x01\x00\x07\x00\x02\x00\x00\x00\x00\x00\xbf\x78"

#endif
Loading