Skip to content

Commit a67ff2f

Browse files
committed
Empty implementation of the ContinousMeasurementDataProtocol class
Details: - Breaking up the DataProcessingInterface to: - ProtocolInterface - DataProcessingInterface - DataExportingInterface - Adding the empty CMDP implementation - Adapting the MDP implementation to the new interfaces
1 parent c7f2d2c commit a67ff2f

9 files changed

+396
-45
lines changed

RDB_Diplomaterv_Monitor.pro

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ TEMPLATE = subdirs
2626
message(===============================)
2727
message(=== RDB Diplomaterv Monitor ===)
2828
message(===============================)
29-
message()
3029
message(Qt version: $$[QT_VERSION])
3130
message(Qt is installed in $$[QT_INSTALL_PREFIX])
3231
message(Qt resources can be found in the following locations:)

application/application.pro

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,40 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
3838
QMAKE_CXXFLAGS += -std=c++17
3939

4040
# Source files of the target
41-
SOURCES += \
42-
sources/backend.cpp \
43-
sources/configuration.cpp \
44-
sources/data_line.cpp \
45-
sources/data_point.cpp \
46-
sources/diagram.cpp \
47-
sources/diagram_container.cpp \
48-
sources/main.cpp \
49-
sources/main_window.cpp \
50-
sources/measurement_data_protocol.cpp \
51-
sources/network_handler.cpp \
41+
SOURCES += \
42+
sources/backend.cpp \
43+
sources/configuration.cpp \
44+
sources/continous_measurement_data_protocol.cpp \
45+
sources/data_line.cpp \
46+
sources/data_point.cpp \
47+
sources/diagram.cpp \
48+
sources/diagram_container.cpp \
49+
sources/main.cpp \
50+
sources/main_window.cpp \
51+
sources/measurement_data_protocol.cpp \
52+
sources/network_handler.cpp \
5253
sources/serial_port.cpp
5354

5455
# Header files of the target
55-
HEADERS += \
56-
sources/backend.hpp \
57-
sources/backend_signal_interface.hpp \
58-
sources/configuration.hpp \
59-
sources/data_connection_interface.hpp \
60-
sources/data_line.hpp \
61-
sources/data_point.hpp \
62-
sources/data_processing_interface.hpp \
63-
sources/diagram.hpp \
64-
sources/diagram_container.hpp \
65-
sources/global.hpp \
66-
sources/gui_signal_interface.hpp \
67-
sources/main_window.hpp \
68-
sources/measurement_data_protocol.hpp \
69-
sources/network_connection_interface.hpp \
70-
sources/network_handler.hpp \
56+
HEADERS += \
57+
sources/backend.hpp \
58+
sources/backend_signal_interface.hpp \
59+
sources/configuration.hpp \
60+
sources/continous_measurement_data_protocol.hpp \
61+
sources/data_connection_interface.hpp \
62+
sources/data_exporting_interface.hpp \
63+
sources/data_line.hpp \
64+
sources/data_point.hpp \
65+
sources/data_processing_interface.hpp \
66+
sources/diagram.hpp \
67+
sources/diagram_container.hpp \
68+
sources/global.hpp \
69+
sources/gui_signal_interface.hpp \
70+
sources/main_window.hpp \
71+
sources/measurement_data_protocol.hpp \
72+
sources/network_connection_interface.hpp \
73+
sources/network_handler.hpp \
74+
sources/protocol_interface.hpp \
7175
sources/serial_port.hpp
7276

