From 4a53c18869b0519046fdd8b59cde8e9c7479a023 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Sun, 4 Oct 2020 10:21:58 +0200 Subject: [PATCH] correctly parse Upstream return write parameter frame --- Protocol.pm | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Protocol.pm b/Protocol.pm index 829b7f0..3ec521d 100644 --- a/Protocol.pm +++ b/Protocol.pm @@ -210,12 +210,16 @@ sub protocol_decode { } elsif ( $up_down eq 'down' && $function_code == 0x03 ) { # type A + # 0x03 => 'Downstream read parameter frame', $data_range = substr($data,0,1); $data = substr($data,1); } elsif ( $up_down eq 'up' && ( $function_code == 0x07 || $function_code == 0x08 || $function_code == 0x03 ) ) { # type B + # 0x07 => 'Upstream Heartbeat Frame', + # 0x08 => 'Upstream alarm frame', + # 0x03 => 'Upstream Read Parameter Frame', $data_len = unpack('C', substr($data,1,1)); $data_range = substr($data,2, $data_len); @@ -224,6 +228,7 @@ sub protocol_decode { } elsif ( $up_down eq 'down' && $function_code == 0x06 ) { # type B + # 0x06 => 'Downstream write parameter frame', $data_len = unpack('C', substr($data,1,1)); $data_range = substr($data,2, $data_len); @@ -232,15 +237,21 @@ sub protocol_decode { } elsif ( $up_down eq 'up' && $function_code == 0x06 ) { # type C + # 0x06 => 'Upstream return write parameter frame', - # FIXME check first byte? - my $data_range = substr($data,1,1); + $data_len = unpack('C', substr($data,1,1)); + $data_range = substr($data,2, $data_len); + if ( $data_len == 1 ) { + # XXX return is OK/not OK + $pack_fmt = 'C'; + } - $data = substr($data,2); + $data = substr($data,2 + $data_len); } else { $hash->{error}->{function_code_unknown} = $function_code; - warn "ERROR unknown function_code = $function_code"; + print STDERR "ERROR unknown function_code = $function_code\n"; + return $hash; } my @v = unpack($pack_fmt, $data_range); -- 2.20.1