123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- ///-------------------------------------------------------------------------------------------------
- ///
- /// \file CBoxAlgorithmUDPStimcodeSender.cpp
- /// \brief Functions of Class UDP-StimCode-Sender
- /// \author Tobias Baumann (TH Nuernberg).
- /// \version 1.2.
- /// \date Mon Oct 04 12:43:53 2021.
- /// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
- ///
- ///-------------------------------------------------------------------------------------------------
-
- //includes
- #include "ovpCBoxAlgorithmUDPStimcodeSender.h"
-
- using namespace OpenViBE;
- using namespace /*OpenViBE::*/Kernel;
- using namespace /*OpenViBE::*/Plugins;
- using namespace /*OpenViBE::Plugins::*/Tactilebci;
-
- bool CBoxAlgorithmUDPStimcodeSender::initialize()
- {
- m_StimDecoder.initialize(*this, 0);
- m_StimEncoder.initialize(*this, 0);
-
- // retrieve box settings
- FeatherIP = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0);
- FeatherPort = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1);
- RowStimulationBase = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 2);
- NumberofTactilos = 6; //if this value is specified via box settings this line is not needed
- //NumberofTactilos = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 3); //used if this value is set in box settings
-
- // connect UDP socket
- boost::asio::ip::udp::endpoint Feather(boost::asio::ip::address::from_string(FeatherIP), FeatherPort);
- socket.connect(Feather);
-
- return true;
- }
- /*******************************************************************************/
-
- bool CBoxAlgorithmUDPStimcodeSender::uninitialize()
- {
- m_StimDecoder.uninitialize();
- m_StimEncoder.uninitialize();
-
- return true;
- }
- /*******************************************************************************/
-
- bool CBoxAlgorithmUDPStimcodeSender::processInput(const size_t index)
- {
- // some pre-processing code if needed...
-
- // ready to process !
- getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
-
- return true;
- }
-
- /*******************************************************************************/
-
-
- bool CBoxAlgorithmUDPStimcodeSender::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; j<StimSet->getStimulationCount(); j++)
- {
- StimulationID = StimSet->getStimulationIdentifier(j);
-
- if(StimulationID >= RowStimulationBase && StimulationID < (RowStimulationBase + NumberofTactilos))
- {
- this->getLogManager() << LogLevel_Debug << "send udp : [StimulusCode " << (StimulationID-RowStimulationBase+1) << "]\n";
- socket.send(boost::asio::buffer(std::to_string(StimulationID-RowStimulationBase+1)));
- }
- }
- }
- // 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;
- }
|