change build number calculation to be more accurate
[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 use DXDebug;
19
20 use strict;
21
22 use vars qw($VERSION $BRANCH);
23 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
24 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0;
25 $main::build += $VERSION;
26 $main::branch += $BRANCH;
27
28 #
29 # All the PCxx generation routines
30 #
31
32 # create a talk string ($from, $to, $via, $text)
33 sub pc10
34 {
35         my ($from, $to, $via, $text) = @_;
36         my ($user1, $user2);
37         if ($via && $via ne $to) {
38                 $user1 = $via;
39                 $user2 = $to;
40         } else {
41                 $user2 = ' ';
42                 $user1 = $to;
43         }
44         $text = unpad($text);
45         $text = ' ' unless $text && length $text > 0;
46         $text =~ s/\^/%5E/g;
47         return "PC10^$from^$user1^$text^*^$user2^$main::mycall^~";  
48 }
49
50 # create a dx message (call, freq, dxcall, text) 
51 sub pc11
52 {
53         my ($mycall, $freq, $dxcall, $text) = @_;
54         my $hops = get_hops(11);
55         my $t = time;
56         $text = ' ' if !$text;
57         $text =~ s/\^/%5E/g;
58         return sprintf "PC11^%.1f^$dxcall^%s^%s^$text^$mycall^$main::mycall^$hops^~", $freq, cldate($t), ztime($t);
59 }
60
61 # create an announce message
62 sub pc12
63 {
64         my ($call, $text, $tonode, $sysop, $wx) = @_;
65         my $hops = get_hops(12);
66         $sysop = ' ' if !$sysop;
67         $text = ' ' if !$text;
68         $wx = '0' if !$wx;
69         $tonode = '*' if !$tonode;
70         $text =~ s/\^/%5E/g;
71         return "PC12^$call^$tonode^$text^$sysop^$main::mycall^$wx^$hops^~";
72 }
73
74 #
75 # add one or more users (I am expecting references that have 'call', 
76 # 'conf' & 'here' method) 
77 #
78 # this will create a list of PC16 with up pc16_max_users in each
79 # called $self->pc16(..)
80 #
81 sub pc16
82 {
83         my $node = shift;
84         my $ncall = $node->call;
85         my @out;
86
87         while (@_) {
88                 my $str = "PC16^$ncall";
89                 for ( ; @_ && length $str < 200; ) {
90                         my $ref = shift;
91                         $str .= sprintf "^%s %s %d", $ref->call, $ref->conf ? '*' : '-', $ref->here;
92                 }
93                 $str .= sprintf "^%s^", get_hops(16);
94                 push @out, $str;
95         }
96         return @out;
97 }
98
99 # remove a local user
100 sub pc17
101 {
102         my @out;
103         while (@_) {
104                 my $node = shift;
105                 my $ref = shift;
106                 my $hops = get_hops(17);
107                 my $ncall = $node->call;
108                 my $ucall = $ref->call;
109                 push @out, "PC17^$ucall^$ncall^$hops^"; 
110         }
111         return @out;
112 }
113
114 # Request init string
115 sub pc18
116 {
117         return "PC18^DXSpider Version: $main::version Build: $main::build^$DXProt::myprot_version^";
118 }
119
120 #
121 # add one or more nodes 
122
123 sub pc19
124 {
125         my @out;
126
127         while(@_) {
128                 my $str = "PC19";
129                 for (; @_ && length $str < 200;) {
130                         my $ref = shift;
131                         my $call = $ref->call;
132                         my $here = $ref->here;
133                         my $conf = $ref->conf;
134                         my $version = $ref->version;
135                         $str .= "^$here^$call^$conf^$version";
136                 }
137                 $str .= sprintf "^%s^", get_hops(19);
138                 push @out, $str;
139         }
140         return @out;
141 }
142
143 # end of Rinit phase
144 sub pc20
145 {
146         return 'PC20^';
147 }
148
149 # delete a node
150 sub pc21
151 {
152         my @out;
153         while (@_) {
154                 my $node = shift;
155                 my $hops = get_hops(21);
156                 my $call = $node->call;
157                 push @out, "PC21^$call^Gone^$hops^";
158         }
159         return @out;
160 }
161
162 # end of init phase
163 sub pc22
164 {
165         return 'PC22^';
166 }
167
168 # here status
169 sub pc24
170 {
171         my $self = shift;
172         my $call = $self->call;
173         my $flag = $self->here ? '1' : '0';
174         my $hops = shift || get_hops(24);
175   
176         return "PC24^$call^$flag^$hops^";
177 }
178
179
180 # create a merged dx message (freq, dxcall, t, text, spotter, orig-node) 
181 sub pc26
182 {
183         my ($freq, $dxcall, $t, $text, $spotter, $orignode) = @_;
184         $text = ' ' unless $text;
185         $orignode = $main::mycall unless $orignode;
186         return sprintf "PC26^%.1f^$dxcall^%s^%s^$text^$spotter^$orignode^ ^~", $freq, cldate($t), ztime($t);
187 }
188
189 # create a merged WWV spot (logger, t, sfi, a, k, forecast, orig-node)
190 sub pc27
191 {
192         my ($logger, $t, $sfi, $a, $k, $forecast, $orignode) = @_;
193         return sprintf "PC27^%s^%-2.2s^$sfi^$a^$k^$forecast^$logger^$orignode^ ^~", cldate($t), ztime($t);
194 }
195
196 # message start (fromnode, tonode, to, from, t, private, subject, origin)
197 sub pc28
198 {
199         my ($tonode, $fromnode, $to, $from, $t, $private, $subject, $origin, $rr) = @_;
200         my $date = cldate($t);
201         my $time = ztime($t);
202         $private = $private ? '1' : '0';
203         $rr = $rr ? '1' : '0';
204         $subject ||= ' ';
205         return "PC28^$tonode^$fromnode^$to^$from^$date^$time^$private^$subject^ ^5^$rr^ ^$origin^~";
206 }
207
208 # message text (from and to node same way round as pc29)
209 sub pc29 
210 {
211         my ($fromnode, $tonode, $stream, $text) = @_;
212         $text = ' ' unless $text && length $text > 0;
213         $text =~ s/\^/%5E/og;                   # remove ^
214         return "PC29^$fromnode^$tonode^$stream^$text^~";
215 }
216
217 # subject acknowledge (will have to and from node reversed to pc28)
218 sub pc30
219 {
220         my ($fromnode, $tonode, $stream) = @_;
221         return "PC30^$fromnode^$tonode^$stream^";
222 }
223
224 # acknowledge this tranche of lines (to and from nodes reversed to pc29 and pc28
225 sub pc31
226 {
227         my ($fromnode, $tonode, $stream) = @_;
228         return "PC31^$fromnode^$tonode^$stream^";
229 }
230
231 #  end of message from the sending end (pc28 node order)
232 sub pc32
233 {
234         my ($fromnode, $tonode, $stream) = @_;
235         return "PC32^$fromnode^$tonode^$stream^";
236 }
237
238 # acknowledge end of message from receiving end (opposite pc28 node order)
239 sub pc33
240 {
241         my ($fromnode, $tonode, $stream) = @_;
242         return "PC33^$fromnode^$tonode^$stream^";
243 }
244
245 # remote cmd send
246 sub pc34
247 {
248         my($fromnode, $tonode, $msg) = @_;
249         return "PC34^$tonode^$fromnode^$msg^~";
250 }
251
252 # remote cmd reply
253 sub pc35
254 {
255         my($fromnode, $tonode, $msg) = @_;
256         return "PC35^$tonode^$fromnode^$msg^~";
257 }
258
259 # send all the DX clusters I reckon are connected
260 sub pc38
261 {
262         return join '^', "PC38", map {$_->call} Route::Node::get_all();
263 }
264
265 # tell the local node to discconnect
266 sub pc39
267 {
268         my ($call, $reason) = @_;
269         my $hops = get_hops(39);
270         $reason = "Gone." if !$reason;
271         return "PC39^$call^$reason^$hops^";
272 }
273
274 # cue up bulletin or file for transfer
275 sub pc40
276 {
277         my ($to, $from, $fn, $bull) = @_;
278         $bull = $bull ? '1' : '0';
279         return "PC40^$to^$from^$fn^$bull^5^";
280 }
281
282 # user info
283 sub pc41
284 {
285         my $call = shift;
286         $call = shift if ref $call;
287         
288         my $sort = shift || '0';
289         my $info = shift || ' ';
290         my $hops = shift || get_hops(41);
291         return "PC41^$call^$sort^$info^$hops^~";
292 }
293
294 # abort message
295 sub pc42
296 {
297         my ($fromnode, $tonode, $stream) = @_;
298         return "PC42^$fromnode^$tonode^$stream^";
299 }
300
301 # remote db request
302 sub pc44
303 {
304         my ($fromnode, $tonode, $stream, $db, $req, $call) = @_;
305         $db = uc $db;
306         return "PC44^$tonode^$fromnode^$stream^$db^$req^$call^";
307 }
308
309 # remote db data
310 sub pc45
311 {
312         my ($fromnode, $tonode, $stream, $data) = @_;
313         return "PC45^$tonode^$fromnode^$stream^$data^";
314 }
315
316 # remote db data complete
317 sub pc46
318 {
319         my ($fromnode, $tonode, $stream) = @_;
320         return "PC46^$tonode^$fromnode^$stream^";
321 }
322
323 # bull delete
324 sub pc49
325 {
326         my ($from, $subject) = @_;
327         my $hops = get_hops(49);
328         return "PC49^$from^$subject^$hops^~";
329 }
330
331 # periodic update of users, plus keep link alive device (always H99)
332 sub pc50
333 {
334         my $self = shift;
335         my $call = $self->call;
336         my $n = shift || '0';
337         my $hops = shift || 'H99';
338         return "PC50^$call^$n^$hops^";
339 }
340
341 # generate pings
342 sub pc51
343 {
344         my ($to, $from, $val) = @_;
345         return "PC51^$to^$from^$val^";
346 }
347
348 # clx remote cmd send
349 sub pc84
350 {
351         my($fromnode, $tonode, $call, $msg) = @_;
352         return "PC84^$tonode^$fromnode^$call^$msg^~";
353 }
354
355 # clx remote cmd reply
356 sub pc85
357 {
358         my($fromnode, $tonode, $call, $msg) = @_;
359         return "PC85^$tonode^$fromnode^$call^$msg^~";
360 }
361
362 1;
363 __END__
364
365
366