RTXI  2.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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;
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;
135  long long count;
136  long long fixedcount;
137  std::vector<std::string> dataTags;
138 
139  QMutex mutex;
140 
141  pthread_t thread;
145  struct timespec sleep;
146 
147  struct file_t
148  {
149  hid_t id;
150  hid_t trial;
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 
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 &) {};
220  {
221  return *getInstance();
222  };
223  static Plugin *instance;
224 
226 
227  size_t buffersize;
228 }; // class Plugin
229 }; // namespace DataRecorder
230 
231 #endif /* DATA_RECORDER_H */
QGroupBox * sampleGroup
data_token_t _token
std::list< Panel * > panelList
virtual void doLoad(const Settings::Object::State &)
virtual ~CustomEvent(void)
Definition: data_recorder.h:73
Definition: io.h:187
Definition: rt.h:98
int openFile(QString &)
void buildChannelList(void)
QPushButton * rButton
Plugin(const Plugin &)
QLineEdit * fileNameEdit
void closeFile(bool=false)
Settings::Object::ID id
Definition: data_recorder.h:58
void updateDownsampleRate(int)
QComboBox * channelList
static Plugin * instance
Panel * createDataRecorderPanel(void)
QPushButton * lButton
QGroupBox * channelGroup
virtual void doLoad(const Settings::Object::State &)
Lockfree SINGLE producer / SINGLE consumer FIFO.
Definition: atomic_fifo.h:33
QListWidget * selectionBox
unsigned long ID
Definition: settings.h:53
Panel(QWidget *, size_t)
QComboBox * typeList
void receiveEventRT(const Event::Object *)
QPushButton * addTag
QMdiSubWindow * subWindow
virtual void doSave(Settings::Object::State &) const
QPushButton * startRecordButton
void stopRecording(long long)
virtual void doDeferred(const Settings::Object::State &)
QComboBox * blockList
void stopRecording(void)
void startRecording(void)
Plugin & operator=(const Plugin &)
QPushButton * closeButton
struct timespec sleep
QGroupBox * buttonGroup
void startRecordClicked(void)
unsigned long flags_t
Definition: io.h:40
void stopRecordClicked(void)
void removeDataRecorderPanel(Panel *)
QGroupBox * listGroup
void openFile(const QString &)
RT::List< Channel > channels
static void * bounce(void *)
QLineEdit * timeStampEdit
QLineEdit * fileFormatEdit
void customEvent(QEvent *)
std::vector< IO::Block * > blockPtrList
static Plugin * getInstance(void)
virtual void doSave(Settings::Object::State &) const
void receiveEvent(const Event::Object *)
int startRecording(long long)
std::vector< std::string > dataTags
void postAsyncData(const double *, size_t)
QPushButton * stopRecordButton
QSpinBox * downsampleSpin
virtual void doDeferred(const Settings::Object::State &)
Classes associated with the loading/unloading of binaries at run-time.
Definition: plugin.h:35
struct DataRecorder::Panel::file_t file
QGroupBox * stampGroup
QGroupBox * fileGroup
Definition: rt.h:542