1. Various detail changes to remove some more warning with -w on
[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 Carp;
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 $user2 = $via ? $to : ' ';
31         my $user1 = $via ? $via : $to;
32         $text = unpad($text);
33         $text = ' ' if !$text;
34         return "PC10^$from^$user1^$text^*^$user2^$main::mycall^~";  
35 }
36
37 # create a dx message (call, freq, dxcall, text) 
38 sub pc11
39 {
40         my ($mycall, $freq, $dxcall, $text) = @_;
41         my $hops = get_hops(11);
42         my $t = time;
43         $text = ' ' if !$text;
44         return sprintf "PC11^%.1f^$dxcall^%s^%s^$text^$mycall^$main::mycall^$hops^~", $freq, cldate($t), ztime($t);
45 }
46
47 # create an announce message
48 sub pc12
49 {
50         my ($call, $text, $tonode, $sysop, $wx) = @_;
51         my $hops = get_hops(12);
52         $sysop = ' ' if !$sysop;
53         $text = ' ' if !$text;
54         $wx = '0' if !$wx;
55         $tonode = '*' if !$tonode;
56         return "PC12^$call^$tonode^$text^$sysop^$main::mycall^$wx^$hops^~";
57 }
58
59 #
60 # add one or more users (I am expecting references that have 'call', 
61 # 'confmode' & 'here' method) 
62 #
63 # this will create a list of PC16 with up pc16_max_users in each
64 # called $self->pc16(..)
65 #
66 sub pc16
67 {
68         my $self = shift;
69         my @out;
70
71         foreach (@_) {
72                 my $str = "PC16^$self->{call}";
73                 my $i;
74     
75                 for ($i = 0; @_ > 0  && $i < $DXProt::pc16_max_users; $i++) {
76                         my $ref = shift;
77                         $str .= sprintf "^%s %s %d", $ref->call, $ref->confmode ? '*' : '-', $ref->here;
78                 }
79                 $str .= sprintf "^%s^", get_hops(16);
80                 push @out, $str;
81         }
82         return (@out);
83 }
84
85 # remove a local user
86 sub pc17
87 {
88         my ($self, $ref) = @_;
89         my $hops = get_hops(17);
90         return "PC17^$ref->{call}^$self->{call}^$hops^";
91 }
92
93 # Request init string
94 sub pc18
95 {
96         my $info = DXCluster::cluster;
97         return "PC18^$info^$DXProt::myprot_version^~";
98 }
99
100 #
101 # add one or more nodes 
102
103 sub pc19
104 {
105         my $self = shift;
106         my @out;
107
108         while (@_) {
109                 my $str = "PC19";
110                 my $i;
111     
112                 for ($i = 0; @_ && $i < $DXProt::pc19_max_nodes; $i++) {
113                         my $ref = shift;
114                         my $here = $ref->{here} ? '1' : '0';
115                         my $confmode = $ref->{confmode} ? '1' : '0';
116                         $str .= "^$here^$ref->{call}^$confmode^$ref->{pcversion}";
117                 }
118                 $str .= sprintf "^%s^", get_hops(19);
119                 push @out, $str;
120         }
121         return @out;
122 }
123
124 # end of Rinit phase
125 sub pc20
126 {
127         return 'PC20^';
128 }
129
130 # delete a node
131 sub pc21
132 {
133         my ($call, $reason) = @_;
134         my $hops = get_hops(21);
135         $reason = "Gone." if !$reason;
136         return "PC21^$call^$reason^$hops^";
137 }
138
139 # end of init phase
140 sub pc22
141 {
142         return 'PC22^';
143 }
144
145 # here status
146 sub pc24
147 {
148         my $self = shift;
149         my $call = $self->call;
150         my $flag = $self->here ? '1' : '0';
151         my $hops = get_hops(24);
152   
153         return "PC24^$call^$flag^$hops^";
154 }
155
156
157 # create a merged dx message (freq, dxcall, t, text, spotter, orig-node) 
158 sub pc26
159 {
160         my ($freq, $dxcall, $t, $text, $spotter, $orignode) = @_;
161         $text = ' ' unless $text;
162         $orignode = $main::mycall unless $orignode;
163         return sprintf "PC26^%.1f^$dxcall^%s^%s^$text^$spotter^$orignode^ ^~", $freq, cldate($t), ztime($t);
164 }
165
166 # create a merged WWV spot (logger, t, sfi, a, k, forecast, orig-node)
167 sub pc27
168 {
169         my ($logger, $t, $sfi, $a, $k, $forecast, $orignode) = @_;
170         return sprintf "PC27^%s^%-2.2s^$sfi^$a^$k^$forecast^$logger^$orignode^ ^~", cldate($t), ztime($t);
171 }
172
173 # message start (fromnode, tonode, to, from, t, private, subject, origin)
174 sub pc28
175 {
176         my ($tonode, $fromnode, $to, $from, $t, $private, $subject, $origin, $rr) = @_;
177         my $date = cldate($t);
178         my $time = ztime($t);
179         $private = $private ? '1' : '0';
180         $rr = $rr ? '1' : '0';
181         return "PC28^$tonode^$fromnode^$to^$from^$date^$time^$private^$subject^ ^5^$rr^ ^$origin^~";
182 }
183
184 # message text (from and to node same way round as pc29)
185 sub pc29 
186 {
187         my ($fromnode, $tonode, $stream, $text) = @_;
188         $text =~ s/\^/:/og;                     # remove ^
189         $text =~ s/\~/S/og;
190         return "PC29^$fromnode^$tonode^$stream^$text^~";
191 }
192
193 # subject acknowledge (will have to and from node reversed to pc28)
194 sub pc30
195 {
196         my ($fromnode, $tonode, $stream) = @_;
197         return "PC30^$fromnode^$tonode^$stream^";
198 }
199
200 # acknowledge this tranche of lines (to and from nodes reversed to pc29 and pc28
201 sub pc31
202 {
203         my ($fromnode, $tonode, $stream) = @_;
204         return "PC31^$fromnode^$tonode^$stream^";
205 }
206
207 #  end of message from the sending end (pc28 node order)
208 sub pc32
209 {
210         my ($fromnode, $tonode, $stream) = @_;
211         return "PC32^$fromnode^$tonode^$stream^";
212 }
213
214 # acknowledge end of message from receiving end (opposite pc28 node order)
215 sub pc33
216 {
217         my ($fromnode, $tonode, $stream) = @_;
218         return "PC33^$fromnode^$tonode^$stream^";
219 }
220
221 # remote cmd send
222 sub pc34
223 {
224         my($fromnode, $tonode, $msg) = @_;
225         return "PC34^$tonode^$fromnode^$msg^~";
226 }
227
228 # remote cmd reply
229 sub pc35
230 {
231         my($fromnode, $tonode, $msg) = @_;
232         return "PC35^$tonode^$fromnode^$msg^~";
233 }
234
235 # send all the DX clusters I reckon are connected
236 sub pc38
237 {
238         my @list = DXNode->get_all();
239         my $list;
240         my @nodes;
241   
242         foreach $list (@list) {
243                 push @nodes, $list->call;
244         }
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 # bull delete
282 sub pc49
283 {
284         my ($from, $subject) = @_;
285         my $hops = get_hops(49);
286         return "PC49^$from^$subject^$hops^~";
287 }
288
289 # periodic update of users, plus keep link alive device (always H99)
290 sub pc50
291 {
292         my $me = DXCluster->get_exact($main::mycall);
293         my $n = $me->users ? $me->users : '0';
294         return "PC50^$main::mycall^$n^H99^";
295 }
296
297 # generate pings
298 sub pc51
299 {
300         my ($to, $from, $val) = @_;
301         return "PC51^$to^$from^$val^";
302 }
303 1;
304 __END__