summaryrefslogtreecommitdiffstats
path: root/server/src/datex2.cpp
diff options
context:
space:
mode:
authorRutger Broekhoff2026-11-30 11:47:36 +0100
committerRutger Broekhoff2026-11-30 11:47:36 +0100
commit02475e05ccd1aa15c6a6163834f28bfebbef796f (patch)
tree6bc6f453f07dc76f763310e1e5eade9a3e1115b7 /server/src/datex2.cpp
parent5732f6c14618f50ffaf315b93795340219a67c66 (diff)
downloadroutemon-02475e05ccd1aa15c6a6163834f28bfebbef796f.tar.gz
routemon-02475e05ccd1aa15c6a6163834f28bfebbef796f.zip
RWGPS webhook and such
Diffstat (limited to 'server/src/datex2.cpp')
-rw-r--r--server/src/datex2.cpp63
1 files changed, 39 insertions, 24 deletions
diff --git a/server/src/datex2.cpp b/server/src/datex2.cpp
index 70c5f94..ab49fd9 100644
--- a/server/src/datex2.cpp
+++ b/server/src/datex2.cpp
@@ -14,11 +14,11 @@ using namespace std::literals::string_view_literals;
14 14
15namespace routemon::datex2 { 15namespace routemon::datex2 {
16 16
17auto parse_timestamp(char const* in) -> std::optional<time::timestamp> 17auto parse_timestamp_secs(char const* in) -> std::optional<time::timestamp<>>
18{ 18{
19 auto res = time::timestamp{}; 19 auto res = time::timestamp<>{};
20 auto is = std::istringstream{in}; 20 auto is = std::istringstream{in};
21 is >> std::chrono::parse("%Y-%m-%dT%H:%M:%SZ", res); 21 is >> std::chrono::parse("%FT%TZ", res);
22 return is.fail() ? std::nullopt : std::make_optional(res); 22 return is.fail() ? std::nullopt : std::make_optional(res);
23} 23}
24 24
@@ -178,7 +178,7 @@ auto loader::handle_road_or_carriageway_or_lane_management(
178 178
179 //---- Check if within the defined validity period 179 //---- Check if within the defined validity period
180 180
181 auto validity = std::optional<time::period_seq>{}; 181 auto validity = std::optional<time::period_seq<std::chrono::minutes>>{};
182 auto const& validity_xml = record_xml.child("sit:validity"); 182 auto const& validity_xml = record_xml.child("sit:validity");
183 if (validity_xml 183 if (validity_xml
184 && validity_xml.child_value("com:validityStatus") 184 && validity_xml.child_value("com:validityStatus")
@@ -187,52 +187,67 @@ auto loader::handle_road_or_carriageway_or_lane_management(
187 auto const& validity_spec_xml = 187 auto const& validity_spec_xml =
188 validity_xml.child("com:validityTimeSpecification"); 188 validity_xml.child("com:validityTimeSpecification");
189 189
190 auto valid_periods = std::vector<time::period>{}; 190 auto valid_periods = std::vector<time::period<std::chrono::minutes>>{};
191 auto exception_periods = std::vector<time::period>{}; 191 auto exception_periods = std::vector<time::period<std::chrono::minutes>>{};
192 192
193 // TODO: com:overallEndTime may be missing (according to the DATEX 193 // TODO: com:overallEndTime may be missing (according to the DATEX
194 // II v3 data model) 194 // II v3 data model)
195 auto const overall_start_time = 195 auto const overall_start_time = parse_timestamp_secs(
196 parse_timestamp(validity_spec_xml.child_value("com:overallStartTime")); 196 validity_spec_xml.child_value("com:overallStartTime"));
197 auto const overall_end_time = 197 auto const overall_end_time = parse_timestamp_secs(
198 parse_timestamp(validity_spec_xml.child_value("com:overallEndTime")); 198 validity_spec_xml.child_value("com:overallEndTime"));
199 if (overall_start_time && overall_end_time 199 if (overall_start_time && overall_end_time
200 && *overall_start_time < *overall_end_time) 200 && *overall_start_time < *overall_end_time)
201 { 201 {
202 valid_periods.emplace_back(*overall_start_time, *overall_end_time); 202 valid_periods.emplace_back(
203 std::chrono::time_point_cast<std::chrono::minutes>(
204 *overall_start_time),
205 std::chrono::time_point_cast<std::chrono::minutes>(
206 *overall_end_time));
203 207
204 for (auto const valid_period_xml : 208 for (auto const valid_period_xml :
205 validity_xml.children("com:validPeriod")) 209 validity_xml.children("com:validPeriod"))
206 { 210 {
207 auto const start_of_period = 211 auto const start_of_period = parse_timestamp_secs(
208 parse_timestamp(valid_period_xml.child_value("com:startOfPeriod")); 212 valid_period_xml.child_value("com:startOfPeriod"));
209 auto const end_of_period = 213 auto const end_of_period = parse_timestamp_secs(
210 parse_timestamp(valid_period_xml.child_value("com:endOfPeriod")); 214 valid_period_xml.child_value("com:endOfPeriod"));
211 if (start_of_period && end_of_period 215 if (start_of_period && end_of_period
212 && *start_of_period < *end_of_period) 216 && *start_of_period < *end_of_period)
213 { 217 {
214 valid_periods.emplace_back(*start_of_period, *end_of_period); 218 valid_periods.emplace_back(
219 std::chrono::time_point_cast<std::chrono::minutes>(
220 *start_of_period),
221 std::chrono::time_point_cast<std::chrono::minutes>(
222 *end_of_period));
215 } 223 }
216 } 224 }
217 for (auto const exception_period_xml : 225 for (auto const exception_period_xml :
218 validity_xml.children("com:exceptionPeriod")) 226 validity_xml.children("com:exceptionPeriod"))
219 { 227 {
220 auto const start_of_period = parse_timestamp( 228 auto const start_of_period = parse_timestamp_secs(
221 exception_period_xml.child_value("com:startOfPeriod")); 229 exception_period_xml.child_value("com:startOfPeriod"));
222 auto const end_of_period = parse_timestamp( 230 auto const end_of_period = parse_timestamp_secs(
223 exception_period_xml.child_value("com:endOfPeriod")); 231 exception_period_xml.child_value("com:endOfPeriod"));
224 if (start_of_period && end_of_period 232 if (start_of_period && end_of_period
225 && *start_of_period < *end_of_period) 233 && *start_of_period < *end_of_period)
226 { 234 {
227 exception_periods.emplace_back(*start_of_period, *end_of_period); 235 exception_periods.emplace_back(
236 std::chrono::time_point_cast<std::chrono::minutes>(
237 *start_of_period),
238 std::chrono::time_point_cast<std::chrono::minutes>(
239 *end_of_period));
228 } 240 }
229 } 241 }
230 242
231 validity = 243 validity =
232 time::period_seq{valid_periods.begin(), valid_periods.end()}.except( 244 time::period_seq<std::chrono::minutes>{
233 time::period_seq{ 245 valid_periods.begin(), valid_periods.end()
234 exception_periods.begin(), exception_periods.end() 246 }
235 }); 247 .except(
248 time::period_seq<std::chrono::minutes>{
249 exception_periods.begin(), exception_periods.end()
250 });
236 } 251 }
237 else 252 else
238 { 253 {
@@ -263,7 +278,7 @@ auto loader::load_situation_publication(std::string const& filename)
263 } 278 }
264 auto payload_xml = doc.child("mc:messageContainer").child("mc:payload"); 279 auto payload_xml = doc.child("mc:messageContainer").child("mc:payload");
265 auto mpublication_time = 280 auto mpublication_time =
266 parse_timestamp(payload_xml.child_value("com:publicationTime")); 281 parse_timestamp_secs(payload_xml.child_value("com:publicationTime"));
267 if (!mpublication_time) 282 if (!mpublication_time)
268 throw std::runtime_error{ 283 throw std::runtime_error{
269 "provided publication does not name publication time" 284 "provided publication does not name publication time"