Commit 7a31a463 authored by Jussi Lindgren's avatar Jussi Lindgren

Merge branch 'wip-jlindgre-merge-openbci-patch' of...

Merge branch 'wip-jlindgre-merge-openbci-patch' of git+ssh://scm.gforge.inria.fr/gitroot/openvibe/openvibe into release-1.2.2
parents db317bf9 2a57e3da
......@@ -2,9 +2,7 @@
* OpenBCI driver for OpenViBE
*
* \author Jeremy Frey
*
* \note Based on OpenEEG code; inherits its AGPL3 license conditions
*
* \author Yann Renard
*/
#ifndef __OpenViBE_AcquisitionServer_CConfigurationOpenBCI_H__
#define __OpenViBE_AcquisitionServer_CConfigurationOpenBCI_H__
......@@ -12,34 +10,66 @@
#include "../ovasCConfigurationBuilder.h"
#include <gtk/gtk.h>
#include <map>
namespace OpenViBEAcquisitionServer
{
class CConfigurationOpenBCI : public OpenViBEAcquisitionServer::CConfigurationBuilder
{
public:
const static OpenViBE::uint16 DefaultSamplingRate = 250; // sampling rate with no daisy module (divided by 2 with daisy module)
const static OpenViBE::uint16 DefaultEEGChannelCount = 8; // number of EEG channels with no daisy module (multiplied by 2 with daisy module)
const static OpenViBE::uint16 DefaultAccChannelCount = 3; // number of Acc channels (daisy module does not have an impact)
typedef enum
{
DaisyStatus_Active,
DaisyStatus_Inactive,
} EDaisyStatus;
typedef struct
{
int iEEGChannelCount;
int iAccChannelCount;
int iSamplingRate;
} SDaisyInformation;
static OpenViBE::uint32 getMaximumTTYCount(void);
static OpenViBE::CString getTTYFileName(const OpenViBE::uint32 ui32TTYNumber);
static bool isTTYFile(const OpenViBE::CString& sTTYFileName);
CConfigurationOpenBCI(const char* sGtkBuilderFileName, OpenViBE::uint32& rUSBIndex);
virtual ~CConfigurationOpenBCI(void);
virtual OpenViBE::boolean preConfigure(void);
virtual OpenViBE::boolean postConfigure(void);
OpenViBE::boolean setComInit(const OpenViBE::CString& sComInit);
OpenViBE::CString getComInit(void) const;
OpenViBE::boolean setComDelay(const OpenViBE::uint32 iComDelay);
OpenViBE::uint32 getComDelay(void) const;
OpenViBE::boolean setAdditionalCommands(const OpenViBE::CString& sAdditionalCommands);
OpenViBE::CString getAdditionalCommands(void) const;
OpenViBE::boolean setReadBoardReplyTimeout(const OpenViBE::uint32 iReadBoardReplyTimeout);
OpenViBE::uint32 getReadBoardReplyTimeout(void) const;
OpenViBE::boolean setFlushBoardReplyTimeout(const OpenViBE::uint32 iFlushBoardReplyTimeout);
OpenViBE::uint32 getFlushBoardReplyTimeout(void) const;
OpenViBE::boolean setDaisyModule(const OpenViBE::boolean sDaisyModule);
OpenViBE::boolean getDaisyModule(void) const;
void checkbuttonDaisyModuleCB(EDaisyStatus eStatus);
static SDaisyInformation getDaisyInformation(EDaisyStatus eStatus);
protected:
std::map <int, int> m_vComboSlotIndexToSerialPort;
OpenViBE::uint32& m_rUSBIndex;
::GtkListStore* m_pListStore;
::GtkEntry* l_pEntryComInit;
OpenViBE::CString m_sComInit;
OpenViBE::uint32 m_iComDelay;
OpenViBE::CString m_sAdditionalCommands;
OpenViBE::uint32 m_iReadBoardReplyTimeout;
OpenViBE::uint32 m_iFlushBoardReplyTimeout;
OpenViBE::boolean m_bDaisyModule;
};
};
......
......@@ -2,8 +2,7 @@
* OpenBCI driver for OpenViBE
*
* \author Jeremy Frey
*
* \note Based on OpenEEG code; inherits its AGPL3 license conditions
* \author Yann Renard
*
*/
#ifndef __OpenViBE_AcquisitionServer_CDriverOpenBCI_H__
......@@ -23,23 +22,14 @@
#endif
#include <vector>
// some constants related to the boardWriteAndPrint
#define ADS1299_VREF 4.5 // reference voltage for ADC in ADS1299. set by its hardware
#define ADS1299_GAIN 24.0 //assumed gain setting for ADS1299. set by its Arduino code
// wait a little before before new writings are initiated (ms)
#define SLEEP_BEFORE_WRITE 500
// start and stop bytes from OpenBCI protocl
#define SAMPLE_START_BYTE 0xA0
#define SAMPLE_STOP_BYTE 0xC0
#include <deque>
namespace OpenViBEAcquisitionServer
{
/**
* \class CDriverOpenBCI
* \author Jeremy Frey
* \author Yann Renard
*/
class CDriverOpenBCI : public OpenViBEAcquisitionServer::IDriver
{
......@@ -49,9 +39,7 @@ namespace OpenViBEAcquisitionServer
virtual void release(void);
virtual const char* getName(void);
virtual OpenViBE::boolean initialize(
const OpenViBE::uint32 ui32SampleCountPerSentBlock,
OpenViBEAcquisitionServer::IDriverCallback& rCallback);
virtual OpenViBE::boolean initialize(const OpenViBE::uint32 ui32SampleCountPerSentBlock, OpenViBEAcquisitionServer::IDriverCallback& rCallback);
virtual OpenViBE::boolean uninitialize(void);
virtual OpenViBE::boolean start(void);
......@@ -61,29 +49,36 @@ namespace OpenViBEAcquisitionServer
virtual OpenViBE::boolean isConfigurable(void);
virtual OpenViBE::boolean configure(void);
virtual const OpenViBEAcquisitionServer::IHeader* getHeader(void) { return &m_oHeader; }
// we're not quite ready yet
virtual OpenViBE::boolean isFlagSet(
const OpenViBEAcquisitionServer::EDriverFlag eFlag) const
public:
typedef enum
{
return eFlag==DriverFlag_IsUnstable;
}
ParserAutomaton_Default,
ParserAutomaton_StartByteReceived,
ParserAutomaton_SampleNumberReceived,
ParserAutomaton_EEGSamplesReceived,
ParserAutomaton_AccelerometerSamplesReceived,
} EParserAutomaton;
protected:
OpenViBE::int32 interpret24bitAsInt32(std::vector < OpenViBE::uint8 > byteBuffer);
OpenViBE::int32 interpret16bitAsInt32(std::vector < OpenViBE::uint8 > byteBuffer);
OpenViBE::int32 interpret24bitAsInt32(const std::vector < OpenViBE::uint8 >& byteBuffer);
OpenViBE::int32 interpret16bitAsInt32(const std::vector < OpenViBE::uint8 >& byteBuffer);
OpenViBE::int16 parseByte(OpenViBE::uint8 ui8Actbyte);
OpenViBE::boolean initTTY(::FD_TYPE * pFileDescriptor, OpenViBE::uint32 ui32TtyNumber);
OpenViBE::boolean boardWriteAndPrint(::FD_TYPE i32FileDescriptor, const char *cmd, OpenViBE::boolean waitForResponse, OpenViBE::uint32 sleepBetween);
OpenViBE::boolean initBoard(::FD_TYPE i32FileDescriptor);
void fastReco(::FD_TYPE i32FileDescriptor);
OpenViBE::int32 readPacketFromTTY(::FD_TYPE i32FileDescriptor);
void closeTTY(::FD_TYPE i32FileDescriptor);
OpenViBE::boolean sendCommand(::FD_TYPE i32FileDescriptor, const char *sCommand, OpenViBE::boolean bWaitForResponse, OpenViBE::boolean bLogResponse, OpenViBE::uint32 ui32Timeout, std::string& sReply);
OpenViBE::boolean resetBoard(::FD_TYPE i32FileDescriptor, bool bRegularInitialization);
OpenViBE::boolean handleCurrentSample(OpenViBE::int32 packetNumber); // will take car of samples fetch from OpenBCI board, dropping/merging packets if necessary
void updateDaisy(OpenViBE::boolean bBeQuiet); // update internal state regarding daisy module
void updateDaisy(OpenViBE::boolean bQuietLogging); // update internal state regarding daisy module
protected:
OpenViBE::boolean openDevice(::FD_TYPE * pFileDescriptor, OpenViBE::uint32 ui32TtyNumber);
void closeDevice(::FD_TYPE i32FileDescriptor);
OpenViBE::uint32 writeToDevice(::FD_TYPE i32FileDescriptor, const void* pBuffer, const OpenViBE::uint32 ui32BufferSize);
OpenViBE::uint32 readFromDevice(::FD_TYPE i32FileDescriptor, void* pBuffer, const OpenViBE::uint32 ui32BufferSize, const OpenViBE::uint64 ui64TimeOut=0);
protected:
SettingsHelper m_oSettings;
......@@ -91,49 +86,78 @@ namespace OpenViBEAcquisitionServer
OpenViBEAcquisitionServer::IDriverCallback* m_pCallback;
OpenViBEAcquisitionServer::CHeader m_oHeader;
::FD_TYPE m_i32FileDescriptor;
OpenViBE::CString m_sDriverName;
OpenViBE::CString m_sTTYName;
OpenViBE::CString m_sAdditionalCommands; // string to send possibly upon initialisation
OpenViBE::uint32 m_ui32ChannelCount;
OpenViBE::uint32 m_ui32DeviceIdentifier;
OpenViBE::CString m_sComInit; // string to send possibly upon initialisation
OpenViBE::uint32 m_ui32ComDelay; // parameter com init string
OpenViBE::uint32 m_ui32ReadBoardReplyTimeout; // parameter com init string
OpenViBE::uint32 m_ui32FlushBoardReplyTimeout; // parameter com init string
OpenViBE::boolean m_bDaisyModule; // daisy module attached or not
OpenViBE::float32* m_pSample;
::FD_TYPE m_i32FileDescriptor;
// OpenBCI protocol related
OpenViBE::int16 m_i16SampleNumber; // returned by the board
OpenViBE::uint16 m_ui16Readstate; // position in the sample (see doc)
OpenViBE::uint32 m_ui32ReadState; // position in the sample (see doc)
OpenViBE::uint8 m_ui8SampleBufferPosition;// position in the buffer
std::vector < OpenViBE::uint8 > m_vEEGValueBuffer; // buffer for one EEG value (int24)
const static OpenViBE::uint8 EEGValueBufferSize = 3; // int24 == 3 bytes
std::vector < OpenViBE::uint8 > m_vAccValueBuffer; // buffer for one accelerometer value (int16)
const static OpenViBE::uint8 EEGValueBufferSize = 3; // int24 == 3 bytes
const static OpenViBE::uint8 AccValueBufferSize = 2; // int16 == 2 bytes
const static OpenViBE::uint8 EEGNbValuesPerSample = 8; // the board send EEG values 8 by 8 (will concatenate 2 samples with daisy module)
const static OpenViBE::uint8 AccNbValuesPerSample = 3; // 3 accelerometer data per sample
const static OpenViBE::uint16 DefaultSamplingRate = 250; // sampling rate with no daisy module (divided by 2 with daisy module)
OpenViBE::uint16 m_ui16ExtractPosition; // used to situate sample reading both with EEG and accelerometer data
OpenViBE::float32 ScaleFacuVoltsPerCount; // convert from int32 to microvolt
OpenViBE::int16 m_i16LastPacketNumber;
OpenViBE::uint16 m_ui16Switches;
const static OpenViBE::uint8 EEGValueCountPerSample = 8; // the board send EEG values 8 by 8 (will concatenate 2 samples with daisy module)
const static OpenViBE::uint8 AccValueCountPerSample = 3; // 3 accelerometer data per sample
std::vector < std::vector < OpenViBE::float32 > > m_vChannelBuffer; // buffer to store channels & chunks
// buffer to store sample coming from OpenBCI -- filled by parseByteP2(), passed to handleCurrentSample()
OpenViBE::uint32 MissingSampleDelayBeforeReset; // in ms - value acquired from configuration manager
OpenViBE::uint32 DroppedSampleCountBeforeReset; // in samples - value acquired from configuration manager
OpenViBE::uint32 DroppedSampleSafetyDelayBeforeReset; // in ms - value acquired from configuration manager
std::deque < OpenViBE::uint32 > m_vDroppedSampleTime;
OpenViBE::float32 m_f32UnitsToMicroVolts; // convert from int32 to microvolt
OpenViBE::float32 m_f32UnitsToRadians; // converts from int16 to radians
OpenViBE::uint32 m_ui32ExtractPosition; // used to situate sample reading both with EEG and accelerometer data
OpenViBE::uint32 m_ui32ValidAccelerometerCount;
OpenViBE::int32 m_i32LastPacketNumber; // used to detect consecutive packets when daisy module is used
// buffer for multibyte reading over serial connection
std::vector < OpenViBE::uint8 > m_vReadBuffer;
// buffer to store sample coming from OpenBCI -- filled by parseByte(), passed to handleCurrentSample()
std::vector < OpenViBE::float32 > m_vSampleEEGBuffer;
std::vector < OpenViBE::float32 > m_vSampleEEGBufferDaisy;
std::vector < OpenViBE::float32 > m_vSampleAccBuffer;
// buffers to store & merge daisy samples
std::vector < OpenViBE::float32 > m_vSampleEEGBufferDaisy;
std::vector < OpenViBE::float32 > m_vSampleAccBufferDaisy;
std::vector < OpenViBE::float32 > m_vSampleAccBufferTemp;
// buffer to store aggregated samples
std::vector < std::vector < OpenViBE::float32 > > m_vChannelBuffer; // buffer to store channels & chunks
std::vector < OpenViBE::float32 > m_vSampleBuffer;
bool m_bSeenPacketFooter; // extra precaution to sync packets
OpenViBE::CString m_sTTYName;
// mechanism to call fastReco() if no data are received
const static OpenViBE::uint32 PollingDelay = 1000; // in ms
OpenViBE::uint32 m_ui32tick; // last tick for polling
// mechanism to call resetBoard() if no data are received
OpenViBE::uint32 m_ui32Tick; // last tick for polling
OpenViBE::uint32 m_ui32StartTime; // actual time since connection
// sample storing for device callback and serial i/o
std::vector < OpenViBE::float32 > m_vCallbackSample;
private:
typedef struct
{
OpenViBE::uint32 ui32DeviceVersion;
OpenViBE::uint32 ui32DeviceChannelCount;
OpenViBE::uint32 ui32BoardId;
OpenViBE::uint32 ui32DaisyId;
OpenViBE::uint32 ui32MocapId;
char sBoardChipset[64];
char sDaisyChipset[64];
char sMocapChipset[64];
} SDeviceInformation;
SDeviceInformation m_oDeviceInformation;
};
};
......
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