ProviderRs232.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #ifndef PROVIDERRS232_H
  2. #define PROVIDERRS232_H
  3. // LedDevice includes
  4. #include <leddevice/LedDevice.h>
  5. // qt includes
  6. #include <QSerialPort>
  7. ///
  8. /// The ProviderRs232 implements an abstract base-class for LedDevices using a RS232-device.
  9. ///
  10. class ProviderRs232 : public LedDevice
  11. {
  12. Q_OBJECT
  13. public:
  14. ///
  15. /// @brief Constructs a RS232 LED-device
  16. ///
  17. ProviderRs232(const QJsonObject &deviceConfig);
  18. ///
  19. /// @brief Destructor of the UDP LED-device
  20. ///
  21. ~ProviderRs232() override;
  22. ///
  23. /// @brief Send an update to the RS232 device to identify it.
  24. ///
  25. /// Following parameters are required
  26. /// @code
  27. /// {
  28. /// "deviceConfig" :
  29. /// }
  30. ///@endcode
  31. ///
  32. /// @param[in] params Parameters to configure device
  33. ///
  34. void identify(const QJsonObject& params) override;
  35. protected:
  36. ///
  37. /// @brief Initialise the RS232 device's configuration and network address details
  38. ///
  39. /// @param[in] deviceConfig the JSON device configuration
  40. /// @return True, if success
  41. ///
  42. bool init(const QJsonObject &deviceConfig) override;
  43. ///
  44. /// @brief Opens the output device.
  45. ///
  46. /// @return Zero on success (i.e. device is ready), else negative
  47. ///
  48. int open() override;
  49. ///
  50. /// @brief Closes the UDP device.
  51. ///
  52. /// @return Zero on success (i.e. device is closed), else negative
  53. ///
  54. int close() override;
  55. ///
  56. /// @brief Power-/turn off a RS232-device
  57. ///
  58. /// The off-state is simulated by writing "Black to LED"
  59. ///
  60. /// @return True, if success
  61. ///
  62. bool powerOff() override;
  63. ///
  64. /// @brief Discover first device of serial devices available (for configuration)
  65. ///
  66. /// @return A string of the device found
  67. ///
  68. QString discoverFirst() override;
  69. ///
  70. /// @brief Discover serial devices available (for configuration).
  71. ///
  72. /// Following parameters can be provided optional
  73. /// @code
  74. /// {
  75. /// "discoverAll" : true/false , "true", in case devices without vendor-id are to be included in the discovery result
  76. /// }
  77. ///@endcode
  78. ///
  79. /// @param[in] params Parameters used to overwrite discovery default behaviour
  80. ///
  81. /// @return A JSON structure holding a list of devices found
  82. ///
  83. QJsonObject discover(const QJsonObject& params) override;
  84. ///
  85. /// @brief Write the given bytes to the RS232-device
  86. ///
  87. /// @param[in[ size The length of the data
  88. /// @param[in] data The data
  89. /// @return Zero on success, else negative
  90. ///
  91. int writeBytes(const qint64 size, const uint8_t *data);
  92. /// The name of the output device
  93. QString _deviceName;
  94. /// The system location of the output device
  95. QString _location;
  96. /// The RS232 serial-device
  97. QSerialPort _rs232Port;
  98. /// The used baud-rate of the output device
  99. qint32 _baudRate_Hz;
  100. protected slots:
  101. ///
  102. /// @brief Set device in error state
  103. ///
  104. /// @param[in] errorMsg The error message to be logged
  105. /// @param[in] isRecoverable If False, no further retries will be done
  106. ///
  107. void setInError( const QString& errorMsg, bool isRecoverable=true) override;
  108. ///
  109. /// @brief Handle any feedback provided by the device
  110. ///
  111. virtual void readFeedback();
  112. private:
  113. ///
  114. /// @brief Try to open device if not opened
  115. ///
  116. /// @return True,if on success
  117. ///
  118. bool tryOpen(int delayAfterConnect_ms);
  119. /// Try to auto-discover device name?
  120. bool _isAutoDeviceName;
  121. /// Sleep after the connect before continuing
  122. int _delayAfterConnect_ms;
  123. /// Frames dropped, as write failed
  124. int _frameDropCounter;
  125. };
  126. #endif // PROVIDERRS232_H