split DXProt into handlers and processing
[spider.git] / perl / Route.pm
index 7858e16ce7500dcce1864b07e2ba4f857cd1cd77..695eed8dffa05aea3e627b4a31c793060d6000f0 100644 (file)
@@ -16,14 +16,16 @@ package Route;
 
 use DXDebug;
 use DXChannel;
+use DXUtil;
+
 use Prefix;
 
 use strict;
 
 
 use vars qw($VERSION $BRANCH);
-$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
-$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /:\s+(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /:\s+\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
 $main::build += $VERSION;
 $main::branch += $BRANCH;
 
@@ -66,7 +68,7 @@ sub new
        $pkg = ref $pkg if ref $pkg;
 
        my $self = bless {call => $call}, $pkg;
-       dbg("create $pkg with $call") if isdbg('routelow');
+       dbg("Create $pkg with $call") if isdbg('routelow');
 
        # add in all the dxcc, itu, zone info
        ($self->{dxcc}, $self->{itu}, $self->{cq}, $self->{state}, $self->{city}) =
@@ -168,6 +170,47 @@ sub conf
        return $r ? 1 : 0;
 }
 
+#
+# pc59 entity encoding and decoding
+#
+sub enc_pc59
+{
+       my $self = shift;
+       my $sort = shift || 'N';
+       my $out = "$sort$self->{flag}$self->{call}";
+       if ($self->{build}) {
+               $out .= "b$self->{build}";
+       } elsif ($self->{version}) {
+               $out .= "v$self->{version}"; 
+       }
+}
+
+sub dec_pc59
+{
+       my $node = shift;
+       my $s = ref($node) ? shift : $node;
+       $node = undef;
+       
+       my ($sort, $here, $call) = unpack "A A A*", $s;
+       return unless is_callsign($call);
+       return unless $here =~ /^[0123]$/;
+       return unless $sort =~ /^[NUE]$/;
+       if ($sort eq 'E' || $sort eq 'N') {
+               $node = Route::Node::get($call) || Route::Node->new($call);
+               if ($s =~ /b([\d\.])/) {
+                       $node->{build} = $1;
+               }
+               if ($s =~ /v([\d\.])/) {
+                       $node->{version} = $1;
+               }
+       } elsif ($sort eq 'U') {
+               $node = Route::User::get($call) || Route::User->new($call);
+       }
+       $node->{flags} = $here;
+       $node->{lastseen} = $main::systime;
+       return $node;
+}
+
 # 
 # display routines
 #