Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

writebdf.c File Reference

#include <assert.h>
#include <openedf.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <pctimer.h>
#include <ctype.h>
#include <nsutil.h>
#include <nsnet.h>

Go to the source code of this file.

Data Structures

struct  Options
 Command line options will be decoded into this structure. More...


Defines

#define MINLINELENGTH   4
#define DELIMS   " \r\n"

Functions

void resetSampleBuffer ()
 reset frame counter

void writeSampleBuffer (unsigned int Channel, unsigned int SampleNr, char Byte0, char Byte1, char Byte2)
 writes sample data into data buffer in the right order

void initSampleBuffer ()
 allocates memory for data buffer

void writeBufferToFile ()
 writes data chunk to file

void handleSamples (int packetCounter, int channels)
 copy data to sample buffer, write buffer to file if it is full

int isANumber (const char *str)
 check, if data is a number

void serverDied (void)
 action to take if server died

int main (int argc, char **argv)

Variables

const char * helpText
 Program to save data from the neuroserver in a file.

EDFDecodedConfig cfg
 EDF header information block.

InputBuffer ib
 network input buffer

char lineBuf [MAXLEN]
 buffer for ASCII data frames

int blockCounter = 0
 number of data blocks written

char * dataarray
 pointer for data block

long samples [MAXCHANNELS]
 channel sample data

size_t sampleSize
 amount of memory for one sample (16 or 24 bits)

unsigned int frameCount
 counter for received data frames

Options opts
 place to store command line options


Define Documentation

#define DELIMS   " \r\n"
 

Definition at line 71 of file writebdf.c.

#define MINLINELENGTH   4
 

Definition at line 70 of file writebdf.c.


Function Documentation

void handleSamples int  packetCounter,
int  channels
 

copy data to sample buffer, write buffer to file if it is full

Definition at line 158 of file writebdf.c.

References cfg, EDFDecodedConfig::chan, frameCount, Options::isBdf, opts, rprintf(), EDFDecodedChannelHeader::sampleCount, samples, writeBufferToFile(), and writeSampleBuffer().

void initSampleBuffer  ) 
 

allocates memory for data buffer

< get 3 bytes/sample (BDF Standard)

< get 2 bytes/sample (EDF Standard)

< allocate one big array of bytes

Definition at line 124 of file writebdf.c.

References cfg, EDFDecodedConfig::chan, dataarray, EDFDecodedHeader::dataRecordChannels, EDFDecodedConfig::hdr, Options::isBdf, opts, resetSampleBuffer(), EDFDecodedChannelHeader::sampleCount, and sampleSize.

Referenced by main().

int isANumber const char *  str  ) 
 

check, if data is a number

Definition at line 200 of file writebdf.c.

int main int  argc,
char **  argv
 

check filename

open file

start networking

configure neuroserver connection

now decode EDF header

check for 24bit BDF data format

write header to data file (if not in CSV mode)

data0 data1 data2 ...

Definition at line 218 of file writebdf.c.

References cfg, cur, EDFDecodedHeader::dataFormat, DEFAULTHOST, DEFAULTPORT, DELIMS, EDFPacket, Options::eegNum, Options::filename, getOK(), handleSamples(), EDFDecodedConfig::hdr, EDFDecodedHeader::headerRecordBytes, helpText, Options::hostname, ib, initSampleBuffer(), isANumber(), Options::isArray, Options::isBdf, isEOF(), Options::isFilenameSet, Options::isLimittedTime, lineBuf, linePos, MAXHEADERLEN, MINLINELENGTH, ob, opts, pctimer(), Options::port, rconnectName(), readEDFString(), readline(), rexit(), rinitNetworking(), rprintf(), rselect(), rsocket(), samples, Options::seconds, serverDied(), sock_fd, sock_t, and writeString().

void resetSampleBuffer  ) 
 

reset frame counter

Definition at line 103 of file writebdf.c.

References frameCount.

Referenced by initSampleBuffer(), and writeBufferToFile().

void serverDied void   ) 
 

action to take if server died

Definition at line 210 of file writebdf.c.

References rprintf().

void writeBufferToFile  ) 
 

writes data chunk to file

goto end of file

