| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- #include "cumsgbuffer.h"
- cumsgbuffer::cumsgbuffer()
- {
- }
- void cumsgbuffer::addmsg(int id, qint64 ntime, std::string strVIN, std::string strqueryMD5, std::string strctrlMD5, std::vector<char> *pxdata,bool bImportant,int nkeeptime)
- {
- qDebug("ntime is %lld",ntime);
- mMutex.lock();
- iv::cumsg * pmsg = 0;
- int nsize = mvectormsg.size();
- int i;
- for(i=0;i<nsize;i++)
- {
- if(strncmp(mvectormsg[i].strVIN.data(),strVIN.data(),255) == 0)
- {
- pmsg = &mvectormsg[i];
- break;
- }
- }
- if(pmsg == 0)
- {
- iv::cumsg cmsg;
- cmsg.id = id;
- cmsg.ntime = ntime;
- cmsg.strVIN = strVIN;
- cmsg.strqueryMD5 = strqueryMD5;
- cmsg.strctrlMD5 = strctrlMD5;
- if(pxdata->size() > 0)
- {
- cmsg.xdata.resize(pxdata->size());
- memcpy(cmsg.xdata.data(),pxdata->data(),pxdata->size());
- }
- cmsg.mlastuptime = QDateTime::currentMSecsSinceEpoch();
- cmsg.mbImportant = bImportant;
- cmsg.mkeeptime = nkeeptime;
- cmsg.mbhavequery = false;
- mvectormsg.push_back(cmsg);
- mMutex.unlock();
- return;
- }
- if((pmsg->mbImportant != true)||(pmsg->mbhavequery)||((QDateTime::currentMSecsSinceEpoch() - pmsg->mlastuptime)>=pmsg->mkeeptime))
- {
- pmsg->id = id;
- pmsg->ntime = ntime;
- pmsg->mbImportant = bImportant;
- pmsg->mbhavequery = false;
- pmsg->mlastuptime = QDateTime::currentMSecsSinceEpoch();
- pmsg->mkeeptime = nkeeptime;
- pmsg->strqueryMD5 = strqueryMD5;
- pmsg->strctrlMD5 = strctrlMD5;
- pmsg->xdata.clear();
- if(pxdata->size()>0)
- {
- pmsg->xdata.resize(pxdata->size());
- memcpy(pmsg->xdata.data(),pxdata->data(),pxdata->size());
- }
- }
- mMutex.unlock();
- }
- int cumsgbuffer::getmsg(std::string strVIN,std::string strqueryMD5, qint64 nlasttime, int &id, qint64 &ntime, std::vector<char> *pxdata)
- {
- mMutex.lock();
- iv::cumsg * pmsg = 0;
- int nsize = mvectormsg.size();
- int i;
- for(i=0;i<nsize;i++)
- {
- if(strncmp(mvectormsg[i].strVIN.data(),strVIN.data(),255) == 0)
- {
- pmsg = &mvectormsg[i];
- break;
- }
- }
- if(pmsg == 0)
- {
- std::cout<<" no this vin data"<<std::endl;;
- mMutex.unlock();
- return -1;
- }
- if(strqueryMD5 != pmsg->strqueryMD5)
- {
- std::cout<<" query error."<<std::endl;
- mMutex.unlock();
- return -2;
- }
- pmsg->mbhavequery = true;
- if(nlasttime == pmsg->ntime)
- {
- mMutex.unlock();
- return 0;
- }
- id = pmsg->id;
- ntime = pmsg->ntime;
- pxdata->clear();
- int ndatasize = pmsg->xdata.size();
- pxdata->resize(ndatasize);
- memcpy(pxdata->data(),pmsg->xdata.data(),ndatasize);
- mMutex.unlock();
- return 1;
- }
- void cumsgbuffer::addPicData(std::string strVIN, const char *strdata, const unsigned int ndatasize,
- qint64 npictime, int nCamPos,qint64 nLatency)
- {
- mMutex.lock();
- iv::cumsg * pmsg = 0;
- int nsize = mvectormsg.size();
- int i;
- for(i=0;i<nsize;i++)
- {
- if(strncmp(mvectormsg[i].strVIN.data(),strVIN.data(),255) == 0)
- {
- pmsg = &mvectormsg[i];
- break;
- }
- }
- if(pmsg == 0)
- {
- std::cout<<" Not Found buf. Need Data Prepare."<<std::endl;
- }
- else
- {
- if((nCamPos<0)||(nCamPos>= CAM_NUM))
- {
- std::cout<<"Camera Postion error . nCamPos = "<<nCamPos<<std::endl;
- }
- else
- {
- iv::PicData xPicData;
- xPicData.mdata_ptr = std::shared_ptr<char>(new char[ndatasize]);
- memcpy(xPicData.mdata_ptr.get(),strdata,ndatasize);
- xPicData.mdatasize = ndatasize;
- xPicData.mnMsgTime = npictime;
- pmsg->mpicbuf[nCamPos].AddData(xPicData);
- pmsg->mpicbuf[nCamPos].SetLatency(nLatency);
- }
- }
- mMutex.unlock();
- }
- int cumsgbuffer::getPicData(std::string strVIN, std::string strqueryMD5,std::shared_ptr<char> &pdata_ptr,
- unsigned int &ndatasize,std::string strclientid, int nCamPos,qint64 & nPicTime,qint64 & nPicLatency,int & nFrameRate)
- {
- mMutex.lock();
- iv::cumsg * pmsg = 0;
- int nsize = mvectormsg.size();
- int i;
- for(i=0;i<nsize;i++)
- {
- if(strncmp(mvectormsg[i].strVIN.data(),strVIN.data(),255) == 0)
- {
- pmsg = &mvectormsg[i];
- break;
- }
- }
- if(pmsg == 0)
- {
- std::cout<<" no this vin data"<<std::endl;;
- mMutex.unlock();
- return -1;
- }
- if(strqueryMD5 != pmsg->strqueryMD5)
- {
- std::cout<<" query error."<<std::endl;
- mMutex.unlock();
- return -2;
- }
- if((nCamPos<0)||(nCamPos>= CAM_NUM))
- {
- std::cout<<"cumsgbuffer::getPicData Camera Postion error . nCamPos = "<<nCamPos<<std::endl;
- mMutex.unlock();
- return -3;
- }
- qint64 nLastPicTime = 0;
- if(mclienttime.GetClientCamLastTime(strclientid,nCamPos,nLastPicTime) < 0)
- {
- std::cout<<"cumsgbuffer::getPicData Can't Get Camera LastTime"<<std::endl;
- mMutex.unlock();
- return -4;
- }
- iv::PicData xPicData;
- int nrtn = pmsg->mpicbuf[nCamPos].GetData(nLastPicTime,xPicData);
- if(nrtn == 1)
- {
- pdata_ptr = xPicData.mdata_ptr;
- ndatasize = xPicData.mdatasize;
- nPicTime = nLastPicTime;
- }
- nPicLatency = pmsg->mpicbuf[nCamPos].GetLatency();
- nFrameRate = pmsg->mpicbuf[nCamPos].GetFrameRate();
- mclienttime.SetClientCamLastTime(strclientid,nCamPos,nLastPicTime);
- mMutex.unlock();
- return nrtn;
- }
|