-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathptt.pl
70 lines (58 loc) · 1.33 KB
/
ptt.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/perl
#
# @file nhrcx.pl
# @brief Perl-script to link a NHRCx controller to SvxLink over
# Linux pseudo tty's
# @author Adi Bier / DL1HRC
# @date 2014-05-01
#
# Run this script after starting SvxLink. Do not configure the
# links in the /dev directory.
#
# SvxLink - A Multi Purpose Voice Services System for Ham Radio Use
# Copyright (C) 2004-2014 Tobias Blomberg / SM0SVX
# Adjusted PE2JKO to control RPITX
use Time::HiRes qw(usleep);
#use Device::SerialPort;
use IO::File;
$ptt_port = "/home/pi/ptt";
$logfile = "/tmp/nhrc-x.log";
$DEBUG = 1;
$PTT = openPtty("$ptt_port"); # ptt port from SvxLink
while (1) {
$PTT->read($p, 1);
if ($p gt ' ') {
$message = $p;
if ($p ne 'T') {
system("/home/pi/rpitx/stop_tx.sh");
&writelog("UIT");
}
if ($p ne 'R') {
system("/home/pi/rpitx/start_tx.sh");
&writelog("AAN");
}
&writelog("PTT-command: $p");
undef $p;
}
usleep(10000);
}
close($PTT);
exit;
sub openPtty {
my $fh = IO::File->new($_[0], O_NONBLOCK|O_RDWR);
if (!(defined $fh)) {
&writelog("Can not open $_[0]");
print "Can not open $_[0]\n";
return 0;
}
$fh->autoflush(1);
&writelog("opening $_[0] OK");
return $fh;
}
sub writelog {
if ($DEBUG) {
open(LOG,">>$logfile");
print LOG $_[0],"\n";
close(LOG);
}
}