Files
giesCANne/connections/gvretserial.h
T
Collin Kidder 2c8e9716a6 Added the ability for GVRET serial to try both normal mode and ESP32 mode.
This way it basically automatically detects the proper connection type to use
and uses that mode to connect. That allows both types to work transparent
to the user. They select GVRET and the serial port and away they go.
2018-07-22 19:28:51 -04:00

107 lines
2.3 KiB
C++

#ifndef GVRETSERIAL_H
#define GVRETSERIAL_H
#include <QSerialPort>
#include <QCanBusDevice>
#include <QThread>
#include <QTimer>
#include <QTcpSocket>
#include <QUdpSocket>
/*************/
#include <QDateTime>
/*************/
#include "canframemodel.h"
#include "canconnection.h"
#include "canconmanager.h"
namespace SERIALSTATE {
enum STATE
{
IDLE,
GET_COMMAND,
BUILD_CAN_FRAME,
TIME_SYNC,
GET_DIG_INPUTS,
GET_ANALOG_INPUTS,
SET_DIG_OUTPUTS,
SETUP_CANBUS,
GET_CANBUS_PARAMS,
GET_DEVICE_INFO,
SET_SINGLEWIRE_MODE,
GET_NUM_BUSES,
GET_EXT_BUSES
};
}
using namespace SERIALSTATE;
class GVRetSerial : public CANConnection
{
Q_OBJECT
public:
GVRetSerial(QString portName, bool useTcp);
virtual ~GVRetSerial();
protected:
virtual void piStarted();
virtual void piStop();
virtual void piSetBusSettings(int pBusIdx, CANBus pBus);
virtual bool piGetBusSettings(int pBusIdx, CANBus& pBus);
virtual void piSuspend(bool pSuspend);
virtual bool piSendFrame(const CANFrame&) ;
void disconnectDevice();
public slots:
void debugInput(QByteArray bytes);
private slots:
void connectDevice();
void connectionTimeout();
void readSerialData();
void serialError(QSerialPort::SerialPortError err);
void tcpConnected();
void handleTick();
private:
void readSettings();
void procRXChar(unsigned char);
void sendCommValidation();
void rebuildLocalTimeBasis();
void sendToSerial(const QByteArray &bytes);
protected:
QTimer mTimer;
QThread mThread;
bool doValidation;
int validationCounter;
bool isAutoRestart;
bool continuousTimeSync;
bool useTcp;
bool espSerialMode; //special serial mode for ESP32 based boards - no flow control and much slower serial baud speed
QSerialPort *serial;
QTcpSocket *tcpClient;
QUdpSocket *udpClient;
int framesRapid;
STATE rx_state;
uint32_t rx_step;
CANFrame buildFrame;
int can0Baud, can1Baud, swcanBaud, lin1Baud, lin2Baud;
bool can0Enabled, can1Enabled, swcanEnabled, lin1Enabled, lin2Enabled;
bool can0ListenOnly, can1ListenOnly, swcanListenOnly;
int deviceBuildNum;
int deviceSingleWireMode;
uint32_t buildTimeBasis;
int32_t timeBasis;
uint64_t lastSystemTimeBasis;
uint64_t timeAtGVRETSync;
};
#endif // GVRETSERIAL_H