Reputation: 49
I have been trying to implement a program to print out my GPS coordinates. However, I receive data which makes no sense at all.
my class files:
class GpsHandler
{
public:
GpsHandler(const std::string& gpsDaemonIpAddress, uint16_t updateRate);
~GpsHandler();
void initialize();
void printoutData();
private:
std::shared_ptr<gpsmm> m_gpsRec;
struct gps_data_t* m_currentGpsData;
};
GpsHandler::GpsHandler(const std::string& gpsDaemonIpAddress, uint16_t updateRate)
m_gpsRec(std::make_shared<gpsmm>(gpsDaemonIpAddress.c_str(), DEFAULT_GPSD_PORT)),
s_updaterate(updateRate)
{}
void GpsHandler::initialize()
{
if (m_gpsRec->stream(WATCH_ENABLE | WATCH_JSON) == nullptr) {
LOG4CPLUS_ERROR(m_logger, "No GPSD daemon running");
throw std::runtime_error("No GPSD daemon running");
}
if (!m_gpsRec->is_open()) {
LOG4CPLUS_ERROR(m_logger, "Open connection to gps daemon failed");
throw std::runtime_error("Open connection to gps daemon failed");
}
}
void GpsHandler::printoutData()
{
if (!m_gpsRec->waiting(50000)) {
LOG4CPLUS_WARN(m_logger, "Wait for gps daemon failed");
}
if ((m_currentGpsData = m_gpsRec->read()) != nullptr) {
if (m_currentGpsData->set & ONLINE_SET) {
LOG4CPLUS_INFO_FMT(m_logger, "Online: %lf", m_currentGpsData->online);
}
if (m_currentGpsData->set & TIME_SET)
LOG4CPLUS_INFO_FMT(m_logger, "Time: %lf", m_currentGpsData->fix.time);
if (m_currentGpsData->set & LATLON_SET)
LOG4CPLUS_INFO_FMT(m_logger, "LATLON: lat/lon: %lf %lf", m_currentGpsData->fix.latitude, m_currentGpsData->fix.longitude);
if (m_currentGpsData->set & ALTITUDE_SET)
LOG4CPLUS_INFO_FMT(m_logger, "ALTITUDE: altitude: %lf U: climb: %lf\n", m_currentGpsData->fix.altitude, m_currentGpsData->fix.climb);
if (m_currentGpsData->set & SPEED_SET)
LOG4CPLUS_INFO_FMT(m_logger, "SPEED: %lf\n", m_currentGpsData->fix.speed);
if (m_currentGpsData->set & TRACK_SET)
LOG4CPLUS_INFO_FMT(m_logger, "TRACK: track: %lf\n", m_currentGpsData->fix.track);
if (m_currentGpsData->set & STATUS_SET)
LOG4CPLUS_INFO_FMT(m_logger, "STATUS: status: %d\n", m_currentGpsData->status);
if (m_currentGpsData->set & MODE_SET)
LOG4CPLUS_INFO_FMT(m_logger, "MODE: mode: %d\n", m_currentGpsData->fix.mode);
} else {
LOG4CPLUS_INFO(m_logger, "error reading ");
}
}
my main program:
int main(int argc, char* argv[])
{
try {
QCoreApplication app(argc, argv);
int sleepStep = 500000;
std::shared_ptr<GpsHandler> m_gpsHandler;
m_gpsHandler = std::make_shared<GpsHandler>("local host ip address", 2);
m_gpsHandler->initialize();
while (!m_signalcaught) {
m_gpsHandler->printoutData();
usleep(sleepStep);
}
} catch (std::exception& e) {
}
return 0;
}
and this is the sample output I get :
One of the observation is that the parsed longtitude value is actually the altitude value (427m) the parsed altitude value fluctuates in an absurd way. the parsed latitude value is actually my longtitude value. the parsed time stamp does not change and is not correct.
Thanks
Upvotes: 0
Views: 175
Reputation: 49
It was a problem of different library versions. Some changes in the gps_data structure were introduced in the newer version of libgpsmm (3.22) , while I used older one. Therefore, I was getting the wrong data.
Upvotes: 0