#!/usr/bin/perl -w ############################################################################### # THIS SOFTWARE IS FREE SOFTWARE! IT IS LICENCED UNDER THE GNU PUBLIC LICENCE # # 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; version 2 of the License # # 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 ############################################################################### # (c) Hartmut Schimmel, 29.09.2007 # TODO # sudo modprobe usbserial vendor=0x03EB product=0x6125 # Kommandozeilenoptienen fuer Device # Unterscheidung SRIFIII und Nemerix use IO::Handle; use strict; STDOUT->autoflush(1); my $device = "/dev/ttyUSB0"; ############################################################################### # Declarations ############################################################################### use constant NULL => chr 0; my @antw; my $now = time(); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( $now); $mon++; $year += 1900; my $outfile = sprintf( "itracku_%04d%02d%02d%02d%02d%02d.dump", $year, $mday, $mon, $hour, $min, $sec); ############################################################################### # Serial device settings ############################################################################### !system( "stty 38400 cs8 raw < $device") or die "Konnte $device nicht mit stty initialisieren: $! - Abbruch\n"; ############################################################################### # Open serial device ############################################################################### open( SERIAL, "+<$device") or die "Konnte $device nicht oeffnen: $! - Abbruch"; SERIAL->autoflush(1); ############################################################################### # Initialization ############################################################################### print SERIAL "WP AP-Exit" . NULL; # close possibly pending session print SERIAL "W'P Camera Detect" . NULL; # init new session for ( my $byte = 1; ; $byte++) { sysread( SERIAL, $_, 1) or die "Error while reading byte No. $byte: $!\n"; last if $_ eq NULL; push @antw, $_; } print "Reading memory of \"", @antw, "\"\n"; ############################################################################### # Request the memory dump ############################################################################### print SERIAL chr(96) . chr(181) . NULL . NULL . NULL . NULL . NULL; my $kbyte = 0; my $timeout = 0; for ( my $byte = 1; ; $byte++) { $SIG{ALRM} = sub { $timeout = 1 }; eval { alarm(2); # timeout after 2 sec sysread( SERIAL, $_, 1) or die $!; alarm(0); # no timeout }; last if $timeout == 1; next if $byte < 10; push @antw, $_; if ( int( $byte / 1024 / 10) > $kbyte / 10 ) { $kbyte = int( $byte / 1024 ); printf "%04d kByte\r", $kbyte; } } printf "%d Bytes read\n", $#antw + 1; ############################################################################### # Close session ############################################################################### print SERIAL "WP AP-Exit" . NULL; close SERIAL; ############################################################################### # Write dump to outfile ############################################################################### print "Writing ", $#antw + 1, " Bytes to $outfile\n"; open OUTFILE, ">$outfile" or die "Error while writing $outfile: $!\n"; print OUTFILE @antw; close OUTFILE; print "Done.\n"; ############################################################################### # Write dump to outfile ############################################################################### exit 0;