2013-11-05 16:46:17 +01:00
|
|
|
#pragma once
|
|
|
|
|
2014-05-04 11:41:55 +02:00
|
|
|
#include <QObject>
|
2016-06-23 00:11:09 +02:00
|
|
|
#include <QSerialPort>
|
2016-10-08 08:14:36 +02:00
|
|
|
#include <QTimer>
|
2013-11-05 16:46:17 +01:00
|
|
|
|
2013-12-17 19:50:15 +01:00
|
|
|
// Leddevice includes
|
|
|
|
#include <leddevice/LedDevice.h>
|
2013-11-05 16:46:17 +01:00
|
|
|
|
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
/// The ProviderRs232 implements an abstract base-class for LedDevices using a RS232-device.
|
2013-11-05 16:46:17 +01:00
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
class ProviderRs232 : public LedDevice
|
2013-11-05 16:46:17 +01:00
|
|
|
{
|
2014-05-04 11:41:55 +02:00
|
|
|
Q_OBJECT
|
|
|
|
|
2013-11-05 16:46:17 +01:00
|
|
|
public:
|
|
|
|
///
|
2016-08-23 20:07:12 +02:00
|
|
|
/// Constructs specific LedDevice
|
2013-11-05 16:46:17 +01:00
|
|
|
///
|
2016-10-08 08:14:36 +02:00
|
|
|
ProviderRs232();
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Sets configuration
|
|
|
|
///
|
|
|
|
/// @param deviceConfig the json device config
|
|
|
|
/// @return true if success
|
2016-10-13 21:59:58 +02:00
|
|
|
virtual bool init(const QJsonObject &deviceConfig);
|
2013-11-05 16:46:17 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Destructor of the LedDevice; closes the output device if it is open
|
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
virtual ~ProviderRs232();
|
2013-11-05 16:46:17 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Opens and configures the output device
|
|
|
|
///
|
|
|
|
/// @return Zero on succes else negative
|
|
|
|
///
|
|
|
|
int open();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Writes the given bytes to the RS232-device and
|
|
|
|
*
|
|
|
|
* @param[in[ size The length of the data
|
|
|
|
* @param[in] data The data
|
|
|
|
*
|
2016-11-29 23:14:15 +01:00
|
|
|
* @return Zero on success else negative
|
2013-11-05 16:46:17 +01:00
|
|
|
*/
|
2016-09-25 22:20:01 +02:00
|
|
|
int writeBytes(const qint64 size, const uint8_t *data);
|
2013-11-05 16:46:17 +01:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
void closeDevice();
|
|
|
|
|
2014-05-04 11:41:55 +02:00
|
|
|
private slots:
|
2016-10-08 08:14:36 +02:00
|
|
|
/// Write the last data to the leds again
|
|
|
|
int rewriteLeds();
|
|
|
|
|
2014-05-04 11:41:55 +02:00
|
|
|
/// Unblock the device after a connection delay
|
|
|
|
void unblockAfterDelay();
|
2016-07-20 23:26:47 +02:00
|
|
|
void error(QSerialPort::SerialPortError error);
|
2016-09-25 22:20:01 +02:00
|
|
|
void bytesWritten(qint64 bytes);
|
|
|
|
void readyRead();
|
2016-08-14 10:46:44 +02:00
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
protected:
|
2016-06-23 00:11:09 +02:00
|
|
|
// tries to open device if not opened
|
2016-09-25 22:20:01 +02:00
|
|
|
bool tryOpen(const int delayAfterConnect_ms);
|
2016-06-23 00:11:09 +02:00
|
|
|
|
2013-11-05 16:46:17 +01:00
|
|
|
/// The name of the output device
|
2016-08-23 20:07:12 +02:00
|
|
|
std::string _deviceName;
|
2014-05-04 11:31:13 +02:00
|
|
|
|
2013-11-05 16:46:17 +01:00
|
|
|
/// The used baudrate of the output device
|
2016-08-23 20:07:12 +02:00
|
|
|
qint32 _baudRate_Hz;
|
2014-05-04 11:31:13 +02:00
|
|
|
|
|
|
|
/// Sleep after the connect before continuing
|
2016-06-23 00:11:09 +02:00
|
|
|
int _delayAfterConnect_ms;
|
2013-11-05 16:46:17 +01:00
|
|
|
|
|
|
|
/// The RS232 serial-device
|
2016-11-29 23:14:15 +01:00
|
|
|
QSerialPort _rs232Port;
|
2014-05-04 11:41:55 +02:00
|
|
|
|
|
|
|
bool _blockedForDelay;
|
2016-07-20 16:04:56 +02:00
|
|
|
|
|
|
|
bool _stateChanged;
|
2016-09-25 22:20:01 +02:00
|
|
|
|
|
|
|
qint64 _bytesToWrite;
|
|
|
|
qint64 _bytesWritten;
|
|
|
|
qint64 _frameDropCounter;
|
|
|
|
QSerialPort::SerialPortError _lastError;
|
2013-11-05 16:46:17 +01:00
|
|
|
};
|