27
27
28
28
ContinousMeasurementDataProtocol::ContinousMeasurementDataProtocol ()
29
29
{
30
- state = Constants::States::WaitingForTransmission ;
30
+ state = Constants::States::WaitingForHeaderMessageStart ;
31
31
}
32
32
33
33
std::string ContinousMeasurementDataProtocol::GetProtocolName (void )
@@ -41,7 +41,6 @@ std::vector<DiagramSpecialized> ContinousMeasurementDataProtocol::ProcessData(st
41
41
std::string received_data;
42
42
std::string actual_line;
43
43
44
- /*
45
44
while (std::getline (input_data, actual_line))
46
45
{
47
46
std::smatch match_results;
@@ -53,18 +52,17 @@ std::vector<DiagramSpecialized> ContinousMeasurementDataProtocol::ProcessData(st
53
52
{
54
53
switch (state)
55
54
{
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 )))
55
+ case Constants::States::WaitingForHeaderMessageStart :
56
+ // If a header message start line was found
57
+ if (std::regex_match (actual_line, std::regex (Constants::Regex::header_start )))
59
58
{
60
- state = Constants::States::ProcessingTitleLine ;
59
+ state = Constants::States::ProcessingHeaderDiagramTitle ;
61
60
}
62
61
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)))
62
+ case Constants::States::ProcessingHeaderDiagramTitle:
63
+ state = Constants::States::ProcessingHeaderDataLines;
64
+ // If a header message diagram title line was found
65
+ if (std::regex_search (actual_line, match_results, std::regex (Constants::Regex::header_diagram_title)))
68
66
{
69
67
// Then we create a diagram object with the title
70
68
actual_diagram = DiagramSpecialized (match_results[1 ]);
@@ -81,50 +79,63 @@ std::vector<DiagramSpecialized> ContinousMeasurementDataProtocol::ProcessData(st
81
79
actual_diagram = DiagramSpecialized (current_date_and_time_string);
82
80
// Switching to the next state without a break --> a new line will NOT be fetched, because this line is the headline
83
81
}
84
-
85
82
// 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))))
83
+ [[fallthrough]];
84
+ case Constants::States::ProcessingHeaderDataLines:
85
+ if (std::regex_match (actual_line, std::regex (Constants::Regex::header_datalines)))
92
86
{
93
- std::string headline = actual_line;
94
- DataIndexType column_index = 0;
87
+ std::string header_data_lines = actual_line;
95
88
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
- }
89
+ // Extracting the title of the X axis
90
+ std::regex_search (header_data_lines, match_results, std::regex (Constants::Regex::header_dataline_x));
91
+ actual_diagram.SetAxisXTitle (match_results[1 ]);
92
+ header_data_lines = match_results.suffix ().str ();
107
93
108
- ++column_index;
109
- headline = match_results.suffix().str();
94
+ // Extracting the title of the Y axis
95
+ while (std::regex_search (header_data_lines, match_results, std::regex (Constants::Regex::header_dataline_y)))
96
+ {
97
+ actual_diagram.AddNewDataLine (match_results[1 ], match_results[2 ]);
98
+ header_data_lines = match_results.suffix ().str ();
110
99
}
111
-
112
- state = Constants::States::ProcessingDataLines;
100
+ state = Constants::States::WaitingForHeaderMessageEnd;
113
101
}
114
102
else
115
103
{
116
- state = Constants::States::WaitingForStartLine ;
104
+ state = Constants::States::WaitingForHeaderMessageStart ;
117
105
}
118
106
break ;
119
- case Constants::States::ProcessingDataLines:
120
- if(std::regex_match(actual_line, std::regex(Constants::Regex::data_line)))
107
+ case Constants::States::WaitingForHeaderMessageEnd:
108
+ // If a header message end line was found
109
+ if (std::regex_match (actual_line, std::regex (Constants::Regex::header_end)))
110
+ {
111
+ state = Constants::States::WaitingForDataMessageStart;
112
+ }
113
+ else
114
+ {
115
+ state = Constants::States::WaitingForHeaderMessageStart;
116
+ }
117
+ break ;
118
+ case Constants::States::WaitingForDataMessageStart:
119
+ // If a header message end line was found
120
+ if (std::regex_match (actual_line, std::regex (Constants::Regex::data_start)))
121
+ {
122
+ state = Constants::States::ProcessingDataMessageContent;
123
+ }
124
+ else if (std::regex_match (actual_line, std::regex (Constants::Regex::tail)))
125
+ {
126
+ assembled_diagrams.push_back (actual_diagram);
127
+ state = Constants::States::WaitingForHeaderMessageStart;
128
+ }
129
+ break ;
130
+ case Constants::States::ProcessingDataMessageContent:
131
+ if (std::regex_match (actual_line, std::regex (Constants::Regex::data_datalines)))
121
132
{
122
133
std::string data_line = actual_line;
123
134
DataIndexType column_index = 0 ;
124
135
DataPointType data_point_x_value = 0 ;
125
136
126
137
// Collecting the data from the dataline
127
- while(std::regex_search(data_line, match_results, std::regex(Constants::Regex::data_line_analyzer )))
138
+ while (std::regex_search (data_line, match_results, std::regex (Constants::Regex::data_datalines )))
128
139
{
129
140
if (0 == column_index)
130
141
{
@@ -142,7 +153,7 @@ std::vector<DiagramSpecialized> ContinousMeasurementDataProtocol::ProcessData(st
142
153
}
143
154
else
144
155
{
145
- state = Constants::States::WaitingForStartLine ;
156
+ state = Constants::States::WaitingForHeaderMessageStart ;
146
157
break ;
147
158
}
148
159
}
@@ -152,20 +163,23 @@ std::vector<DiagramSpecialized> ContinousMeasurementDataProtocol::ProcessData(st
152
163
}
153
164
if ((column_index - 1 ) != actual_diagram.GetTheNumberOfDataLines ())
154
165
{
155
- state = Constants::States::WaitingForStartLine ;
166
+ state = Constants::States::WaitingForHeaderMessageStart ;
156
167
}
157
168
}
158
169
else
159
170
{
160
- if(std::regex_match(actual_line, std::regex(Constants::Regex::end_line)))
171
+ if (std::regex_match (actual_line, std::regex (Constants::Regex::data_end)))
172
+ {
173
+ state = Constants::States::WaitingForDataMessageStart;
174
+ }
175
+ else
161
176
{
162
- assembled_diagrams.push_back(actual_diagram) ;
177
+ state = Constants::States::WaitingForHeaderMessageStart ;
163
178
}
164
- state = Constants::States::WaitingForStartLine;
165
179
}
166
180
break ;
167
181
default :
168
- state = Constants::States::WaitingForStartLine ;
182
+ state = Constants::States::WaitingForHeaderMessageStart ;
169
183
throw (" The DataProcessor::ProcessData's statemachine switched to an unexpected state: " + std::to_string (static_cast <std::underlying_type<Constants::States>::type>(state)));
170
184
break ;
171
185
}
@@ -175,15 +189,20 @@ std::vector<DiagramSpecialized> ContinousMeasurementDataProtocol::ProcessData(st
175
189
throw (" A regex exception was caught: " + std::to_string (exception.code ()) + " : " + exception.what ());
176
190
}
177
191
}
178
- */
179
192
180
193
return assembled_diagrams;
181
194
}
182
195
183
196
bool ContinousMeasurementDataProtocol::CanThisFileBeProcessed (const std::string path_to_file)
184
197
{
185
- (void ) path_to_file;
198
+ bool bResult = false ;
199
+
200
+ std::string file_extension = QFileInfo (QString::fromStdString (path_to_file)).completeSuffix ().toStdString ();
201
+
202
+ if (std::string (Constants::native_file_extension) == file_extension)
203
+ {
204
+ bResult = true ;
205
+ }
186
206
187
- // The CMDP can not process files
188
- return false ;
207
+ return bResult;
189
208
}
0 commit comments