summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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 ) = @_;