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