got routing essentially working
[spider.git] / perl / DXProtout.pm
1 #!/usr/bin/perl
2 #
3 # This module impliments the outgoing PCxx generation routines
4 #
5 # These are all the namespace of DXProt and are separated for "clarity"
6 #
7 # Copyright (c) 1998 Dirk Koopman G1TLH
8 #
9 # $Id$
10
11
12 package DXProt;
13
14 @ISA = qw(DXProt DXChannel);
15
16 use DXUtil;
17 use DXM;
18
19 use strict;
20
21 #
22 # All the PCxx generation routines
23 #
24
25 # create a talk string (called $self->pc10(...)
26 sub pc10
27 {
28   my ($self, $to, $via, $text) = @_;
29   my $user2 = $via ? $to : ' ';
30   my $user1 = $via ? $via : $to;
31   my $from = $self->call();
32   $text = unpad($text);
33   $text = ' ' if !$text;
34   return "PC10^$from^$user1^$text^*^$user2^$main::mycall^~";  
35 }
36
37 # create a dx message (called $self->pc11(...)
38 sub pc11
39 {
40   my ($self, $freq, $dxcall, $text) = @_;
41   my $mycall = $self->call;
42   my $hops = get_hops(11);
43   my $t = time;
44   $text = ' ' if !$text;
45   return sprintf "PC11^%.1f^$dxcall^%s^%s^$text^$mycall^$hops^~", $freq, cldate($t), ztime($t);
46 }
47
48 # create an announce message
49 sub pc12
50 {
51   my ($self, $text, $tonode, $sysop, $wx) = @_;
52   my $hops = get_hops(12);
53   $sysop = $sysop ? '*' : ' ';
54   $text = ' ' if !$text;
55   $wx = '0' if !$wx;
56   $tonode = '*' if !$tonode;
57   return "PC12^$self->{call}^$tonode^$text^$sysop^$main::mycall^$wx^$hops^~";
58 }
59
60 #
61 # add one or more users (I am expecting references that have 'call', 
62 # 'confmode' & 'here' method) 
63 #
64 # this will create a list of PC16 with up pc16_max_users in each
65 # called $self->pc16(..)
66 #
67 sub pc16
68 {
69   my $self = shift;
70   my @out;
71
72   foreach (@_) {
73     my $str = "PC16^$self->{call}";
74     my $i;
75     
76     for ($i = 0; @_ > 0  && $i < $DXProt::pc16_max_users; $i++) {
77       my $ref = shift;
78           $str .= sprintf "^%s %s %d", $ref->call, $ref->confmode ? '*' : '-', $ref->here;
79         }
80     $str .= sprintf "^%s^", get_hops(16);
81         push @out, $str;
82   }
83   return (@out);
84 }
85
86 # remove a local user
87 sub pc17
88 {
89   my ($self, $ref) = @_;
90   my $hops = get_hops(17);
91   return "PC17^$self->{call}^$ref->{call}^$hops^";
92 }
93
94 # Request init string
95 sub pc18
96 {
97   return "PC18^wot a load of twaddle^$DXProt::myprot_version^~";
98 }
99
100 #
101 # add one or more nodes 
102
103 sub pc19
104 {
105   my $self = shift;
106   my @out;
107
108   while (@_) {
109     my $str = "PC19";
110     my $i;
111     
112     for ($i = 0; @_ && $i < $DXProt::pc19_max_nodes; $i++) {
113       my $ref = shift;
114           my $here = $ref->{here} ? '1' : '0';
115           my $confmode = $ref->{confmode} ? '1' : '0';
116       $str .= "^$here^$ref->{call}^$confmode^$ref->{pcversion}";
117         }
118     $str .= sprintf "^%s^", get_hops(19);
119         push @out, $str;
120   }
121   return @out;
122 }
123
124 # end of Rinit phase
125 sub pc20
126 {
127   return 'PC20^';
128 }
129
130 # delete a node
131 sub pc21
132 {
133   my ($ref, $reason) = @_;
134   my $call = $ref->call;
135   my $hops = get_hops(21);
136   $reason = "Gone." if !$reason;
137   return "PC21^$call^$reason^$hops^";
138 }
139
140 # end of init phase
141 sub pc22
142 {
143   return 'PC22^';
144 }
145
146 # send all the DX clusters I reckon are connected
147 sub pc38
148 {
149   my @list = DXNode->get_all();
150   my $list;
151   my @nodes;
152   
153   foreach $list (@list) {
154     push @nodes, $list->call;
155   }
156   return "PC38^" . join(',', @nodes) . "^~";
157 }
158
159 # periodic update of users, plus keep link alive device (always H99)
160 sub pc50
161 {
162   my $me = DXCluster->get($main::mycall);
163   my $n = $me->users ? $me->users : '0';
164   return "PC50^$main::mycall^$n^H99^";
165 }
166
167 # generate pings
168 sub pc51
169 {
170   my ($self, $to, $from, $val) = @_;
171   return "PC51^$to^$from^$val^";
172 }
173 1;
174 __END__