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