Commit 49466879 authored by Jussi Lindgren's avatar Jussi Lindgren

Drivers: Added Generic Time Signal driver for debugging

parent eac6fb18
#include "ovasCConfigurationGenericTimeSignal.h"
using namespace OpenViBE;
using namespace OpenViBE::Kernel;
using namespace OpenViBEAcquisitionServer;
using namespace std;
CConfigurationGenericTimeSignal::CConfigurationGenericTimeSignal(IDriverContext& rDriverContext, const char* sGtkBuilderFileName)
:CConfigurationBuilder(sGtkBuilderFileName)
,m_rDriverContext(rDriverContext)
{
}
boolean CConfigurationGenericTimeSignal::preConfigure(void)
{
if(! CConfigurationBuilder::preConfigure())
{
return false;
}
return true;
}
boolean CConfigurationGenericTimeSignal::postConfigure(void)
{
if(m_bApplyConfiguration)
{
//
}
if(! CConfigurationBuilder::postConfigure()) // normal header is filled (Subject ID, Age, Gender, channels, sampling frequency)
{
return false;
}
return true;
}
#ifndef __OpenViBE_AcquisitionServer_CConfigurationGenericTimeSignal_H__
#define __OpenViBE_AcquisitionServer_CConfigurationGenericTimeSignal_H__
#include "../ovasCConfigurationBuilder.h"
#include "ovasIDriver.h"
#include <gtk/gtk.h>
namespace OpenViBEAcquisitionServer
{
/**
* \class CConfigurationGenericTimeSignal
* \sa CDriverGenericTimeSignal
*/
class CConfigurationGenericTimeSignal : public OpenViBEAcquisitionServer::CConfigurationBuilder
{
public:
CConfigurationGenericTimeSignal(OpenViBEAcquisitionServer::IDriverContext& rDriverContext, const char* sGtkBuilderFileName);
virtual OpenViBE::boolean preConfigure(void);
virtual OpenViBE::boolean postConfigure(void);
protected:
OpenViBEAcquisitionServer::IDriverContext& m_rDriverContext;
private:
};
};
#endif // __OpenViBE_AcquisitionServer_CConfigurationGenericTimeSignal_H__
#include "ovasCDriverGenericTimeSignal.h"
#include "../ovasCConfigurationBuilder.h"
#include "ovasCConfigurationGenericTimeSignal.h"
#include <toolkit/ovtk_all.h>
#include <openvibe/ovITimeArithmetics.h>
#include <system/ovCTime.h>
#include <cmath>
using namespace OpenViBEAcquisitionServer;
using namespace OpenViBE;
using namespace OpenViBE::Kernel;
//___________________________________________________________________//
// //
CDriverGenericTimeSignal::CDriverGenericTimeSignal(IDriverContext& rDriverContext)
:IDriver(rDriverContext)
,m_oSettings("AcquisitionServer_Driver_GenericTimeSignal", m_rDriverContext.getConfigurationManager())
,m_pCallback(NULL)
,m_ui64TotalSampleCount(0)
,m_ui64StartTime(0)
{
m_rDriverContext.getLogManager() << LogLevel_Trace << "CDriverGenericTimeSignal::CDriverGenericTimeSignal\n";
m_oHeader.setSamplingFrequency(512);
m_oHeader.setChannelCount(1);
m_oHeader.setChannelName(0, "Time(s)");
m_oHeader.setChannelUnits(0, OVTK_UNIT_Second, OVTK_FACTOR_Base);
m_oSettings.add("Header", &m_oHeader);
m_oSettings.load();
}
void CDriverGenericTimeSignal::release(void)
{
m_rDriverContext.getLogManager() << LogLevel_Trace << "CDriverGenericTimeSignal::release\n";
delete this;
}
const char* CDriverGenericTimeSignal::getName(void)
{
m_rDriverContext.getLogManager() << LogLevel_Trace << "CDriverGenericTimeSignal::getName\n";
return "Generic Time Signal";
}
//___________________________________________________________________//
// //
boolean CDriverGenericTimeSignal::initialize(
const uint32 ui32SampleCountPerSentBlock,
IDriverCallback& rCallback)
{
m_rDriverContext.getLogManager() << LogLevel_Trace << "CDriverGenericTimeSignal::initialize\n";
if(m_rDriverContext.isConnected()) { return false; }
if(!m_oHeader.isChannelCountSet()
||!m_oHeader.isSamplingFrequencySet())
{
return false;
}
m_pCallback=&rCallback;
return true;
}
boolean CDriverGenericTimeSignal::start(void)
{
m_rDriverContext.getLogManager() << LogLevel_Trace << "CDriverGenericTimeSignal::start\n";
if(!m_rDriverContext.isConnected()) { return false; }
if(m_rDriverContext.isStarted()) { return false; }
m_ui64TotalSampleCount=0;
m_ui64StartTime = System::Time::zgetTime();
return true;
}
#include <iostream>
boolean CDriverGenericTimeSignal::loop(void)
{
m_rDriverContext.getLogManager() << LogLevel_Debug << "CDriverGenericTimeSignal::loop\n";
if(!m_rDriverContext.isConnected()) { return false; }
if(!m_rDriverContext.isStarted()) { return true; }
const uint64 ui64TimeNow = System::Time::zgetTime();
// Find out how many samples to send; note that we always just send 1 at a time with this driver
const uint64 l_ui64Elapsed = ui64TimeNow - m_ui64StartTime;
const uint64 l_ui64SamplesNeededSoFar = (m_oHeader.getSamplingFrequency() * l_ui64Elapsed) >> 32;
if (l_ui64SamplesNeededSoFar <= m_ui64TotalSampleCount)
{
// Too early
return true;
}
const float32 timeNow = static_cast<float32>(ITimeArithmetics::timeToSeconds(ui64TimeNow));
m_pCallback->setSamples(&timeNow, 1);
m_ui64TotalSampleCount++;
m_rDriverContext.correctDriftSampleCount(m_rDriverContext.getSuggestedDriftCorrectionSampleCount());
return true;
}
boolean CDriverGenericTimeSignal::stop(void)
{
m_rDriverContext.getLogManager() << LogLevel_Trace << "CDriverGenericTimeSignal::stop\n";
if(!m_rDriverContext.isConnected()) { return false; }
if(!m_rDriverContext.isStarted()) { return false; }
return true;
}
boolean CDriverGenericTimeSignal::uninitialize(void)
{
m_rDriverContext.getLogManager() << LogLevel_Trace << "CDriverGenericTimeSignal::uninitialize\n";
if(!m_rDriverContext.isConnected()) { return false; }
if(m_rDriverContext.isStarted()) { return false; }
m_pCallback=NULL;
return true;
}
//___________________________________________________________________//
// //
boolean CDriverGenericTimeSignal::isConfigurable(void)
{
m_rDriverContext.getLogManager() << LogLevel_Trace << "CDriverGenericTimeSignal::isConfigurable\n";
return true;
}
boolean CDriverGenericTimeSignal::configure(void)
{
m_rDriverContext.getLogManager() << LogLevel_Trace << "CDriverGenericTimeSignal::configure\n";
CConfigurationGenericTimeSignal m_oConfiguration(m_rDriverContext,
OpenViBE::Directories::getDataDir() + "/applications/acquisition-server/interface-Generic-TimeSignal.ui");
if(!m_oConfiguration.configure(m_oHeader))
{
return false;
}
m_oSettings.save();
return true;
}
#ifndef __OpenViBE_AcquisitionServer_CDriverGenericTimeSignal_H__
#define __OpenViBE_AcquisitionServer_CDriverGenericTimeSignal_H__
#include "ovasIDriver.h"
#include "../ovasCHeader.h"
#include "../ovasCSettingsHelper.h"
#include "../ovasCSettingsHelperOperators.h"
namespace OpenViBEAcquisitionServer
{
/**
* \class CDriverGenericTimeSignal
* \author Jussi Lindgren (Inria)
*
* This driver may have some utility in debugging. For each sample, it returns the
* current time as obtained from openvibe's System::Time:zgettime() converted to float seconds.
*
*/
class CDriverGenericTimeSignal : public OpenViBEAcquisitionServer::IDriver
{
public:
CDriverGenericTimeSignal(OpenViBEAcquisitionServer::IDriverContext& rDriverContext);
virtual void release(void);
virtual const char* getName(void);
virtual OpenViBE::boolean initialize(
const OpenViBE::uint32 ui32SampleCountPerSentBlock,
OpenViBEAcquisitionServer::IDriverCallback& rCallback);
virtual OpenViBE::boolean uninitialize(void);
virtual OpenViBE::boolean start(void);
virtual OpenViBE::boolean stop(void);
virtual OpenViBE::boolean loop(void);
virtual OpenViBE::boolean isConfigurable(void);
virtual OpenViBE::boolean configure(void);
virtual const OpenViBEAcquisitionServer::IHeader* getHeader(void) { return &m_oHeader; }
protected:
OpenViBEAcquisitionServer::IDriverCallback* m_pCallback;
OpenViBEAcquisitionServer::CHeader m_oHeader;
SettingsHelper m_oSettings;
OpenViBE::uint64 m_ui64TotalSampleCount;
OpenViBE::uint64 m_ui64StartTime;
};
};
#endif // __OpenViBE_AcquisitionServer_CDriverGenericTimeSignal_H__
......@@ -12,6 +12,7 @@
#include "generic-oscillator/ovasCDriverGenericOscillator.h"
#include "generic-sawtooth/ovasCDriverGenericSawTooth.h"
#include "generic-time-signal/ovasCDriverGenericTimeSignal.h"
#include "generic-raw-reader/ovasCDriverGenericRawFileReader.h"
#include "generic-raw-reader/ovasCDriverGenericRawTelnetReader.h"
......@@ -149,6 +150,7 @@ CAcquisitionServerGUI::CAcquisitionServerGUI(const IKernelContext& rKernelContex
m_vDriver.push_back(new CDriverGenericOscillator(m_pAcquisitionServer->getDriverContext()));
m_vDriver.push_back(new CDriverGenericSawTooth(m_pAcquisitionServer->getDriverContext()));
m_vDriver.push_back(new CDriverGenericTimeSignal(m_pAcquisitionServer->getDriverContext()));
m_vDriver.push_back(new CDriverGenericRawFileReader(m_pAcquisitionServer->getDriverContext()));
m_vDriver.push_back(new CDriverGenericRawTelnetReader(m_pAcquisitionServer->getDriverContext()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment