sensor_gps.cpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <perception_sf/sensor_gps.h>
  2. #include "ivlog.h"
  3. extern std::string gstrmemgps;
  4. extern iv::Ivlog * givlog;
  5. namespace iv {
  6. namespace perception {
  7. GPSSensor * ggpsimu;
  8. void Listengpsimu(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  9. {
  10. // ggpsimu->UpdateGPSIMU(strdata,nSize);
  11. iv::gps::gpsimu xgpsimu;
  12. if(!xgpsimu.ParseFromArray(strdata,nSize))
  13. {
  14. std::cout<<"ListenRaw Parse error."<<std::endl;
  15. }
  16. // qDebug(" gps time is %ld",QDateTime::currentMSecsSinceEpoch());
  17. ggpsimu->UpdateGPSIMU(xgpsimu);
  18. static qint64 oldtime;
  19. if((oldtime - QDateTime::currentMSecsSinceEpoch())<-100)
  20. {
  21. qDebug("gps diff time is %ld diff is %ld ",QDateTime::currentMSecsSinceEpoch(),oldtime - QDateTime::currentMSecsSinceEpoch());
  22. givlog->warn("gps diff time is %ld diff is %ld ",QDateTime::currentMSecsSinceEpoch(),oldtime - QDateTime::currentMSecsSinceEpoch());
  23. }
  24. givlog->verbose("gps diff time is %ld diff is %ld ",QDateTime::currentMSecsSinceEpoch(),oldtime - QDateTime::currentMSecsSinceEpoch());
  25. oldtime = QDateTime::currentMSecsSinceEpoch();
  26. }
  27. }
  28. }
  29. iv::perception::GPSSensor::GPSSensor() {
  30. signal_gps_data = createSignal<sig_cb_gps_sensor_data>();
  31. ggpsimu = this;
  32. }
  33. iv::perception::GPSSensor::~GPSSensor() {
  34. }
  35. void iv::perception::GPSSensor::start()
  36. {
  37. thread_sensor_run_ = new boost::thread(boost::bind(&iv::perception::GPSSensor::processSensor, this));
  38. mpagpsimu = iv::modulecomm::RegisterRecv(gstrmemgps.data(),iv::perception::Listengpsimu);
  39. //OutputDebugString(TEXT("\nGPS thread Run\n"));
  40. }
  41. void iv::perception::GPSSensor::stop()
  42. {
  43. thread_sensor_run_->interrupt();
  44. thread_sensor_run_->join();
  45. //OutputDebugString(TEXT("\nGPS thread Stop\n"));
  46. }
  47. bool iv::perception::GPSSensor::isRunning() const
  48. {
  49. return (thread_sensor_run_ != NULL && !thread_sensor_run_->timed_join(boost::posix_time::milliseconds(10)));
  50. }