|
@@ -248,12 +248,15 @@ void nvcan::run()
|
|
|
void nvcan::threadsend()
|
|
|
{
|
|
|
int currmax = 1;
|
|
|
- unsigned int i;
|
|
|
+ int i;
|
|
|
while(mbCANOpen == false)
|
|
|
{
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
}
|
|
|
|
|
|
+ qint64 nLastSecond = 0;
|
|
|
+ int nsecondsend = 0;
|
|
|
+ int nretry = 0;
|
|
|
while(mbSendRun)
|
|
|
{
|
|
|
mWaitMutex.lock();
|
|
@@ -261,7 +264,7 @@ void nvcan::threadsend()
|
|
|
mWaitMutex.unlock();
|
|
|
|
|
|
#ifdef TEST_PROG
|
|
|
- qDebug("send time : %lld",QDateTime::currentMSecsSinceEpoch());
|
|
|
+// qDebug("send time : %lld",QDateTime::currentMSecsSinceEpoch());
|
|
|
#endif
|
|
|
|
|
|
struct canfd_frame framesend[2500];
|
|
@@ -298,10 +301,45 @@ void nvcan::threadsend()
|
|
|
if(nsend > 0)
|
|
|
{
|
|
|
for(i=0;i<nsend;i++)
|
|
|
- if (write(mps[nch], &framesend[i],16) != 16) {
|
|
|
- mivlog->error("write error 1");
|
|
|
- perror("write error 1.");
|
|
|
- continue;
|
|
|
+ {
|
|
|
+ if (write(mps[nch], &framesend[i],16) != 16) {
|
|
|
+ mivlog->error("write error 1");
|
|
|
+ // perror("write error 1.");
|
|
|
+ nretry++;
|
|
|
+ if(nretry > 30)
|
|
|
+ {
|
|
|
+ std::cout<<"retry fail,retry:"<<nretry<<std::endl;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ if(nretry < 100)
|
|
|
+ {
|
|
|
+ i--;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::cout<<"retry more than 10ms"<<std::endl;
|
|
|
+ }
|
|
|
+ std::this_thread::sleep_for(std::chrono::microseconds(100));
|
|
|
+ // std::cout<<"retry send."<<std::endl;
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ nretry = 0;
|
|
|
+ nsecondsend++;
|
|
|
+ qint64 nnowsecond = QDateTime::currentSecsSinceEpoch();
|
|
|
+ if( nnowsecond != nLastSecond)
|
|
|
+ {
|
|
|
+ nLastSecond = nnowsecond;
|
|
|
+ std::cout<<" second send count: "<<nsecondsend<<std::endl;
|
|
|
+ nsecondsend = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -366,9 +404,20 @@ int nvcan::SetMessage(const int nch, basecan_msg *pMsg)
|
|
|
{
|
|
|
if((nch>1)||(nch < 0))return -1;
|
|
|
|
|
|
- if(mMsgSendBuf[nch].size() > BUF_SIZE)return -2;
|
|
|
-
|
|
|
mMutex.lock();
|
|
|
+ if(mMsgSendBuf[nch].size() > BUF_SIZE)
|
|
|
+ {
|
|
|
+ std::cout<<"buffer full."<<std::endl;
|
|
|
+ mMutex.unlock();
|
|
|
+ return -2;
|
|
|
+ }
|
|
|
+
|
|
|
+ if(mMsgRecvBuf[nch].size() > 100)
|
|
|
+ {
|
|
|
+ std::cout<<"buffer data more 100"<<std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
mMsgSendBuf[nch].push_back(*pMsg);
|
|
|
mMutex.unlock();
|
|
|
return 0;
|