release 1.5
[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^$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   return "PC18^wot a load of twaddle^$DXProt::myprot_version^~";
97 }
98
99 #
100 # add one or more nodes 
101
102 sub pc19
103 {
104   my $self = shift;
105   my @out;
106
107   while (@_) {
108     my $str = "PC19";
109     my $i;
110     
111     for ($i = 0; @_ && $i < $DXProt::pc19_max_nodes; $i++) {
112       my $ref = shift;
113           my $here = $ref->{here} ? '1' : '0';
114           my $confmode = $ref->{confmode} ? '1' : '0';
115       $str .= "^$here^$ref->{call}^$confmode^$ref->{pcversion}";
116         }
117     $str .= sprintf "^%s^", get_hops(19);
118         push @out, $str;
119   }
120   return @out;
121 }
122
123 # end of Rinit phase
124 sub pc20
125 {
126   return 'PC20^';
127 }
128
129 # delete a node
130 sub pc21
131 {
132   my ($call, $reason) = @_;
133   my $hops = get_hops(21);
134   $reason = "Gone." if !$reason;
135   return "PC21^$call^$reason^$hops^";
136 }
137
138 # end of init phase
139 sub pc22
140 {
141   return 'PC22^';
142 }
143
144 # here status
145 sub pc24
146 {
147   my $self = shift;
148   my $call = $self->call;
149   my $flag = $self->here ? '1' : '0';
150   my $hops = get_hops(24);
151   
152   return "PC24^$call^$flag^$hops^";
153 }
154
155 # message start (fromnode, tonode, to, from, t, private, subject, origin)
156 sub pc28
157 {
158   my ($tonode, $fromnode, $to, $from, $t, $private, $subject, $origin, $rr) = @_;
159   my $date = cldate($t);
160   my $time = ztime($t);
161   $private = $private ? '1' : '0';
162   $rr = $rr ? '1' : '0';
163   return "PC28^$tonode^$fromnode^$to^$from^$date^$time^$private^$subject^ ^5^$rr^ ^$origin^~";
164 }
165
166 # message text (from and to node same way round as pc29)
167 sub pc29 
168 {
169   my ($fromnode, $tonode, $stream, $text) = @_;
170   $text =~ s/\^//og;        # remove ^
171   return "PC29^$fromnode^$tonode^$stream^$text^~";
172 }
173
174 # subject acknowledge (will have to and from node reversed to pc28)
175 sub pc30
176 {
177   my ($fromnode, $tonode, $stream) = @_;
178   return "PC30^$fromnode^$tonode^$stream^";
179 }
180
181 # acknowledge this tranche of lines (to and from nodes reversed to pc29 and pc28
182 sub pc31
183 {
184   my ($fromnode, $tonode, $stream) = @_;
185   return "PC31^$fromnode^$tonode^$stream^";
186 }
187
188 #  end of message from the sending end (pc28 node order)
189 sub pc32
190 {
191   my ($fromnode, $tonode, $stream) = @_;
192   return "PC32^$fromnode^$tonode^$stream^";
193 }
194
195 # acknowledge end of message from receiving end (opposite pc28 node order)
196 sub pc33
197 {
198   my ($fromnode, $tonode, $stream) = @_;
199   return "PC33^$fromnode^$tonode^$stream^";
200 }
201
202 # remote cmd send
203 sub pc34
204 {
205         my($fromnode, $tonode, $msg) = @_;
206         return "PC34^$tonode^$fromnode^$msg^~";
207 }
208
209 # remote cmd reply
210 sub pc35
211 {
212         my($fromnode, $tonode, $msg) = @_;
213         return "PC35^$tonode^$fromnode^$msg^~";
214 }
215
216 # send all the DX clusters I reckon are connected
217 sub pc38
218 {
219   my @list = DXNode->get_all();
220   my $list;
221   my @nodes;
222   
223   foreach $list (@list) {
224     push @nodes, $list->call;
225   }
226   return "PC38^" . join(',', @nodes) . "^~";
227 }
228
229 # tell the local node to discconnect
230 sub pc39
231 {
232   my ($call, $reason) = @_;
233   my $hops = get_hops(39);
234   $reason = "Gone." if !$reason;
235   return "PC39^$call^$reason^$hops^";
236 }
237
238 # cue up bulletin or file for transfer
239 sub pc40
240 {
241   my ($to, $from, $fn, $bull) = @_;
242   $bull = $bull ? '1' : '0';
243   return "PC40^$to^$from^$fn^$bull^5^";
244 }
245
246 # user info
247 sub pc41
248 {
249   my ($call, $sort, $info) = @_;
250   my $hops = get_hops(41);
251   $sort = $sort ? "$sort" : '0';
252   return "PC41^$call^$sort^$info^$hops^~";
253 }
254
255 # abort message
256 sub pc42
257 {
258   my ($fromnode, $tonode, $stream) = @_;
259   return "PC42^$fromnode^$tonode^$stream^";
260 }
261
262 # bull delete
263 sub pc49
264 {
265   my ($from, $subject) = @_;
266   my $hops = get_hops(49);
267   return "PC49^$from^$subject^$hops^~";
268 }
269
270 # periodic update of users, plus keep link alive device (always H99)
271 sub pc50
272 {
273   my $me = DXCluster->get($main::mycall);
274   my $n = $me->users ? $me->users : '0';
275   return "PC50^$main::mycall^$n^H99^";
276 }
277
278 # generate pings
279 sub pc51
280 {
281   my ($self, $to, $from, $val) = @_;
282   return "PC51^$to^$from^$val^";
283 }
284 1;
285 __END__