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
|
|
|
|
|
|
|
///
|
|
|
|
/// The LedRs232Device implements an abstract base-class for LedDevices using a RS232-device.
|
|
|
|
///
|
2014-05-04 11:41:55 +02:00
|
|
|
class LedRs232Device : public QObject, 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:
|
|
|
|
///
|
|
|
|
/// Constructs the LedDevice attached to a RS232-device
|
|
|
|
///
|
|
|
|
/// @param[in] outputDevice The name of the output device (eg '/etc/ttyS0')
|
|
|
|
/// @param[in] baudrate The used baudrate for writing to the output device
|
|
|
|
///
|
2014-05-04 11:31:13 +02:00
|
|
|
LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms = 0);
|
2013-11-05 16:46:17 +01:00
|
|
|
|
|
|
|
///
|
|
|
|
/// Destructor of the LedDevice; closes the output device if it is open
|
|
|
|
///
|
|
|
|
virtual ~LedRs232Device();
|
|
|
|
|
|
|
|
///
|
|
|
|
/// 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);
|
|
|
|
|
2014-05-04 11:41:55 +02:00
|
|
|
private slots:
|
|
|
|
/// Unblock the device after a connection delay
|
|
|
|
void unblockAfterDelay();
|
|
|
|
|
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
|
2014-05-04 11:31:13 +02:00
|
|
|
const std::string _deviceName;
|
|
|
|
|
2013-11-05 16:46:17 +01:00
|
|
|
/// The used baudrate of the output device
|
2016-06-23 00:11:09 +02:00
|
|
|
const 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;
|
2013-11-05 16:46:17 +01:00
|
|
|
};
|