2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-12 16:46:35 +00:00
git-svn-id: https://svn.fhem.de/fhem/trunk@928 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2011-07-05 18:04:27 +00:00
parent d25e1bec4b
commit 2364c55219
2 changed files with 99 additions and 9 deletions

View File

@ -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=>"<cul> <type>,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 <Fhem-CUL-Device> <CUL-type>, ".
"where <CUL-type> 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($$)
{

View File

@ -38,6 +38,7 @@
<ul>
<a href="#attr">attr</a> &nbsp;
<a href="#CULflash">CULflash</a> &nbsp;
<a href="#define">define</a> &nbsp;
<a href="#delete">delete</a> &nbsp;
<a href="#deleteattr">deleteattr</a> &nbsp;
@ -534,15 +535,36 @@ A line ending with \ will be concatenated with the next one, so long lines
<code>updatefhem [filename]</code> <br>
<br>
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.<br>
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.<br>
If an explicit filename is given, then this file will be downloaded
unconditionally.<br>
Note: if the main program (fhem.pl) is changed, a manual restart of fhem
will be necessary to apply the changes.
<br> </ul>
<br>
</ul>
<a name="CULflash"></a>
<h3>CULflash</h3>
<ul>
<code>CULflash &lt;CUL-Name&gt; &lt;CUL-Version&gt;</code> <br>
<br>
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.<br>
<b>Note:</b> dfu-programmer has to be installed in the path.<br>
If the CUL is not yet flashed, then first define a <a href="#CUL">CUL</a>
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.<br>
Example:
<ul>
<code>fhem> CULflash CUL CUL_V3</code>
</ul>
</ul>
<a name="list"></a>
<h3>list</h3>