从 gps 检索错误数据
Retrieving the wrong data from gps
我一直在尝试实现一个程序来打印出我的 GPS 坐标。但是,我收到的数据完全没有意义。
我的 class 个文件:
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 ");
}
}
我的主程序:
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;
}
这是我得到的示例输出:
其中一个观察是解析的经度值实际上是海拔值(427m)
解析的高度值以荒谬的方式波动。
解析的纬度值实际上是我的经度值。
已解析的时间戳未更改且不正确。
谢谢
是库版本不同的问题。 gps_data 结构的一些变化是在较新版本的 libgpsmm (3.22) 中引入的,而我使用的是旧版本。因此,我得到了错误的数据。
我一直在尝试实现一个程序来打印出我的 GPS 坐标。但是,我收到的数据完全没有意义。
我的 class 个文件:
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 ");
}
}
我的主程序:
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;
}
这是我得到的示例输出:
其中一个观察是解析的经度值实际上是海拔值(427m) 解析的高度值以荒谬的方式波动。 解析的纬度值实际上是我的经度值。 已解析的时间戳未更改且不正确。
谢谢
是库版本不同的问题。 gps_data 结构的一些变化是在较新版本的 libgpsmm (3.22) 中引入的,而我使用的是旧版本。因此,我得到了错误的数据。