|
@@ -25,6 +25,7 @@
|
|
|
#include <QDateTime>
|
|
|
|
|
|
#include <iostream>
|
|
|
+#include <thread>
|
|
|
|
|
|
/* for hardware timestamps - since Linux 2.6.30 */
|
|
|
#ifndef SO_TIMESTAMPING
|
|
@@ -65,6 +66,8 @@ nvcan::nvcan(const char * strcanname)
|
|
|
|
|
|
mfault->SetFaultState(0,0,"Prepare Initialize.");
|
|
|
|
|
|
+ mpsendthread = new std::thread(&nvcan::threadsend,this);
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
@@ -116,6 +119,7 @@ void nvcan::run()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ mps = &s[0];
|
|
|
mbCANOpen = true;
|
|
|
mivlog->verbose("open can succesfully.");
|
|
|
mfault->SetFaultState(0,0,"CAN OK.");
|
|
@@ -229,6 +233,37 @@ void nvcan::run()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ for (i=0; i<currmax; i++)
|
|
|
+ {
|
|
|
+ close(s[i]);
|
|
|
+ }
|
|
|
+ qDebug("nvcan thread close.");
|
|
|
+ mbRunning = false;
|
|
|
+}
|
|
|
+
|
|
|
+void nvcan::threadsend()
|
|
|
+{
|
|
|
+ int currmax = 1;
|
|
|
+ unsigned int i;
|
|
|
+ while(mbCANOpen == false)
|
|
|
+ {
|
|
|
+ std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
|
+ }
|
|
|
+
|
|
|
+ while(mbSendRun)
|
|
|
+ {
|
|
|
+ mWaitMutex.lock();
|
|
|
+ mwc.wait(&mWaitMutex,100);
|
|
|
+ mWaitMutex.unlock();
|
|
|
+
|
|
|
+#ifdef TEST_PROG
|
|
|
+ qDebug("send time : %lld",QDateTime::currentMSecsSinceEpoch());
|
|
|
+#endif
|
|
|
+
|
|
|
struct canfd_frame framesend[2500];
|
|
|
|
|
|
for(int nch =0;nch<currmax;nch++)
|
|
@@ -259,10 +294,11 @@ void nvcan::run()
|
|
|
}
|
|
|
mMsgSendBuf[nch].clear();
|
|
|
mMutex.unlock();
|
|
|
+
|
|
|
if(nsend > 0)
|
|
|
{
|
|
|
for(i=0;i<nsend;i++)
|
|
|
- if (write(s[nch], &framesend[i],16) != 16) {
|
|
|
+ if (write(mps[nch], &framesend[i],16) != 16) {
|
|
|
mivlog->error("write error 1");
|
|
|
perror("write error 1.");
|
|
|
continue;
|
|
@@ -270,15 +306,10 @@ void nvcan::run()
|
|
|
}
|
|
|
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- for (i=0; i<currmax; i++)
|
|
|
- {
|
|
|
- close(s[i]);
|
|
|
- }
|
|
|
- qDebug("nvcan thread close.");
|
|
|
- mbRunning = false;
|
|
|
+ std::cout<<"nvcan::threadsend exit."<<std::endl;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
void nvcan::startdev()
|
|
@@ -343,6 +374,11 @@ int nvcan::SetMessage(const int nch, basecan_msg *pMsg)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+void nvcan::CmdSend()
|
|
|
+{
|
|
|
+ mwc.wakeAll();
|
|
|
+}
|
|
|
+
|
|
|
void nvcan::onMsg(bool bCAN, int nR, const char *strres)
|
|
|
{
|
|
|
mivlog->verbose("msg is %s ",strres);
|