1 | #------------------------------------------------------------------------------- |
---|
2 | # This file is part of the FLARM®-Radar Project. |
---|
3 | # |
---|
4 | # Copyright by the Authors |
---|
5 | # |
---|
6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
---|
7 | # you may not use this file except in compliance with the License. |
---|
8 | # You may obtain a copy of the License at |
---|
9 | # |
---|
10 | # http://www.apache.org/licenses/LICENSE-2.0 |
---|
11 | # |
---|
12 | # Unless required by applicable law or agreed to in writing, software |
---|
13 | # distributed under the License is distributed on an "AS IS" BASIS, |
---|
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
15 | # See the License for the specific language governing permissions and |
---|
16 | # limitations under the License. |
---|
17 | # |
---|
18 | # Project Website: www.flarmradar.ch |
---|
19 | # Email: info@flarmradar.ch |
---|
20 | # Authors: |
---|
21 | # 2012-2014 Simon Moser |
---|
22 | # 2013-2014 Dominic Spreitz |
---|
23 | # 2014-2014 Giorgio Tresoldi |
---|
24 | #------------------------------------------------------------------------------- |
---|
25 | #!/usr/bin/perl -w |
---|
26 | |
---|
27 | use strict; |
---|
28 | use Device::SerialPort; |
---|
29 | |
---|
30 | |
---|
31 | my $PortObj = new Device::SerialPort ("/dev/ttyAMA0"); |
---|
32 | $PortObj->baudrate(57600); |
---|
33 | $PortObj->parity("none"); |
---|
34 | $PortObj->databits(8); |
---|
35 | $PortObj->stopbits(1); |
---|
36 | $PortObj->handshake("none"); |
---|
37 | $PortObj->stty_igncr; |
---|
38 | $PortObj->are_match("\r\n"); |
---|
39 | |
---|
40 | $| = 1; |
---|
41 | |
---|
42 | my $count = 0; |
---|
43 | while (1) { |
---|
44 | my $char = $PortObj->lookfor(); |
---|
45 | chomp($char); |
---|
46 | if ($char) { |
---|
47 | print "Read " . $char . "\n"; |
---|
48 | } else { |
---|
49 | sleep(1); |
---|
50 | $count++; |
---|
51 | if ($count % 3 == 0) { |
---|
52 | my $cmd = "\$PFLAC,S,ACFT,0\r\n"; |
---|
53 | print " Send $cmd"; |
---|
54 | my $count_out = $PortObj->write($cmd); |
---|
55 | warn "write failed\n" unless ($count_out); |
---|
56 | warn "write incomplete\n" if ( $count_out != length($cmd) ); |
---|
57 | } |
---|
58 | } |
---|
59 | } |
---|
60 | |
---|
61 | exit 0; |
---|