„src/TactiloController/ovpCBoxAlgorithmTactiloController.cpp“ ändern
This commit is contained in:
parent
8324315bf2
commit
f36283fc6e
@ -1,122 +1,127 @@
|
|||||||
///-------------------------------------------------------------------------------------------------
|
///-------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
/// \file ovpCBoxAlgorithmTactiloController.cpp
|
/// \file ovpCBoxAlgorithmTactiloController.cpp
|
||||||
/// \brief Functions of the Box Tactilo Controller.
|
/// \brief Functions of the Box Tactilo Controller.
|
||||||
/// \author Tobias Baumann (TH-Nürnberg).
|
/// \author Tobias Baumann (TH-Nürnberg).
|
||||||
/// \version 1.0.
|
/// \version 1.0.
|
||||||
/// \date Mon Feb 21 14:59:56 2022.
|
/// \date Mon Feb 21 14:59:56 2022.
|
||||||
/// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
|
/// \copyright <a href="https://choosealicense.com/licenses/agpl-3.0/">GNU Affero General Public License v3.0</a>.
|
||||||
///
|
///
|
||||||
///-------------------------------------------------------------------------------------------------
|
///-------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
//includes
|
//includes
|
||||||
#include "ovpCBoxAlgorithmTactiloController.h"
|
#include "ovpCBoxAlgorithmTactiloController.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
using namespace OpenViBE;
|
using namespace OpenViBE;
|
||||||
using namespace /*OpenViBE::*/Kernel;
|
using namespace /*OpenViBE::*/Kernel;
|
||||||
using namespace /*OpenViBE::*/Plugins;
|
using namespace /*OpenViBE::*/Plugins;
|
||||||
using namespace /*OpenViBE::Plugins::*/Tactilebci;
|
using namespace /*OpenViBE::Plugins::*/Tactilebci;
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
||||||
|
|
||||||
bool CBoxAlgorithmTactiloController::initialize()
|
bool CBoxAlgorithmTactiloController::initialize()
|
||||||
{
|
{
|
||||||
m_StimDecoder.initialize(*this, 0);
|
m_StimDecoder.initialize(*this, 0);
|
||||||
m_StimEncoder.initialize(*this, 0);
|
m_StimEncoder.initialize(*this, 0);
|
||||||
|
|
||||||
//get Box Settings
|
//get Box Settings
|
||||||
m_PortName = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0);
|
m_PortName = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0);
|
||||||
m_RowBase = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1);
|
m_RowBase = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1);
|
||||||
m_StartStimulation = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 2);
|
m_StartStimulation = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 2);
|
||||||
m_StopStimulation = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 3);
|
m_StopStimulation = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 3);
|
||||||
m_NumberofTactilos = 6; //if this value is specified via box settings this line is not needed
|
m_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
|
//NumberofTactilos = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 3); //used if this value is set in box settings
|
||||||
|
|
||||||
//open serial port
|
//open serial port and set baudrate to 115200
|
||||||
m_Port.open(m_PortName.toASCIIString());
|
m_Port.open(m_PortName.toASCIIString());
|
||||||
|
m_Port.set_option(boost::asio::serial_port::baud_rate(115200));
|
||||||
if(m_Port.is_open())
|
|
||||||
{
|
if(m_Port.is_open())
|
||||||
this->getLogManager() << LogLevel_Info << "Connected to Serial Port: " << m_PortName << "\n";
|
{
|
||||||
}
|
this->getLogManager() << LogLevel_Info << "Connected to Serial Port: " << m_PortName << "\n";
|
||||||
|
}
|
||||||
return true;
|
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
/*******************************************************************************/
|
|
||||||
|
/*******************************************************************************/
|
||||||
bool CBoxAlgorithmTactiloController::uninitialize()
|
|
||||||
{
|
bool CBoxAlgorithmTactiloController::uninitialize()
|
||||||
m_StimDecoder.uninitialize();
|
{
|
||||||
m_StimEncoder.uninitialize();
|
m_StimDecoder.uninitialize();
|
||||||
|
m_StimEncoder.uninitialize();
|
||||||
m_Port.close();
|
|
||||||
|
m_Port.close();
|
||||||
return true;
|
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
/*******************************************************************************/
|
|
||||||
|
/*******************************************************************************/
|
||||||
bool CBoxAlgorithmTactiloController::processInput(const size_t index)
|
|
||||||
{
|
bool CBoxAlgorithmTactiloController::processInput(const size_t index)
|
||||||
// some pre-processing code if needed...
|
{
|
||||||
|
// some pre-processing code if needed...
|
||||||
// ready to process !
|
|
||||||
getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
|
// ready to process !
|
||||||
|
getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
|
||||||
return true;
|
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
/*******************************************************************************/
|
|
||||||
bool CBoxAlgorithmTactiloController::process()
|
/*******************************************************************************/
|
||||||
{
|
bool CBoxAlgorithmTactiloController::process()
|
||||||
|
{
|
||||||
// the static box context describes the box inputs, outputs, settings structures
|
|
||||||
const IBox& staticBoxContext = this->getStaticBoxContext();
|
// the static box context describes the box inputs, outputs, settings structures
|
||||||
// the dynamic box context describes the current state of the box inputs and outputs (i.e. the chunks)
|
const IBox& staticBoxContext = this->getStaticBoxContext();
|
||||||
IBoxIO& boxContext = this->getDynamicBoxContext();
|
// the dynamic box context describes the current state of the box inputs and outputs (i.e. the chunks)
|
||||||
|
IBoxIO& boxContext = this->getDynamicBoxContext();
|
||||||
uint64_t TactiloNr = 0;
|
|
||||||
uint64_t StimulationID = 0;
|
uint64_t TactiloNr = 0;
|
||||||
uint64_t ChunkStartTime = 0;
|
uint64_t StimulationID = 0;
|
||||||
uint64_t ChunkEndTime = 0;
|
uint64_t ChunkStartTime = 0;
|
||||||
uint64_t Size = 0;
|
uint64_t ChunkEndTime = 0;
|
||||||
const uint8_t* Buffer = nullptr;
|
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)
|
//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);
|
// decode the chunk i
|
||||||
if(m_StimDecoder.isBufferReceived())
|
m_StimDecoder.decode(i);
|
||||||
{
|
if(m_StimDecoder.isBufferReceived())
|
||||||
//check received stimulations
|
{
|
||||||
IStimulationSet* StimSet = m_StimDecoder.getOutputStimulationSet();
|
//check received stimulations
|
||||||
for(uint64_t j=0; j<StimSet->getStimulationCount(); j++)
|
IStimulationSet* StimSet = m_StimDecoder.getOutputStimulationSet();
|
||||||
{
|
for(uint64_t j=0; j<StimSet->getStimulationCount(); j++)
|
||||||
StimulationID = StimSet->getStimulationIdentifier(j);
|
{
|
||||||
|
StimulationID = StimSet->getStimulationIdentifier(j);
|
||||||
if(StimulationID >= m_RowBase && StimulationID < (m_RowBase + m_NumberofTactilos))
|
|
||||||
{
|
if(StimulationID >= m_RowBase && StimulationID < (m_RowBase + m_NumberofTactilos))
|
||||||
this->getLogManager() << LogLevel_Debug << "Tactilo Nr. " << (StimulationID-m_RowBase+1) << "\n";
|
{
|
||||||
TactiloNr = StimulationID-m_RowBase+1;
|
TactiloNr = StimulationID-m_RowBase+1;
|
||||||
}
|
}
|
||||||
if(StimulationID == m_StartStimulation || StimulationID == m_StopStimulation)
|
if(StimulationID == m_StartStimulation || StimulationID == m_StopStimulation)
|
||||||
{
|
{
|
||||||
this->getLogManager() << LogLevel_Debug << "Toggle Tactilo Nr. " << (StimulationID-m_RowBase+1) << "\n";
|
this->getLogManager() << LogLevel_Debug << "Tactilo Nr. " << TactiloNr << " ON\n";
|
||||||
m_Port.write_some(boost::asio::buffer(std::to_string(TactiloNr)));
|
m_Port.write_some(boost::asio::buffer(std::to_string(TactiloNr)));
|
||||||
}
|
}
|
||||||
}
|
if(StimulationID == m_StopStimulation)
|
||||||
}
|
{
|
||||||
// forward input chunks
|
this->getLogManager() << LogLevel_Debug << "Tactilo Nr. " << TactiloNr << " OFF\n";
|
||||||
boxContext.getInputChunk(0, i, ChunkStartTime, ChunkEndTime, Size, Buffer);
|
m_Port.write_some(boost::asio::buffer(std::to_string(TactiloNr)));
|
||||||
boxContext.appendOutputChunkData(0, Buffer, Size);
|
}
|
||||||
boxContext.markOutputAsReadyToSend(0, ChunkStartTime, ChunkEndTime);
|
}
|
||||||
boxContext.markInputAsDeprecated(0, i);
|
}
|
||||||
}
|
// forward input chunks
|
||||||
|
boxContext.getInputChunk(0, i, ChunkStartTime, ChunkEndTime, Size, Buffer);
|
||||||
return true;
|
boxContext.appendOutputChunkData(0, Buffer, Size);
|
||||||
}
|
boxContext.markOutputAsReadyToSend(0, ChunkStartTime, ChunkEndTime);
|
||||||
|
boxContext.markInputAsDeprecated(0, i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
Loading…
x
Reference in New Issue
Block a user