add frame write support

This commit is contained in:
canpadawan
2016-06-24 17:26:30 +02:00
parent 10515e4cdf
commit d4f0bd4b19
7 changed files with 62 additions and 70 deletions
+16 -11
View File
@@ -15,14 +15,12 @@ SocketCan::SocketCan(QString portName) :
mDev_p(NULL),
mTimer(this) /*NB: set connection as parent of timer to manage it from working thread */
{
qDebug() << "SocketCan()";
}
SocketCan::~SocketCan()
{
stop();
qDebug() << "~SocketCan()";
}
@@ -102,8 +100,20 @@ void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus)
}
void SocketCan::piSendFrame(const CANFrame&) {}
void SocketCan::piSendFrameBatch(const QList<CANFrame>&){}
bool SocketCan::piSendFrame(const CANFrame& pFrame)
{
/* sanity checks */
if(0 != pFrame.bus || pFrame.len>8)
return false;
/* fill frame */
QCanBusFrame frame;
frame.setFrameId(pFrame.ID);
frame.setExtendedFrameFormat(false);
frame.setPayload(QByteArray((const char*)pFrame.data, pFrame.len));
return mDev_p->writeFrame(frame);
}
/***********************************/
@@ -143,7 +153,6 @@ void SocketCan::framesWritten(qint64 count)
void SocketCan::framesReceived()
{
/* test */
bool enqueued = false;
bool sndNotif = false;
/* sanity checks */
@@ -180,18 +189,14 @@ void SocketCan::framesReceived()
/* enqueue frame */
getQueue().queue();
/* set enqueued */
enqueued = true;
}
#if 0
else
qDebug() << "can't get a frame, ERROR";
#endif
}
}
if(enqueued) {
callback(CANCon::READ);
}
if(sndNotif) {
emit notify();
}