From: Michael Wiebusch <stratomaster@gmx.net>
Date: Wed, 10 Jul 2013 20:32:22 +0000 (+0200)
Subject: xml2ini working, inheriting still buggy
X-Git-Url: https://jspc29.x-matter.uni-frankfurt.de/git/?a=commitdiff_plain;h=ae0d9e369e8140892d19fb427dc0a5630335df66;p=mvdsensorcontrol.git

xml2ini working, inheriting still buggy
---

diff --git a/xml_spielwiese/Common.pm b/xml_spielwiese/Common.pm
index ad2115f..aa988da 100644
--- a/xml_spielwiese/Common.pm
+++ b/xml_spielwiese/Common.pm
@@ -1,6 +1,9 @@
 #!/usr/bin/perl -w
 
 
+#TODO
+# padZeros strangely not working!
+
 sub any2hex {
 
   my $argument = $_[0];
@@ -26,6 +29,14 @@ sub any2hex {
   
 }
 
+
+sub stripBasePrefix{
+  my $argument = $_[0];
+  
+  $argument =~ s/^0[xXbB]//;
+  return $argument;
+}
+
 sub any2dec { # converts numeric expressions 0x, 0b or decimal to decimal
   
   my $argument = $_[0];
@@ -88,12 +99,18 @@ sub binStr2hexStr {
 
 }
 
+sub zeros{
+  # return a string with [argument] zeros inside :D
+  if($_[0] == 0) { return ""; }
+  return sprintf("%0".$_[0]."d",0);
+}
+
 
 sub getFieldVal {
 
   my $regStr = $_[0]; # pointer!
-  my $start = $_[1];
-  my $end = $_[2];
+  my $start = $_[1]; # start position
+  my $end = $_[2]; # end position
   
   my $regStrLen = length($$regStr);
   
@@ -105,6 +122,41 @@ sub getFieldVal {
 
 }
 
+sub padZeros{
+  my $string = $_[0]; # pointer!
+  my $paddingGroupSize = $_[1];
+  $$string =~ s/^0+//; # remove leading zeros
+  my $stringLength = length($$string);
+  print "strangeString:".$$string."\n";
+  
+  my $neededZeros = ($paddingGroupSize-($stringLength % $paddingGroupSize)) % $paddingGroupSize;
+  
+  $$string=zeros($neededZeros).$$string;
+}
+
+sub writeFieldInRegister {
+
+  my $regStr = $_[0]; # pointer!
+  my $newFieldVal = stripLeadingZeros($_[1]); # the new content in form of binary string
+  my $newFieldValLength = length($newFieldVal);
+  my $start = $_[2]; # start position in register
+  my $end = $_[3]; # end position in register
+  my $substrLength = $end-$start+1; 
+  #check if everything fits!
+  if($newFieldValLength > $substrLength) {
+    die "the field value is too big for the field size!\n";
+  }
+  
+  my $fieldStr = zeros($substrLength); # fill needed length with zeros
+  substr($fieldStr,-$newFieldValLength) = $newFieldVal; # paste the new field val inside the field string
+  
+  my $regStrLen = length($$regStr);
+  
+  my $substrStart = $regStrLen-1-$end;
+
+  substr($$regStr,$substrStart,$substrLength) = $fieldStr; # paste the field string into the register string
+
+}
 
 
 1;
diff --git a/xml_spielwiese/cgitest.pl b/xml_spielwiese/cgitest.pl
index e2d78a2..c5a3b62 100755
--- a/xml_spielwiese/cgitest.pl
+++ b/xml_spielwiese/cgitest.pl
@@ -739,26 +739,7 @@ sub printHash {
 	}
 }
 
-#sub assignFieldColors {
-#
-#	my @fieldColors = (
-#		"#CCFFCC", "#CCFFFF", "#CCCCFF", "#FFCCFF",
-#		"#FFCCCC", "#FFFFCC", "#FFFFFF"
-#	);
-#
-#	my @ancestryWithChild;
-#	push(@ancestryWithChild,@ancestryList);
-#	push(@ancestryWithChild,$configFileName);
-#
-#	my $index=0;
-#	for my $fileName (reverse(@ancestryWithChild)){
-#		$fieldColorHash{$fileName}= $fieldColors[$index];
-#		if($index < @fieldColors){
-#			$index++;
-#		}
-#	}
-#
-#}
+
 
 sub print_registers {
 	my $xmlfile = $_[0];