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
22 use vars qw($sentencelth $pc19_version $pc9x_nodupe_first_slot);
25 $pc9x_nodupe_first_slot = 1;
28 # All the PCxx generation routines
31 # create a talk string ($from, $to, $via, $text)
34 my ($from, $to, $via, $text, $origin) = @_;
36 if ($via && $via ne $to && $via ne '*') {
43 $origin ||= $main::mycall;
45 $text = ' ' unless $text && length $text > 0;
47 return "PC10^$from^$user1^$text^*^$user2^$origin^~";
50 # create a dx message (call, freq, dxcall, text) see also pc61
53 my ($mycall, $freq, $dxcall, $text) = @_;
54 my $hops = get_hops(11);
56 $text = ' ' if !$text;
58 return sprintf "PC11^%.1f^$dxcall^%s^%s^$text^$mycall^$main::mycall^$hops^~", $freq, cldate($t), ztime($t);
61 # create a dx message (call, freq, dxcall, text, $ipaddr) see also pc11
64 my ($mycall, $freq, $dxcall, $text, $ipaddr) = @_;
65 my $hops = get_hops(61) || get_hops(11);
67 $text = ' ' if !$text;
69 return sprintf "PC61^%.1f^$dxcall^%s^%s^$text^$mycall^$main::mycall^$ipaddr^$hops^~", $freq, cldate($t), ztime($t);
72 # create an announce message
75 my ($call, $text, $tonode, $sysop, $wx, $origin) = @_;
76 my $hops = get_hops(12);
82 $origin ||= $main::mycall;
83 return "PC12^$call^$tonode^$text^$sysop^$origin^$wx^$hops^~";
87 # add one or more users (I am expecting references that have 'call',
88 # 'conf' & 'here' method)
90 # this will create a list of PC16 with up pc16_max_users in each
91 # called $self->pc16(..)
96 my $ncall = $node->call;
103 my $str = sprintf "^%s %s %d", $ref->call, $ref->conf ? '*' : '-', $ref->here;
104 if (length($s) + length($str) > $sentencelth) {
105 push @out, "PC16^$ncall" . $s . sprintf "^%s^", get_hops(16);
110 push @out, "PC16^$ncall" . $s . sprintf "^%s^", get_hops(16);
114 # remove a local user
121 my $hops = get_hops(17);
122 my $ncall = $node->call;
123 my $ucall = $ref->call;
124 push @out, "PC17^$ucall^$ncall^$hops^";
129 # Request init string
133 return "PC18^DXSpider Version: $main::version Build: $main::build Git: $main::gitversion$flags^$DXProt::myprot_version^";
137 # add one or more nodes
148 my $call = $ref->call;
149 my $here = $ref->here;
150 my $conf = $ref->conf;
151 my $version = $ref->version;
152 $version = $pc19_version unless $version =~ /^\d\d\d\d$/;
154 my $str = "^$here^$call^$conf^$version";
155 if (length($s) + length($str) > $sentencelth) {
156 push @out, "PC19" . $s . sprintf "^%s^", get_hops(19);
161 push @out, "PC19" . $s . sprintf "^%s^", get_hops(19);
177 my $hops = get_hops(21);
178 my $call = $node->call;
179 push @out, "PC21^$call^Gone^$hops^";
194 my $call = $self->call;
195 my $flag = $self->here ? '1' : '0';
196 my $hops = shift || get_hops(24);
198 return "PC24^$call^$flag^$hops^";
202 # create a merged dx message (freq, dxcall, t, text, spotter, orig-node)
205 my ($freq, $dxcall, $t, $text, $spotter, $orignode) = @_;
206 $text = ' ' unless $text;
207 $orignode = $main::mycall unless $orignode;
208 return sprintf "PC26^%.1f^$dxcall^%s^%s^$text^$spotter^$orignode^ ^~", $freq, cldate($t), ztime($t);
211 # create a merged WWV spot (logger, t, sfi, a, k, forecast, orig-node)
214 my ($logger, $t, $sfi, $a, $k, $forecast, $orignode) = @_;
215 return sprintf "PC27^%s^%-2.2s^$sfi^$a^$k^$forecast^$logger^$orignode^ ^~", cldate($t), ztime($t);
218 # message start (fromnode, tonode, to, from, t, private, subject, origin)
221 my ($tonode, $fromnode, $to, $from, $t, $private, $subject, $origin, $rr) = @_;
222 my $date = cldate($t);
223 my $time = ztime($t);
224 $private = $private ? '1' : '0';
225 $rr = $rr ? '1' : '0';
227 return "PC28^$tonode^$fromnode^$to^$from^$date^$time^$private^$subject^ ^5^$rr^ ^$origin^~";
230 # message text (from and to node same way round as pc29)
233 my ($fromnode, $tonode, $stream, $text) = @_;
234 $text = ' ' unless defined $text && length $text > 0;
235 $text =~ s/\^/%5E/og; # remove ^
236 return "PC29^$fromnode^$tonode^$stream^$text^~";
239 # subject acknowledge (will have to and from node reversed to pc28)
242 my ($fromnode, $tonode, $stream) = @_;
243 return "PC30^$fromnode^$tonode^$stream^";
246 # acknowledge this tranche of lines (to and from nodes reversed to pc29 and pc28
249 my ($fromnode, $tonode, $stream) = @_;
250 return "PC31^$fromnode^$tonode^$stream^";
253 # end of message from the sending end (pc28 node order)
256 my ($fromnode, $tonode, $stream) = @_;
257 return "PC32^$fromnode^$tonode^$stream^";
260 # acknowledge end of message from receiving end (opposite pc28 node order)
263 my ($fromnode, $tonode, $stream) = @_;
264 return "PC33^$fromnode^$tonode^$stream^";
270 my($fromnode, $tonode, $msg) = @_;
271 return "PC34^$tonode^$fromnode^$msg^~";
277 my($fromnode, $tonode, $msg) = @_;
278 return "PC35^$tonode^$fromnode^$msg^~";
281 # send all the DX clusters I reckon are connected
284 return join '^', "PC38", map {$_->call} Route::Node::get_all();
287 # tell the local node to discconnect
290 my ($call, $reason) = @_;
291 my $hops = get_hops(39);
292 $reason = "Gone." if !$reason;
293 return "PC39^$call^$reason^$hops^";
296 # cue up bulletin or file for transfer
299 my ($to, $from, $fn, $bull) = @_;
300 $bull = $bull ? '1' : '0';
301 return "PC40^$to^$from^$fn^$bull^5^";
308 $call = shift if ref $call;
310 my $sort = shift || '0';
311 my $info = shift || ' ';
312 my $hops = shift || get_hops(41);
313 return "PC41^$call^$sort^$info^$hops^~";
319 my ($fromnode, $tonode, $stream) = @_;
320 return "PC42^$fromnode^$tonode^$stream^";
326 my ($fromnode, $tonode, $stream, $db, $req, $call) = @_;
328 return "PC44^$tonode^$fromnode^$stream^$db^$req^$call^";
334 my ($fromnode, $tonode, $stream, $data) = @_;
335 return "PC45^$tonode^$fromnode^$stream^$data^";
338 # remote db data complete
341 my ($fromnode, $tonode, $stream) = @_;
342 return "PC46^$tonode^$fromnode^$stream^";
348 my ($from, $subject) = @_;
349 my $hops = get_hops(49);
350 return "PC49^$from^$subject^$hops^~";
353 # periodic update of users, plus keep link alive device (always H99)
357 my $call = $self->call;
358 my $n = shift || '0';
359 my $hops = shift || 'H99';
360 return "PC50^$call^$n^$hops^";
366 my ($to, $from, $val) = @_;
367 return "PC51^$to^$from^$val^";
370 # clx remote cmd send
373 my($fromnode, $tonode, $call, $msg) = @_;
374 return "PC84^$tonode^$fromnode^$call^$msg^~";
377 # clx remote cmd reply
380 my($fromnode, $tonode, $call, $msg) = @_;
381 return "PC85^$tonode^$fromnode^$call^$msg^~";
384 # spider route broadcasts
392 my $s = "PC92^$main::mycall^" . gen_pc9x_t() . "^$sort";
393 if ($pc9x_nodupe_first_slot && ($sort eq 'A' || $sort eq 'D') && $_[0]->call eq $main::mycall) {
398 $s .= '^' . _encode_pc92_call($_, $ext);
399 $ext = 0 unless $sort eq 'A'; # only the first slot has an ext.
404 sub gen_pc92_with_time
410 my $s = "PC92^$call^$t^$sort";
411 if ($pc9x_nodupe_first_slot && ($sort eq 'A' || $sort eq 'D') && $_[0]->call eq $main::mycall) {
416 $s .= "^" . _encode_pc92_call($_, $ext);
424 return _gen_pc92('A', 2, @_);
430 return _gen_pc92('D', 0, @_);
436 return _gen_pc92('C', 1, @_);
443 my $s = "PC92^$main::mycall^" . gen_pc9x_t() . "^K";
444 $s .= "^" . _encode_pc92_call($nref, 1) . ":$main::me->{build}";
445 $s .= "^" . scalar $nref->nodes;
446 $s .= "^" . scalar $nref->users;
450 # send a 'find' message
455 return "PC92^$main::mycall^" . gen_pc9x_t() . "^F^$from^$target^H99^"
458 # send a 'reply' message
465 return "PC92^$main::mycall^" . gen_pc9x_t() . "^R^$to^$target^$flag^$ms^H99^"
470 my $to = shift; # *, callsign, chat group name, sysop
471 my $from = shift; # from user callsign
472 my $via = shift || '*'; # *, node call
473 my $line = shift; # the text
474 my $origin = shift; # this will be present on proxying from PC10
476 $line = unpad($line);
477 $line =~ s/\^/\\5E/g; # remove any ^ characters
478 my $s = "PC93^$main::mycall^" . gen_pc9x_t() . "^$to^$from^$via^$line";
479 $s .= "^$origin" if $origin;