fanyaapi.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #include "fanyaapi.h"
  2. #include <QMutex>
  3. QMutex gMutexDecison;
  4. qint64 gTimeDecision = 0;
  5. double gdecision[3];
  6. void ListenDecision(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
  7. {
  8. if(nSize < 3*sizeof(double))return;
  9. gMutexDecison.lock();
  10. memcpy(gdecision,strdata,3*sizeof(double));
  11. gTimeDecision = QDateTime::currentMSecsSinceEpoch();
  12. gMutexDecison.unlock();
  13. }
  14. fanyaapi::fanyaapi()
  15. {
  16. mpa = iv::modulecomm::RegisterRecv("mpcdecision",ListenDecision);
  17. mpb = iv::modulecomm::RegisterSend("GPS",1000,1);
  18. mpc = iv::modulecomm::RegisterSend("MAP",10000000,1);
  19. mpd = iv::modulecomm::RegisterSend("desiredspeed",1000,1);
  20. }
  21. int fanyaapi::GetDecision(double &speed, double &decison, double &wheel)
  22. {
  23. qint64 now = QDateTime::currentMSecsSinceEpoch();
  24. if((now - gTimeDecision)> 3000)
  25. {
  26. return -1;
  27. }
  28. gMutexDecison.lock();
  29. speed = gdecision[0];
  30. decison = gdecision[1];
  31. wheel = gdecision[2];
  32. gMutexDecison.unlock();
  33. return 0;
  34. }
  35. void fanyaapi::SetGPS(GPS_INS xgps)
  36. {
  37. iv::modulecomm::ModuleSendMsg(mpb,(char *)&xgps,sizeof(GPS_INS));
  38. }
  39. void fanyaapi::SetMAP(std::vector<MAP_DATA> xvectorMAP)
  40. {
  41. iv::modulecomm::ModuleSendMsg(mpc,(char *)xvectorMAP.data(),xvectorMAP.size() *sizeof(MAP_DATA));
  42. }
  43. void fanyaapi::SetDesiredspeed(double fspeed)
  44. {
  45. iv::modulecomm::ModuleSendMsg(mpd,(char *)&fspeed,sizeof(fspeed));
  46. }