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>
|
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-08-23 20:07:12 +02:00
|
|
|
/// @param deviceConfig json device config
|
2013-11-05 16:46:17 +01:00
|
|
|
///
|
2016-08-28 07:12:48 +02:00
|
|
|
ProviderRs232(const Json::Value &deviceConfig);
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Sets configuration
|
|
|
|
///
|
|
|
|
/// @param deviceConfig the json device config
|
|
|
|
/// @return true if success
|
|
|
|
virtual bool setConfig(const Json::Value &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
|
|
|
|
*
|
|
|
|
* @return Zero on succes else negative
|
|
|
|
*/
|
|
|
|
int writeBytes(const unsigned size, const uint8_t *data);
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
void closeDevice();
|
|
|
|
|
2014-05-04 11:41:55 +02:00
|
|
|
private slots:
|
|
|
|
/// Unblock the device after a connection delay
|
|
|
|
void unblockAfterDelay();
|
2016-07-20 23:26:47 +02:00
|
|
|
void error(QSerialPort::SerialPortError error);
|
2016-08-14 10:46:44 +02:00
|
|
|
|
2013-11-05 16:46:17 +01:00
|
|
|
private:
|
2016-06-23 00:11:09 +02:00
|
|
|
// tries to open device if not opened
|
|
|
|
bool tryOpen();
|
|
|
|
|
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-06-23 00:11:09 +02:00
|
|
|
QSerialPort _rs232Port;
|
2014-05-04 11:41:55 +02:00
|
|
|
|
|
|
|
bool _blockedForDelay;
|
2016-07-20 16:04:56 +02:00
|
|
|
|
|
|
|
bool _stateChanged;
|
2013-11-05 16:46:17 +01:00
|
|
|
};
|