From 67939b980f05f69f7d74bab5f6a5fc97b096debd Mon Sep 17 00:00:00 2001 From: rudolfkoenig <> Date: Sat, 16 Jul 2016 07:29:21 +0000 Subject: [PATCH] 00_ZWDongle: add the MEMORY functions to the backup commands (Forum #53023) git-svn-id: https://svn.fhem.de/fhem/trunk@11798 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/00_ZWDongle.pm | 52 +++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/fhem/FHEM/00_ZWDongle.pm b/fhem/FHEM/00_ZWDongle.pm index 3e3ab890d..6d8878e5e 100755 --- a/fhem/FHEM/00_ZWDongle.pm +++ b/fhem/FHEM/00_ZWDongle.pm @@ -253,21 +253,29 @@ ZWDongle_Set($@) } if($type eq "backupCreate") { + my $caps = ReadingsVal($name, "caps",""); + my $is4 = ($caps =~ m/MEMORY_GET_BUFFER/); + my $is5 = ($caps =~ m/NVM_EXT_READ_LONG_BUFFER/); return "Creating a backup is not supported by this device" - if(ReadingsVal($name, "caps","") !~ m/NVM_EXT_READ_LONG_BUFFER/); - return "Usage: set $name backupCreate [64k|128k|256k]" - if(int(@a) != 1 || $a[0] !~ m/^(64|128|256)k$/); + if(!$is4 && !$is5); + return "Usage: set $name backupCreate [16k|32k|64k|128k|256k]" + if(int(@a) != 1 || $a[0] !~ m/^(16|32|64|128|256)k$/); + + my $fn = ($is5 ? "NVM_EXT_READ_LONG_BUFFER" : "MEMORY_GET_BUFFER"); + my $cmdFormat = ($is5 ? "002a%06x0040" : "0023%04x20"); + my $cmdRe = ($is5 ? "^012a" : "^0123"); + my $inc = ($is5 ? 64 : 32); + my $l = $1 * 1024; my $fName = "$attr{global}{modpath}/$name.bin"; open(OUT, ">$fName") || return "Cant open $fName: $!"; binmode(OUT); for(my $off = 0; $off < $l;) { - ZWDongle_Write($hash, "", sprintf("002a%06x0040", $off)); - my ($err, $ret) = - ZWDongle_ReadAnswer($hash, "NVM_EXT_READ_LONG_BUFFER", "^012a"); + ZWDongle_Write($hash, "", sprintf($cmdFormat, $off)); + my ($err, $ret) = ZWDongle_ReadAnswer($hash, $fn, $cmdRe); return $err if($err); print OUT pack('H*', substr($ret, 4)); - $off += 64; + $off += $inc; Log 3, "$name backupCreate at $off bytes" if($off % 16384 == 0); } @@ -276,8 +284,17 @@ ZWDongle_Set($@) } if($type eq "backupRestore") { + my $caps = ReadingsVal($name, "caps",""); + my $is4 = ($caps =~ m/MEMORY_PUT_BUFFER/); + my $is5 = ($caps =~ m/NVM_EXT_WRITE_LONG_BUFFER/); return "Restoring a backup is not supported by this device" - if(ReadingsVal($name, "caps","") !~ m/NVM_EXT_WRITE_LONG_BUFFER/); + if(!$is4 && !$is5); + my $fn = ($is5 ? "NVM_EXT_WRITE_LONG_BUFFER" : "MEMORY_PUT_BUFFER"); + my $cmdFormat = ($is5 ? "002b%06x0040%s" : "0024%04x40%s"); + my $cmdRe = ($is5 ? "^012b" : "^0124"); + my $cmdRet = ($is5 ? "^012b01" : "^012401"); + my $inc = ($is5 ? 64 : 32); + return "Usage: set $name backupRestore" if(int(@a) != 0); my $fName = "$attr{global}{modpath}/$name.bin"; my $l = -s $fName; @@ -287,16 +304,15 @@ ZWDongle_Set($@) my $buf; for(my $off = 0; $off < $l;) { - if(sysread(IN, $buf, 64) != 64) { - return "Cant read 64 bytes from $fName"; + if(sysread(IN, $buf, $inc) != $inc) { + return "Cant read $inc bytes from $fName"; } - ZWDongle_Write($hash,"",sprintf("002b%06x0040%s",$off,unpack('H*',$buf))); - my ($err, $ret) = - ZWDongle_ReadAnswer($hash, "NVM_EXT_WRITE_LONG_BUFFER", "^012b"); + ZWDongle_Write($hash, "", sprintf($cmdFormat, $off, unpack('H*',$buf))); + my ($err, $ret) = ZWDongle_ReadAnswer($hash, $fn, $cmdRe); return $err if($err); - return "Unexpected NVM_EXT_WRITE_LONG_BUFFER return value $ret" - if($ret !~ m/^012b01/); - $off += 64; + return "Unexpected $fn return value $ret" + if($ret !~ m/$cmdRet/); + $off += $inc; Log 3, "$name backupRestore at $off bytes" if($off % 16384 == 0); } @@ -981,7 +997,7 @@ ZWDongle_Ready($) device supports the SECURITY class, then a secure inclusion is attempted. -