31c9a7fc75a8215f76bf0a237ab8dfaf91627328
[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 $handle_xml);
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         my $flags = " xml" if $handle_xml; 
127         return "PC18^DXSpider Version: $main::version Build: $main::build$flags^$DXProt::myprot_version^";
128 }
129
130 #
131 # add one or more nodes 
132
133 sub pc19
134 {
135         my @out;
136         my @in;
137
138         my $s = "";
139         for (@_) {
140                 next unless $_;
141                 my $ref = $_;
142                 my $call = $ref->call;
143                 my $here = $ref->here;
144                 my $conf = $ref->conf;
145                 my $version = $ref->version;
146                 my $str = "^$here^$call^$conf^$version";
147                 if (length($s) + length($str) > $sentencelth) {
148                         push @out, "PC19" . $s . sprintf "^%s^", get_hops(19);
149                         $s = "";
150                 }
151                 $s .= $str;
152         }
153         push @out, "PC19" . $s . sprintf "^%s^", get_hops(19);
154         return @out;
155 }
156
157 # end of Rinit phase
158 sub pc20
159 {
160         return 'PC20^';
161 }
162
163 # delete a node
164 sub pc21
165 {
166         my @out;
167         while (@_) {
168                 my $node = shift;
169                 my $hops = get_hops(21);
170                 my $call = $node->call;
171                 push @out, "PC21^$call^Gone^$hops^";
172         }
173         return @out;
174 }
175
176 # end of init phase
177 sub pc22
178 {
179         return 'PC22^';
180 }
181
182 # here status
183 sub pc24
184 {
185         my $self = shift;
186         my $call = $self->call;
187         my $flag = $self->here ? '1' : '0';
188         my $hops = shift || get_hops(24);
189   
190         return "PC24^$call^$flag^$hops^";
191 }
192
193
194 # create a merged dx message (freq, dxcall, t, text, spotter, orig-node) 
195 sub pc26
196 {
197         my ($freq, $dxcall, $t, $text, $spotter, $orignode) = @_;
198         $text = ' ' unless $text;
199         $orignode = $main::mycall unless $orignode;
200         return sprintf "PC26^%.1f^$dxcall^%s^%s^$text^$spotter^$orignode^ ^~", $freq, cldate($t), ztime($t);
201 }
202
203 # create a merged WWV spot (logger, t, sfi, a, k, forecast, orig-node)
204 sub pc27
205 {
206         my ($logger, $t, $sfi, $a, $k, $forecast, $orignode) = @_;
207         return sprintf "PC27^%s^%-2.2s^$sfi^$a^$k^$forecast^$logger^$orignode^ ^~", cldate($t), ztime($t);
208 }
209
210 # message start (fromnode, tonode, to, from, t, private, subject, origin)
211 sub pc28
212 {
213         my ($tonode, $fromnode, $to, $from, $t, $private, $subject, $origin, $rr) = @_;
214         my $date = cldate($t);
215         my $time = ztime($t);
216         $private = $private ? '1' : '0';
217         $rr = $rr ? '1' : '0';
218         $subject ||= ' ';
219         return "PC28^$tonode^$fromnode^$to^$from^$date^$time^$private^$subject^ ^5^$rr^ ^$origin^~";
220 }
221
222 # message text (from and to node same way round as pc29)
223 sub pc29 
224 {
225         my ($fromnode, $tonode, $stream, $text) = @_;
226         $text = ' ' unless defined $text && length $text > 0;
227         $text =~ s/\^/%5E/og;                   # remove ^
228         return "PC29^$fromnode^$tonode^$stream^$text^~";
229 }
230
231 # subject acknowledge (will have to and from node reversed to pc28)
232 sub pc30
233 {
234         my ($fromnode, $tonode, $stream) = @_;
235         return "PC30^$fromnode^$tonode^$stream^";
236 }
237
238 # acknowledge this tranche of lines (to and from nodes reversed to pc29 and pc28
239 sub pc31
240 {
241         my ($fromnode, $tonode, $stream) = @_;
242         return "PC31^$fromnode^$tonode^$stream^";
243 }
244
245 #  end of message from the sending end (pc28 node order)
246 sub pc32
247 {
248         my ($fromnode, $tonode, $stream) = @_;
249         return "PC32^$fromnode^$tonode^$stream^";
250 }
251
252 # acknowledge end of message from receiving end (opposite pc28 node order)
253 sub pc33
254 {
255         my ($fromnode, $tonode, $stream) = @_;
256         return "PC33^$fromnode^$tonode^$stream^";
257 }
258
259 # remote cmd send
260 sub pc34
261 {
262         my($fromnode, $tonode, $msg) = @_;
263         return "PC34^$tonode^$fromnode^$msg^~";
264 }
265
266 # remote cmd reply
267 sub pc35
268 {
269         my($fromnode, $tonode, $msg) = @_;
270         return "PC35^$tonode^$fromnode^$msg^~";
271 }
272
273 # send all the DX clusters I reckon are connected
274 sub pc38
275 {
276         return join '^', "PC38", map {$_->call} Route::Node::get_all();
277 }
278
279 # tell the local node to discconnect
280 sub pc39
281 {
282         my ($call, $reason) = @_;
283         my $hops = get_hops(39);
284         $reason = "Gone." if !$reason;
285         return "PC39^$call^$reason^$hops^";
286 }
287
288 # cue up bulletin or file for transfer
289 sub pc40
290 {
291         my ($to, $from, $fn, $bull) = @_;
292         $bull = $bull ? '1' : '0';
293         return "PC40^$to^$from^$fn^$bull^5^";
294 }
295
296 # user info
297 sub pc41
298 {
299         my $call = shift;
300         $call = shift if ref $call;
301         
302         my $sort = shift || '0';
303         my $info = shift || ' ';
304         my $hops = shift || get_hops(41);
305         return "PC41^$call^$sort^$info^$hops^~";
306 }
307
308 # abort message
309 sub pc42
310 {
311         my ($fromnode, $tonode, $stream) = @_;
312         return "PC42^$fromnode^$tonode^$stream^";
313 }
314
315 # remote db request
316 sub pc44
317 {
318         my ($fromnode, $tonode, $stream, $db, $req, $call) = @_;
319         $db = uc $db;
320         return "PC44^$tonode^$fromnode^$stream^$db^$req^$call^";
321 }
322
323 # remote db data
324 sub pc45
325 {
326         my ($fromnode, $tonode, $stream, $data) = @_;
327         return "PC45^$tonode^$fromnode^$stream^$data^";
328 }
329
330 # remote db data complete
331 sub pc46
332 {
333         my ($fromnode, $tonode, $stream) = @_;
334         return "PC46^$tonode^$fromnode^$stream^";
335 }
336
337 # bull delete
338 sub pc49
339 {
340         my ($from, $subject) = @_;
341         my $hops = get_hops(49);
342         return "PC49^$from^$subject^$hops^~";
343 }
344
345 # periodic update of users, plus keep link alive device (always H99)
346 sub pc50
347 {
348         my $self = shift;
349         my $call = $self->call;
350         my $n = shift || '0';
351         my $hops = shift || 'H99';
352         return "PC50^$call^$n^$hops^";
353 }
354
355 # generate pings
356 sub pc51
357 {
358         my ($to, $from, $val) = @_;
359         return "PC51^$to^$from^$val^";
360 }
361
362 # clx remote cmd send
363 sub pc84
364 {
365         my($fromnode, $tonode, $call, $msg) = @_;
366         return "PC84^$tonode^$fromnode^$call^$msg^~";
367 }
368
369 # clx remote cmd reply
370 sub pc85
371 {
372         my($fromnode, $tonode, $call, $msg) = @_;
373         return "PC85^$tonode^$fromnode^$call^$msg^~";
374 }
375
376 # spider route broadcast
377 sub pc90
378 {
379 }
380
381 1;
382 __END__
383
384
385