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.

ovasCPluginExternalStimulations.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #pragma once
  2. /**
  3. * \brief Acquisition Server plugin adding the capability to receive stimulations from external sources
  4. *
  5. * \author Anton Andreev
  6. * \author Jozef Legeny
  7. *
  8. * \note This plugin is deprecated. The users are recommended to use the TCP Tagging plugin instead. (11.05.2016)
  9. *
  10. */
  11. #include <thread>
  12. #include <mutex>
  13. #include <condition_variable>
  14. #include <sys/timeb.h>
  15. #include "ovasIAcquisitionServerPlugin.h"
  16. namespace OpenViBE {
  17. namespace AcquisitionServer {
  18. class CAcquisitionServer;
  19. namespace Plugins {
  20. class CPluginExternalStimulations final : public IAcquisitionServerPlugin
  21. {
  22. // Plugin interface
  23. public:
  24. explicit CPluginExternalStimulations(const Kernel::IKernelContext& ctx);
  25. ~CPluginExternalStimulations() override {}
  26. bool startHook(const std::vector<CString>& selectedChannelNames, const size_t sampling, const size_t nChannel, const size_t nSamplePerSentBlock) override;
  27. void stopHook() override;
  28. void loopHook(std::deque<std::vector<float>>& vPendingBuffer, CStimulationSet& stimulationSet, const uint64_t start, const uint64_t end,
  29. const uint64_t sampleTime) override;
  30. void acceptNewConnectionHook() override { m_ExternalStimulations.clear(); }
  31. // Plugin implementation
  32. struct SExternalStimulation
  33. {
  34. uint64_t timestamp;
  35. uint64_t identifier;
  36. };
  37. void addExternalStimulations(CStimulationSet* ss, Kernel::ILogManager& logm, const uint64_t start, const uint64_t end);
  38. void readExternalStimulations();
  39. //void acquireExternalStimulationsVRPN(CStimulationSet* ss, Kernel::ILogManager& logm, uint64_t start, uint64_t end);
  40. struct timeb m_CTStartTime; //time when the acquisition process started in local computer time
  41. std::vector<SExternalStimulation> m_ExternalStimulations;
  42. bool m_IsExternalStimulationsEnabled = false;
  43. CString m_ExternalStimulationsQueueName;
  44. bool setExternalStimulationsEnabled(bool active);
  45. bool isExternalStimulationsEnabled() const { return m_IsExternalStimulationsEnabled; }
  46. // Debugging of external stimulations
  47. int m_DebugStimulationsLost = 0;
  48. int m_DebugExternalStimulationsSent = 0;
  49. int m_DebugCurrentReadIPCStimulations = 0;
  50. int m_DebugStimulationsReceivedEarlier = 0;
  51. int m_DebugStimulationsReceivedLate = 0;
  52. int m_DebugStimulationsReceivedWrongSize = 0;
  53. int m_DebugStimulationsBuffered = 0;
  54. //added for acquiring external stimulations
  55. std::unique_ptr<std::thread> m_ESthreadPtr;
  56. bool m_IsESThreadRunning = false;
  57. std::mutex m_es_mutex;
  58. std::condition_variable m_esAvailable;
  59. };
  60. } // namespace Plugins
  61. } // namespace AcquisitionServer
  62. } // namespace OpenViBE