You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ovpCBoxAlgorithmUDPStimcodeSender.h 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ///-------------------------------------------------------------------------------------------------
  2. ///
  3. /// \file CBoxAlgorithmUDPStimcodeSender.h
  4. /// \brief Classes of the Box UDPStimcodeSender.
  5. /// \author Tobias Baumann (TH Nuernberg).
  6. /// \version 1.1.
  7. /// \date Mon Oct 04 12:43:53 2021.
  8. /// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
  9. ///
  10. ///-------------------------------------------------------------------------------------------------
  11. //includes
  12. #pragma once
  13. //You may have to change this path to match your folder organisation
  14. #include "../ovp_defines.h"
  15. #include <openvibe/ov_all.h>
  16. #include <toolkit/ovtk_all.h>
  17. #include <boost/asio.hpp>
  18. namespace OpenViBE
  19. {
  20. namespace Plugins
  21. {
  22. namespace Tactilebci
  23. {
  24. /// <summary> The class CBoxAlgorithmUDPStimcodeSender describes the box UDPStimcodeSender. </summary>
  25. class CBoxAlgorithmUDPStimcodeSender final : virtual public Toolkit::TBoxAlgorithm<IBoxAlgorithm>
  26. {
  27. public:
  28. void release() override { delete this; }
  29. bool initialize() override;
  30. bool uninitialize() override;
  31. bool processInput(const size_t index) override;
  32. bool process() override;
  33. // As we do with any class in openvibe, we use the macro below to associate this box to an unique identifier.
  34. // The inheritance information is also made available, as we provide the superclass Toolkit::TBoxAlgorithm < IBoxAlgorithm >
  35. _IsDerivedFromClass_Final_(Toolkit::TBoxAlgorithm<IBoxAlgorithm>, OVP_ClassId_BoxAlgorithm_UDPStimcodeSender)
  36. protected:
  37. // Input decoder:
  38. Toolkit::TStimulationDecoder<CBoxAlgorithmUDPStimcodeSender> m_StimDecoder;
  39. // Output decoder:
  40. Toolkit::TStimulationEncoder<CBoxAlgorithmUDPStimcodeSender> m_StimEncoder;
  41. private:
  42. // Box setting variables
  43. CString m_IP = "";
  44. uint64_t m_Port = 0;
  45. uint64_t m_RowBase = 0;
  46. uint64_t m_nTactilos = 0;
  47. // Socket
  48. boost::asio::io_service m_IOService;
  49. boost::asio::ip::udp::socket m_Socket{m_IOService};
  50. };
  51. /// <summary> Descriptor of the box UDPStimcodeSender. </summary>
  52. class CBoxAlgorithmUDPStimcodeSenderDesc final : virtual public IBoxAlgorithmDesc
  53. {
  54. public:
  55. void release() override { }
  56. CString getName() const override { return CString("UDPStimcodeSender"); }
  57. CString getAuthorName() const override { return CString("Tobias Baumann"); }
  58. CString getAuthorCompanyName() const override { return CString("TH Nuernberg"); }
  59. CString getShortDescription() const override { return CString("Sends Stimulationcodes via UDP"); }
  60. CString getDetailedDescription() const override { return CString("Sends the received Stimulationcodes the Adafruit Feather, using UDP. The Input Stimulation will be passed to the Output unchanged."); }
  61. CString getCategory() const override { return CString("TactileBCI"); }
  62. CString getVersion() const override { return CString("1.1"); }
  63. CString getStockItemName() const override { return CString("gtk-network"); }
  64. CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_UDPStimcodeSender; }
  65. IPluginObject* create() override { return new CBoxAlgorithmUDPStimcodeSender; }
  66. bool getBoxPrototype(Kernel::IBoxProto& prototype) const override
  67. {
  68. prototype.addInput("StimcodeIn",OV_TypeId_Stimulations);
  69. //prototype.addFlag(Kernel::BoxFlag_CanModifyInput);
  70. //prototype.addFlag(Kernel::BoxFlag_CanAddInput);
  71. prototype.addOutput("StimcodeOut",OV_TypeId_Stimulations);
  72. //prototype.addFlag(Kernel::BoxFlag_CanModifyOutput);
  73. //prototype.addFlag(Kernel::BoxFlag_CanAddOutput);
  74. prototype.addSetting("FeatherIP",OV_TypeId_String,"192.168.4.1");
  75. prototype.addSetting("FeatherPort",OV_TypeId_Integer,"8888");
  76. prototype.addSetting("RowStimulationBase",OV_TypeId_Stimulation,"OVTK_StimulationId_Label_01");
  77. prototype.addSetting("Number of Tactilos",OV_TypeId_Integer,"6");
  78. prototype.addFlag(Kernel::BoxFlag_CanModifySetting);
  79. //prototype.addFlag(Kernel::BoxFlag_CanAddSetting);
  80. prototype.addFlag(OV_AttributeId_Box_FlagIsUnstable);
  81. return true;
  82. }
  83. _IsDerivedFromClass_Final_(IBoxAlgorithmDesc, OVP_ClassId_BoxAlgorithm_UDPStimcodeSenderDesc)
  84. };
  85. } // namespace Tactilebci
  86. } // namespace Plugins
  87. } // namespace OpenViBE