Dateien hochladen nach „src/UDPStimCodeSender“

This commit is contained in:
Tobias Baumann 2022-05-02 14:02:45 +00:00
parent 666b3b4ec5
commit 6360e97231
2 changed files with 27 additions and 65 deletions

View File

@ -23,15 +23,25 @@ bool CBoxAlgorithmUDPStimcodeSender::initialize()
m_StimEncoder.initialize(*this, 0); m_StimEncoder.initialize(*this, 0);
// retrieve box settings // retrieve box settings
FeatherIP = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0); m_IP = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 0);
FeatherPort = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1); m_Port = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 1);
RowStimulationBase = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 2); m_RowBase = FSettingValueAutoCast(*this->getBoxAlgorithmContext(), 2);
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
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;
}
// connect UDP socket // connect UDP socket
boost::asio::ip::udp::endpoint Feather(boost::asio::ip::address::from_string(FeatherIP), FeatherPort); boost::asio::ip::udp::endpoint m_Endpoint(boost::asio::ip::address::from_string(m_IP), m_Port);
socket.connect(Feather); m_Socket.connect(m_Endpoint);
return true; return true;
} }
@ -85,10 +95,10 @@ bool CBoxAlgorithmUDPStimcodeSender::process()
{ {
StimulationID = StimSet->getStimulationIdentifier(j); StimulationID = StimSet->getStimulationIdentifier(j);
if(StimulationID >= RowStimulationBase && StimulationID < (RowStimulationBase + NumberofTactilos)) if(StimulationID >= m_RowBase && StimulationID < (m_RowBase + m_nTactilos))
{ {
this->getLogManager() << LogLevel_Debug << "send udp : [StimulusCode " << (StimulationID-RowStimulationBase+1) << "]\n"; this->getLogManager() << LogLevel_Debug << "send udp : [StimulusCode " << (StimulationID-m_RowBase+1) << "]\n";
socket.send(boost::asio::buffer(std::to_string(StimulationID-RowStimulationBase+1))); m_Socket.send(boost::asio::buffer(std::to_string(StimulationID-m_RowBase+1)));
} }
} }
} }

View File

