2020-07-12 20:27:56 +02:00
|
|
|
#ifndef PROVIDERRS232_H
|
|
|
|
#define PROVIDERRS232_H
|
2013-11-05 16:46:17 +01:00
|
|
|
|
2020-02-10 15:21:58 +01:00
|
|
|
// LedDevice includes
|
2013-12-17 19:50:15 +01:00
|
|
|
#include <leddevice/LedDevice.h>
|
2013-11-05 16:46:17 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
// qt includes
|
|
|
|
#include <QSerialPort>
|
|
|
|
|
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:
|
2020-07-12 20:27:56 +02:00
|
|
|
|
2013-11-05 16:46:17 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Constructs a RS232 LED-device
|
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
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Destructor of the UDP LED-device
|
2016-08-23 20:07:12 +02:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
virtual ~ProviderRs232() override;
|
|
|
|
|
|
|
|
protected:
|
2013-11-05 16:46:17 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Initialise the RS232 device's configuration and network address details
|
2013-11-05 16:46:17 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @param[in] deviceConfig the JSON device configuration
|
|
|
|
/// @return True, if success
|
|
|
|
///
|
|
|
|
virtual bool init(const QJsonObject &deviceConfig) override;
|
2013-11-05 16:46:17 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Opens the output device.
|
2013-11-05 16:46:17 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @return Zero on success (i.e. device is ready), else negative
|
2013-11-05 16:46:17 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
virtual int open() override;
|
2020-02-10 15:21:58 +01:00
|
|
|
|
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
/// @brief Closes the UDP device.
|
|
|
|
///
|
|
|
|
/// @return Zero on success (i.e. device is closed), else negative
|
2020-02-10 15:21:58 +01:00
|
|
|
///
|
2020-07-12 20:27:56 +02:00
|
|
|
virtual int close() override;
|
2013-11-05 16:46:17 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Power-/turn off a RS232-device
|
|
|
|
///
|
|
|
|
/// The off-state is simulated by writing "Black to LED"
|
|
|
|
///
|
|
|
|
/// @return True, if success
|
|
|
|
///
|
|
|
|
virtual bool powerOff() override;
|
2017-02-09 20:10:57 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Discover first devices of a serial device available (for configuration)
|
|
|
|
///
|
|
|
|
/// @return A string of the device found
|
|
|
|
///
|
|
|
|
virtual QString discoverFirst() override;
|
2017-02-09 20:10:57 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Discover RS232 serial devices available (for configuration).
|
|
|
|
///
|
|
|
|
/// @return A JSON structure holding a list of devices found
|
|
|
|
///
|
|
|
|
virtual QJsonObject discover() override;
|
2017-02-09 20:10:57 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Write the given bytes to the RS232-device
|
|
|
|
///
|
|
|
|
/// @param[in[ size The length of the data
|
|
|
|
/// @param[in] data The data
|
|
|
|
/// @return Zero on success, else negative
|
|
|
|
///
|
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
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
/// The name of the output device
|
|
|
|
QString _deviceName;
|
|
|
|
/// The RS232 serial-device
|
|
|
|
QSerialPort _rs232Port;
|
|
|
|
/// The used baud-rate of the output device
|
|
|
|
qint32 _baudRate_Hz;
|
2016-08-23 20:07:12 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
protected slots:
|
2016-08-14 10:46:44 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Set device in error state
|
|
|
|
///
|
|
|
|
/// @param errorMsg The error message to be logged
|
|
|
|
///
|
|
|
|
virtual void setInError( const QString& errorMsg) override;
|
2017-02-09 20:10:57 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
private:
|
2017-02-09 20:10:57 +01:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
///
|
|
|
|
/// @brief Try to open device if not opened
|
|
|
|
///
|
|
|
|
/// @return True,if on success
|
|
|
|
///
|
|
|
|
bool tryOpen(const int delayAfterConnect_ms);
|
2014-05-04 11:31:13 +02:00
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
/// Try to auto-discover device name?
|
|
|
|
bool _isAutoDeviceName;
|
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
|
|
|
|
2020-07-12 20:27:56 +02:00
|
|
|
/// Frames dropped, as write failed
|
|
|
|
int _frameDropCounter;
|
2013-11-05 16:46:17 +01:00
|
|
|
};
|
2020-07-12 20:27:56 +02:00
|
|
|
|
|
|
|
#endif // PROVIDERRS232_H
|