mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-03 14:38:30 -04:00
HAL_SITL: use common nmea_printf()
This commit is contained in:
parent
3650c02745
commit
266b425115
@ -19,6 +19,7 @@
|
||||
#include "UARTDriver.h"
|
||||
#include <AP_GPS/AP_GPS.h>
|
||||
#include <AP_GPS/AP_GPS_UBLOX.h>
|
||||
#include <AP_Common/NMEA.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
@ -652,39 +653,21 @@ void SITL_State::_update_gps_mtk19(const struct gps_data *d, uint8_t instance)
|
||||
_gps_write((uint8_t*)&p, sizeof(p), instance);
|
||||
}
|
||||
|
||||
/*
|
||||
NMEA checksum
|
||||
*/
|
||||
uint8_t SITL_State::_gps_nmea_checksum(const char *s)
|
||||
{
|
||||
uint8_t cs = 0;
|
||||
const uint8_t *b = (const uint8_t *)s;
|
||||
for (uint16_t i=1; s[i]; i++) {
|
||||
cs ^= b[i];
|
||||
}
|
||||
return cs;
|
||||
}
|
||||
|
||||
/*
|
||||
formatted print of NMEA message, with checksum appended
|
||||
*/
|
||||
void SITL_State::_gps_nmea_printf(uint8_t instance, const char *fmt, ...)
|
||||
{
|
||||
char *s = nullptr;
|
||||
uint8_t csum;
|
||||
char trailer[6];
|
||||
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
vasprintf(&s, fmt, ap);
|
||||
char *s = nmea_vaprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
csum = _gps_nmea_checksum(s);
|
||||
snprintf(trailer, sizeof(trailer), "*%02X\r\n", (unsigned)csum);
|
||||
if (s != nullptr) {
|
||||
_gps_write((const uint8_t*)s, strlen(s), instance);
|
||||
_gps_write((const uint8_t*)trailer, 5, instance);
|
||||
free(s);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user