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