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)
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 an announce message
64 my ($call, $text, $tonode, $sysop, $wx, $origin) = @_;
65 my $hops = get_hops(12);
71 $origin ||= $main::mycall;
72 return "PC12^$call^$tonode^$text^$sysop^$origin^$wx^$hops^~";
76 # add one or more users (I am expecting references that have 'call',
77 # 'conf' & 'here' method)
79 # this will create a list of PC16 with up pc16_max_users in each
80 # called $self->pc16(..)
85 my $ncall = $node->call;
92 my $str = sprintf "^%s %s %d", $ref->call, $ref->conf ? '*' : '-', $ref->here;
93 if (length($s) + length($str) > $sentencelth) {
94 push @out, "PC16^$ncall" . $s . sprintf "^%s^", get_hops(16);
99 push @out, "PC16^$ncall" . $s . sprintf "^%s^", get_hops(16);
103 # remove a local user
110 my $hops = get_hops(17);
111 my $ncall = $node->call;
112 my $ucall = $ref->call;
113 push @out, "PC17^$ucall^$ncall^$hops^";
118 # Request init string
122 return "PC18^DXSpider Version: $main::version Build: $main::subversion.$main::build$flags^$DXProt::myprot_version^";
126 # add one or more nodes
137 my $call = $ref->call;
138 my $here = $ref->here;
139 my $conf = $ref->conf;
140 my $version = $ref->version;
141 $version = $pc19_version unless $version =~ /^\d\d\d\d$/;
143 my $str = "^$here^$call^$conf^$version";
144 if (length($s) + length($str) > $sentencelth) {
145 push @out, "PC19" . $s . sprintf "^%s^", get_hops(19);
150 push @out, "PC19" . $s . sprintf "^%s^", get_hops(19);
166 my $hops = get_hops(21);
167 my $call = $node->call;
168 push @out, "PC21^$call^Gone^$hops^";
183 my $call = $self->call;
184 my $flag = $self->here ? '1' : '0';
185 my $hops = shift || get_hops(24);
187 return "PC24^$call^$flag^$hops^";
191 # create a merged dx message (freq, dxcall, t, text, spotter, orig-node)
194 my ($freq, $dxcall, $t, $text, $spotter, $orignode) = @_;
195 $text = ' ' unless $text;
196 $orignode = $main::mycall unless $orignode;
197 return sprintf "PC26^%.1f^$dxcall^%s^%s^$text^$spotter^$orignode^ ^~", $freq, cldate($t), ztime($t);
200 # create a merged WWV spot (logger, t, sfi, a, k, forecast, orig-node)
203 my ($logger, $t, $sfi, $a, $k, $forecast, $orignode) = @_;
204 return sprintf "PC27^%s^%-2.2s^$sfi^$a^$k^$forecast^$logger^$orignode^ ^~", cldate($t), ztime($t);
207 # message start (fromnode, tonode, to, from, t, private, subject, origin)
210 my ($tonode, $fromnode, $to, $from, $t, $private, $subject, $origin, $rr) = @_;
211 my $date = cldate($t);
212 my $time = ztime($t);
213 $private = $private ? '1' : '0';
214 $rr = $rr ? '1' : '0';
216 return "PC28^$tonode^$fromnode^$to^$from^$date^$time^$private^$subject^ ^5^$rr^ ^$origin^~";
219 # message text (from and to node same way round as pc29)
222 my ($fromnode, $tonode, $stream, $text) = @_;
223 $text = ' ' unless defined $text && length $text > 0;
224 $text =~ s/\^/%5E/og; # remove ^
225 return "PC29^$fromnode^$tonode^$stream^$text^~";
228 # subject acknowledge (will have to and from node reversed to pc28)
231 my ($fromnode, $tonode, $stream) = @_;
232 return "PC30^$fromnode^$tonode^$stream^";
235 # acknowledge this tranche of lines (to and from nodes reversed to pc29 and pc28
238 my ($fromnode, $tonode, $stream) = @_;
239 return "PC31^$fromnode^$tonode^$stream^";
242 # end of message from the sending end (pc28 node order)
245 my ($fromnode, $tonode, $stream) = @_;
246 return "PC32^$fromnode^$tonode^$stream^";
249 # acknowledge end of message from receiving end (opposite pc28 node order)
252 my ($fromnode, $tonode, $stream) = @_;
253 return "PC33^$fromnode^$tonode^$stream^";
259 my($fromnode, $tonode, $msg) = @_;
260 return "PC34^$tonode^$fromnode^$msg^~";
266 my($fromnode, $tonode, $msg) = @_;
267 return "PC35^$tonode^$fromnode^$msg^~";
270 # send all the DX clusters I reckon are connected
273 return join '^', "PC38", map {$_->call} Route::Node::get_all();
276 # tell the local node to discconnect
279 my ($call, $reason) = @_;
280 my $hops = get_hops(39);
281 $reason = "Gone." if !$reason;
282 return "PC39^$call^$reason^$hops^";
285 # cue up bulletin or file for transfer
288 my ($to, $from, $fn, $bull) = @_;
289 $bull = $bull ? '1' : '0';
290 return "PC40^$to^$from^$fn^$bull^5^";
297 $call = shift if ref $call;
299 my $sort = shift || '0';
300 my $info = shift || ' ';
301 my $hops = shift || get_hops(41);
302 return "PC41^$call^$sort^$info^$hops^~";
308 my ($fromnode, $tonode, $stream) = @_;
309 return "PC42^$fromnode^$tonode^$stream^";
315 my ($fromnode, $tonode, $stream, $db, $req, $call) = @_;
317 return "PC44^$tonode^$fromnode^$stream^$db^$req^$call^";
323 my ($fromnode, $tonode, $stream, $data) = @_;
324 return "PC45^$tonode^$fromnode^$stream^$data^";
327 # remote db data complete
330 my ($fromnode, $tonode, $stream) = @_;
331 return "PC46^$tonode^$fromnode^$stream^";
337 my ($from, $subject) = @_;
338 my $hops = get_hops(49);
339 return "PC49^$from^$subject^$hops^~";
342 # periodic update of users, plus keep link alive device (always H99)
346 my $call = $self->call;
347 my $n = shift || '0';
348 my $hops = shift || 'H99';
349 return "PC50^$call^$n^$hops^";
355 my ($to, $from, $val) = @_;
356 return "PC51^$to^$from^$val^";
359 # clx remote cmd send
362 my($fromnode, $tonode, $call, $msg) = @_;
363 return "PC84^$tonode^$fromnode^$call^$msg^~";
366 # clx remote cmd reply
369 my($fromnode, $tonode, $call, $msg) = @_;
370 return "PC85^$tonode^$fromnode^$call^$msg^~";
373 # spider route broadcasts
381 my $s = "PC92^$main::mycall^" . gen_pc9x_t() . "^$sort";
382 if ($pc9x_nodupe_first_slot && ($sort eq 'A' || $sort eq 'D') && $_[0]->call eq $main::mycall) {
387 $s .= '^' . _encode_pc92_call($_, $ext);
388 $ext = 0 unless $sort eq 'A'; # only the first slot has an ext.
393 sub gen_pc92_with_time
399 my $s = "PC92^$call^$t^$sort";
400 if ($pc9x_nodupe_first_slot && ($sort eq 'A' || $sort eq 'D') && $_[0]->call eq $main::mycall) {
405 $s .= "^" . _encode_pc92_call($_, $ext);
413 return _gen_pc92('A', 2, @_);
419 return _gen_pc92('D', 0, @_);
425 return _gen_pc92('C', 1, @_);
432 my $s = "PC92^$main::mycall^" . gen_pc9x_t() . "^K";
433 $s .= "^" . _encode_pc92_call($nref, 1) . ":$main::me->{build}";
434 $s .= "^" . scalar $nref->nodes;
435 $s .= "^" . scalar $nref->users;
439 # send a 'find' message
444 return "PC92^$main::mycall^" . gen_pc9x_t() . "^F^$from^$target^H99^"
447 # send a 'reply' message
454 return "PC92^$main::mycall^" . gen_pc9x_t() . "^R^$to^$target^$flag^$ms^H99^"
459 my $to = shift; # *, callsign, chat group name, sysop
460 my $from = shift; # from user callsign
461 my $via = shift || '*'; # *, node call
462 my $line = shift; # the text
463 my $origin = shift; # this will be present on proxying from PC10
465 $line = unpad($line);
466 $line =~ s/\^/\\5E/g; # remove any ^ characters
467 my $s = "PC93^$main::mycall^" . gen_pc9x_t() . "^$to^$from^$via^$line";
468 $s .= "^$origin" if $origin;