7377
RESOURCES = ../resources.qrc
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
//==============================================================================//
2+
// //
3+
// RDB Diplomaterv Monitor //
4+
// A monitor program for the RDB Diplomaterv project //
5+
// Copyright (C) 2018 András Gergő Kocsis //
6+
// //
7+
// This program is free software: you can redistribute it and/or modify //
8+
// it under the terms of the GNU General Public License as published by //
9+
// the Free Software Foundation, either version 3 of the License, or //
10+
// (at your option) any later version. //
11+
// //
12+
// This program is distributed in the hope that it will be useful, //
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15+
// GNU General Public License for more details. //
16+
// //
17+
// You should have received a copy of the GNU General Public License //
18+
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
19+
// //
20+
//==============================================================================//
21+
22+
23+
24+
#include "continous_measurement_data_protocol.hpp"
25+
26+
27+
28+
ContinousMeasurementDataProtocol::ContinousMeasurementDataProtocol()
29+
{
30+
state = Constants::States::WaitingForTransmission;
31+
}
32+
33+
std::string ContinousMeasurementDataProtocol::GetProtocolName(void)
34+
{
35+
return std::string(Constants::protocol_name);
36+
}
37+
38+
std::vector<DiagramSpecialized> ContinousMeasurementDataProtocol::ProcessData(std::istream& input_data)
39+
{
40+
std::vector<DiagramSpecialized> assembled_diagrams;
41+
std::string received_data;
42+
std::string actual_line;
43+
44+
/*
45+
while(std::getline(input_data, actual_line))
46+
{
47+
std::smatch match_results;
48+
49+
// Removing the whitespaces from the actual line
50+
actual_line.erase(std::remove_if(actual_line.begin(), actual_line.end(), isspace), actual_line.end());
51+
52+
try
53+
{
54+
switch(state)
55+
{
56+
case Constants::States::WaitingForStartLine:
57+
// If a start line was found...
58+
if(std::regex_match(actual_line, std::regex(Constants::Regex::start_line)))
59+
{
60+
state = Constants::States::ProcessingTitleLine;
61+
}
62+
break;
63+
case Constants::States::ProcessingTitleLine:
64+
// In any case, we will switch to the next state
65+
state = Constants::States::ProcessingHeadline;
66+
// If this is a diagram title line
67+
if(std::regex_search(actual_line, match_results, std::regex(Constants::Regex::title_line)))
68+
{
69+
// Then we create a diagram object with the title
70+
actual_diagram = DiagramSpecialized(match_results[1]);
71+
// Switching to the next state with a break --> a new line will be fetched
72+
break;
73+
}
74+
else
75+
{
76+
// No title was found, we will generate a title from the current date and time and create a diagram object with it
77+
auto current_date_and_time = std::time(nullptr);
78+
std::string current_date_and_time_string = ctime(&current_date_and_time);
79+
// The ctime adds an extra newline to the string, this needs to be removed
80+
current_date_and_time_string.pop_back();
81+
actual_diagram = DiagramSpecialized(current_date_and_time_string);
82+
// Switching to the next state without a break --> a new line will NOT be fetched, because this line is the headline
83+
}
84+
85+
// The falltrough is not an error in this case, this behaviour needed because there was no diagram title found, the actual_line contains the headline
86+
[[fallthrough]];
87+
case Constants::States::ProcessingHeadline:
88+
// If this is a headline but not a dataline
89+
// (this is needed because with regex it is difficult to define the differences between the data and headlines)
90+
if((std::regex_match(actual_line, std::regex(Constants::Regex::headline))) &&
91+
(!std::regex_match(actual_line, std::regex(Constants::Regex::data_line))))
92+
{
93+
std::string headline = actual_line;
94+
DataIndexType column_index = 0;
95+
96+
// Collecting the labels from the headline
97+
while(std::regex_search(headline, match_results, std::regex(Constants::Regex::headline_analyzer)))
98+
{
99+
if(0 == column_index)
100+
{
101+
actual_diagram.SetAxisXTitle(match_results[1]);
102+
}
103+
else
104+
{
105+
actual_diagram.AddNewDataLine(match_results[1]);
106+
}
107+
108+
++column_index;
109+
headline = match_results.suffix().str();
110+
}
111+
112+
state = Constants::States::ProcessingDataLines;
113+
}
114+
else
115+
{
116+
state = Constants::States::WaitingForStartLine;
117+
}
118+
break;
119+
case Constants::States::ProcessingDataLines:
120+
if(std::regex_match(actual_line, std::regex(Constants::Regex::data_line)))
121+
{
122+
std::string data_line = actual_line;
123+
DataIndexType column_index = 0;
124+
DataPointType data_point_x_value = 0;
125+
126+
// Collecting the data from the dataline
127+
while(std::regex_search(data_line, match_results, std::regex(Constants::Regex::data_line_analyzer)))
128+
{
129+
if(0 == column_index)
130+
{
131+
std::stringstream stringstream(match_results[1]);
132+
stringstream >> data_point_x_value;
133+
}
134+
else
135+
{
136+
if((column_index - 1) < actual_diagram.GetTheNumberOfDataLines())
137+
{
138+
std::stringstream stringstream(match_results[1]);
139+
DataPointType data_point_y_value;
140+
stringstream >> data_point_y_value;
141+
actual_diagram.AddNewDataPoint((column_index - 1), DataPointSpecialized(data_point_x_value, data_point_y_value));
142+
}
143+
else
144+
{
145+
state = Constants::States::WaitingForStartLine;
146+
break;
147+
}
148+
}
149+
150+
++column_index;
151+
data_line = match_results.suffix().str();
152+
}
153+
if((column_index - 1) != actual_diagram.GetTheNumberOfDataLines())
154+
{
155+
state = Constants::States::WaitingForStartLine;
156+
}
157+
}
158+
else
159+
{
160+
if(std::regex_match(actual_line, std::regex(Constants::Regex::end_line)))
161+
{
162+
assembled_diagrams.push_back(actual_diagram);
163+
}
164+
state = Constants::States::WaitingForStartLine;
165+
}
166+
break;
167+
default:
168+
state = Constants::States::WaitingForStartLine;
169+
throw("The DataProcessor::ProcessData's statemachine switched to an unexpected state: " + std::to_string(static_cast<std::underlying_type<Constants::States>::type>(state)));
170+
break;
171+
}
172+
}
173+
catch(const std::regex_error& exception)
174+
{
175+
throw("A regex exception was caught: " + std::to_string(exception.code()) + ": " + exception.what());
176+
}
177+
}
178+
*/
179+
180+
return assembled_diagrams;
181+
}
182+
183+
bool ContinousMeasurementDataProtocol::CanThisFileBeProcessed(const std::string path_to_file)
184+
{
185+
(void) path_to_file;
186+
187+
// The CMDP can not process files
188+
return false;
189+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//==============================================================================//
2+
// //
3+
// RDB Diplomaterv Monitor //
4+
// A monitor program for the RDB Diplomaterv project //
5+
// Copyright (C) 2018 András Gergő Kocsis //
6+
// //
7+
// This program is free software: you can redistribute it and/or modify //
8+
// it under the terms of the GNU General Public License as published by //
9+
// the Free Software Foundation, either version 3 of the License, or //
10+
// (at your option) any later version. //
11+
// //
12+
// This program is distributed in the hope that it will be useful, //
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15+
// GNU General Public License for more details. //
16+
// //
17+
// You should have received a copy of the GNU General Public License //
18+
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
19+
// //
20+
//==============================================================================//
21+
22+
23+
24+
#include <iostream>
25+
#include <memory>
26+
#include <string>
27+
#include <sstream>
28+
#include <algorithm>
29+
#include <functional>
30+
#include <ctime>
31+
#include <cctype>
32+
#include <regex>
33+
#include <type_traits>
34+
35+
#include <QFileInfo>
36+
37+
#include "global.hpp"
38+
#include "data_processing_interface.hpp"
39+
#include "diagram.hpp"
40+
41+
42+
43+
#ifndef CONTINOUS_MEAUREMENT_DATA_PROTOCOL_HPP
44+
#define CONTINOUS_MEAUREMENT_DATA_PROTOCOL_HPP
45+
46+
47+
48+
class ContinousMeasurementDataProtocol : public DataProcessingInterface
49+
{
50+
public:
51+
ContinousMeasurementDataProtocol();
52+
virtual ~ContinousMeasurementDataProtocol() = default;
53+
54+
ContinousMeasurementDataProtocol(const ContinousMeasurementDataProtocol&) = delete;
55+
ContinousMeasurementDataProtocol(ContinousMeasurementDataProtocol&&) = delete;
56+
57+
ContinousMeasurementDataProtocol& operator=(const ContinousMeasurementDataProtocol&) = delete;
58+
ContinousMeasurementDataProtocol& operator=(ContinousMeasurementDataProtocol&&) = delete;
59+
60+
std::string GetProtocolName(void) override;
61+
std::vector<DiagramSpecialized> ProcessData(std::istream& input_data) override;
62+
bool CanThisFileBeProcessed(const std::string path_to_file) override;
63+
std::string GetSupportedFileType(void) override {return Constants::native_file_extension;}
64+
65+
private:
66+
struct Constants
67+
{
68+
static constexpr char protocol_name[] = "Continous Measurement Data Protocol CMDP";
69+
static constexpr char native_file_extension[] = "cmdp";
70+
71+
enum class States : uint8_t
72+
{
73+
WaitingForTransmission
74+
};
75+
};
76+
77+
Constants::States state;
78+
DiagramSpecialized actual_diagram;
79+
};
80+
81+
82+
83+
#endif // CONTINOUS_MEAUREMENT_DATA_PROTOCOL_HPP
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
//==============================================================================//
2+
// //
3+
// RDB Diplomaterv Monitor //
4+
// A monitor program for the RDB Diplomaterv project //
5+
// Copyright (C) 2018 András Gergő Kocsis //
6+
// //
7+
// This program is free software: you can redistribute it and/or modify //
8+
// it under the terms of the GNU General Public License as published by //
9+
// the Free Software Foundation, either version 3 of the License, or //
10+
// (at your option) any later version. //
11+
// //
12+
// This program is distributed in the hope that it will be useful, //
13+
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
14+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
15+
// GNU General Public License for more details. //
16+
// //
17+
// You should have received a copy of the GNU General Public License //
18+
// along with this program. If not, see <https://www.gnu.org/licenses/>. //
19+
// //
20+
//==============================================================================//
21+
22+
23+
24+
#include <vector>
25+
#include <string>
26+
27+
#include "global.hpp"
28+
#include "protocol_interface.hpp"
29+
30+
31+
32+
#ifndef DATA_EXPORTING_INTERFACE_HPP
33+
#define DATA_EXPORTING_INTERFACE_HPP
34+
35+
36+
37+
class DataExportingInterface: public ProtocolInterface
38+
{
39+
public:
40+
virtual std::stringstream ExportData(const std::vector<DiagramSpecialized>& diagrams_to_export) = 0;
41+
};
42+
43+
#endif // DATA_EXPORTING_INTERFACE_HPP

0 commit comments

Comments
 (0)