slight changes due to change of pointer for object

This commit is contained in:
canpadawan
2016-06-08 11:46:07 +02:00
parent 18b1a86a56
commit 64079e8dcf
2 changed files with 46 additions and 35 deletions
+43 -33
View File
@@ -11,7 +11,7 @@ SerialWorker::SerialWorker(CANFrameModel *model, int base) : CANConnection(model
serial = NULL; serial = NULL;
rx_state = IDLE; rx_state = IDLE;
rx_step = 0; rx_step = 0;
buildFrame = new CANFrame; buildFrame;
ticker = NULL; ticker = NULL;
framesRapid = 0; framesRapid = 0;
gotValidated = true; gotValidated = true;
@@ -166,8 +166,13 @@ void SerialWorker::sendFrame(const CANFrame *frame)
//qDebug() << "Sending out frame with id " << frame->ID; //qDebug() << "Sending out frame with id " << frame->ID;
//show our sent frames in the list too. This happens even if we're not connected. //show our sent frames in the list too. This happens even if we're not connected.
model->addFrame(tempFrame, false); /* model lives in UI thread, we need to call invokeMethod */
QMetaObject::invokeMethod(model, "addFrame",
Qt::QueuedConnection,
Q_ARG(CANFrame, tempFrame),
Q_ARG(bool, false));
framesRapid++; framesRapid++;
if (serial == NULL) return; if (serial == NULL) return;
@@ -275,56 +280,61 @@ void SerialWorker::procRXChar(unsigned char c)
switch (rx_step) switch (rx_step)
{ {
case 0: case 0:
buildFrame->timestamp = c; buildFrame.timestamp = c;
break; break;
case 1: case 1:
buildFrame->timestamp |= (uint)(c << 8); buildFrame.timestamp |= (uint)(c << 8);
break; break;
case 2: case 2:
buildFrame->timestamp |= (uint)c << 16; buildFrame.timestamp |= (uint)c << 16;
break; break;
case 3: case 3:
buildFrame->timestamp |= (uint)c << 24; buildFrame.timestamp |= (uint)c << 24;
break; break;
case 4: case 4:
buildFrame->ID = c; buildFrame.ID = c;
break; break;
case 5: case 5:
buildFrame->ID |= c << 8; buildFrame.ID |= c << 8;
break; break;
case 6: case 6:
buildFrame->ID |= c << 16; buildFrame.ID |= c << 16;
break; break;
case 7: case 7:
buildFrame->ID |= c << 24; buildFrame.ID |= c << 24;
if ((buildFrame->ID & 1 << 31) == 1 << 31) if ((buildFrame.ID & 1 << 31) == 1 << 31)
{ {
buildFrame->ID &= 0x7FFFFFFF; buildFrame.ID &= 0x7FFFFFFF;
buildFrame->extended = true; buildFrame.extended = true;
} }
else buildFrame->extended = false; else buildFrame.extended = false;
break; break;
case 8: case 8:
buildFrame->len = c & 0xF; buildFrame.len = c & 0xF;
if (buildFrame->len > 8) buildFrame->len = 8; if (buildFrame.len > 8) buildFrame.len = 8;
buildFrame->bus = (c & 0xF0) >> 4; buildFrame.bus = (c & 0xF0) >> 4;
break; break;
default: default:
if (rx_step < buildFrame->len + 9) if (rx_step < buildFrame.len + 9)
{ {
buildFrame->data[rx_step - 9] = c; buildFrame.data[rx_step - 9] = c;
} }
else else
{ {
rx_state = IDLE; rx_state = IDLE;
rx_step = 0; rx_step = 0;
//qDebug() << "emit from serial handler to main form id: " << buildFrame->ID; //qDebug() << "emit from serial handler to main form id: " << buildFrame.ID;
//if (capturing) //if (capturing)
//{ //{
buildFrame->isReceived = true; buildFrame.isReceived = true;
model->addFrame(*buildFrame, false); /* model lives in UI thread, we need to call invokeMethod */
QMetaObject::invokeMethod(model, "addFrame",
Qt::QueuedConnection,
Q_ARG(CANFrame, buildFrame),
Q_ARG(bool, false));
//take the time the frame came in and try to resync the time base. //take the time the frame came in and try to resync the time base.
if (continuousTimeSync) txTimestampBasis = QDateTime::currentMSecsSinceEpoch() - (buildFrame->timestamp / 1000); if (continuousTimeSync) txTimestampBasis = QDateTime::currentMSecsSinceEpoch() - (buildFrame.timestamp / 1000);
framesRapid++; framesRapid++;
//} //}
} }
@@ -576,24 +586,24 @@ QString SerialWorker::getConnTypeName()
return QString("GVRET"); return QString("GVRET");
} }
void SerialWorker::updateBusSettings(CAN_Bus *bus) void SerialWorker::updateBusSettings(CANBus bus)
{ {
int busNum = bus->busNum - busBase; int busNum = bus.busNum - busBase;
if (busNum < 0) return; if (busNum < 0) return;
if (busNum >= numBuses) return; if (busNum >= numBuses) return;
qDebug() << "About to update bus " << busNum << " on GVRET"; qDebug() << "About to update bus " << busNum << " on GVRET";
if (busNum == 0) if (busNum == 0)
{ {
can0Baud = bus->getSpeed(); can0Baud = bus.getSpeed();
can0Baud |= 0x80000000; can0Baud |= 0x80000000;
if (bus->isActive()) if (bus.isActive())
{ {
can0Baud |= 0x40000000; can0Baud |= 0x40000000;
can0Enabled = true; can0Enabled = true;
} }
else can0Enabled = false; else can0Enabled = false;
if (bus->isListenOnly()) if (bus.isListenOnly())
{ {
can0Baud |= 0x20000000; can0Baud |= 0x20000000;
can0ListenOnly = true; can0ListenOnly = true;
@@ -602,23 +612,23 @@ void SerialWorker::updateBusSettings(CAN_Bus *bus)
} }
if (busNum == 1) if (busNum == 1)
{ {
can1Baud = bus->getSpeed(); can1Baud = bus.getSpeed();
can1Baud |= 0x80000000; can1Baud |= 0x80000000;
if (bus->isActive()) if (bus.isActive())
{ {
can1Baud |= 0x40000000; can1Baud |= 0x40000000;
can1Enabled = true; can1Enabled = true;
} }
else can1Enabled = false; else can1Enabled = false;
if (bus->isListenOnly()) if (bus.isListenOnly())
{ {
can1Baud |= 0x20000000; can1Baud |= 0x20000000;
can1ListenOnly = true; can1ListenOnly = true;
} }
else can1ListenOnly = false; else can1ListenOnly = false;
if (bus->isSingleWire()) if (bus.isSingleWire())
{ {
can1Baud |= 0x10000000; can1Baud |= 0x10000000;
deviceSingleWireMode = 1; deviceSingleWireMode = 1;
+3 -2
View File
@@ -10,6 +10,7 @@
#include "canframemodel.h" #include "canframemodel.h"
#include "canconnection.h" #include "canconnection.h"
namespace SERIALSTATE { namespace SERIALSTATE {
enum STATE //keep this enum synchronized with the Arduino firmware project enum STATE //keep this enum synchronized with the Arduino firmware project
@@ -57,7 +58,7 @@ public slots:
//void stopFrameCapture(int) override; //void stopFrameCapture(int) override;
//void startFrameCapture(int) override; //void startFrameCapture(int) override;
void updatePortName(QString) override; //string version of the port to connect to. This base doesnt know a thing about this value void updatePortName(QString) override; //string version of the port to connect to. This base doesnt know a thing about this value
void updateBusSettings(CAN_Bus *bus) override; void updateBusSettings(CANBus) override;
private: private:
bool doValidation; bool doValidation;
@@ -71,7 +72,7 @@ private:
int framesRapid; int framesRapid;
STATE rx_state; STATE rx_state;
int rx_step; int rx_step;
CANFrame *buildFrame; CANFrame buildFrame;
int can0Baud, can1Baud; int can0Baud, can1Baud;
bool can0Enabled, can1Enabled; bool can0Enabled, can1Enabled;
bool can0ListenOnly, can1ListenOnly; bool can0ListenOnly, can1ListenOnly;