Big change to serial code - moved out to its own class and thread. Serial comm is now run on a separate thread. This code now certainly leaks a small amount of memory but that'll get fixed.

This commit is contained in:
Collin Kidder
2015-05-06 22:22:14 -04:00
parent c37bca4132
commit 5f4fd37839
5 changed files with 249 additions and 168 deletions
+49
View File
@@ -0,0 +1,49 @@
#ifndef SERIALWORKER_H
#define SERIALWORKER_H
#include <QObject>
#include <QSerialPort>
#include "can_structs.h"
enum STATE //keep this enum synchronized with the Arduino firmware project
{
IDLE,
GET_COMMAND,
BUILD_CAN_FRAME,
TIME_SYNC,
GET_DIG_INPUTS,
GET_ANALOG_INPUTS,
SET_DIG_OUTPUTS,
SETUP_CANBUS
};
class SerialWorker : public QObject
{
Q_OBJECT
public:
SerialWorker(QObject *parent = 0);
~SerialWorker();
signals: //we emit signals
void error(const QString &s);
void receivedFrame(CANFrame *frame);
private slots: //we receive things in slots
void readSerialData();
public slots:
void setSerialPort(QString portName);
private:
QString portName;
bool quit;
QSerialPort *serial;
STATE rx_state;
int rx_step;
CANFrame *buildFrame;
void procRXChar(unsigned char c);
};
#endif // SERIALTHREAD_H