3 # This module impliments the outgoing PCxx generation routines
5 # These are all the namespace of DXProt and are separated for "clarity"
7 # Copyright (c) 1998 Dirk Koopman G1TLH
14 @ISA = qw(DXProt DXChannel);
22 use vars qw($sentencelth $pc19_version);
27 # All the PCxx generation routines
30 # create a talk string ($from, $to, $via, $text)
33 my ($from, $to, $via, $text, $origin) = @_;
35 if ($via && $via ne $to && $via ne '*') {
42 $origin ||= $main::mycall;
44 $text = ' ' unless $text && length $text > 0;
46 return "PC10^$from^$user1^$text^*^$user2^$origin^~";
49 # create a dx message (call, freq, dxcall, text)
52 my ($mycall, $freq, $dxcall, $text) = @_;
53 my $hops = get_hops(11);
55 $text = ' ' if !$text;
57 return sprintf "PC11^%.1f^$dxcall^%s^%s^$text^$mycall^$main::mycall^$hops^~", $freq, cldate($t), ztime($t);
60 # create an announce message
63 my ($call, $text, $tonode, $sysop, $wx, $origin) = @_;
64 my $hops = get_hops(12);
70 $origin ||= $main::mycall;
71 return "PC12^$call^$tonode^$text^$sysop^$origin^$wx^$hops^~";
75 # add one or more users (I am expecting references that have 'call',
76 # 'conf' & 'here' method)
78 # this will create a list of PC16 with up pc16_max_users in each
79 # called $self->pc16(..)
84 my $ncall = $node->call;
91 my $str = sprintf "^%s %s %d", $ref->call, $ref->conf ? '*' : '-', $ref->here;
92 if (length($s) + length($str) > $sentencelth) {
93 push @out, "PC16^$ncall" . $s . sprintf "^%s^", get_hops(16);
98 push @out, "PC16^$ncall" . $s . sprintf "^%s^", get_hops(16);
102 # remove a local user
109 my $hops = get_hops(17);
110 my $ncall = $node->call;
111 my $ucall = $ref->call;
112 push @out, "PC17^$ucall^$ncall^$hops^";
117 # Request init string
121 return "PC18^DXSpider Version: $main::version Build: $main::subversion.$main::build$flags^$DXProt::myprot_version^";
125 # add one or more nodes
136 my $call = $ref->call;
137 my $here = $ref->here;
138 my $conf = $ref->conf;
139 my $version = $ref->version;
140 $version = $pc19_version unless $version =~ /^\d\d\d\d$/;
142 my $str = "^$here^$call^$conf^$version";
143 if (length($s) + length($str) > $sentencelth) {
144 push @out, "PC19" . $s . sprintf "^%s^", get_hops(19);
149 push @out, "PC19" . $s . sprintf "^%s^", get_hops(19);
165 my $hops = get_hops(21);
166 my $call = $node->call;
167 push @out, "PC21^$call^Gone^$hops^";
182 my $call = $self->call;
183 my $flag = $self->here ? '1' : '0';
184 my $hops = shift || get_hops(24);
186 return "PC24^$call^$flag^$hops^";
190 # create a merged dx message (freq, dxcall, t, text, spotter, orig-node)
193 my ($freq, $dxcall, $t, $text, $spotter, $orignode) = @_;
194 $text = ' ' unless $text;
195 $orignode = $main::mycall unless $orignode;
196 return sprintf "PC26^%.1f^$dxcall^%s^%s^$text^$spotter^$orignode^ ^~", $freq, cldate($t), ztime($t);
199 # create a merged WWV spot (logger, t, sfi, a, k, forecast, orig-node)
202 my ($logger, $t, $sfi, $a, $k, $forecast, $orignode) = @_;
203 return sprintf "PC27^%s^%-2.2s^$sfi^$a^$k^$forecast^$logger^$orignode^ ^~", cldate($t), ztime($t);
206 # message start (fromnode, tonode, to, from, t, private, subject, origin)
209 my ($tonode, $fromnode, $to, $from, $t, $private, $subject, $origin, $rr) = @_;
210 my $date = cldate($t);
211 my $time = ztime($t);
212 $private = $private ? '1' : '0';
213 $rr = $rr ? '1' : '0';
215 return "PC28^$tonode^$fromnode^$to^$from^$date^$time^$private^$subject^ ^5^$rr^ ^$origin^~";
218 # message text (from and to node same way round as pc29)
221 my ($fromnode, $tonode, $stream, $text) = @_;
222 $text = ' ' unless defined $text && length $text > 0;
223 $text =~ s/\^/%5E/og; # remove ^
224 return "PC29^$fromnode^$tonode^$stream^$text^~";
227 # subject acknowledge (will have to and from node reversed to pc28)
230 my ($fromnode, $tonode, $stream) = @_;
231 return "PC30^$fromnode^$tonode^$stream^";
234 # acknowledge this tranche of lines (to and from nodes reversed to pc29 and pc28
237 my ($fromnode, $tonode, $stream) = @_;
238 return "PC31^$fromnode^$tonode^$stream^";
241 # end of message from the sending end (pc28 node order)
244 my ($fromnode, $tonode, $stream) = @_;
245 return "PC32^$fromnode^$tonode^$stream^";
248 # acknowledge end of message from receiving end (opposite pc28 node order)
251 my ($fromnode, $tonode, $stream) = @_;
252 return "PC33^$fromnode^$tonode^$stream^";
258 my($fromnode, $tonode, $msg) = @_;
259 return "PC34^$tonode^$fromnode^$msg^~";
265 my($fromnode, $tonode, $msg) = @_;
266 return "PC35^$tonode^$fromnode^$msg^~";
269 # send all the DX clusters I reckon are connected
272 return join '^', "PC38", map {$_->call} Route::Node::get_all();
275 # tell the local node to discconnect
278 my ($call, $reason) = @_;
279 my $hops = get_hops(39);
280 $reason = "Gone." if !$reason;
281 return "PC39^$call^$reason^$hops^";
284 # cue up bulletin or file for transfer
287 my ($to, $from, $fn, $bull) = @_;
288 $bull = $bull ? '1' : '0';
289 return "PC40^$to^$from^$fn^$bull^5^";
296 $call = shift if ref $call;
298 my $sort = shift || '0';
299 my $info = shift || ' ';
300 my $hops = shift || get_hops(41);
301 return "PC41^$call^$sort^$info^$hops^~";
307 my ($fromnode, $tonode, $stream) = @_;
308 return "PC42^$fromnode^$tonode^$stream^";
314 my ($fromnode, $tonode, $stream, $db, $req, $call) = @_;
316 return "PC44^$tonode^$fromnode^$stream^$db^$req^$call^";
322 my ($fromnode, $tonode, $stream, $data) = @_;
323 return "PC45^$tonode^$fromnode^$stream^$data^";
326 # remote db data complete
329 my ($fromnode, $tonode, $stream) = @_;
330 return "PC46^$tonode^$fromnode^$stream^";
336 my ($from, $subject) = @_;
337 my $hops = get_hops(49);
338 return "PC49^$from^$subject^$hops^~";
341 # periodic update of users, plus keep link alive device (always H99)
345 my $call = $self->call;
346 my $n = shift || '0';
347 my $hops = shift || 'H99';
348 return "PC50^$call^$n^$hops^";
354 my ($to, $from, $val) = @_;
355 return "PC51^$to^$from^$val^";
358 # clx remote cmd send
361 my($fromnode, $tonode, $call, $msg) = @_;
362 return "PC84^$tonode^$fromnode^$call^$msg^~";
365 # clx remote cmd reply
368 my($fromnode, $tonode, $call, $msg) = @_;
369 return "PC85^$tonode^$fromnode^$call^$msg^~";
372 # spider route broadcasts
380 my $s = "PC92^$main::mycall^" . gen_pc9x_t() . "^$sort";
382 $s .= "^" . _encode_pc92_call($_, $ext);
383 $ext = 0; # only the first slot has an ext.
388 sub gen_pc92_with_time
394 my $s = "PC92^$call^$t^$sort";
396 $s .= "^" . _encode_pc92_call($_, $ext);
404 return _gen_pc92('A', 0, @_);
410 return _gen_pc92('D', 0, @_);
416 return _gen_pc92('C', 1, @_);
423 my $s = "PC92^$main::mycall^" . gen_pc9x_t() . "^K";
424 $s .= "^" . _encode_pc92_call($nref, 1);
425 $s .= "^" . scalar $nref->nodes;
426 $s .= "^" . scalar $nref->users;
430 # send a 'find' message
435 return "PC92^$main::mycall^" . gen_pc9x_t() . "^F^$from^$target^H99^"
438 # send a 'reply' message
445 return "PC92^$main::mycall^" . gen_pc9x_t() . "^R^$to^$target^$flag^$ms^H99^"
450 my $to = shift; # *, callsign, chat group name, sysop
451 my $from = shift; # from user callsign
452 my $via = shift || '*'; # *, node call
453 my $line = shift; # the text
454 my $origin = shift; # this will be present on proxying from PC10
456 $line = unpad($line);
457 $line =~ s/\^/\\5E/g; # remove any ^ characters
458 my $s = "PC93^$main::mycall^" . gen_pc9x_t() . "^$to^$from^$via^$line";
459 $s .= "^$origin" if $origin;