/usr/bin/modemtest is in libdevice-serialport-perl 1.04-3+b3.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | #!/usr/bin/perl
#
# This tool is used to check how Device::SerialPort is behaving on
# your machine. It will list all the possible values for each function
# as it runs. Edit this tool to test various settings.
#
# $Id: modemtest 281 2004-02-24 05:27:24Z nemies $
#
# Copyright (C) 2000-2003 Kees Cook
# kees@outflux.net, http://outflux.net/
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# http://www.gnu.org/copyleft/gpl.html
use Device::SerialPort qw (:STAT);
use strict;
use warnings;
=head1 NAME
modemtest - Tool to examining your modem through Perl's Device::SerialPort
=head1 SYNOPSIS
modemtest [OPTS] [DEVICE [BAUD [DATA [PARITY [STOP [FLOW]]]]]]
DEVICE Device to use as a serial port (default: "/dev/modem")
BAUD Serial speed to use (default: 9600)
DATA Number of databits to use (default: 8)
PARITY Type of parity to use (default: "none")
STOP Number of stop bits to use (default: 1)
FLOW Kind of flow control to use (default: "none")
-h, --help Help report
--skip-status Skip modem status bit tests
--hide-possible Don't show all possible settings
=head1 DESCRIPTION
Some systems, serial ports, and modem behave in strange ways. To test
the capabilities of Perl's Device::SerialPort, this tool queries the
system settings for the given DEVICE, and attempts to set up the port
and send the initialization string "ATE1" to the modem, reporting the
results seen.
=head1 SEE ALSO
L<Device::SerialPort(3)>
L<perl(1)>
=head1 AUTHOR
Kees Cook <kees@outflux.net>.
=head1 COPYRIGHT AND LICENSE
Copyright 2000-2004 by Kees Cook <kees@outflux.net>.
This program is free software; you may redistribute it and/or modify
it under the same terms ans Perl itself.
=cut
printf "Device::SerialPort v%d.%d.%d loaded.\n",
int(${Device::SerialPort::VERSION}),
(int(${Device::SerialPort::VERSION}*1000)=~/(\d{3})$/),
(int(${Device::SerialPort::VERSION}*1000000)=~/(\d{3})$/);
my $opt_skip_status=0;
my $opt_hide_possible=0;
# quick params
if ($ARGV[0] eq "-h" ||
$ARGV[0] eq "--help") {
die "Usage: $0 [DEVICE [BAUD [DATABITS [PARITY [STOPBITS [FLOW]]]]]]
-h, --help Help report
--skip-status Skip modem status bit tests
--hide-possible Don't show all possible settings
";
}
while ($ARGV[0]=~/^--(.*)/) {
if ($1 eq "skip-status") {
$opt_skip_status=1;
}
elsif ($1 eq "hide-possible") {
$opt_hide_possible=1;
}
else {
die "Unknown option '--$1'. Try '--help'.\n";
}
shift @ARGV;
}
# your serial port.
my ($device,$baudrate,$databits,$parity,$stopbits,$handshake)=@ARGV;
$device ||= "/dev/modem";
$baudrate ||= "9600";
$databits ||= "8";
$parity ||= "none";
$stopbits ||= "1";
$handshake ||= "none";
my $port=new Device::SerialPort($device) || die "new($device): $!\n";
print "Port '$device' open\n";
# Are the ioctls loaded?
my $bool=$port->can_ioctl();
print "can ioctl: ",($bool ? "Yes" : "No"),"\n";
if (!$bool) {
die "The rest of this test is useless without ioctl methods.\n";
}
# Handshaking
if (!$opt_hide_possible) {
my @handshakes=$port->handshake;
print "Handshakes:\n";
grep(print("\t$_\n"),sort(@handshakes));
}
$handshake=$port->handshake($handshake);
print "Got handshake: $handshake\n";
# Baud rate
if (!$opt_hide_possible) {
my @bauds=$port->baudrate;
print "Bauds:\n";
grep(print("\t$_\n"),sort { $b <=> $a } @bauds);
}
$baudrate=$port->baudrate($baudrate);
print "Got baud: $baudrate\n";
# Databits
if (!$opt_hide_possible) {
my @databits=$port->databits;
print "Databits:\n";
grep(print("\t$_\n"),sort { $b <=> $a } @databits);
}
$databits=$port->databits($databits);
print "Got databits: $databits\n";
# Parity
if (!$opt_hide_possible) {
my @parity=$port->parity;
print "Parity:\n";
grep(print("\t$_\n"),sort @parity);
}
$parity=$port->parity($parity);
print "Got parity: $parity\n";
# Stopbits
if (!$opt_hide_possible) {
my @stopbits=$port->stopbits;
print "Stopbits:\n";
grep(print("\t$_\n"),sort { $b <=> $a } @stopbits);
}
$stopbits=$port->stopbits($stopbits);
print "Got stopbits: $stopbits\n";
if (!$opt_skip_status) {
linestatus();
print "\n";
my $delay=3;
# Flip on DTR and RTS
my $dtr=$port->dtr_active(1) ? "okay" : "failed";
my $rts=$port->rts_active(1) ? "okay" : "failed";
print "Activated DTR($dtr) and RTS($rts) ... pausing for $delay seconds\n";
linestatus();
print "\n";
sleep $delay;
$dtr=$port->dtr_active(0) ? "okay" : "failed";
$rts=$port->rts_active(0) ? "okay" : "failed";
print "Deactivated DTR($dtr) and RTS($rts) ... pausing for $delay seconds\n";
linestatus();
print "\n";
sleep $delay;
$dtr=$port->dtr_active(1) ? "okay" : "failed";
print "Activated DTR($dtr) ... pausing for $delay seconds\n";
linestatus();
print "\n";
sleep $delay;
$rts=$port->rts_active(1) ? "okay" : "failed";
print "Activated RTS($rts) ... pausing for $delay seconds\n";
linestatus();
print "\n";
sleep $delay;
}
# Just in case: reset our timing and buffers
$port->lookclear();
$port->read_const_time(100);
$port->read_char_time(5);
# Turn on parity checking:
#$port->stty_inpck(1);
#$port->stty_istrip(1);
# Read a chunk
my ($count,$str,$got,$cnt);
readchunk();
# Write some AT commands to the modem
writechunk("ATE1\r");
# Read a few chunks
readchunk();
readchunk();
print "\n";
linestatus();
# close the port
undef $port;
print "Port closed\n";
sub writechunk
{
my $str=shift;
my $count = $port->write($str);
print "wrote: $count\n";
$str=~s/([^\040-\176])/sprintf("{0x%02X}",ord($1))/ge;
print "written ->$str<-\n";
}
sub readchunk
{
# read a chunk of data
sleep 1;
my ($count,$str)=$port->read(1);
my $got;
$cnt=$count;
while ($count>0) {
($count,$got)=$port->read(1);
$str.=$got;
$cnt+=$count;
}
print "read: $cnt\n";
$str=~s/([^\040-\176])/sprintf("{0x%02X}",ord($1))/ge;
print "saw ->$str<-\n";
}
sub linestatus
{
my $status = $port->modemlines;
printf("Modem status = 0x%04X (DTR=%s CTS=%s RTS=%s DSR=%s RNG=%s CD=%s)\n",
$status,
($status & MS_DTR_ON) ? "ON " : "off",
($status & MS_CTS_ON) ? "ON " : "off",
($status & MS_RTS_ON) ? "ON " : "off",
($status & MS_DSR_ON) ? "ON " : "off",
($status & MS_RING_ON) ? "ON " : "off",
($status & MS_RLSD_ON) ? "ON " : "off",
);
}
# /* vi:set ai ts=4 sw=4 expandtab: */
|