From e98206b11ff976e5d10178c037c9f8422eddf0ea Mon Sep 17 00:00:00 2001 From: Tobias Baumann Date: Thu, 19 May 2022 11:10:43 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=9Esrc/TactiloController/ovpCBoxAlgorithm?= =?UTF-8?q?TactiloController.cpp=E2=80=9C=20=C3=A4ndern?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ovpCBoxAlgorithmTactiloController.cpp | 274 +++++++++--------- 1 file changed, 137 insertions(+), 137 deletions(-) diff --git a/src/TactiloController/ovpCBoxAlgorithmTactiloController.cpp b/src/TactiloController/ovpCBoxAlgorithmTactiloController.cpp index 2058247..9e5ffe7 100644 --- a/src/TactiloController/ovpCBoxAlgorithmTactiloController.cpp +++ b/src/TactiloController/ovpCBoxAlgorithmTactiloController.cpp @@ -1,138 +1,138 @@ -///------------------------------------------------------------------------------------------------- -/// -/// \file ovpCBoxAlgorithmTactiloController.cpp -/// \brief Functions of the Box Tactilo Controller. -/// \author Tobias Baumann (TH-Nürnberg). -/// \version 1.0. -/// \date Mon Feb 21 14:59:56 2022. -/// \copyright GNU Affero General Public License v3.0. -/// -///------------------------------------------------------------------------------------------------- - -//includes -#include "ovpCBoxAlgorithmTactiloController.h" -#include - -using namespace OpenViBE; -using namespace /*OpenViBE::*/Kernel; -using namespace /*OpenViBE::*/Plugins; -using namespace /*OpenViBE::Plugins::*/Tactilebci; - -/*******************************************************************************/ - -bool CBoxAlgorithmTactiloController::initialize() -{ - m_StimDecoder.initialize(*this, 0); - m_StimEncoder.initialize(*this, 0); - - //get Box Settings - m_PortName = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0); - m_RowBase = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1); - m_nTactilos = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 3); - - //set m_nTactilos to 2 if lower than 2 - if(m_nTactilos < 2) - { - m_nTactilos = 2; - } - //set m_nTactilos to MAX if greater than MAX_TACTILOS - if(m_nTactilos > MAX_TACTILOS) - { - m_nTactilos = MAX_TACTILOS; - } - - //open serial port and set baudrate to 115200 - m_Port.open(m_PortName.toASCIIString()); - m_Port.set_option(boost::asio::serial_port::baud_rate(115200)); - - if(m_Port.is_open()) - { - this->getLogManager() << LogLevel_Info << "Connected to Serial Port: " << m_PortName << "\n"; - m_Port.write_some(boost::asio::buffer("b")); - } - - return true; -} - -/*******************************************************************************/ - -bool CBoxAlgorithmTactiloController::uninitialize() -{ - this->getLogManager() << LogLevel_Info << "Disconnect from Serial Port: " << m_PortName << "\n"; - m_Port.write_some(boost::asio::buffer("e")); - m_Port.close(); - - m_StimDecoder.uninitialize(); - m_StimEncoder.uninitialize(); - - return true; -} - -/*******************************************************************************/ - -bool CBoxAlgorithmTactiloController::processInput(const size_t index) -{ - // some pre-processing code if needed... - - // ready to process ! - getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess(); - - return true; -} - -/*******************************************************************************/ -bool CBoxAlgorithmTactiloController::process() -{ - - // the static box context describes the box inputs, outputs, settings structures - const IBox& staticBoxContext = this->getStaticBoxContext(); - // the dynamic box context describes the current state of the box inputs and outputs (i.e. the chunks) - IBoxIO& boxContext = this->getDynamicBoxContext(); - - uint64_t StimulationID = 0; - uint64_t ChunkStartTime = 0; - uint64_t ChunkEndTime = 0; - uint64_t Size = 0; - const uint8_t* Buffer = nullptr; - - //iterate over all chunk on input 0 - for (uint64_t i = 0; i < boxContext.getInputChunkCount(0); ++i) - { - // decode the chunk i - m_StimDecoder.decode(i); - - if(m_StimDecoder.isBufferReceived()) - { - //check received stimulations - IStimulationSet* StimSet = m_StimDecoder.getOutputStimulationSet(); - for(uint64_t j=0; jgetStimulationCount(); j++) - { - StimulationID = StimSet->getStimulationIdentifier(j); - - if(StimulationID >= m_RowBase && StimulationID < (m_RowBase + m_nTactilos)) - { - m_currTactiloNr = StimulationID-m_RowBase+1; - } - if(StimulationID == OVTK_StimulationId_VisualStimulationStart) - { - this->getLogManager() << LogLevel_Info << "Tactilo Nr. " << m_currTactiloNr << " ON\n"; - m_Port.write_some(boost::asio::buffer(std::to_string(m_currTactiloNr))); - } - if(StimulationID == OVTK_StimulationId_VisualStimulationStop) - { - this->getLogManager() << LogLevel_Info << "Tactilo Nr. " << m_currTactiloNr << " OFF\n"; - m_Port.write_some(boost::asio::buffer(std::to_string(m_currTactiloNr))); - } - } - } - // forward input chunks - boxContext.getInputChunk(0, i, ChunkStartTime, ChunkEndTime, Size, Buffer); - boxContext.appendOutputChunkData(0, Buffer, Size); - boxContext.markOutputAsReadyToSend(0, ChunkStartTime, ChunkEndTime); - boxContext.markInputAsDeprecated(0, i); - } - - return true; -} - +///------------------------------------------------------------------------------------------------- +/// +/// \file ovpCBoxAlgorithmTactiloController.cpp +/// \brief Functions of the Box Tactilo Controller. +/// \author Tobias Baumann (TH-Nürnberg). +/// \version 1.0. +/// \date Mon Feb 21 14:59:56 2022. +/// \copyright GNU Affero General Public License v3.0. +/// +///------------------------------------------------------------------------------------------------- + +//includes +#include "ovpCBoxAlgorithmTactiloController.h" +#include + +using namespace OpenViBE; +using namespace /*OpenViBE::*/Kernel; +using namespace /*OpenViBE::*/Plugins; +using namespace /*OpenViBE::Plugins::*/Tactilebci; + +/*******************************************************************************/ + +bool CBoxAlgorithmTactiloController::initialize() +{ + m_StimDecoder.initialize(*this, 0); + m_StimEncoder.initialize(*this, 0); + + //get Box Settings + m_PortName = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0); + m_RowBase = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1); + m_nTactilos = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 2); + + //set m_nTactilos to 2 if lower than 2 + if(m_nTactilos < 2) + { + m_nTactilos = 2; + } + //set m_nTactilos to MAX if greater than MAX_TACTILOS + if(m_nTactilos > MAX_TACTILOS) + { + m_nTactilos = MAX_TACTILOS; + } + + //open serial port and set baudrate to 115200 + m_Port.open(m_PortName.toASCIIString()); + m_Port.set_option(boost::asio::serial_port::baud_rate(115200)); + + if(m_Port.is_open()) + { + this->getLogManager() << LogLevel_Info << "Connected to Serial Port: " << m_PortName << "\n"; + m_Port.write_some(boost::asio::buffer("b")); + } + + return true; +} + +/*******************************************************************************/ + +bool CBoxAlgorithmTactiloController::uninitialize() +{ + this->getLogManager() << LogLevel_Info << "Disconnect from Serial Port: " << m_PortName << "\n"; + m_Port.write_some(boost::asio::buffer("e")); + m_Port.close(); + + m_StimDecoder.uninitialize(); + m_StimEncoder.uninitialize(); + + return true; +} + +/*******************************************************************************/ + +bool CBoxAlgorithmTactiloController::processInput(const size_t index) +{ + // some pre-processing code if needed... + + // ready to process ! + getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess(); + + return true; +} + +/*******************************************************************************/ +bool CBoxAlgorithmTactiloController::process() +{ + + // the static box context describes the box inputs, outputs, settings structures + const IBox& staticBoxContext = this->getStaticBoxContext(); + // the dynamic box context describes the current state of the box inputs and outputs (i.e. the chunks) + IBoxIO& boxContext = this->getDynamicBoxContext(); + + uint64_t StimulationID = 0; + uint64_t ChunkStartTime = 0; + uint64_t ChunkEndTime = 0; + uint64_t Size = 0; + const uint8_t* Buffer = nullptr; + + //iterate over all chunk on input 0 + for (uint64_t i = 0; i < boxContext.getInputChunkCount(0); ++i) + { + // decode the chunk i + m_StimDecoder.decode(i); + + if(m_StimDecoder.isBufferReceived()) + { + //check received stimulations + IStimulationSet* StimSet = m_StimDecoder.getOutputStimulationSet(); + for(uint64_t j=0; jgetStimulationCount(); j++) + { + StimulationID = StimSet->getStimulationIdentifier(j); + + if(StimulationID >= m_RowBase && StimulationID < (m_RowBase + m_nTactilos)) + { + m_currTactiloNr = StimulationID-m_RowBase+1; + } + if(StimulationID == OVTK_StimulationId_VisualStimulationStart) + { + this->getLogManager() << LogLevel_Info << "Tactilo Nr. " << m_currTactiloNr << " ON\n"; + m_Port.write_some(boost::asio::buffer(std::to_string(m_currTactiloNr))); + } + if(StimulationID == OVTK_StimulationId_VisualStimulationStop) + { + this->getLogManager() << LogLevel_Info << "Tactilo Nr. " << m_currTactiloNr << " OFF\n"; + m_Port.write_some(boost::asio::buffer(std::to_string(m_currTactiloNr))); + } + } + } + // forward input chunks + boxContext.getInputChunk(0, i, ChunkStartTime, ChunkEndTime, Size, Buffer); + boxContext.appendOutputChunkData(0, Buffer, Size); + boxContext.markOutputAsReadyToSend(0, ChunkStartTime, ChunkEndTime); + boxContext.markInputAsDeprecated(0, i); + } + + return true; +} + /*******************************************************************************/ \ No newline at end of file