Merge branch 'WIP2' into WIP
Conflicts: SavvyCAN.pro config.h mainwindow.cpp mainwindow.h mainwindow.ui Resolved conflicts between branches
This commit is contained in:
+33
-23
@@ -40,6 +40,19 @@ SerialWorker::~SerialWorker()
|
||||
if (ticker != NULL) ticker->stop();
|
||||
}
|
||||
|
||||
void SerialWorker::run()
|
||||
{
|
||||
ticker = new QTimer;
|
||||
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
|
||||
|
||||
elapsedTime = new QTime;
|
||||
elapsedTime->start();
|
||||
|
||||
ticker->setInterval(250); //tick four times per second
|
||||
ticker->setSingleShot(false); //keep ticking
|
||||
ticker->start();
|
||||
}
|
||||
|
||||
void SerialWorker::readSettings()
|
||||
{
|
||||
QSettings settings;
|
||||
@@ -110,19 +123,6 @@ void SerialWorker::setSerialPort(QSerialPortInfo *port)
|
||||
else connected = true;
|
||||
connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData()));
|
||||
if (doValidation) QTimer::singleShot(1000, this, SLOT(connectionTimeout()));
|
||||
if (ticker == NULL)
|
||||
{
|
||||
ticker = new QTimer;
|
||||
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
|
||||
}
|
||||
if (elapsedTime == NULL)
|
||||
{
|
||||
elapsedTime = new QTime;
|
||||
elapsedTime->start();
|
||||
}
|
||||
ticker->setInterval(250); //tick four times per second
|
||||
ticker->setSingleShot(false); //keep ticking
|
||||
ticker->start();
|
||||
}
|
||||
|
||||
void SerialWorker::connectionTimeout()
|
||||
@@ -155,9 +155,17 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
|
||||
QByteArray buffer;
|
||||
int c;
|
||||
int ID;
|
||||
CANFrame tempFrame = *frame;
|
||||
tempFrame.isReceived = false;
|
||||
|
||||
//qDebug() << "Sending out frame with id " << frame->ID;
|
||||
|
||||
//show our sent frames in the list too. This happens even if we're not connected.
|
||||
canModel->addFrame(tempFrame, false);
|
||||
gotFrames++;
|
||||
|
||||
if (serial == NULL) return;
|
||||
if (!serial->isOpen()) return;
|
||||
if (!connected) return;
|
||||
|
||||
ID = frame->ID;
|
||||
@@ -177,8 +185,6 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
|
||||
}
|
||||
buffer[8 + frame->len] = 0;
|
||||
|
||||
if (serial == NULL) return;
|
||||
if (!serial->isOpen()) return;
|
||||
//qDebug() << "writing " << buffer.length() << " bytes to serial port";
|
||||
serial->write(buffer);
|
||||
}
|
||||
@@ -187,7 +193,7 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
|
||||
//Don't get carried away here. The GVRET firmware only has finite
|
||||
//buffers and besides, the other end will get buried in traffic.
|
||||
void SerialWorker::sendFrameBatch(const QList<CANFrame> *frames)
|
||||
{
|
||||
{
|
||||
for (int i = 0; i < frames->length(); i++) sendFrame(&frames->at(i), frames->at(i).bus);
|
||||
}
|
||||
|
||||
@@ -306,6 +312,7 @@ void SerialWorker::procRXChar(unsigned char c)
|
||||
//qDebug() << "emit from serial handler to main form id: " << buildFrame->ID;
|
||||
if (capturing)
|
||||
{
|
||||
buildFrame->isReceived = true;
|
||||
canModel->addFrame(*buildFrame, false);
|
||||
gotFrames++;
|
||||
if (buildFrame->ID == targetID) emit gotTargettedFrame(canModel->rowCount() - 1);
|
||||
@@ -422,14 +429,17 @@ void SerialWorker::handleTick()
|
||||
{
|
||||
//qDebug() << "Tick!";
|
||||
|
||||
if (!gotValidated)
|
||||
if (connected)
|
||||
{
|
||||
if (serial->isOpen()) //if it's still false we have a problem...
|
||||
if (!gotValidated)
|
||||
{
|
||||
qDebug() << "Comm validation failed. ";
|
||||
closeSerialPort(); //start by stopping everything.
|
||||
QTimer::singleShot(500, this, SLOT(handleReconnect()));
|
||||
return;
|
||||
if (serial->isOpen()) //if it's still false we have a problem...
|
||||
{
|
||||
qDebug() << "Comm validation failed. ";
|
||||
closeSerialPort(); //start by stopping everything.
|
||||
QTimer::singleShot(500, this, SLOT(handleReconnect()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -438,7 +448,7 @@ void SerialWorker::handleTick()
|
||||
emit frameUpdateTick(framesPerSec / 4, gotFrames); //sends stats to interested parties
|
||||
canModel->sendBulkRefresh(gotFrames);
|
||||
gotFrames = 0;
|
||||
if (doValidation) sendCommValidation();
|
||||
if (doValidation && serial) sendCommValidation();
|
||||
}
|
||||
|
||||
void SerialWorker::handleReconnect()
|
||||
|
||||
Reference in New Issue
Block a user