BioSignalPi  v2
datalogger.cpp
Go to the documentation of this file.
1 #include "datalogger.h"
2 #include "settingssingleton.h"
3 #include <QDebug>
4 #include <iostream>
5 #include "ecgstreamobject.h"
6 #include <QFile>
7 
8 
9 DataLogger::DataLogger(QObject *parent) : QObject(parent)
10 {
11 
12 }
13 
15 
16 }
22  saveAsText(input);
23 
24  if (SettingsSingleton::instance().getSaveAsEdf()){
25  saveAsEdf(input);
26  }
27 }
36 void DataLogger::saveAsText(DataStream &input){
37 
38 
39  QFile outFileHeader(SettingsSingleton::instance().getFileName()+"_header.txt");
40 
41  if (!outFileHeader.open(QIODevice::WriteOnly | QIODevice::Text)) {
42  emit updateStatus("Failed to open data file for write!");
43  std::cerr << "Failed to open header-data file for write!!" << endl;
44  } else {
45  QTextStream outHeader(&outFileHeader);
46 
47  outHeader << "[ECG CAPTURE SETTINGS]\n"
48  << "Filename: " << SettingsSingleton::instance().getFileName() << ".txt \n"
49  << "Samples: " << QString::number(input.size()) << "\n"
50  << "Duration: " << QString::number(input.back().time) << "ms \n"
51  << "Sample rate: " << QString::number(SettingsSingleton::instance().getSampleRate()) << " Hz\n"
52  << "Source: " << SettingsSingleton::instance().getSource() << "\n"
53  << "\n[RECORDING INFORMATION]\n"
54  << "Recording name: " << SettingsSingleton::instance().getRecordingName() << "\n"
55  << "Patient code: " << SettingsSingleton::instance().getPatientCode() << "\n"
56  << "Name: " << SettingsSingleton::instance().getName() << "\n"
57  << "Gender: " << SettingsSingleton::instance().getGender() << "\n"
58  << "Birthdate: " << SettingsSingleton::instance().getBirthDate() << "\n"
59  << "Notes: " << SettingsSingleton::instance().getNotes() << "\n";
60 
61  outFileHeader.close();
62 
63  }
64 
65  QFile outFile(SettingsSingleton::instance().getFileName() + ".txt");
66 
67  if (!outFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
68  emit updateStatus("Failed to open data file for write!");
69  std::cerr << "Failed to open data file for write" << std::endl;
70  } else {
71  QTextStream out(&outFile);
72 
73  emit updateStatus(QString("Writing " + QString::number(input.size()) + " samples to " + SettingsSingleton::instance().getFileName() + "..."));
74  qDebug() << "Writing " << input.size() << " samples to " << SettingsSingleton::instance().getFileName() << "..." << endl;
75 
76  for (int i ; i<input.size();i++){
77  const EcgStreamObject tmp=input.at(i);
78  out << tmp.toText() << endl; //"\n";
79 
80 
81  }
82 
83  emit updateStatus(QString("Samples saved in text format"));
84  std::cerr << "Samples saved in text format" << std::endl;
85 
86  outFile.close();
87  }
88 
89 
90 
91 }
98 void DataLogger::saveAsEdf(DataStream &input){
99  qDebug() << "Save as EDF not implemented yet" << endl;
100  updateStatus("Save as EDF not implemented yet");
101 
102 
103 }
QString getPatientCode()
Returns a QString containing the value from private QString patientCode.
int getSampleRate()
Returns a int containing the value from private int sampleRate.
QString getRecordingName()
Returns a QString containing the value from private QString recordingName.
void updateStatus(QString status)
Signal emitting status messages during the process.
QString getSource()
Returns a QString containing the value from private QString source.
QString getName()
Returns a QString containing the value from private QString name.
static SettingsSingleton & instance()
Retrives a reference to the ONE and ONLY SettingsSingleton created for the application.
QString getFileName()
Returns a QString containing the value from private QString fileName.
DataLogger(QObject *parent=0)
Definition: datalogger.cpp:9
void save(DataStream &input)
Saves the input to a txt-file, header-file and edf-file(if bool saveAsEdf in SettingsSingleton) ...
Definition: datalogger.cpp:21
Abstract Interface that should be used for storing data in the memory.
Definition: datastream.h:16
virtual QString toText() const
Converts the data from the struct into a QString representation.
Struct to store Biosignal data from a specific time, combined with DataStream it will store a sequenc...
QString getGender()
Returns a QString containing the value from private QString gender.
QString getNotes()
Returns a QString containing the value from private QString notes.
QString getBirthDate()
Returns a QString containing the value from private QString birthDate.