This commit is contained in:
2021-10-14 13:47:35 +02:00
commit 6625a8dfaa
4026 changed files with 844291 additions and 0 deletions
@@ -0,0 +1,34 @@
PROJECT(openvibe-external-stimulation-connection-example)
SET(PROJECT_VERSION_MAJOR ${OV_GLOBAL_VERSION_MAJOR})
SET(PROJECT_VERSION ${OV_GLOBAL_VERSION_STRING})
FILE(GLOB_RECURSE SRC_FILES src/*.cpp src/*.h src/*.hpp src/*.inl include/*.h)
INCLUDE_DIRECTORIES(include)
ADD_EXECUTABLE(${PROJECT_NAME} ${SRC_FILES})
SET_PROPERTY(TARGET ${PROJECT_NAME} PROPERTY FOLDER ${APP_FOLDER})
INCLUDE("FindThirdPartyBoost")
INCLUDE("FindThirdPartyBoost_Thread")
# ---------------------------------
# ---------------------------------
# ----------------------
# Generate launch script
# ----------------------
OV_INSTALL_LAUNCH_SCRIPT(SCRIPT_PREFIX "${PROJECT_NAME}" EXECUTABLE_NAME "${PROJECT_NAME}")
# -----------------------------
# Install files
# -----------------------------
INSTALL(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${DIST_BINDIR}
LIBRARY DESTINATION ${DIST_LIBDIR}
ARCHIVE DESTINATION ${DIST_LIBDIR})
@@ -0,0 +1,75 @@
#pragma once
#include <sys/timeb.h>
#include <boost/interprocess/ipc/message_queue.hpp>
#include <iostream> // log
#include <utility>
namespace OpenViBE {
class CStimulationConnection
{
public:
/**
* Create a new OpenvibeStimulationConnection object.
*
* Initiates the message queue.
*
* @param queueName The name of the queue.
* @throw boost::interprocess::interprocess_exception Throws an
* interprocess exception in the queue fails to be created.
*/
explicit CStimulationConnection(std::string queueName = "openvibeExternalStimulations")
: m_messageQueueName(std::move(queueName))
{
boost::interprocess::message_queue::remove(m_messageQueueName.c_str());
try
{
m_messageQueue = new boost::interprocess::message_queue(boost::interprocess::create_only, m_messageQueueName.c_str(), m_maxMessages,
m_chunkLength * sizeof(uint64_t));
}
catch (boost::interprocess::interprocess_exception& exception)
{
std::cout << exception.what() << std::endl; // log
throw;
}
}
/**
* Send a stimulation to the OpenViBE Acquisition server on the initiated
* queue.
*
* @throw boost::interprocess::interprocess_exception Throws an exception
* if the message sending failed.
*/
void sendStimulation(const uint64_t stimulationID) const
{
struct timeb currentTime;
ftime(&currentTime);
const uint64_t stimulationTime = currentTime.time * 1000 + currentTime.millitm;
uint64_t message[3];
message[0] = 0; // unused at the moment
message[1] = stimulationID;
message[2] = stimulationTime;
try { m_messageQueue->send(&message, sizeof(message), 0); }
catch (boost::interprocess::interprocess_exception& exception)
{
std::cout << exception.what() << std::endl; // log
throw;
}
}
protected:
std::string m_messageQueueName;
int m_chunkLength = 3;
int m_maxMessages = 5000;
// openvibe currently uses messages of length of 3
boost::interprocess::message_queue* m_messageQueue = nullptr;
};
} // namespace OpenViBE
@@ -0,0 +1,47 @@
// WARNING: The External Stimulations are a deprecated technique.
// Please use the TCP Tagging approach instead. You can find examples of
// TCP Tagging usage e.g. in the Graz Visualization and the Display Cue Image boxes.
// It is described in the OV web documentation. A simple client can be found
// under modules/tcptagging/.
#include "openvibeStimulationConnection.h"
// for the purpose of this example we are using the Beep stimulation
#define OVTK_StimulationId_Beep 0x00008202
#include <iostream>
#if defined(TARGET_OS_Linux)
#include <unistd.h>
#else
#include <windows.h>
#endif
/** @file ovesce_main.cpp
* This program is a very simple example of the usage of the Software Stimulation capabilities of OpenViBE Acquisition server.
*
* This program sends a Beep stimulation to the acquisition server, using the default message queue name.
*/
int main()
{
std::cout << "WARNING: External Stimulations approach is deprecated.\nFor new code please use the TCP Tagging approach.\n";
std::cout << "Creating a new OpenvibeStimulationConnection object" << std::endl;
OpenViBE::CStimulationConnection* osc = new OpenViBE::CStimulationConnection();
while (true)
{
std::cout << "Sending a Beep stimulation" << std::endl;
osc->sendStimulation(OVTK_StimulationId_Beep);
#if defined(TARGET_OS_Linux)
sleep(1);
#else
Sleep(1000);
#endif
}
delete osc;
return 0;
}