Dateien hochladen nach „src/TactiloController“
This commit is contained in:
parent
6360e97231
commit
a4b9a30d83
@ -1,128 +1,138 @@
|
|||||||
///-------------------------------------------------------------------------------------------------
|
///-------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
/// \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_NumberofTactilos = 6; //if this value is specified via box settings this line is not needed
|
m_nTactilos = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 3);
|
||||||
//NumberofTactilos = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 3); //used if this value is set in box settings
|
|
||||||
|
//set m_nTactilos to 2 if lower than 2
|
||||||
//open serial port and set baudrate to 115200
|
if(m_nTactilos < 2)
|
||||||
m_Port.open(m_PortName.toASCIIString());
|
{
|
||||||
m_Port.set_option(boost::asio::serial_port::baud_rate(115200));
|
m_nTactilos = 2;
|
||||||
|
}
|
||||||
if(m_Port.is_open())
|
//set m_nTactilos to MAX if greater than MAX_TACTILOS
|
||||||
{
|
if(m_nTactilos > MAX_TACTILOS)
|
||||||
this->getLogManager() << LogLevel_Info << "Connected to Serial Port: " << m_PortName << "\n";
|
{
|
||||||
m_Port.write_some(boost::asio::buffer("b"));
|
m_nTactilos = MAX_TACTILOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
//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())
|
||||||
bool CBoxAlgorithmTactiloController::uninitialize()
|
{
|
||||||
{
|
this->getLogManager() << LogLevel_Info << "Connected to Serial Port: " << m_PortName << "\n";
|
||||||
this->getLogManager() << LogLevel_Info << "Disconnect from Serial Port: " << m_PortName << "\n";
|
m_Port.write_some(boost::asio::buffer("b"));
|
||||||
m_Port.write_some(boost::asio::buffer("e"));
|
}
|
||||||
m_Port.close();
|
|
||||||
|
return true;
|
||||||
m_StimDecoder.uninitialize();
|
}
|
||||||
m_StimEncoder.uninitialize();
|
|
||||||
|
/*******************************************************************************/
|
||||||
return true;
|
|
||||||
}
|
bool CBoxAlgorithmTactiloController::uninitialize()
|
||||||
|
{
|
||||||
/*******************************************************************************/
|
this->getLogManager() << LogLevel_Info << "Disconnect from Serial Port: " << m_PortName << "\n";
|
||||||
|
m_Port.write_some(boost::asio::buffer("e"));
|
||||||
bool CBoxAlgorithmTactiloController::processInput(const size_t index)
|
m_Port.close();
|
||||||
{
|
|
||||||
// some pre-processing code if needed...
|
m_StimDecoder.uninitialize();
|
||||||
|
m_StimEncoder.uninitialize();
|
||||||
// ready to process !
|
|
||||||
getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
|
return true;
|
||||||
|
}
|
||||||
return true;
|
|
||||||
}
|
/*******************************************************************************/
|
||||||
|
|
||||||
/*******************************************************************************/
|
bool CBoxAlgorithmTactiloController::processInput(const size_t index)
|
||||||
bool CBoxAlgorithmTactiloController::process()
|
{
|
||||||
{
|
// some pre-processing code if needed...
|
||||||
|
|
||||||
// the static box context describes the box inputs, outputs, settings structures
|
// ready to process !
|
||||||
const IBox& staticBoxContext = this->getStaticBoxContext();
|
getBoxAlgorithmContext()->markAlgorithmAsReadyToProcess();
|
||||||
// the dynamic box context describes the current state of the box inputs and outputs (i.e. the chunks)
|
|
||||||
IBoxIO& boxContext = this->getDynamicBoxContext();
|
return true;
|
||||||
|
}
|
||||||
uint64_t StimulationID = 0;
|
|
||||||
uint64_t ChunkStartTime = 0;
|
/*******************************************************************************/
|
||||||
uint64_t ChunkEndTime = 0;
|
bool CBoxAlgorithmTactiloController::process()
|
||||||
uint64_t Size = 0;
|
{
|
||||||
const uint8_t* Buffer = nullptr;
|
|
||||||
|
// the static box context describes the box inputs, outputs, settings structures
|
||||||
//iterate over all chunk on input 0
|
const IBox& staticBoxContext = this->getStaticBoxContext();
|
||||||
for (uint64_t i = 0; i < boxContext.getInputChunkCount(0); ++i)
|
// the dynamic box context describes the current state of the box inputs and outputs (i.e. the chunks)
|
||||||
{
|
IBoxIO& boxContext = this->getDynamicBoxContext();
|
||||||
// decode the chunk i
|
|
||||||
m_StimDecoder.decode(i);
|
uint64_t StimulationID = 0;
|
||||||
|
uint64_t ChunkStartTime = 0;
|
||||||
if(m_StimDecoder.isBufferReceived())
|
uint64_t ChunkEndTime = 0;
|
||||||
{
|
uint64_t Size = 0;
|
||||||
//check received stimulations
|
const uint8_t* Buffer = nullptr;
|
||||||
IStimulationSet* StimSet = m_StimDecoder.getOutputStimulationSet();
|
|
||||||
for(uint64_t j=0; j<StimSet->getStimulationCount(); j++)
|
//iterate over all chunk on input 0
|
||||||
{
|
for (uint64_t i = 0; i < boxContext.getInputChunkCount(0); ++i)
|
||||||
StimulationID = StimSet->getStimulationIdentifier(j);
|
{
|
||||||
|
// decode the chunk i
|
||||||
if(StimulationID >= m_RowBase && StimulationID < (m_RowBase + m_NumberofTactilos))
|
m_StimDecoder.decode(i);
|
||||||
{
|
|
||||||
m_TactiloNr = StimulationID-m_RowBase+1;
|
if(m_StimDecoder.isBufferReceived())
|
||||||
}
|
{
|
||||||
if(StimulationID == OVTK_StimulationId_VisualStimulationStart)
|
//check received stimulations
|
||||||
{
|
IStimulationSet* StimSet = m_StimDecoder.getOutputStimulationSet();
|
||||||
this->getLogManager() << LogLevel_Info << "Tactilo Nr. " << m_TactiloNr << " ON\n";
|
for(uint64_t j=0; j<StimSet->getStimulationCount(); j++)
|
||||||
m_Port.write_some(boost::asio::buffer(std::to_string(m_TactiloNr)));
|
{
|
||||||
}
|
StimulationID = StimSet->getStimulationIdentifier(j);
|
||||||
if(StimulationID == OVTK_StimulationId_VisualStimulationStop)
|
|
||||||
{
|
if(StimulationID >= m_RowBase && StimulationID < (m_RowBase + m_nTactilos))
|
||||||
this->getLogManager() << LogLevel_Info << "Tactilo Nr. " << m_TactiloNr << " OFF\n";
|
{
|
||||||
m_Port.write_some(boost::asio::buffer(std::to_string(m_TactiloNr)));
|
m_currTactiloNr = StimulationID-m_RowBase+1;
|
||||||
}
|
}
|
||||||
}
|
if(StimulationID == OVTK_StimulationId_VisualStimulationStart)
|
||||||
}
|
{
|
||||||
// forward input chunks
|
this->getLogManager() << LogLevel_Info << "Tactilo Nr. " << m_currTactiloNr << " ON\n";
|
||||||
boxContext.getInputChunk(0, i, ChunkStartTime, ChunkEndTime, Size, Buffer);
|
m_Port.write_some(boost::asio::buffer(std::to_string(m_currTactiloNr)));
|
||||||
boxContext.appendOutputChunkData(0, Buffer, Size);
|
}
|
||||||
boxContext.markOutputAsReadyToSend(0, ChunkStartTime, ChunkEndTime);
|
if(StimulationID == OVTK_StimulationId_VisualStimulationStop)
|
||||||
boxContext.markInputAsDeprecated(0, i);
|
{
|
||||||
}
|
this->getLogManager() << LogLevel_Info << "Tactilo Nr. " << m_currTactiloNr << " OFF\n";
|
||||||
|
m_Port.write_some(boost::asio::buffer(std::to_string(m_currTactiloNr)));
|
||||||
return true;
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// 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;
|
||||||
|
}
|
||||||
|
|
||||||
/*******************************************************************************/
|
/*******************************************************************************/
|
@ -1,113 +1,109 @@
|
|||||||
///-------------------------------------------------------------------------------------------------
|
///-------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
/// \file ovpCBoxAlgorithmTactiloController.h
|
/// \file ovpCBoxAlgorithmTactiloController.h
|
||||||
/// \brief Classes of the Box Tactilo Controller.
|
/// \brief Classes 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
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../ovp_defines.h"
|
#include "../ovp_defines.h"
|
||||||
|
|
||||||
#include <openvibe/ov_all.h>
|
#include <openvibe/ov_all.h>
|
||||||
#include <toolkit/ovtk_all.h>
|
#include <toolkit/ovtk_all.h>
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace OpenViBE
|
namespace OpenViBE
|
||||||
{
|
{
|
||||||
namespace Plugins
|
namespace Plugins
|
||||||
{
|
{
|
||||||
namespace Tactilebci
|
namespace Tactilebci
|
||||||
{
|
{
|
||||||
/// <summary> The class CBoxAlgorithmTactiloController describes the box Tactilo Controller. </summary>
|
/// <summary> The class CBoxAlgorithmTactiloController describes the box Tactilo Controller. </summary>
|
||||||
class CBoxAlgorithmTactiloController final : virtual public Toolkit::TBoxAlgorithm<IBoxAlgorithm>
|
class CBoxAlgorithmTactiloController final : virtual public Toolkit::TBoxAlgorithm<IBoxAlgorithm>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void release() override { delete this; }
|
void release() override { delete this; }
|
||||||
|
|
||||||
bool initialize() override;
|
bool initialize() override;
|
||||||
bool uninitialize() override;
|
bool uninitialize() override;
|
||||||
bool processInput(const size_t index) override;
|
bool processInput(const size_t index) override;
|
||||||
bool process() override;
|
bool process() override;
|
||||||
|
|
||||||
// As we do with any class in openvibe, we use the macro below to associate this box to an unique identifier.
|
// As we do with any class in openvibe, we use the macro below to associate this box to an unique identifier.
|
||||||
// The inheritance information is also made available, as we provide the superclass Toolkit::TBoxAlgorithm < IBoxAlgorithm >
|
// The inheritance information is also made available, as we provide the superclass Toolkit::TBoxAlgorithm < IBoxAlgorithm >
|
||||||
_IsDerivedFromClass_Final_(Toolkit::TBoxAlgorithm<IBoxAlgorithm>, OVP_ClassId_BoxAlgorithm_TactiloController)
|
_IsDerivedFromClass_Final_(Toolkit::TBoxAlgorithm<IBoxAlgorithm>, OVP_ClassId_BoxAlgorithm_TactiloController)
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Input decoder:
|
// Input decoder:
|
||||||
Toolkit::TStimulationDecoder<CBoxAlgorithmTactiloController> m_StimDecoder;
|
Toolkit::TStimulationDecoder<CBoxAlgorithmTactiloController> m_StimDecoder;
|
||||||
// Output decoder:
|
// Output decoder:
|
||||||
Toolkit::TStimulationEncoder<CBoxAlgorithmTactiloController> m_StimEncoder;
|
Toolkit::TStimulationEncoder<CBoxAlgorithmTactiloController> m_StimEncoder;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//variable to store the current TactiloNr
|
//variable to store the current TactiloNr
|
||||||
uint64_t m_TactiloNr = 0;
|
uint64_t m_currTactiloNr = 0;
|
||||||
//Box Settings
|
//Box Settings
|
||||||
CString m_PortName = "";
|
CString m_PortName = "";
|
||||||
uint64_t m_RowBase = 0;
|
uint64_t m_RowBase = 0;
|
||||||
uint64_t m_NumberofTactilos = 0;
|
uint64_t m_nTactilos = 0;
|
||||||
|
|
||||||
//Serial Port
|
//Serial Port
|
||||||
boost::asio::io_service m_IO;
|
boost::asio::io_service m_IOService;
|
||||||
boost::asio::serial_port m_Port{m_IO};
|
boost::asio::serial_port m_Port{m_IOService};
|
||||||
};
|
};
|
||||||
|
|
||||||
/// <summary> Descriptor of the box Tactilo Controller. </summary>
|
/// <summary> Descriptor of the box Tactilo Controller. </summary>
|
||||||
class CBoxAlgorithmTactiloControllerDesc final : virtual public IBoxAlgorithmDesc
|
class CBoxAlgorithmTactiloControllerDesc final : virtual public IBoxAlgorithmDesc
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void release() override { }
|
void release() override { }
|
||||||
|
|
||||||
CString getName() const override { return CString("Tactilo Controller"); }
|
CString getName() const override { return CString("Tactilo Controller"); }
|
||||||
CString getAuthorName() const override { return CString("Tobias Baumann"); }
|
CString getAuthorName() const override { return CString("Tobias Baumann"); }
|
||||||
CString getAuthorCompanyName() const override { return CString("TH-Nürnberg"); }
|
CString getAuthorCompanyName() const override { return CString("TH-Nürnberg"); }
|
||||||
CString getShortDescription() const override { return CString("Controls the Tactilos on the Lattepandas GPIOs"); }
|
CString getShortDescription() const override { return CString("Controls the Tactilos on the Lattepandas GPIOs"); }
|
||||||
CString getDetailedDescription() const override { return CString("Communicates with the Arduino Coprocessor of the Lattepanda over a Serial Inteface, to control the Tactilos connected to the Arduinos GPIOs"); }
|
CString getDetailedDescription() const override { return CString("Communicates with the Arduino Coprocessor of the Lattepanda over a Serial Inteface, to control the Tactilos connected to the Arduinos GPIOs"); }
|
||||||
CString getCategory() const override { return CString("TactileBCI"); }
|
CString getCategory() const override { return CString("TactileBCI"); }
|
||||||
CString getVersion() const override { return CString("1.0"); }
|
CString getVersion() const override { return CString("1.0"); }
|
||||||
CString getStockItemName() const override { return CString("gtk-network"); }
|
CString getStockItemName() const override { return CString("gtk-network"); }
|
||||||
|
|
||||||
CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_TactiloController; }
|
CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_TactiloController; }
|
||||||
IPluginObject* create() override { return new CBoxAlgorithmTactiloController; }
|
IPluginObject* create() override { return new CBoxAlgorithmTactiloController; }
|
||||||
|
|
||||||
/*
|
bool getBoxPrototype(Kernel::IBoxProto& prototype) const override
|
||||||
IBoxListener* createBoxListener() const override { return new CBoxAlgorithmTactiloControllerListener; }
|
{
|
||||||
void releaseBoxListener(IBoxListener* listener) const override { delete listener; }
|
prototype.addInput("StimInput",OV_TypeId_Stimulations);
|
||||||
*/
|
|
||||||
bool getBoxPrototype(Kernel::IBoxProto& prototype) const override
|
//prototype.addFlag(Kernel::BoxFlag_CanModifyInput);
|
||||||
{
|
//prototype.addFlag(Kernel::BoxFlag_CanAddInput);
|
||||||
prototype.addInput("StimInput",OV_TypeId_Stimulations);
|
|
||||||
|
prototype.addOutput("StimOutput",OV_TypeId_Stimulations);
|
||||||
//prototype.addFlag(Kernel::BoxFlag_CanModifyInput);
|
|
||||||
//prototype.addFlag(Kernel::BoxFlag_CanAddInput);
|
//prototype.addFlag(Kernel::BoxFlag_CanModifyOutput);
|
||||||
|
//prototype.addFlag(Kernel::BoxFlag_CanAddOutput);
|
||||||
prototype.addOutput("StimOutput",OV_TypeId_Stimulations);
|
|
||||||
|
//Box Settings
|
||||||
//prototype.addFlag(Kernel::BoxFlag_CanModifyOutput);
|
prototype.addSetting("Serial Port Name",OV_TypeId_String,"/dev/ttyACM0");
|
||||||
//prototype.addFlag(Kernel::BoxFlag_CanAddOutput);
|
prototype.addSetting("Row Stimulation Base",OV_TypeId_Stimulation,"OVTK_StimulationId_Label_01");
|
||||||
|
prototype.addSetting("Number of Tactilos",OV_TypeId_Integer,"6");
|
||||||
//Box Settings
|
|
||||||
prototype.addSetting("Serial Port Name",OV_TypeId_String,"/dev/ttyACM0");
|
//prototype.addFlag(Kernel::BoxFlag_CanModifySetting);
|
||||||
prototype.addSetting("Row Stimulation Base",OV_TypeId_Stimulation,"OVTK_StimulationId_Label_01");
|
//prototype.addFlag(Kernel::BoxFlag_CanAddSetting);
|
||||||
//prototype.addSetting("Number of Tactilos",OV_TypeId_Integer,"6"); //used to make this setting accessable in the box settings
|
|
||||||
|
prototype.addFlag(OV_AttributeId_Box_FlagIsUnstable);
|
||||||
//prototype.addFlag(Kernel::BoxFlag_CanModifySetting);
|
|
||||||
//prototype.addFlag(Kernel::BoxFlag_CanAddSetting);
|
return true;
|
||||||
|
}
|
||||||
prototype.addFlag(OV_AttributeId_Box_FlagIsUnstable);
|
_IsDerivedFromClass_Final_(IBoxAlgorithmDesc, OVP_ClassId_BoxAlgorithm_TactiloControllerDesc)
|
||||||
|
};
|
||||||
return true;
|
} // namespace Tactilebci
|
||||||
}
|
} // namespace Plugins
|
||||||
_IsDerivedFromClass_Final_(IBoxAlgorithmDesc, OVP_ClassId_BoxAlgorithm_TactiloControllerDesc)
|
} // namespace OpenViBE
|
||||||
};
|
|
||||||
} // namespace Tactilebci
|
|
||||||
} // namespace Plugins
|
|
||||||
} // namespace OpenViBE
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user