98_CULflash.pm 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. ##############################################
  2. # $Id: 98_CULflash.pm 11984 2016-08-19 12:47:50Z rudolfkoenig $
  3. package main;
  4. use strict;
  5. use warnings;
  6. use HttpUtils;
  7. sub CommandCULflash($$);
  8. my $urlbase = "http://fhem.de/fhemupdate/";
  9. #####################################
  10. sub
  11. CULflash_Initialize($$)
  12. {
  13. my %chash = ( Fn=>"CommandCULflash",
  14. Hlp=>"<cul> <type>,flash the CUL from the nightly SVN" );
  15. $cmds{CULflash} = \%chash;
  16. }
  17. #####################################
  18. sub
  19. CommandCULflash($$)
  20. {
  21. my ($cl, $param) = @_;
  22. my %ctypes = (
  23. CUL_V2 =>
  24. { cmd => 'dfu-programmer at90usb162 erase && '.
  25. 'dfu-programmer at90usb162 flash $filepath && '.
  26. 'dfu-programmer at90usb162 start',
  27. flash => 'CUL_SimpleWrite($defs{$device},"B01");sleep(4); undef;' },
  28. CUL_V2_HM =>
  29. { cmd => 'dfu-programmer at90usb162 erase && '.
  30. 'dfu-programmer at90usb162 flash $filepath && '.
  31. 'dfu-programmer at90usb162 start',
  32. flash => 'CUL_SimpleWrite($defs{$device},"B01");sleep(4); undef;' },
  33. CUL_V3 =>
  34. { cmd => 'dfu-programmer atmega32u4 erase && '.
  35. 'dfu-programmer atmega32u4 flash $filepath && '.
  36. 'dfu-programmer atmega32u4 start',
  37. flash => 'CUL_SimpleWrite($defs{$device},"B01");sleep(4); undef;' },
  38. CUL_V3_ZWAVE =>
  39. { cmd => 'dfu-programmer atmega32u4 erase && '.
  40. 'dfu-programmer atmega32u4 flash $filepath && '.
  41. 'dfu-programmer atmega32u4 start',
  42. flash => 'CUL_SimpleWrite($defs{$device},"B01");sleep(4); undef;' },
  43. CUL_V4 =>
  44. { cmd => 'dfu-programmer atmega32u2 erase && '.
  45. 'dfu-programmer atmega32u2 flash $filepath && '.
  46. 'dfu-programmer atmega32u2 start',
  47. flash => 'CUL_SimpleWrite($defs{$device},"B01");sleep(4); undef' },
  48. );
  49. my @a = split("[ \t]+", $param);
  50. return "Usage: CULflash [FHEM-Device|none] TYPE>, ".
  51. "where TYPE is one of ". join(" ", sort keys %ctypes)
  52. if(int(@a)!=2 || !($a[0] eq "none" || $defs{$a[0]}) || !$ctypes{$a[1]});
  53. my $device = $a[0];
  54. my $type = $a[1];
  55. my $filename = $a[1].".hex";
  56. my $fwdir = $attr{global}{modpath} . "/FHEM/firmware";
  57. my $filepath = "$fwdir/$filename";
  58. ################################
  59. # Get the firmware file:
  60. if(! -d $fwdir) {
  61. mkdir($fwdir) || return "$fwdir: $!";
  62. }
  63. my $content = GetFileFromURL("$urlbase/FHEM/firmware/$filename");
  64. return "Cannot get $urlbase/FHEM/firmware/$filename"
  65. if(!$content);
  66. if($content !~ m/:00000001FF/) {
  67. Log3 undef, 3, $content;
  68. return "The retrieved $filename is not a correct .hex file";
  69. }
  70. my $localfile = "$filepath";
  71. open(FH,">$localfile") || return "Can't write $localfile";
  72. print FH $content;
  73. close(FH);
  74. if($device ne "none" && $ctypes{$type}{flash}) {
  75. my $ret = eval $ctypes{$type}{flash};
  76. Log 1, "CULflash $device: $ret"
  77. if($ret);
  78. }
  79. my $cmd = eval "return \"$ctypes{$type}{cmd};\"";
  80. Log3 undef, 1, "CULflash $cmd";
  81. my $result = `($cmd) 2>&1`;
  82. Log3 undef, 1, "CULflash $result";
  83. return $result;
  84. }
  85. 1;
  86. =pod
  87. =item command
  88. =item summary flash (USB-)CUL device with culfw
  89. =item summary_DE USB-CUL Ger&auml;te mit Firmware versorgen (flashen)
  90. =begin html
  91. <a name="CULflash"></a>
  92. <h3>CULflash</h3>
  93. <ul>
  94. <code>CULflash [fhem-device|none]; &lt;TYPE&gt;</code> <br>
  95. <br>
  96. Download the firmware from a nightly SVN chekout and flash the
  97. hardware.
  98. Currently the CUL is supported with its versions:
  99. CUL_V2, CUL_V2_HM, CUL_V3, CUL_V3_ZWAVE, CUL_V4.<br>
  100. If the fhem-device is none, than the inserted device must already be in the
  101. flash-mode.<br>
  102. <b>Note:</b>for flashing the CUL dfu-programmer has to be installed in the
  103. path, this is already the case with the Fritz!Box 7390 image from
  104. fhem.de<br>
  105. Example:
  106. <ul>
  107. <code>CULflash CUL CUL_V3<br>
  108. CULflash none CUL_V3</code>
  109. </ul>
  110. Note: the message "dfu-programmer: failed to release interface 0." is
  111. normal on the FB7390.
  112. </ul>
  113. =end html
  114. =begin html_DE
  115. <a name="CULflash"></a>
  116. <h3>CULflash</h3>
  117. <ul>
  118. <code>CULflash [fhem-device|none]; &lt;TYPE&gt;</code> <br>
  119. <br>
  120. L&auml;dt die spezifizierte Firmware von fhem.de und programmiert das
  121. angeschlossene Ger&auml;t.
  122. Z.Zt unterst&uuml;tzt wird das CUL und folgende Versionen:
  123. CUL_V2, CUL_V2_HM, CUL_V3, CUL_V3_ZWAVE, CUL_V4.<br>
  124. Falls als fhem-device none angegeben wurde, dann muss sich das
  125. angeschlossene Ger&auml;t bereits in flash-mode befinden.<br>
  126. <b>Achtung:</b>F&uuml;r CUL flashen muss dfu-programmer installiert und im
  127. Pfad auffindbar sein, das ist der Fall bei dem Fritz!BOX 7390 Paket von
  128. fhem.de<br>
  129. Beispiele:
  130. <ul>
  131. <code>CULflash CUL CUL_V3<br>
  132. CULflash none CUL_V3</code>
  133. </ul>
  134. Achtung: die Meldung "dfu-programmer: failed to release interface 0." ist
  135. auf der FB7390 "normal".
  136. </ul>
  137. =end html_DE
  138. =cut