|
@@ -22,6 +22,8 @@
|
|
#include <linux/can.h>
|
|
#include <linux/can.h>
|
|
#include <linux/can/raw.h>
|
|
#include <linux/can/raw.h>
|
|
|
|
|
|
|
|
+#include <QDateTime>
|
|
|
|
+
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
|
|
/* for hardware timestamps - since Linux 2.6.30 */
|
|
/* for hardware timestamps - since Linux 2.6.30 */
|
|
@@ -60,6 +62,9 @@ nvcan::nvcan()
|
|
mivlog = new iv::Ivlog("can_agx");
|
|
mivlog = new iv::Ivlog("can_agx");
|
|
|
|
|
|
|
|
|
|
|
|
+ mfault->SetFaultState(0,0,"Prepare Initialize.");
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
void nvcan::run()
|
|
void nvcan::run()
|
|
@@ -79,11 +84,14 @@ void nvcan::run()
|
|
struct ifreq ifr;
|
|
struct ifreq ifr;
|
|
struct timeval tv, last_tv;
|
|
struct timeval tv, last_tv;
|
|
struct timeval timeout_config = { 0, 0 }, *timeout_current = 0;
|
|
struct timeval timeout_config = { 0, 0 }, *timeout_current = 0;
|
|
|
|
+
|
|
|
|
+ mfault->SetFaultState(0,0,"Initializing.");
|
|
|
|
|
|
for(i=0;i<currmax;i++)
|
|
for(i=0;i<currmax;i++)
|
|
{
|
|
{
|
|
s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
|
s[i] = socket(PF_CAN, SOCK_RAW, CAN_RAW);
|
|
if (s[i] < 0) {
|
|
if (s[i] < 0) {
|
|
|
|
+ mfault->SetFaultState(2,1,"Create Socket Error.");
|
|
emit SIG_CANOPENSTATE(false,-1,"Create Socket Error");
|
|
emit SIG_CANOPENSTATE(false,-1,"Create Socket Error");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -94,12 +102,14 @@ void nvcan::run()
|
|
strncpy(ifr.ifr_name, CANNAME[i].data(), 5);
|
|
strncpy(ifr.ifr_name, CANNAME[i].data(), 5);
|
|
|
|
|
|
if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) {
|
|
if (ioctl(s[i], SIOCGIFINDEX, &ifr) < 0) {
|
|
|
|
+ mfault->SetFaultState(2,2,"SIOCGIFINDEX.");
|
|
emit SIG_CANOPENSTATE(false,-2,"SIOCGIFINDEX");
|
|
emit SIG_CANOPENSTATE(false,-2,"SIOCGIFINDEX");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
addr.can_ifindex = ifr.ifr_ifindex;
|
|
addr.can_ifindex = ifr.ifr_ifindex;
|
|
|
|
|
|
if (bind(s[i], (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
|
if (bind(s[i], (struct sockaddr *)&addr, sizeof(addr)) < 0) {
|
|
|
|
+ mfault->SetFaultState(2,3,"bind error.");
|
|
emit SIG_CANOPENSTATE(false,-3,"bind error");
|
|
emit SIG_CANOPENSTATE(false,-3,"bind error");
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
@@ -107,6 +117,7 @@ void nvcan::run()
|
|
|
|
|
|
mbCANOpen = true;
|
|
mbCANOpen = true;
|
|
mivlog->verbose("open can succesfully.");
|
|
mivlog->verbose("open can succesfully.");
|
|
|
|
+ mfault->SetFaultState(0,0,"CAN OK.");
|
|
emit SIG_CANOPENSTATE(true,0,"open can card successfully");
|
|
emit SIG_CANOPENSTATE(true,0,"open can card successfully");
|
|
|
|
|
|
iov.iov_base = &frame;
|
|
iov.iov_base = &frame;
|
|
@@ -115,6 +126,9 @@ void nvcan::run()
|
|
msg.msg_iovlen = 1;
|
|
msg.msg_iovlen = 1;
|
|
msg.msg_control = &ctrlmsg;
|
|
msg.msg_control = &ctrlmsg;
|
|
|
|
|
|
|
|
+ qint64 nLastRecv = QDateTime::currentMSecsSinceEpoch();
|
|
|
|
+ int nRecvState = 0; // 0 Have Data 1 No Data;
|
|
|
|
+
|
|
while((!QThread::isInterruptionRequested())&&(mbCANOpen))
|
|
while((!QThread::isInterruptionRequested())&&(mbCANOpen))
|
|
{
|
|
{
|
|
FD_ZERO(&rdfs);
|
|
FD_ZERO(&rdfs);
|
|
@@ -130,6 +144,7 @@ void nvcan::run()
|
|
ret = select(s[currmax-1]+1, &rdfs, NULL, NULL, timeout_current);
|
|
ret = select(s[currmax-1]+1, &rdfs, NULL, NULL, timeout_current);
|
|
if (ret < 0) {
|
|
if (ret < 0) {
|
|
emit SIG_CANOPENSTATE(false,-4,"select error");
|
|
emit SIG_CANOPENSTATE(false,-4,"select error");
|
|
|
|
+ mfault->SetFaultState(2,4,"select error.");
|
|
mbCANOpen = false;
|
|
mbCANOpen = false;
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
@@ -138,6 +153,7 @@ void nvcan::run()
|
|
|
|
|
|
if (FD_ISSET(s[i], &rdfs)) {
|
|
if (FD_ISSET(s[i], &rdfs)) {
|
|
|
|
|
|
|
|
+ nLastRecv = QDateTime::currentMSecsSinceEpoch();
|
|
/* these settings may be modified by recvmsg() */
|
|
/* these settings may be modified by recvmsg() */
|
|
iov.iov_len = sizeof(frame);
|
|
iov.iov_len = sizeof(frame);
|
|
msg.msg_namelen = sizeof(addr);
|
|
msg.msg_namelen = sizeof(addr);
|
|
@@ -190,6 +206,23 @@ void nvcan::run()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if((QDateTime::currentMSecsSinceEpoch() - nLastRecv)> 1000)
|
|
|
|
+ {
|
|
|
|
+ if(nRecvState == 0)
|
|
|
|
+ {
|
|
|
|
+ nRecvState = -1;
|
|
|
|
+ mfault->SetFaultState(0,1,"More than 1 second not receive data.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ if(nRecvState == -1)
|
|
|
|
+ {
|
|
|
|
+ nRecvState = 0;
|
|
|
|
+ mfault->SetFaultState(0,0,"CAN OK.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
struct canfd_frame framesend[2500];
|
|
struct canfd_frame framesend[2500];
|
|
|
|
|
|
for(int nch =0;nch<currmax;nch++)
|
|
for(int nch =0;nch<currmax;nch++)
|