CEBL  2.1
FileDataStream.cpp
Go to the documentation of this file.
1 
9 #include "FileDataStream.hpp"
10 #include "FileDataStreamConfig.hpp"
11 #include <cppR/cppR.hpp>
12 #include <iostream>
13 using namespace std;
14 //----------------------------------------------------------------------
15 // CONSTRUCTORS / DESTRUCTORS
16 
18 {
19  this->model = model;
20  this->file_opened = false;
21  this->data_index = 0;
22 }
24 {}
25 
26 
27 //----------------------------------------------------------------------
28 
29 void FileDataStream::updater()
30 {
31  int num_new_samples = sample_rate * (timeout_length / 1000.0);
32 
33  int start_sample = data_index;
34  this->data_index += num_new_samples;
35  int end_sample = data_index;
36  ublas::matrix<double> temp_data;
37 
38  if(end_sample >= this->data.numSamples())
39  {
40  this->data_index = 0;
41  start_sample = data_index;
42  this->data_index += num_new_samples;
43  end_sample = data_index;
44  }
45 
46  temp_data = cppR::submatrix(this->data.getMatrix(),0,0,start_sample,end_sample);
47 
48  //add the temp data to the buffer
49  {
50  boost::mutex::scoped_lock lock(thread_lock);
51  buffer.append(temp_data);
52  }
53 
54 }
55 
56 void FileDataStream::onStart()
57 {
58  //check to see if file stream configuration is set up correctly
59  if(!model->getFileDataStreamConfig()->isReady())
60  {
61  throw DataSourceException("File data stream is not ready.");
62  }
63  this->data_index = 0;
64 
65  string filename = model->getFileDataStreamConfig()->getFilename();
66  this->sample_rate = model->getFileDataStreamConfig()->getSampleRate();
67  this->data = model->getFileDataStreamConfig()->getData();
68 }
69 
70 void FileDataStream::onStop()
71 {
72  this->data_index = 0;
73 }
74 
75 
76 
77