- dbg('agw', "AGW Heard port: $port \"$d\"");
- }
- } elsif ($sort eq 'X') {
- my ($r) = unpack "C", $data;
- $r = $r ? "Successful" : "Failed";
- dbg('err', "AGW Register $from $r");
- finish() unless $r;
- } elsif ($sort eq 'R') {
- my ($major, $minor) = unpack "v x2 v x2", $data;
- dbg('agw', "AGW Version $major.$minor");
- } elsif ($sort eq 'G') {
- my @ports = split /;/, $data;
- $noports = shift @ports || '0';
- dbg('agw', "AGW $noports Ports available");
- pop @ports while @ports > $noports;
- for (@ports) {
- next unless $_;
- dbg('agw', "AGW Port: $_");
- }
- for (my $i = 0; $i < $noports; $i++) {
- _sendf('y', undef, undef, $i );
+ dbg("AGW '$from'->'$to' port: $port Disconnected ($d)") if isdbg('agw');
+ my $conn = _find($from eq $main::mycall ? $to : $from);
+ if ($conn) {
+ &{$conn->{eproc}}() if $conn->{eproc};
+ $conn->in_disconnect;
+ }
+ } elsif ($sort eq 'y') {
+ my ($frames) = unpack "V", $data;
+ dbg("AGW Frames Outstanding on port $port = $frames") if isdbg('agwpollans');
+ my $conn = _find($from);
+ $conn->{oframes} = $frames if $conn;
+ } elsif ($sort eq 'Y') {
+ my ($frames) = unpack "V", $data;
+ dbg("AGW Frames Outstanding on circuit '$from'->'$to' = $frames") if isdbg('agw');
+ my $conn = _find($from eq $main::mycall ? $to : $from);
+ $conn->{oframes} = $frames if $conn;
+ } elsif ($sort eq 'H') {
+ unless ($from =~ /^\s+$/) {
+ my $d = unpack "Z*", $data;
+ $d =~ s/\cM$//;
+ dbg("AGW Heard port: $port \"$d\"") if isdbg('agw');
+ }
+ } elsif ($sort eq 'X') {
+ my ($r) = unpack "C", $data;
+ $r = $r ? "Successful" : "Failed";
+ dbg("AGW Register $from $r");
+ finish() unless $r;
+ } elsif ($sort eq 'R') {
+ my ($major, $minor) = unpack "v x2 v x2", $data;
+ dbg("AGW Version $major.$minor") if isdbg('agw');
+ } elsif ($sort eq 'G') {
+ my @ports = split /;/, $data;
+ $noports = shift @ports || '0';
+ dbg("AGW $noports Ports available") if isdbg('agw');
+ pop @ports while @ports > $noports;
+ for (@ports) {
+ next unless $_;
+ dbg("AGW Port: $_") if isdbg('agw');
+ }
+ for (my $i = 0; $i < $noports; $i++) {
+ _sendf('y', undef, undef, $i);
+ _sendf('g', undef, undef, $i);
+ }
+ } else {
+ my $d = unpack "Z*", $data;
+ dbg("AGW decode $sort port: $port pid: $pid '$from'->'$to' length: $len \"$d\"") if isdbg('agw');