diff --git a/fhem/FHEM/99_updatefhem.pm b/fhem/FHEM/99_updatefhem.pm index 751a25e17..55bbb3e92 100644 --- a/fhem/FHEM/99_updatefhem.pm +++ b/fhem/FHEM/99_updatefhem.pm @@ -4,19 +4,25 @@ use warnings; use IO::Socket; sub CommandUpdatefhem($$); +sub CommandCULflash($$); my $server = "fhem.de:80"; my $sdir = "/fhemupdate"; my $ftime = "filetimes.txt"; +my $dfu = "dfu-programmer"; ##################################### sub updatefhem_Initialize($$) { - my %lhash = ( Fn=>"CommandUpdatefhem", - Hlp=>",update fhem from the nightly CVS checkout" ); - $cmds{updatefhem} = \%lhash; + my %fhash = ( Fn=>"CommandUpdatefhem", + Hlp=>",update fhem from the nightly CVS" ); + $cmds{updatefhem} = \%fhash; + + my %chash = ( Fn=>"CommandCULflash", + Hlp=>" ,flash the CUL from the nightly CVS" ); + $cmds{CULflash} = \%chash; } @@ -27,7 +33,6 @@ CommandUpdatefhem($$) my ($cl, $param) = @_; my $lt = ""; my $ret = ""; - #my $moddir = "$attr{global}{modpath}/FHEM"; my $moddir = "XXX"; @@ -62,6 +67,7 @@ CommandUpdatefhem($$) next if($f ne $param); } else { next if($oldtime{$f} && $filetime{$f} eq $oldtime{$f}); + next if($f =~ m/.hex$/); # skip firmware files } my $localfile = "$moddir/$f"; my $remfile = $f; @@ -101,6 +107,68 @@ CommandUpdatefhem($$) return $ret; } +sub +CommandCULflash($$) +{ + my ($cl, $param) = @_; + #my $moddir = "$attr{global}{modpath}/FHEM"; + my $moddir = "XXX"; + + my %ctypes = ( + CUL_V2 => "at90usb162", + CUL_V2_HM => "at90usb162", + CUL_V3 => "atmega32u4", + CUL_V4 => "atmega32u2", + ); + my @a = split("[ \t]+", $param); + return "Usage: CULflash , ". + "where is one of ". join(" ", sort keys %ctypes) + if(int(@a) != 2 || + !$defs{$a[0]} || + $defs{$a[0]}{TYPE} ne "CUL" || + !$ctypes{$a[1]}); + + my $cul = $a[0]; + my $target = $a[1]; + + ################################ + # First get the index file to prove the file size + my $filetimes = GetHttpFile($server, "$sdir/$ftime"); + return "Can't get $ftime from $server" if(!$filetimes); + + my (%filetime, %filesize); + foreach my $l (split("[\r\n]", $filetimes)) { + chomp($l); + return "Corrupted filetimes.txt file" + if($l !~ m/^20\d\d-\d\d-\d\d_\d\d:\d\d:\d\d /); + my ($ts, $fs, $file) = split(" ", $l, 3); + $filetime{$file} = $ts; + $filesize{$file} = $fs; + } + + ################################ + # Now get the firmware file: + my $content = GetHttpFile($server, "$sdir/$target.hex"); + return "File size for $target.hex does not correspond to filetimes.txt entry" + if(length($content) ne $filesize{"$target.hex"}); + my $localfile = "$moddir/$target.hex"; + open(FH,">$localfile") || return "Can't write $localfile"; + print FH $content; + close(FH); + + my $cmd = "($dfu MCU erase && $dfu MCU flash TARGET && $dfu MCU start) 2>&1"; + my $mcu = $ctypes{$target}; + $cmd =~ s/MCU/$mcu/g; + $cmd =~ s/TARGET/$localfile/g; + + CUL_SimpleWrite($defs{CUL}, "B01"); + sleep(4); # B01 needs 2 seconds for the reset + Log 1, $cmd; + my $result = `$cmd`; + Log 1, $result; + return $result; +} + sub GetHttpFile($$) { diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index bb1e78074..703552176 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -38,6 +38,7 @@
    attr   + CULflash   define   delete   deleteattr   @@ -534,15 +535,36 @@ A line ending with \ will be concatenated with the next one, so long lines updatefhem [filename]

    Update the fhem modules and documentation from a nightly CVS chekout. For - this purpose fhem contants http://fhem.de, compares the stored timestamps - of the local files with the filelist on the server, and downloads the files - changed on the server. For all downloaded modules a reload will be - scheduled if the corresponding module is loaded.
    + this purpose fhem contacts http://fhem.de/fhemupdate, compares the stored + timestamps of the local files with the filelist on the server, and + downloads the files changed on the server. For all downloaded modules a + reload will be scheduled if the corresponding module is loaded.
    If an explicit filename is given, then this file will be downloaded unconditionally.
    Note: if the main program (fhem.pl) is changed, a manual restart of fhem will be necessary to apply the changes. -
+
+ + + +

CULflash

+
    + CULflash <CUL-Name> <CUL-Version>
    +
    + Download the CUL firmware from a nightly CVS chekout and flash the + hardware. Currently only the CUL is supported with its versions: + CUL_V2, CUL_V2_HM, CUL_V3, CUL_V4.
    + Note: dfu-programmer has to be installed in the path.
    + If the CUL is not yet flashed, then first define a CUL + device (even if fhem won't be able to open the device), insert it with the + button pressed (this will set the device into flash-mode), then issue the + CULflash command.
    + Example: +
      + fhem> CULflash CUL CUL_V3 +
    +
+

list