BioSignalPi  v2
ecgmock.cpp
Go to the documentation of this file.
1 /*
2  * ECGmock.cpp
3  *
4  * Created on: Sep 14, 2015
5  * Author: Martin Rostin
6  */
7 
8 #include "ecgmock.h"
9 #include <iostream>
10 #include <math.h>
11 #include <QDebug>
12 #include "ecgstreamobject.h"
13 
14 
15 EcgMock::EcgMock(DataStream& inputStream): DeviceInterface(inputStream) {
16  init();
17 }
18 
20  close();
21 }
28 void EcgMock::getData(DataStream& inputStream){
29  int _sizeArray=2000;
30  updateStatus(QString("EcgMock::GetData"));
31  int _angle=0;
32 
33  for (int i=0;i<_sizeArray;i++){
34  // EcgStruct4 tmp=EcgStruct4(cnt++,cnt++,cnt++,cnt++,cnt++);
35  stream.push_back(EcgStreamObject(sin(_angle*PI/180),cos(_angle*PI/180),tan(_angle*PI/180),sin(_angle*2*PI/180),_angle*PI/180));
36  if(_angle>360){
37  _angle-=360;
38  }
39  _angle+=6;
40  /* std::cerr << tmp.time << " " << tmp.frame1 << " " << tmp.frame1
41  << " " << tmp.frame2
42  << " " << tmp.frame3
43  <<std::endl; */
44  }
45  return;
46 }
47 void EcgMock::run(){
48  double counter,counter2=0;
49  double cosinus,angle,sinus,sinus2x,tangens=0.0;
50  double _angle=0;
51  condition=true;
52  emit updateStatus(QString("EcgMock Started"));
53  while(condition) {
54  stream.append(EcgStreamObject(sin(_angle*PI/180),cos(_angle*PI/180),tan(_angle*PI/180),sin(_angle*2*PI/180),_angle*PI/180));
55  if(counter2>100){
56  counter2=0;
57  msleep(200);
58  }
59  angle+=_angle;
60  cosinus+=cos(_angle*PI/180);
61  sinus2x+=sin(_angle*2*PI/180);
62  sinus+=sin(_angle*PI/180);
63  tangens+=tan(_angle*PI/180);
64  _angle+=0.2;
65  counter++;
66  counter2++;
67 
68 
69  if (counter >= 10) {
70  QVector<QPointF> tmp;
71  double time=(_angle)*PI/1800;
72  tmp << QPointF(time,sinus/10) << QPointF(time,cosinus/10) << QPointF(time,tangens/10) << QPointF(time,sinus2x/10);
73  //privateSamples->append(QPointF(elapsed/1000,lead1/10));
74  privateSamples->append(tmp);
75  tmp.clear();
76 
77  angle = 0;
78  sinus = 0.0;
79  cosinus = 0.0;
80  tangens = 0.0;
81  sinus2x = 0.0;
82  counter=0.0;
83  }
84 
85  if (privateSamples->size() >= 20) {
86  QVector<QVector<QPointF> > sampleVector = *privateSamples;
87  emit sendSampleVector(sampleVector);
88  privateSamples->clear();
89 
90 
91  }
92  }
93 }
95  condition=false;
96 }
97 
98 
100 
101  return state;
102 }
104  if (!state)
105  init();
106 }
108  state=false;
109  delete privateSamples;
110  delete sampleData;
111 }
112 
113 void EcgMock::init(){
114  state=true;
115  privateSamples = new QVector<QVector<QPointF> >;
116  sampleData = new QVector<QVector<double> >;
117 }
virtual void run()
Definition: ecgmock.cpp:47
void sendSampleVector(QVector< QVector< QPointF > >)
#define PI
Definition: ecgmock.h:50
virtual void getData(DataStream &)
Definition: ecgmock.cpp:28
virtual void reconnect()
sets state=true
Definition: ecgmock.cpp:103
void updateStatus(QString)
Abstract Interface that should be used for storing data in the memory.
Definition: datastream.h:16
virtual ~EcgMock()
Definition: ecgmock.cpp:19
DataStream & stream
Struct to store Biosignal data from a specific time, combined with DataStream it will store a sequenc...
EcgMock(DataStream &inputStream)
Definition: ecgmock.cpp:15
virtual void close()
sets state=false
Definition: ecgmock.cpp:107
Abstract interface for all devices.
virtual void stop()
Definition: ecgmock.cpp:94
virtual bool connected()
true as long as close() isn&#39;t called.
Definition: ecgmock.cpp:99