ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/aor/aor8000
Revision: 1.1
Committed: Sat Oct 1 03:37:45 2005 UTC (18 years, 7 months ago) by root
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# Content
1 #!/opt/bin/perl
2
3 # http://www.dia.unisa.it/professori/ads/corso-security/www/CORSO-9900/a5/Netsec/netsec.html
4
5 use strict;
6 use POSIX;
7 use Event;
8
9 my %tput_cache;
10
11 sub tput {
12 $tput_cache{join "\x00", @_} ||= qx<tput @_>
13 }
14
15 my $tty = $ARGV[0] || "/dev/ttyS0";
16
17 open my $aor, "+<:raw", $tty
18 or die "$tty: $!";
19
20 {
21 my $tio = new POSIX::Termios;
22
23 $tio->getattr (fileno $aor);
24
25 $tio->setiflag (POSIX::IXOFF | POSIX::IXON);
26 $tio->setoflag (0);
27 $tio->setcflag (POSIX::CLOCAL | POSIX::CREAD | POSIX::CSTOPB | POSIX::CS8);
28 $tio->setlflag (0);
29 $tio->setispeed (&POSIX::B9600);
30 $tio->setospeed (&POSIX::B9600);
31
32 $tio->setattr (fileno $aor);
33 }
34
35 my @info;
36 my @output;
37
38 sub refresh {
39 $| = 0;
40
41 print tput "cup", 0, 0;
42 my $clreol = tput "el";
43
44 for (0..15) {
45 print "$info[$_]$clreol\n";
46 }
47
48 shift @output while @output > 8;
49 print join "$clreol\n", @output;
50
51 print "$clreol\n> ";
52 print tput "ed";
53 $| = 1;
54 }
55
56 Event->timer (after => 0.5, interval => 1, cb => sub {
57 print $aor "RX\015\012LM\015\012LC\015\012";
58 });
59
60 Event->io (fd => \*STDIN, poll => 'r', cb => sub {
61 my $line = <>;
62 $line =~ s/[\015\012]+$//;
63 $line = "\x1e" if $line eq "u";
64 $line = "\x1f" if $line eq "d";
65 print $aor uc "$line\015\012LC\015\012";
66 });
67
68 my %mode = (
69 0 => "WFM",
70 1 => "NFM",
71 2 => "AM",
72 3 => "USB",
73 4 => "LSB",
74 5 => "CW",
75 );
76
77 my %info;
78
79 my $rbuf;
80
81 Event->io (fd => $aor, poll => 'r', cb => sub {
82 sysread $aor, $rbuf, 8192, length $rbuf;
83
84 while ($rbuf =~ s/^(.*)[\012\015]+//s) {
85 local $_ = $1;
86
87 s/[\012\015]//g;
88
89 $info{substr $_, 0, 2} = $_;
90
91 $info{freq} = "00 freq $1" if /\bRF(\d+)\b/;
92 $info{mode} = "01 mode $mode{$1}" if /\bMD(\d+)\b/;
93
94 @info = sort values %info;
95 push @output, $_ unless /^($|SS|LM|VF|MR|MS|SM)/;
96 }
97
98 refresh;
99 });
100
101 refresh;
102
103 Event::loop;
104