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

openedf.h

Go to the documentation of this file.
00001 /*
00002 NeuroServer
00003  
00004 A collection of programs to translate between EEG data and TCP network
00005 messages. This is a part of the OpenEEG project, see http://openeeg.sf.net
00006 for details.
00007     
00008 Copyright (C) 2003, 2004 Rudi Cilibrasi (cilibrar@ofb.net)
00009      
00010 This library is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU Lesser General Public
00012 License as published by the Free Software Foundation; either
00013 version 2.1 of the License, or (at your option) any later version.
00014          
00015 This library is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018 Lesser General Public License for more details.
00019              
00020 You should have received a copy of the GNU Lesser General Public
00021 License along with this library; if not, write to the Free Software
00022 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00023 */
00024                 
00025 #ifndef __OPENEDF_H
00026 #define __OPENEDF_H
00027 
00028 #include <stdio.h>
00029 
00030 #include <nsnet.h>
00031 
00032 #define MAXCHANNELS 32
00033 #define BYTESPERSAMPLE 2
00034 #define MAXHEADERLEN ((MAXCHANNELS+1) * 256)
00035 
00036 #pragma pack(1)
00037 
00038 struct EDFPackedHeader {
00039         char dataFormat[8];                     // identification code
00040         char localPatient[80];                  // local subject identification [ASCII]
00041         char localRecorder[80];                 // local recording identification [ASCII]
00042         char recordingStartDate[8];             // dd.mm.yy local start date of recording [ASCII]
00043         char recordingStartTime[8];             // hh.mm.ss local start time of recording [ASCII]
00044         char headerRecordBytes[8];              // number of bytes in header record [ASCII]
00045         char manufacturerID[44];                // version/data format/manufact. [ASCII]
00046         char dataRecordCount[8];                // number of data records, -1 if unknown
00047         char dataRecordSeconds[8];              // duration of a data record in seconds [ASCII] z.B. 1
00048         char dataRecordChannels[4];             // number of recording channels in data record
00049 };
00050 
00051 struct EDFPackedChannelHeader {
00052         char label[16];                         // channel label
00053         char transducer[80];                    // type of transducer
00054         char dimUnit[8];                        // physical dimension of channel, e.g. uV 
00055         char physMin[8];                        // minimal physical value (in above units)
00056         char physMax[8];                        // maximal physical value
00057         char digiMin[8];                        // minimal digital value
00058         char digiMax[8];                        // max. digital value
00059         char prefiltering[80];                  // pre-filtering description
00060         char sampleCount[8];                    // number of samples in each record/data chunk
00061         char reserved[32];                      // reserved for future extensions
00062 };
00063 
00064 #pragma pack(4)
00065 
00066 struct EDFDecodedHeader {
00067         int headerRecordBytes;                  // size of header in bytes
00068         int dataRecordCount;                    // number of data records/chunks
00069         int dataRecordChannels;                 // number of channels
00070         char dataFormat[9];
00071         char localPatient[81];
00072         char localRecorder[81];
00073         char recordingStartDate[9];
00074         char recordingStartTime[9];
00075         char manufacturerID[45];
00076         double dataRecordSeconds;               // duration of a data record in seconds
00077 };
00078 
00079 struct EDFDecodedChannelHeader {
00080         int sampleCount;
00081         double physMin, physMax;                // physical maxima/minima
00082         double digiMin, digiMax;                // digital maxima/minima -->gain
00083         char label[17];
00084         char transducer[81];
00085         char dimUnit[9];
00086         char prefiltering[81];
00087         char reserved[33];
00088 };
00089 
00090 struct EDFDecodedConfig {
00091         struct EDFDecodedHeader hdr;
00092         struct EDFDecodedChannelHeader chan[MAXCHANNELS];
00093 };
00094 
00095 struct EDFInputIterator {
00096         struct EDFDecodedConfig cfg;
00097         int dataRecordNum;
00098         int sampleNum;
00099         char *dataRecord;
00100 };
00101 
00102 struct EDFInputIterator *newEDFInputIterator(const struct EDFDecodedConfig *cfg);
00103 int stepEDFInputIterator(struct EDFInputIterator *edfi);
00104 int fetchSamples(const struct EDFInputIterator *edfi, short *samples, FILE *fp);
00105 void freeEDFInputIterator(struct EDFInputIterator *edfi);
00106 
00107 int EDFUnpackInt(const char *inp, int fieldLen);
00108 double EDFUnpackDouble(const char *inp, int fieldLen);
00109 const char *EDFUnpackString(const char *inp, int fieldLen);
00110 
00111 int EDFEncodePacket(char *target, const struct EDFDecodedConfig *cfg);
00112 
00113 int writeEDF(int fd, const struct EDFDecodedConfig *cfg);
00114 int readEDF(int fd, struct EDFDecodedConfig *cfg);
00115 int writeEDFString(const struct EDFDecodedConfig *cfg, char *buf, int *buflen);
00116 int readEDFString(struct EDFDecodedConfig *cfg, const char *buf, int len);
00117 
00118 int setEDFHeaderBytes(struct EDFDecodedConfig *cfg);
00119 int getDataRecordChunkSize(const struct EDFDecodedConfig *cfg);
00120 
00121 double getSamplesPerSecond(const struct EDFDecodedConfig *cfg, int whichChan);
00122 double getSecondsPerSample(const struct EDFDecodedConfig *cfg, int whichChan);
00123 
00124 /* Realtime EDF (REDF) is a restricted type of EDF for the network */
00125 int isValidREDF(const struct EDFDecodedConfig *cfg);
00126 int makeREDFConfig(struct EDFDecodedConfig *result, const struct EDFDecodedConfig *source);
00127 
00128 /* Returns a text description of the last error */
00129 const char *getLastError(void);
00130 
00131 const char *getDMY(void);
00132 const char *getHMS(void);
00133 
00134 #endif
00135 

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