From 78b23950f926be26be68daa37e2d56b9c5eec02f Mon Sep 17 00:00:00 2001 From: adamwit <> Date: Wed, 3 Feb 2016 17:35:10 +0000 Subject: [PATCH] 89_VCONTROL: New Parse Methods 1ByteH added, multiplicator for conv Methods added git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@10714 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- FHEM/89_VCONTROL.pm | 88 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 69 insertions(+), 19 deletions(-) diff --git a/FHEM/89_VCONTROL.pm b/FHEM/89_VCONTROL.pm index 395a7db83..4a8894f5d 100644 --- a/FHEM/89_VCONTROL.pm +++ b/FHEM/89_VCONTROL.pm @@ -81,17 +81,18 @@ sub VCONTROL_1ByteU2Parse($$); sub VCONTROL_1ByteSParse($$); sub VCONTROL_2ByteSParse($$); sub VCONTROL_2ByteUParse($$); +sub VCONTROL_1ByteHexParse($); sub VCONTROL_2ByteHexParse($); sub VCONTROL_2BytePercentParse($$); sub VCONTROL_4ByteParse($$); sub VCONTROL_timerParse($); sub VCONTROL_ModusParse($); sub VCONTROL_DateParse($); -sub VCONTROL_1ByteUConv($); -sub VCONTROL_1ByteSConv($); +sub VCONTROL_1ByteUConv($$); +sub VCONTROL_1ByteSConv($$); sub VCONTROL_1ByteUx10Conv($); -sub VCONTROL_2ByteUConv($); -sub VCONTROL_2ByteSConv($); +sub VCONTROL_2ByteUConv($$); +sub VCONTROL_2ByteSConv($$); sub VCONTROL_DateConv($); sub VCONTROL_TimerConv($$); sub VCONTROL_RegisterConv($); @@ -576,6 +577,8 @@ VCONTROL_Parse($$$$) $value = VCONTROL_2ByteSParse($hexline,$cmd_list[$cmd][3]) if (length($hexline) > 3); } elsif ($cmd_list[$cmd][2] eq "2ByteU"){ $value = VCONTROL_2ByteUParse($hexline,$cmd_list[$cmd][3]) if (length($hexline) > 3); + } elsif ($cmd_list[$cmd][2] eq "1ByteH"){ + $value = VCONTROL_1ByteHexParse($hexline) if (length($hexline) > 1); } elsif ($cmd_list[$cmd][2] eq "2ByteH"){ $value = VCONTROL_2ByteHexParse($hexline) if (length($hexline) > 3); } elsif ($cmd_list[$cmd][2] eq "2BytePercent"){ @@ -788,19 +791,19 @@ VCONTROL_Set($@) $send_now=$$_[5]; if ($$_[3] eq "1ByteU"){ - $send_additonal_param=VCONTROL_1ByteUConv($value); + $send_additonal_param=VCONTROL_1ByteUConv($value,$$_[4]); } elsif ($$_[3] eq "1ByteS"){ - $send_additonal_param=VCONTROL_1ByteSConv($value); + $send_additonal_param=VCONTROL_1ByteSConv($value,$$_[4]); } elsif ($$_[3] eq "1ByteUx10"){ $send_additonal_param=VCONTROL_1ByteUx10Conv($value); } elsif ($$_[3] eq "2ByteU"){ - $send_additonal_param=VCONTROL_2ByteUConv($value); + $send_additonal_param=VCONTROL_2ByteUConv($value,$$_[4]); } elsif ($$_[3] eq "2ByteS"){ - $send_additonal_param=VCONTROL_2ByteSConv($value); + $send_additonal_param=VCONTROL_2ByteSConv($value,$$_[4]); } elsif ($$_[3] eq "date"){ my $strtemp = VCONTROL_DateConv($value); @@ -969,6 +972,7 @@ sub VCONTROL_CmdConfig($) && $cfgarray[2] ne "1ByteS" && $cfgarray[2] ne "2ByteS" && $cfgarray[2] ne "2ByteU" + && $cfgarray[2] ne "1ByteH" && $cfgarray[2] ne "2ByteH" && $cfgarray[2] ne "2BytePercent" && $cfgarray[2] ne "4Byte" @@ -1076,6 +1080,13 @@ sub VCONTROL_1ByteSParse($$) return unpack('c', pack('C',hex(substr($hexvalue,0,2))))/$divisor; } ##################################### +sub VCONTROL_1ByteHexParse($) +{ + my $hexvalue = shift; + + return (substr($hexvalue,0,2)); +} +##################################### sub VCONTROL_2ByteUParse($$) { my $hexvalue = shift; @@ -1183,16 +1194,28 @@ sub VCONTROL_DateParse($){ ## CONV ROUTINES ########################################################################### ########################################################################### -sub VCONTROL_1ByteUConv($) +sub VCONTROL_1ByteUConv($$) { my $convvalue = shift; - return (sprintf "%02X", $convvalue); + my $multiplicator = shift; + + if ( $multiplicator =~ /^\d+$/) { + return (sprintf "%02X", $convvalue*$multiplicator); + } + else + { return (sprintf "%02X", $convvalue); } } ##################################### -sub VCONTROL_1ByteSConv($) +sub VCONTROL_1ByteSConv($$) { my $convvalue = shift; - my $cnvstrvalue = (sprintf "%02X", $convvalue); + my $multiplicator = shift; + my $cnvstrvalue; + if ( $multiplicator =~ /^\d+$/) { + $cnvstrvalue = (sprintf "%02X", $convvalue*$multiplicator); + } + else + {$cnvstrvalue = (sprintf "%02X", $convvalue);} if ($convvalue <0){ return substr($cnvstrvalue,length($cnvstrvalue)-2,2); } @@ -1207,17 +1230,33 @@ sub VCONTROL_1ByteUx10Conv($) return (sprintf "%02X", $convvalue*10); } ##################################### -sub VCONTROL_2ByteUConv($) +sub VCONTROL_2ByteUConv($$) { my $convvalue = shift; - my $hexstr = (sprintf "%04X", $convvalue); + my $multiplicator = shift; + my $hexstr; + if ( $multiplicator =~ /^\d+$/) { + $hexstr = (sprintf "%04X", $convvalue*$multiplicator); + } + else { + $hexstr = (sprintf "%04X", $convvalue); + } + return substr($hexstr,2,2).substr($hexstr,0,2); } ##################################### -sub VCONTROL_2ByteSConv($) +sub VCONTROL_2ByteSConv($$) { my $convvalue = shift; - my $cnvstrvalue = (sprintf "%04X", $convvalue); + my $multiplicator = shift; + my $cnvstrvalue; + + if ( $multiplicator =~ /^\d+$/) { + $cnvstrvalue = (sprintf "%04X", $convvalue*$multiplicator); + } + else { + $cnvstrvalue = (sprintf "%04X", $convvalue); + } if ($convvalue <0){ return substr($cnvstrvalue,6,2).substr($cnvstrvalue,4,2); } @@ -1502,10 +1541,15 @@ sub VCONTROL_RegisterConv($)
  • NEXT_CMD or DAY
    - This column has two functions: + This column has three functions: