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