block write sample data

Definition at line 139 of file writebdf.c.

References blockCounter, cfg, dataarray, EDFDecodedHeader::dataRecordChannels, Options::filename, frameCount, EDFDecodedConfig::hdr, opts, resetSampleBuffer(), rprintf(), and sampleSize.

Referenced by handleSamples().

void writeSampleBuffer unsigned int  Channel,
unsigned int  SampleNr,
char  Byte0,
char  Byte1,
char  Byte2
 

writes sample data into data buffer in the right order

Definition at line 110 of file writebdf.c.

References cfg, EDFDecodedConfig::chan, dataarray, Options::isBdf, opts, EDFDecodedChannelHeader::sampleCount, and sampleSize.

Referenced by handleSamples().


Variable Documentation

int blockCounter = 0
 

number of data blocks written

Definition at line 92 of file writebdf.c.

Referenced by writeBuffers(), and writeBufferToFile().

struct EDFDecodedConfig cfg
 

EDF header information block.

Definition at line 88 of file writebdf.c.

Referenced by EDFEncodePacket(), getDataRecordChunkSize(), getSamplesPerSecond(), getSecondsPerSample(), handleSamples(), initSampleBuffer(), initSampleBuffers(), isValidREDF(), main(), newEDFInputIterator(), readEDF(), readEDFString(), setEDFHeaderBytes(), writeBuffers(), writeBufferToFile(), writeEDF(), writeEDFString(), and writeSampleBuffer().

char* dataarray
 

pointer for data block

Definition at line 94 of file writebdf.c.

Referenced by initSampleBuffer(), writeBufferToFile(), and writeSampleBuffer().

unsigned int frameCount
 

counter for received data frames

Definition at line 98 of file writebdf.c.

Referenced by handleSamples(), resetSampleBuffer(), and writeBufferToFile().

const char* helpText
 

Initial value:

"writeedf   v 0.35 by Rudi Cilibrasi, Moritz von Buttlar\n"
"\n"
"Usage:  writeedf [options] <filename>\n"
"\n"
"        -p port          Port number to use (default 8336)\n"
"        -n hostname      Host name of the NeuroCaster server to connect to\n"
"                         (this defaults to 'localhost')\n"
"        -s <num>         Only record this many seconds.\n"
"                         (default is to record until interrupted)\n"
"        -e <intnum>      Integer ID specifying which EEG to log (default: 0)\n"
"        -b               use bdf format (same as edf, only 24 bits/sample) \n"
"        -c               write as CSV array (can be imported to Excel, Scilab,etc.)"
"The filename specifies the new EDF file to create.\n"
Program to save data from the neuroserver in a file.

Author:
Rudi Cilibrasi, Moritz von Buttlar
Todo:
add CSV output (excel, Scilab, gnuplot etc. direct import)
This program is used to connect to the neuroserver and receive an eeg data stream. It saves this data in a file using the European Data Format (EDF). There's also an option to use the 24bit extended format like it is specified and used by BioSemi (also called BDF). This is useful for e.g. 24bit DC coupled eeg devices. The 24bit mode is also auto-detected if the data format field starts with "24". For the file data binary numbers are used.

The program writes data blockwise: it opens the file, writes one data record, then closes the file (in the write_buffers function)

Definition at line 54 of file writebdf.c.

struct InputBuffer ib
 

network input buffer

Definition at line 90 of file writebdf.c.

char lineBuf[MAXLEN]
 

buffer for ASCII data frames

Definition at line 91 of file writebdf.c.

struct Options opts
 

place to store command line options

Definition at line 99 of file writebdf.c.

long samples[MAXCHANNELS]
 

channel sample data

Definition at line 95 of file writebdf.c.

Referenced by cmdDataFrame(), doesMatchP3(), fetchSamples(), handleSamples(), idleHandler(), isValidPacket(), and main().

size_t sampleSize
 

amount of memory for one sample (16 or 24 bits)

Definition at line 97 of file writebdf.c.

Referenced by initSampleBuffer(), writeBufferToFile(), and writeSampleBuffer().


Generated on Tue Feb 8 00:05:22 2005 for Neuroserver by doxygen 1.3.3