From 8f26eda530339bd0204916538d08816382696bbd Mon Sep 17 00:00:00 2001 From: Michael Wiebusch Date: Fri, 20 Jun 2014 18:20:57 +0200 Subject: [PATCH] first iteration works --- user_interface/analyzer.pl | 124 ++++++++++++++++++++++++++++++++++++ user_interface/out.dat | 127 +++++++++++++++++++++++++++++++++++++ 2 files changed, 251 insertions(+) create mode 100755 user_interface/analyzer.pl create mode 100644 user_interface/out.dat diff --git a/user_interface/analyzer.pl b/user_interface/analyzer.pl new file mode 100755 index 0000000..819b28f --- /dev/null +++ b/user_interface/analyzer.pl @@ -0,0 +1,124 @@ +#!/usr/bin/perl +use strict; +use warnings; +use Device::SerialPort; +use Time::HiRes; +use Getopt::Long; +use POSIX qw/strftime/; + +# plot destination +# check for tools + + + + +# defaults +my $baudrate=115200; +my $port; + + +my $ser_dev = "/dev/ttyUSB0"; + + + +init_port(); + +for (my $i=0;$i<128;$i++){ + my $rstring = communicate("R".chr($i)); +# printf ("length of response: %d \n",length($rstring)); + + + my $byte3 = ord(substr($rstring,0,1)); + my $byte2 = ord(substr($rstring,1,1)); + my $byte1 = ord(substr($rstring,2,1)); + my $byte0 = ord(substr($rstring,3,1)); + my $val = (($byte3<<24)|($byte2<<16)|($byte1<<8)|$byte0); + printf("%d\t%d\n",$i,$val); +# printf("addr %d:\t%d.%d.%d.%d\n",$i,$byte3,$byte2,$byte1,$byte0); +# Time::HiRes::sleep(.01); +} + + + + +sub communicate { + + my $ack_timeout=0.5; + + my $command = $_[0]; +# print "sending command $command\n"; + my $cmd_echo; + + + $port->are_match(chr(10)); + $port->lookclear; + $port->write("$command\n"); + + my $ack = 0; + + + + +ACK_POLLING: for (my $i = 0; ($i<$ack_timeout*100) ;$i++) { +# print $i."\n"; + while(my $a = $port->lookfor) { + if($a=~ m/R(....)/) { + $cmd_echo = $1; +# print "padiwa sent: $cmd_echo\n\n"; + $ack=1; + last ACK_POLLING; + } + + } + Time::HiRes::sleep(.01); + + } + + unless($ack) { + print "no answer\n"; + return "0"; + } + + return $cmd_echo; + + + +} + + + + + + +sub init_port { + + + # talk to the serial interface + + $port = new Device::SerialPort($ser_dev); + unless ($port) + { + print "can't open serial interface $ser_dev\n"; + exit; + } + + $port->user_msg('ON'); + $port->baudrate($baudrate); + $port->parity("none"); + $port->databits(8); + $port->stopbits(1); + $port->handshake("xoff"); + $port->write_settings; + +} + + + +sub getValue { + my $valName=$_[0]; + my $answer = communicate($valName); + if($answer =~ m/$valName=([^=]+)/){ + return $1; + } + die "could not retrieve desired value $valName!"; +} diff --git a/user_interface/out.dat b/user_interface/out.dat new file mode 100644 index 0000000..ec215d9 --- /dev/null +++ b/user_interface/out.dat @@ -0,0 +1,127 @@ +0 59 +1 0 +2 0 +3 0 +4 0 +5 0 +6 0 +7 0 +8 0 +9 0 +10 742 +11 0 +12 0 +13 0 +14 0 +15 0 +16 0 +17 0 +18 0 +19 0 +20 0 +21 377 +22 0 +23 0 +24 0 +25 0 +26 0 +27 0 +28 0 +29 0 +30 0 +31 0 +32 170 +33 0 +34 0 +35 0 +36 0 +37 0 +38 0 +39 0 +40 0 +41 0 +42 0 +43 95 +44 0 +45 0 +46 0 +47 0 +48 0 +49 0 +50 0 +51 0 +52 0 +53 0 +54 49 +55 0 +56 0 +57 0 +58 0 +59 0 +60 0 +61 0 +62 0 +63 0 +64 23 +65 6 +66 0 +67 0 +68 0 +69 0 +70 0 +71 0 +72 0 +73 0 +74 0 +76 0 +77 0 +78 0 +79 0 +80 0 +81 0 +82 0 +83 0 +84 0 +85 0 +86 6 +87 0 +88 0 +89 0 +90 0 +91 0 +92 0 +93 0 +94 0 +95 0 +96 0 +97 3 +98 0 +99 0 +100 0 +101 0 +102 0 +103 0 +104 0 +105 0 +106 0 +107 0 +108 1 +109 0 +110 0 +111 0 +112 0 +113 0 +114 0 +115 0 +116 0 +117 0 +118 0 +119 2 +120 0 +121 0 +122 0 +123 0 +124 0 +125 0 +126 0 +127 3 -- 2.43.0