| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- #include "fanyaapi.h"
- #include <QMutex>
- QMutex gMutexDecison;
- qint64 gTimeDecision = 0;
- double gdecision[3];
- void ListenDecision(const char * strdata,const unsigned int nSize,const unsigned int index,const QDateTime * dt,const char * strmemname)
- {
- if(nSize < 3*sizeof(double))return;
- gMutexDecison.lock();
- memcpy(gdecision,strdata,3*sizeof(double));
- gTimeDecision = QDateTime::currentMSecsSinceEpoch();
- gMutexDecison.unlock();
- }
- fanyaapi::fanyaapi()
- {
- mpa = iv::modulecomm::RegisterRecv("mpcdecision",ListenDecision);
- mpb = iv::modulecomm::RegisterSend("GPS",1000,1);
- mpc = iv::modulecomm::RegisterSend("MAP",10000000,1);
- mpd = iv::modulecomm::RegisterSend("desiredspeed",1000,1);
- }
- int fanyaapi::GetDecision(double &speed, double &decison, double &wheel)
- {
- qint64 now = QDateTime::currentMSecsSinceEpoch();
- if((now - gTimeDecision)> 3000)
- {
- return -1;
- }
- gMutexDecison.lock();
- speed = gdecision[0];
- decison = gdecision[1];
- wheel = gdecision[2];
- gMutexDecison.unlock();
- return 0;
- }
- void fanyaapi::SetGPS(GPS_INS xgps)
- {
- iv::modulecomm::ModuleSendMsg(mpb,(char *)&xgps,sizeof(GPS_INS));
- }
- void fanyaapi::SetMAP(std::vector<MAP_DATA> xvectorMAP)
- {
- iv::modulecomm::ModuleSendMsg(mpc,(char *)xvectorMAP.data(),xvectorMAP.size() *sizeof(MAP_DATA));
- }
- void fanyaapi::SetDesiredspeed(double fspeed)
- {
- iv::modulecomm::ModuleSendMsg(mpd,(char *)&fspeed,sizeof(fspeed));
- }
|