GPS - Read/discard approach, add nmea rates to hardware
This commit is contained in:
parent
bede6ab7eb
commit
650916747c
3 changed files with 91 additions and 9 deletions
|
|
@ -77,5 +77,28 @@ void GPSController::update() {
|
|||
|
||||
// Did read period elapse?
|
||||
ulong cur_time = millis();
|
||||
}
|
||||
}
|
||||
if (cur_time - drv->GetPollPeriodPrv() < drv->GetPollPeriod())
|
||||
continue; // Not yet elapsed, skip this driver
|
||||
|
||||
// Discard the GPS buffer before we attempt to do a fresh read
|
||||
size_t bytes_avail = drv->GetAdaGps()->available();
|
||||
if (bytes_avail > 0) {
|
||||
// TODO: Remove these two WS_DEBUG_PRINTs!
|
||||
WS_DEBUG_PRINT("[gps] Discarding GPS data: ");
|
||||
WS_DEBUG_PRINTLN(bytes_avail);
|
||||
// Read the available data from the GPS module
|
||||
// and discard it
|
||||
for (size_t i = 0; i < bytes_avail; i++) {
|
||||
drv->GetAdaGps()->read();
|
||||
}
|
||||
}
|
||||
|
||||
// Unset the received flag
|
||||
if (drv->GetAdaGps()->newNMEAreceived()) {
|
||||
drv->GetAdaGps()->lastNMEA();
|
||||
}
|
||||
|
||||
// Let's attempt to get a sentence from the GPS module
|
||||
// TODO: Are we expecting RMC, GGA, or other sentences?
|
||||
// TODO: Use a timeout for the read here
|
||||
}
|
||||
|
|
@ -40,6 +40,12 @@ GPSHardware::~GPSHardware() {
|
|||
* @returns True if the message was handled successfully, False otherwise.
|
||||
*/
|
||||
bool GPSHardware::Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config) {
|
||||
WS_DEBUG_PRINTLN("[gps] Handling GPSConfig message...");
|
||||
if (gps_config == nullptr)
|
||||
return false;
|
||||
// Set the polling period for GPS data
|
||||
SetPollPeriod(gps_config->period);
|
||||
|
||||
// Attempt to decode the GPSConfig message
|
||||
if (_driver_type == GPS_DRV_MTK) {
|
||||
WS_DEBUG_PRINTLN("[gps] Handling GPSConfig for MediaTek driver...");
|
||||
|
|
@ -206,6 +212,8 @@ bool GPSHardware::DetectMediatek() {
|
|||
return false;
|
||||
}
|
||||
_driver_type = GPS_DRV_MTK;
|
||||
_nmea_baud_rate = DEFAULT_MTK_NMEA_BAUD_RATE;
|
||||
_nmea_update_rate = DEFAULT_MTK_NMEA_UPDATE_RATE;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +239,13 @@ bool GPSHardware::BuildPmtkAck(char *msg_cmd, char *msg_resp) {
|
|||
* @param poll_period
|
||||
* The polling period in milliseconds.
|
||||
*/
|
||||
void GPSHardware::SetPollPeriod(ulong poll_period) { _period = poll_period; }
|
||||
void GPSHardware::SetPollPeriod(ulong poll_period) {
|
||||
if (poll_period < 0) {
|
||||
_period = 0;
|
||||
return;
|
||||
}
|
||||
_period = (unsigned long)(poll_period * 1000.0f);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Sets the previous polling period for GPS data.
|
||||
|
|
@ -252,4 +266,40 @@ ulong GPSHardware::GetPollPeriod() { return _period; }
|
|||
* @brief Gets the previous polling period for GPS data.
|
||||
* @returns The previous polling period in milliseconds.
|
||||
*/
|
||||
ulong GPSHardware::GetPollPeriodPrv() { return _period_prv; }
|
||||
ulong GPSHardware::GetPollPeriodPrv() { return _period_prv; }
|
||||
|
||||
/*!
|
||||
* @brief Returns the Adafruit_GPS instance.
|
||||
* @returns Pointer to the Adafruit_GPS instance.
|
||||
*/
|
||||
Adafruit_GPS *GPSHardware::GetAdaGps() { return _ada_gps; }
|
||||
|
||||
/*!
|
||||
* @brief Sets the NMEA update rate for GPS data.
|
||||
* @param nmea_update_rate
|
||||
* The NMEA update rate, in Hz.
|
||||
*/
|
||||
void GPSHardware::SetNmeaUpdateRate(int nmea_update_rate) {
|
||||
_nmea_update_rate = nmea_update_rate;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns the NMEA port update rate for GPS data.
|
||||
* @returns The NMEA update rate, in Hz.
|
||||
*/
|
||||
int GPSHardware::GetNmeaUpdateRate() { return _nmea_update_rate; }
|
||||
|
||||
/*!
|
||||
* @brief Sets the NMEA baud rate for GPS data.
|
||||
* @param nmea_baud_rate
|
||||
* The NMEA baud rate, in bits per second.
|
||||
*/
|
||||
void GPSHardware::SetNmeaBaudRate(int nmea_baud_rate) {
|
||||
_nmea_baud_rate = nmea_baud_rate;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief Returns the NMEA port baud rate for GPS data.
|
||||
* @returns The NMEA baud rate, in bits per second.
|
||||
*/
|
||||
int GPSHardware::GetNmeaBaudRate() { return _nmea_baud_rate; }
|
||||
|
|
@ -22,7 +22,9 @@
|
|||
#define CMD_MTK_QUERY_FW_RESP \
|
||||
"$PMTK705" ///< Response from querying MediaTek firmware version without the
|
||||
///< ReleaseStr
|
||||
#define MAX_NEMA_SENTENCE_LEN 82 ///< Maximum length of a NMEA sentence
|
||||
#define DEFAULT_MTK_NMEA_UPDATE_RATE 1 ///< Default NMEA update rate in Hz
|
||||
#define DEFAULT_MTK_NMEA_BAUD_RATE 9600 ///< Default NMEA baud rate in bits per
|
||||
#define MAX_NEMA_SENTENCE_LEN 82 ///< Maximum length of a NMEA sentence
|
||||
|
||||
class Wippersnapper_V2; ///< Forward declaration
|
||||
class UARTHardware; ///< Forward declaration
|
||||
|
|
@ -57,8 +59,13 @@ public:
|
|||
void SetPollPeriodPrv(ulong poll_period_prv);
|
||||
ulong GetPollPeriod();
|
||||
ulong GetPollPeriodPrv();
|
||||
void SetNmeaUpdateRate(int nmea_update_rate);
|
||||
int GetNmeaUpdateRate();
|
||||
void SetNmeaBaudRate(int nmea_baud_rate);
|
||||
int GetNmeaBaudRate();
|
||||
// TODO: Add SetInterface(I2C *_i2c_hardware) for I2C support here!
|
||||
bool Handle_GPSConfig(wippersnapper_gps_GPSConfig *gps_config);
|
||||
Adafruit_GPS *GetAdaGps();
|
||||
|
||||
private:
|
||||
bool QueryModuleType();
|
||||
|
|
@ -68,10 +75,12 @@ private:
|
|||
GpsDriverType _driver_type; ///< Type of GPS driver used
|
||||
HardwareSerial *_hw_serial = nullptr; ///< HardwareSerial instance for GPS;
|
||||
Adafruit_GPS *_ada_gps = nullptr; ///< Adafruit GPS instance
|
||||
ulong _period; ///< Polling period for GPS data (Specified by IO), in
|
||||
///< milliseconds
|
||||
ulong _period_prv; ///< Previous period for GPS data (Specified by IO), in
|
||||
///< milliseconds
|
||||
ulong _period; ///< Polling period for GPS data (Specified by IO), in
|
||||
///< milliseconds
|
||||
ulong _period_prv; ///< Previous period for GPS data (Specified by IO), in
|
||||
///< milliseconds
|
||||
int _nmea_update_rate; ///< NMEA update rate for GPS data, in Hz
|
||||
int _nmea_baud_rate; ///< NMEA baud rate for GPS data, in bits per second
|
||||
};
|
||||
extern Wippersnapper_V2 WsV2; ///< Wippersnapper V2 instance
|
||||
#endif // WS_GPS_HARDWARE_H
|
||||
Loading…
Reference in a new issue