summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2022-10-03 08:04:36 +0200
committerDaniel Friesel <derf@finalrewind.org>2022-10-03 08:04:36 +0200
commit4a3feb4cb5f97e5ae992bca9b34042c162580238 (patch)
tree19d16663f8fc66444425f5d16810a1a4be5a8f36
parent5c2e92955a045a1245123629ca0915b0b9bfd213 (diff)
mgate: add message support
-rwxr-xr-xbin/hafas-m13
-rw-r--r--lib/Travel/Status/DE/HAFAS.pm38
-rw-r--r--lib/Travel/Status/DE/HAFAS/Message.pm3
3 files changed, 49 insertions, 5 deletions
diff --git a/bin/hafas-m b/bin/hafas-m
index 95e01a9..d4590f6 100755
--- a/bin/hafas-m
+++ b/bin/hafas-m
@@ -185,10 +185,10 @@ sub display_result {
print "\n";
$first_message = 0;
}
- printf( "# %s\n", $msg->header );
- if ( $msg->lead ) {
- printf( "# %s\n", $msg->lead );
+ if ( $msg->short ) {
+ printf( "# %s\n", $msg->short );
}
+ printf( "# %s\n", $msg->text );
}
}
@@ -219,7 +219,12 @@ my $message_id = 1;
for my $m ( $status->messages ) {
if ( $m->ref_count > 1 ) {
$m->{id} = $message_id++;
- printf( "# (%d) %s\n# %s\n\n", $m->{id}, $m->header, $m->lead );
+ if ( $m->short ) {
+ printf( "# (%d) %s\n# %s\n\n", $m->{id}, $m->short, $m->text );
+ }
+ else {
+ printf( "# (%d) %s\n\n", $m->{id}, $m->text );
+ }
}
}
diff --git a/lib/Travel/Status/DE/HAFAS.pm b/lib/Travel/Status/DE/HAFAS.pm
index 8d6c81b..e67c72b 100644
--- a/lib/Travel/Status/DE/HAFAS.pm
+++ b/lib/Travel/Status/DE/HAFAS.pm
@@ -497,6 +497,32 @@ sub similar_stops {
return;
}
+sub add_message {
+ my ( $self, $json ) = @_;
+
+ my $short = $json->{txtS};
+ my $text = $json->{txtN};
+ my $code = $json->{code};
+ my $prio = $json->{prio};
+
+ for my $message ( @{ $self->{messages} } ) {
+ if ( $code eq $message->{code} and $text eq $message->{text} ) {
+ $message->{ref_count}++;
+ return $message;
+ }
+ }
+
+ my $message = Travel::Status::DE::HAFAS::Message->new(
+ short => $short,
+ text => $text,
+ code => $code,
+ prio => $prio,
+ ref_count => 1,
+ );
+ push( @{ $self->{messages} }, $message );
+ return $message;
+}
+
sub add_message_node {
my ( $self, $node ) = @_;
@@ -623,6 +649,7 @@ sub parse_mgate {
my @prodL = @{ $self->{raw_json}{svcResL}[0]{res}{common}{prodL} // [] };
my @opL = @{ $self->{raw_json}{svcResL}[0]{res}{common}{opL} // [] };
my @icoL = @{ $self->{raw_json}{svcResL}[0]{res}{common}{icoL} // [] };
+ my @remL = @{ $self->{raw_json}{svcResL}[0]{res}{common}{remL} // [] };
my @jnyL = @{ $self->{raw_json}{svcResL}[0]{res}{jnyL} // [] };
for my $result (@jnyL) {
@@ -660,6 +687,16 @@ sub parse_mgate {
}
}
+ my @messages;
+ for my $msg ( @{ $result->{msgL} // [] } ) {
+ if ( $msg->{type} eq 'REM' and defined $msg->{remX} ) {
+ push( @messages, $self->add_message( $remL[ $msg->{remX} ] ) );
+ }
+ else {
+ say "Unknown message type $msg->{type}";
+ }
+ }
+
push(
@{ $self->{results} },
Travel::Status::DE::HAFAS::Result->new(
@@ -674,6 +711,7 @@ sub parse_mgate {
route_end => $destination,
platform => $platform,
new_platform => $new_platform,
+ messages => \@messages,
)
);
}
diff --git a/lib/Travel/Status/DE/HAFAS/Message.pm b/lib/Travel/Status/DE/HAFAS/Message.pm
index f691a94..bfbf0ba 100644
--- a/lib/Travel/Status/DE/HAFAS/Message.pm
+++ b/lib/Travel/Status/DE/HAFAS/Message.pm
@@ -8,7 +8,8 @@ use parent 'Class::Accessor';
our $VERSION = '3.01';
-Travel::Status::DE::HAFAS::Message->mk_ro_accessors(qw(header lead ref_count));
+Travel::Status::DE::HAFAS::Message->mk_ro_accessors(
+ qw(short text code prio ref_count));
sub new {
my ( $obj, %conf ) = @_;