Skip to content
Open
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
8 changes: 8 additions & 0 deletions src/TinyGPS++.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ bool TinyGPSPlus::endOfTermHandler()
case COMBINE(GPS_SENTENCE_GPRMC, 1): // Time in both sentences
case COMBINE(GPS_SENTENCE_GPGGA, 1):
time.setTime(term);
location.time.setTime(term);
break;
case COMBINE(GPS_SENTENCE_GPRMC, 2): // GPRMC validity
sentenceHasFix = term[0] == 'A';
Expand Down Expand Up @@ -261,6 +262,7 @@ bool TinyGPSPlus::endOfTermHandler()
break;
case COMBINE(GPS_SENTENCE_GPGGA, 6): // Fix data (GPGGA)
sentenceHasFix = term[0] > '0';
location.newFixQuality = sentenceHasFix ? (FixQuality)(term[0] - '0') : Invalid;
break;
case COMBINE(GPS_SENTENCE_GPGGA, 7): // Satellites used (GPGGA)
satellites.set(term);
Expand All @@ -271,6 +273,9 @@ bool TinyGPSPlus::endOfTermHandler()
case COMBINE(GPS_SENTENCE_GPGGA, 9): // Altitude (GPGGA)
altitude.set(term);
break;
case COMBINE(GPS_SENTENCE_GPRMC, 12):
location.newFixMode = (FixMode)term[0];
break;
}

// Set custom values as needed
Expand Down Expand Up @@ -338,6 +343,9 @@ void TinyGPSLocation::commit()
{
rawLatData = rawNewLatData;
rawLngData = rawNewLngData;
fixQuality = newFixQuality;
fixMode = newFixMode;
time.commit();
lastCommitTime = millis();
valid = updated = true;
}
Expand Down
61 changes: 36 additions & 25 deletions src/TinyGPS++.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,35 @@ struct RawDegrees
{}
};

enum FixQuality { Invalid = 0, GPS = 1, DGPS = 2, PPS = 3, RTK = 4, FloatRTK = 5, Estimated = 6, Manual = 7, Simulated = 8 };
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

enum class allows stronger typechecking than the old C style: https://en.cppreference.com/w/cpp/language/enum

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Consider enum class.

enum FixMode { N = 'N', A = 'A', D = 'D', E = 'E'};
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same. Consider an 'inivalid'.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same. Consider an Invalid member.
Should anything returning either of these also be a return of an std::optional?


struct TinyGPSTime
{
friend class TinyGPSPlus;
friend class TinyGPSLocation;
public:
bool isValid() const { return valid; }
bool isUpdated() const { return updated; }
uint32_t age() const { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; }

uint32_t value() { updated = false; return time; }
uint8_t hour();
uint8_t minute();
uint8_t second();
uint8_t centisecond();

TinyGPSTime() : valid(false), updated(false), time(0)
{}

private:
bool valid, updated;
uint32_t time, newTime;
uint32_t lastCommitTime;
void commit();
void setTime(const char *term);
};

struct TinyGPSLocation
{
friend class TinyGPSPlus;
Expand All @@ -59,19 +88,25 @@ struct TinyGPSLocation
uint32_t age() const { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; }
const RawDegrees &rawLat() { updated = false; return rawLatData; }
const RawDegrees &rawLng() { updated = false; return rawLngData; }
const TinyGPSTime &Time() { updated = false; return time; }
double lat();
double lng();
FixQuality Quality() { updated = false; return fixQuality; }
FixMode Mode() { updated = false; return fixMode; }
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This should return an std::optional


TinyGPSLocation() : valid(false), updated(false)
TinyGPSLocation() : valid(false), updated(false), fixQuality(Invalid), newFixQuality(Invalid), fixMode(N), newFixMode(N)
{}

private:
bool valid, updated;
RawDegrees rawLatData, rawLngData, rawNewLatData, rawNewLngData;
TinyGPSTime time;
uint32_t lastCommitTime;
void commit();
void setLatitude(const char *term);
void setLongitude(const char *term);
FixQuality fixQuality, newFixQuality;
FixMode fixMode, newFixMode;
};

struct TinyGPSDate
Expand All @@ -98,30 +133,6 @@ struct TinyGPSDate
void setDate(const char *term);
};

struct TinyGPSTime
{
friend class TinyGPSPlus;
public:
bool isValid() const { return valid; }
bool isUpdated() const { return updated; }
uint32_t age() const { return valid ? millis() - lastCommitTime : (uint32_t)ULONG_MAX; }

uint32_t value() { updated = false; return time; }
uint8_t hour();
uint8_t minute();
uint8_t second();
uint8_t centisecond();

TinyGPSTime() : valid(false), updated(false), time(0)
{}

private:
bool valid, updated;
uint32_t time, newTime;
uint32_t lastCommitTime;
void commit();
void setTime(const char *term);
};

struct TinyGPSDecimal
{
Expand Down