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