@ -47,60 +47,16 @@ namespace OpenViBE
Toolkit::TStimulationEncoder<CBoxAlgorithmUDPStimcodeSender> m_StimEncoder; Toolkit::TStimulationEncoder<CBoxAlgorithmUDPStimcodeSender> m_StimEncoder;
private: private:
// Box setting variables // Box setting variables
CString FeatherIP; CString m_IP = "";
uint64_t FeatherPort; uint64_t m_Port = 0;
uint64_t RowStimulationBase; uint64_t m_RowBase = 0;
uint64_t NumberofTactilos; uint64_t m_nTactilos = 0;
// Socket // Socket
boost::asio::io_service io_service; boost::asio::io_service m_IOService;
boost::asio::ip::udp::socket socket{io_service}; boost::asio::ip::udp::socket m_Socket{m_IOService};
}; };
// If you need to implement a box Listener, here is a sekeleton for you.
// Use only the callbacks you need.
// For example, if your box has a variable number of input, but all of them must be stimulation inputs.
// The following listener callback will ensure that any newly added input is stimulations :
/*
bool onInputAdded(Kernel::IBox& box, const size_t index) override
{
box.setInputType(index, OV_TypeId_Stimulations);
};
*/
/*
// The box listener can be used to call specific callbacks whenever the box structure changes : input added, name changed, etc.
// Please uncomment below the callbacks you want to use.
/// <summary> Listener of the box UDPStimcodeSender. </summary>
class CBoxAlgorithmUDPStimcodeSenderListener final : public Toolkit::TBoxListener<IBoxListener>
{
public:
//bool onInitialized(Kernel::IBox& box) override { return true; };
//bool onNameChanged(Kernel::IBox& box) override { return true; };
//bool onInputConnected(Kernel::IBox& box, const size_t index) override { return true; };
//bool onInputDisconnected(Kernel::IBox& box, const size_t index) override { return true; };
//bool onInputAdded(Kernel::IBox& box, const size_t index) override { return true; };
//bool onInputRemoved(Kernel::IBox& box, const size_t index) override { return true; };
//bool onInputTypeChanged(Kernel::IBox& box, const size_t index) override { return true; };
//bool onInputNameChanged(Kernel::IBox& box, const size_t index) override { return true; };
//bool onOutputConnected(Kernel::IBox& box, const size_t index) override { return true; };
//bool onOutputDisconnected(Kernel::IBox& box, const size_t index) { return true; };
//bool onOutputAdded(Kernel::IBox& box, const size_t index) override { return true; };
//bool onOutputRemoved(Kernel::IBox& box, const size_t index) override { return true; };
//bool onOutputTypeChanged(Kernel::IBox& box, const size_t index) override override { return true; };
//bool onOutputNameChanged(Kernel::IBox& box, const size_t index) override { return true; };
//bool onSettingAdded(Kernel::IBox& box, const size_t index) override { return true; };
//bool onSettingRemoved(Kernel::IBox& box, const size_t index) override { return true; };
//bool onSettingTypeChanged(Kernel::IBox& box, const size_t index) override { return true; };
//bool onSettingNameChanged(Kernel::IBox& box, const size_t index) override { return true; };
//bool onSettingDefaultValueChanged(Kernel::IBox& box, const size_t index) override { return true; };
//bool onSettingValueChanged(Kernel::IBox& box, const size_t index) override { return true; };
_IsDerivedFromClass_Final_(Toolkit::TBoxListener<IBoxListener>, CIdentifier::undefined())
};
*/
/// <summary> Descriptor of the box UDPStimcodeSender. </summary> /// <summary> Descriptor of the box UDPStimcodeSender. </summary>
class CBoxAlgorithmUDPStimcodeSenderDesc final : virtual public IBoxAlgorithmDesc class CBoxAlgorithmUDPStimcodeSenderDesc final : virtual public IBoxAlgorithmDesc
{ {
@ -120,10 +76,6 @@ namespace OpenViBE
CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_UDPStimcodeSender; } CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_UDPStimcodeSender; }
IPluginObject* create() override { return new CBoxAlgorithmUDPStimcodeSender; } IPluginObject* create() override { return new CBoxAlgorithmUDPStimcodeSender; }
/*
IBoxListener* createBoxListener() const override { return new CBoxAlgorithmUDPStimcodeSenderListener; }
void releaseBoxListener(IBoxListener* listener) const override { delete listener; }
*/
bool getBoxPrototype(Kernel::IBoxProto& prototype) const override bool getBoxPrototype(Kernel::IBoxProto& prototype) const override
{ {
prototype.addInput("StimcodeIn",OV_TypeId_Stimulations); prototype.addInput("StimcodeIn",OV_TypeId_Stimulations);
@ -139,7 +91,7 @@ namespace OpenViBE
prototype.addSetting("FeatherIP",OV_TypeId_String,"192.168.4.1"); prototype.addSetting("FeatherIP",OV_TypeId_String,"192.168.4.1");
prototype.addSetting("FeatherPort",OV_TypeId_Integer,"8888"); prototype.addSetting("FeatherPort",OV_TypeId_Integer,"8888");
prototype.addSetting("RowStimulationBase",OV_TypeId_Stimulation,"OVTK_StimulationId_Label_01"); prototype.addSetting("RowStimulationBase",OV_TypeId_Stimulation,"OVTK_StimulationId_Label_01");
//prototype.addSetting("Number of Tactilos",OV_TypeId_Integer,"6"); //used to make this setting accessable in the box settings prototype.addSetting("Number of Tactilos",OV_TypeId_Integer,"6");
prototype.addFlag(Kernel::BoxFlag_CanModifySetting); prototype.addFlag(Kernel::BoxFlag_CanModifySetting);
//prototype.addFlag(Kernel::BoxFlag_CanAddSetting); //prototype.addFlag(Kernel::BoxFlag_CanAddSetting);