RTXI  2.4
The Real-Time eXperiment Interface Documentation
data_recorder.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2011 Georgia Institute of Technology, University of Utah, Weill Cornell Medical College
3 
4  This program is free software: you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation, either version 3 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 */
18 
19 #ifndef DATA_RECORDER_H
20 #define DATA_RECORDER_H
21 
22 #include <atomic_fifo.h>
23 #include <event.h>
24 #include <io.h>
25 #include <mutex.h>
26 #include <plugin.h>
27 #include <workspace.h>
28 #include <vector>
29 #include <time.h>
30 #include <daq.h>
31 
32 #include <hdf5.h>
33 #include <hdf5_hl.h>
34 
35 namespace DataRecorder
36 {
38 {
47 };
48 
50 {
52  size_t size;
53  long long time;
54 };
55 
57 {
59  size_t index;
60  long long step;
61  double value;
62 };
63 
64 void startRecording(void);
65 void stopRecording(void);
66 void openFile(const QString &);
67 void postAsyncData(const double *,size_t);
68 
69 class CustomEvent : public QEvent
70 {
71 public:
72  CustomEvent(QEvent::Type);
73  virtual ~CustomEvent(void) {};
74  void setData(void *data);
75  void *getData(void);
76 
77 private:
78  void *data;
79 };
80 
81 class Channel : public RT::List<Channel>::Node
82 {
83 
84  friend class Panel;
85 
86 private:
87  Channel(void);
88  ~Channel(void);
89  QString name;
90  IO::Block *block;
91  IO::flags_t type;
92  size_t index;
93 }; // class Channel
94 
95 class Panel : public QWidget, virtual public Settings::Object, public Event::Handler, public Event::RTHandler, public RT::Thread
96 {
97  Q_OBJECT
98 
99 public:
100  Panel(QWidget *, size_t);
101  ~Panel(void);
102 
103  void execute(void);
104  void receiveEvent(const Event::Object *);
105  void receiveEventRT(const Event::Object *);
106 
107 public slots:
108  void startRecordClicked(void);
109  void stopRecordClicked(void);
110  void updateDownsampleRate(int);
111 
112 private slots:
113  void buildChannelList(void);
114  void changeDataFile(void);
115  void insertChannel(void);
116  void removeChannel(void);
117  void addNewTag(void);
118 
119 protected:
120  void customEvent(QEvent *);
121  virtual void doDeferred(const Settings::Object::State &);
122  virtual void doLoad(const Settings::Object::State &);
123  virtual void doSave(Settings::Object::State &) const;
124 
125 private:
126  static void *bounce(void *);
127  void processData(void);
128  int openFile(QString &);
129  void closeFile(bool =false);
130  int startRecording(long long);
131  void stopRecording(long long);
132  double prev_input;
133  size_t counter;
134  size_t downsample_rate;
135  long long count;
136  long long fixedcount;
137  std::vector<std::string> dataTags;
138 
139  QMutex mutex;
140 
141  pthread_t thread;
142  AtomicFifo fifo;
143  data_token_t _token;
144  bool tokenRetrieved;
145  struct timespec sleep;
146 
147  struct file_t
148  {
149  hid_t id;
150  hid_t trial;
151  hid_t adata, cdata, pdata, sdata, tdata, sysdata;
152  hid_t chandata;
153  long long idx;
154  } file;
155 
156  bool recording;
157 
158  QMdiSubWindow *subWindow;
159 
160  QGroupBox *channelGroup;
161  QGroupBox *stampGroup;
162  QGroupBox *sampleGroup;
163  QGroupBox *fileGroup;
164  QGroupBox *buttonGroup;
165  QGroupBox *listGroup;
166 
167  QComboBox *blockList;
168  QComboBox *channelList;
169  QComboBox *typeList;
170  QListWidget *selectionBox;
171  QLabel *recordStatus;
172  QPushButton *rButton;
173  QPushButton *lButton;
174  QPushButton *addTag;
175 
176  QSpinBox *downsampleSpin;
177 
178  QLineEdit *fileNameEdit;
179  QLineEdit *timeStampEdit;
180  QLineEdit *fileFormatEdit;
181  QLabel *fileSizeLbl;
182  QLabel *fileSize;
183  QLabel *trialLengthLbl;
184  QLabel *trialLength;
185  QLabel *trialNumLbl;
186  QLabel *trialNum;
187 
188  QPushButton *startRecordButton;
189  QPushButton *stopRecordButton;
190  QPushButton *closeButton;
191 
192  RT::List<Channel> channels;
193  std::vector<IO::Block *> blockPtrList;
194 }; // class Panel
195 
196 class Plugin : public QObject, public ::Plugin::Object
197 {
198  Q_OBJECT
199 
200  friend class Panel;
201 
202 public:
203  static Plugin *getInstance(void);
204  std::list<Panel *> panelList;
205 
206 public slots:
208 
209 protected:
210  virtual void doDeferred(const Settings::Object::State &);
211  virtual void doLoad(const Settings::Object::State &);
212  virtual void doSave(Settings::Object::State &) const;
213 
214 private:
215 
216  Plugin(void);
217  ~Plugin(void);
218  Plugin(const Plugin &) : QObject() {};
219  Plugin &operator=(const Plugin &)
220  {
221  return *getInstance();
222  };
223  static Plugin *instance;
224 
225  void removeDataRecorderPanel(Panel *);
226 
227  size_t buffersize;
228 }; // class Plugin
229 }; // namespace DataRecorder
230 
231 #endif /* DATA_RECORDER_H */
DataRecorder
Definition: data_recorder.h:35
DataRecorder::Plugin::doDeferred
virtual void doDeferred(const Settings::Object::State &)
Definition: data_recorder.cpp:1624
DataRecorder::STOP
@ STOP
Definition: data_recorder.h:42
DataRecorder::Panel
Definition: data_recorder.h:95
DataRecorder::Plugin::panelList
std::list< Panel * > panelList
Definition: data_recorder.h:204
DataRecorder::Plugin::getInstance
static Plugin * getInstance(void)
Definition: data_recorder.cpp:1652
DataRecorder::data_type_t
data_type_t
Definition: data_recorder.h:37
DataRecorder::CLOSE
@ CLOSE
Definition: data_recorder.h:40
IO::flags_t
unsigned long flags_t
Definition: io.h:40
DataRecorder::stopRecording
void stopRecording(void)
Definition: data_recorder.cpp:347
DataRecorder::Panel::doSave
virtual void doSave(Settings::Object::State &) const
Definition: data_recorder.cpp:1054
Event::RTHandler
Definition: event.h:282
Plugin::Object
Definition: plugin.h:145
DataRecorder::param_change_t::id
Settings::Object::ID id
Definition: data_recorder.h:58
workspace.h
DataRecorder::param_change_t::index
size_t index
Definition: data_recorder.h:59
plugin.h
DataRecorder::startRecording
void startRecording(void)
Definition: data_recorder.cpp:338
DataRecorder::Channel
Definition: data_recorder.h:81
DataRecorder::OPEN
@ OPEN
Definition: data_recorder.h:39
DataRecorder::DONE
@ DONE
Definition: data_recorder.h:45
DataRecorder::Plugin::doLoad
virtual void doLoad(const Settings::Object::State &)
Definition: data_recorder.cpp:1631
DataRecorder::SYNC
@ SYNC
Definition: data_recorder.h:43
DataRecorder::postAsyncData
void postAsyncData(const double *, size_t)
Definition: data_recorder.cpp:366
DataRecorder::Plugin::Panel
friend class Panel
Definition: data_recorder.h:200
DataRecorder::CustomEvent::CustomEvent
CustomEvent(QEvent::Type)
Definition: data_recorder.cpp:323
DataRecorder::Panel::Panel
Panel(QWidget *, size_t)
Definition: data_recorder.cpp:385
DataRecorder::Panel::doLoad
virtual void doLoad(const Settings::Object::State &)
Definition: data_recorder.cpp:1043
DataRecorder::Panel::doDeferred
virtual void doDeferred(const Settings::Object::State &)
Definition: data_recorder.cpp:1016
DataRecorder::CustomEvent::~CustomEvent
virtual ~CustomEvent(void)
Definition: data_recorder.h:73
DataRecorder::Panel::execute
void execute(void)
Definition: data_recorder.cpp:614
Settings::Object::ID
unsigned long ID
Definition: settings.h:53
daq.h
DataRecorder::param_change_t::value
double value
Definition: data_recorder.h:61
DataRecorder::ASYNC
@ ASYNC
Definition: data_recorder.h:44
DataRecorder::Panel::startRecordClicked
void startRecordClicked(void)
Definition: data_recorder.cpp:936
IO::Block
Definition: io.h:188
DataRecorder::Plugin::createDataRecorderPanel
Panel * createDataRecorderPanel(void)
Definition: data_recorder.cpp:1612
DataRecorder::data_token_t
Definition: data_recorder.h:49
DataRecorder::data_token_t::type
data_type_t type
Definition: data_recorder.h:51
event.h
AtomicFifo
Lockfree SINGLE producer / SINGLE consumer FIFO.
Definition: atomic_fifo.h:33
DataRecorder::Plugin::doSave
virtual void doSave(Settings::Object::State &) const
Definition: data_recorder.cpp:1641
DataRecorder::Panel::updateDownsampleRate
void updateDownsampleRate(int)
Definition: data_recorder.cpp:959
DataRecorder::CustomEvent::setData
void setData(void *data)
Definition: data_recorder.cpp:328
DataRecorder::Panel::~Panel
~Panel(void)
Definition: data_recorder.cpp:602
DataRecorder::PARAM
@ PARAM
Definition: data_recorder.h:46
DataRecorder::Panel::receiveEventRT
void receiveEventRT(const Event::Object *)
Definition: data_recorder.cpp:698
Event::Handler
Definition: event.h:256
DataRecorder::data_token_t::size
size_t size
Definition: data_recorder.h:52
DataRecorder::Panel::receiveEvent
void receiveEvent(const Event::Object *)
Definition: data_recorder.cpp:636
mutex.h
Settings::Object
Definition: settings.h:43
Settings::Object::State
Definition: settings.h:62
Plugin
Classes associated with the loading/unloading of binaries at run-time.
Definition: plugin.h:35
RT::Thread
Definition: rt.h:561
DataRecorder::CustomEvent::getData
void * getData(void)
Definition: data_recorder.cpp:333
io.h
DataRecorder::Panel::stopRecordClicked
void stopRecordClicked(void)
Definition: data_recorder.cpp:952
DataRecorder::openFile
void openFile(const QString &)
Definition: data_recorder.cpp:356
DataRecorder::param_change_t::step
long long step
Definition: data_recorder.h:60
RT::List
Definition: rt.h:110
DataRecorder::param_change_t
Definition: data_recorder.h:56
Event::Object
Definition: event.h:128
DataRecorder::CustomEvent
Definition: data_recorder.h:69
atomic_fifo.h
DataRecorder::Panel::customEvent
void customEvent(QEvent *)
Definition: data_recorder.cpp:965
DataRecorder::data_token_t::time
long long time
Definition: data_recorder.h:53
DataRecorder::START
@ START
Definition: data_recorder.h:41