#!/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 # Kommandozeilenoption fuer Device # Unterscheidung SRIFIII und Nemerix - erledigt ??? # Versionsnummern extrahieren # Ende Dump-Daten "WP Update Over" erkennen use IO::Handle; use strict; STDOUT->autoflush(1); my $device = "/dev/ttyUSB0"; ############################################################################### # Declarations ############################################################################### use constant NULL => chr 0; my $dump; my $now = time(); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime( $now); $mon++; $year += 1900; ############################################################################### # Serial device settings ############################################################################### # speed seems to be auto-detected, so only 8N1 raw needs to be set !system( "stty 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 my $name; for ( my $byte = 1; ; $byte++) { sysread( SERIAL, $_, 1) or die "Error while reading byte No. $byte: $!\n"; last if $_ eq NULL; $name .= $_; } print "Name : $name\n"; ############################################################################### # Request device info ############################################################################### # 0x5B 0xB0 print SERIAL chr(91) . chr(176) . NULL . NULL . NULL . NULL . NULL; my $device_info; for ( my $byte = 1; ; $byte++) { my $timeout = 0; $SIG{ALRM} = sub { $timeout = 1 }; eval { alarm(1); # timeout after 1 sec sysread( SERIAL, $_, 1) or die $!; alarm(0); # no timeout }; last if $timeout == 1; $device_info .= $_; } my ( $dummy0, $serial_no, $dummy1, $type, $dummy2 ) = unpack( "L L A32 A8 A*", $device_info); # Serial No. : Byte 8-5 : unsigned 32 bit # Type : Byte 41-48: Bytestring my $chipset = "unknown"; if ( $type eq "BT-CD100" ) { $chipset = "Nemerix"; } elsif ( $type eq "BT-CD160" ) { # does BT-CD160 realy means SRIFIII ? $chipset = "SRIFIII"; } print "Type : $type\n"; print "Chipset : $chipset\n"; print "Serial No. : $serial_no\n"; # TODO: wo steht das: # Firmware 2.5 # Hardware 2.2 ############################################################################### # Request configuration settings ############################################################################### # 0x62 0xB6 print SERIAL chr(98) . chr(182) . NULL . NULL . NULL . NULL . NULL; my $config_setting; for ( my $byte = 1; ; $byte++) { my $timeout = 0; $SIG{ALRM} = sub { $timeout = 1 }; eval { alarm(1); # timeout after 1 sec sysread( SERIAL, $_, 1) or die $!; alarm(0); # no timeout }; last if $timeout == 1; $config_setting .= $_; } my ( $time, $distance, $sensitivy, $dummy3, $tag, $dummy4 ) = unpack( "L L C A15 C A*", $config_setting); # Time : Byte 4-1: unsigned 32 bit # Distance : Byte 8-5: unsigned 32 bit # Sensitivity: Byte 9: 2-high, 1-middle, 3-low, 0-disable # Tag : Byte 25: 0-off, 1-on $time = "unused" if $time == 4294967295; $distance = "unused" if $distance == 4294967295; print "Time : $time\n"; print "Distance : $distance\n"; print "Sensitivity: $sensitivy\n"; print "Tag : $tag\n"; ############################################################################### # Request the memory dump ############################################################################### # 0x60 0xB5 print SERIAL chr(96) . chr(181) . NULL . NULL . NULL . NULL . NULL; print "Reading memory\n"; my $kbyte = 0; for ( my $byte = 1; ; $byte++) { my $timeout = 0; $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; $dump .= $_; if ( int( $byte / 1024 / 10) > $kbyte / 10 ) { $kbyte = int( $byte / 1024 ); printf "%04d kByte\r", $kbyte; } } printf "%d Bytes read\n", length( $dump); ############################################################################### # Close session ############################################################################### print SERIAL "WP AP-Exit" . NULL; close SERIAL; ############################################################################### # Check for correct end of data ############################################################################### # 57 50 20 55 70 64 61 74 65 20 4F 76 65 72 00 WP Update Over. die <$outfile" or die "Error while writing $outfile: $!\n"; print OUTFILE $dump; close OUTFILE; print "Done.\n"; ############################################################################### # Write dump to outfile ############################################################################### exit 0;