00_CUL.pm 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733
  1. ##############################################
  2. # $Id: 00_CUL.pm 17559 2018-10-18 07:45:07Z rudolfkoenig $
  3. package main;
  4. use strict;
  5. use warnings;
  6. use Time::HiRes qw(gettimeofday);
  7. sub CUL_Attr(@);
  8. sub CUL_Clear($);
  9. sub CUL_HandleCurRequest($$);
  10. sub CUL_HandleWriteQueue($);
  11. sub CUL_Parse($$$$@);
  12. sub CUL_Read($);
  13. sub CUL_ReadAnswer($$$$);
  14. sub CUL_Ready($);
  15. sub CUL_Write($$$);
  16. sub CUL_SimpleWrite(@);
  17. sub CUL_WriteInit($);
  18. my %gets = ( # Name, Data to send to the CUL, Regexp for the answer
  19. "ccconf" => 1,
  20. "version" => ["V", '^V .*'],
  21. "raw" => ["", '.*'],
  22. "uptime" => ["t", '^[0-9A-F]{8}[\r\n]*$' ],
  23. "fhtbuf" => ["T03", '^[0-9A-F]+[\r\n]*$' ],
  24. "cmds" => ["?", '.*Use one of( .)*[\r\n]*$' ],
  25. "credit10ms" => [ "X", '^.. *\d*[\r\n]*$' ],
  26. );
  27. my %sets = (
  28. "reopen" => "",
  29. "hmPairForSec" => "HomeMatic",
  30. "hmPairSerial" => "HomeMatic",
  31. "raw" => "",
  32. "freq" => "SlowRF",
  33. "bWidth" => "SlowRF",
  34. "rAmpl" => "SlowRF",
  35. "sens" => "SlowRF",
  36. "led" => "",
  37. "patable" => "",
  38. "ITClock" => "SlowRF"
  39. );
  40. my @ampllist = (24, 27, 30, 33, 36, 38, 40, 42); # rAmpl(dB)
  41. my $sccMods = "STACKABLE_CC:TSSTACKED:STACKABLE";
  42. my $culNameRe = "^(CUL|TSCUL)\$";
  43. my $clientsSlowRF = ":FS20:FHT.*:KS300:USF1000:BS:HMS:FS20V: ".
  44. ":CUL_EM:CUL_WS:CUL_FHTTK:CUL_HOERMANN: ".
  45. ":ESA2000:CUL_IR:CUL_TX:Revolt:IT:UNIRoll:SOMFY: ".
  46. ":$sccMods:CUL_RFR::CUL_TCM97001:CUL_REDIRECT:";
  47. my $clientsHomeMatic = ":CUL_HM:HMS:CUL_IR:$sccMods:";
  48. my $clientsMAX = ":CUL_MAX:HMS:CUL_IR:$sccMods:";
  49. my $clientsWMBus = ":WMBUS:HMS:CUL_IR:$sccMods:";
  50. my $clientsKOPP_FC = ":KOPP_FC:HMS:CUL_IR:$sccMods:";
  51. my %matchListSlowRF = (
  52. "0:FS20V" => "^81..(04|0c)..0101a001......00[89a-f]...",
  53. "1:USF1000" => "^81..(04|0c)..0101a001a5ceaa00....",
  54. "2:BS" => "^81..(04|0c)..0101a001a5cf",
  55. "3:FS20" => "^81..(04|0c)..0101a001",
  56. "4:FHT" => "^81..(04|09|0d)..(0909a001|83098301|c409c401)..",
  57. "5:KS300" => "^810d04..4027a001",
  58. "6:CUL_WS" => "^K.....",
  59. "7:CUL_EM" => "^E0.................\$",
  60. "8:HMS" => "^810e04......a001",
  61. "9:CUL_FHTTK" => "^T[A-F0-9]{8}",
  62. "A:CUL_RFR" => "^[0-9A-F]{4}U.",
  63. "B:CUL_HOERMANN"=> "^R..........",
  64. "C:ESA2000" => "^S................................\$",
  65. "D:CUL_IR" => "^I............",
  66. "E:CUL_TX" => "^TX[A-F0-9]{10}",
  67. "F:Revolt" => "^r......................\$",
  68. "G:IT" => "^i......",
  69. "H:STACKABLE_CC"=>"^\\*",
  70. "I:UNIRoll" => "^[0-9A-F]{5}(B|D|E)",
  71. "J:SOMFY" => "^Y[r|t|s]:?[A-F0-9]+",
  72. "K:CUL_TCM97001" => "^s[A-F0-9]+",
  73. "L:CUL_REDIRECT" => "^o+",
  74. "M:TSSTACKED"=>"^\\*",
  75. "N:STACKABLE"=>"^\\*",
  76. );
  77. my %matchListHomeMatic = (
  78. "1:CUL_HM" => "^A....................",
  79. "8:HMS" => "^810e04....(1|5|9).a001", # CUNO OneWire HMS Emulation
  80. "D:CUL_IR" => "^I............",
  81. "H:STACKABLE_CC"=>"^\\*",
  82. "M:TSSTACKED"=>"^\\*",
  83. "N:STACKABLE"=>"^\\*",
  84. );
  85. my %matchListMAX = (
  86. "1:CUL_MAX" => "^Z........................",
  87. "8:HMS" => "^810e04....(1|5|9).a001", # CUNO OneWire HMS Emulation
  88. "D:CUL_IR" => "^I............",
  89. "H:STACKABLE_CC"=>"^\\*",
  90. "M:TSSTACKED"=>"^\\*",
  91. "N:STACKABLE"=>"^\\*",
  92. );
  93. my %matchListWMBus = (
  94. "J:WMBUS" => "^b.*",
  95. "8:HMS" => "^810e04....(1|5|9).a001", # CUNO OneWire HMS Emulation
  96. "D:CUL_IR" => "^I............",
  97. "H:STACKABLE_CC"=>"^\\*",
  98. "M:TSSTACKED"=>"^\\*",
  99. "N:STACKABLE"=>"^\\*",
  100. );
  101. my %matchListKOPP_FC = (
  102. "1:Kopp_FC" => "^kr..................",
  103. "8:HMS" => "^810e04....(1|5|9).a001", # CUNO OneWire HMS Emulation
  104. "D:CUL_IR" => "^I............",
  105. "H:STACKABLE_CC"=>"^\\*",
  106. "M:TSSTACKED"=>"^\\*",
  107. "N:STACKABLE"=>"^\\*",
  108. );
  109. sub
  110. CUL_Initialize($)
  111. {
  112. my ($hash) = @_;
  113. require "$attr{global}{modpath}/FHEM/DevIo.pm";
  114. # Provider
  115. $hash->{ReadFn} = "CUL_Read";
  116. $hash->{WriteFn} = "CUL_Write";
  117. $hash->{ReadyFn} = "CUL_Ready";
  118. # Normal devices
  119. $hash->{DefFn} = "CUL_Define";
  120. $hash->{FingerprintFn} = "CUL_FingerprintFn";
  121. $hash->{UndefFn} = "CUL_Undef";
  122. $hash->{GetFn} = "CUL_Get";
  123. $hash->{SetFn} = "CUL_Set";
  124. $hash->{AttrFn} = "CUL_Attr";
  125. no warnings 'qw';
  126. my @attrList = qw(
  127. addvaltrigger
  128. connectCommand
  129. do_not_notify:1,0
  130. dummy:1,0
  131. hmId longids
  132. hmProtocolEvents:0_off,1_dump,2_dumpFull,3_dumpTrigger
  133. model:CUL,CUN,CUNO,SCC,nanoCUL
  134. rfmode:SlowRF,HomeMatic,MAX,WMBus_T,WMBus_S,WMBus_C,KOPP_FC
  135. sendpool
  136. showtime:1,0
  137. );
  138. use warnings 'qw';
  139. $hash->{AttrList} = join(" ", @attrList)." ".$readingFnAttributes;
  140. $hash->{ShutdownFn} = "CUL_Shutdown";
  141. }
  142. sub
  143. CUL_FingerprintFn($$)
  144. {
  145. my ($name, $msg) = @_;
  146. # Store only the "relevant" part, as the CUL won't compute the checksum
  147. $msg = substr($msg, 8) if($msg =~ m/^81/ && length($msg) > 8);
  148. return ($name, $msg);
  149. }
  150. #####################################
  151. sub
  152. CUL_Define($$)
  153. {
  154. my ($hash, $def) = @_;
  155. my @a = split("[ \t][ \t]*", $def);
  156. if(@a < 4 || @a > 5) {
  157. my $msg = "wrong syntax: define <name> CUL {none | devicename[\@baudrate] ".
  158. "| devicename\@directio | hostname:port} <FHTID>";
  159. Log3 undef, 2, $msg;
  160. return $msg;
  161. }
  162. DevIo_CloseDev($hash);
  163. my $name = $a[0];
  164. my $dev = $a[2];
  165. return "FHTID must be H1H2, with H1 and H2 hex and both smaller than 64"
  166. if(uc($a[3]) !~ m/^[0-6][0-9A-F][0-6][0-9A-F]$/);
  167. if(uc($a[3]) =~ m/^([0-6][0-9A-F])/ && $1 ne "00") {
  168. my $x = $1;
  169. foreach my $d (keys %defs) {
  170. next if($d eq $name);
  171. if($defs{$d}{TYPE} =~ m/$culNameRe/) {
  172. if(uc($defs{$d}{FHTID}) =~ m/^$x/) {
  173. my $m = "$name: Cannot define multiple CULs with identical ".
  174. "first two digits ($x)";
  175. Log3 $name, 1, $m;
  176. return $m;
  177. }
  178. }
  179. }
  180. }
  181. $hash->{FHTID} = uc($a[3]);
  182. $hash->{initString} = "X21";
  183. $hash->{CMDS} = "";
  184. $hash->{Clients} = $clientsSlowRF;
  185. $hash->{MatchList} = \%matchListSlowRF;
  186. if($dev eq "none") {
  187. Log3 $name, 1, "$name device is none, commands will be echoed only";
  188. $attr{$name}{dummy} = 1;
  189. return undef;
  190. }
  191. $hash->{DeviceName} = $dev;
  192. my $ret = DevIo_OpenDev($hash, 0, "CUL_DoInit");
  193. return $ret;
  194. }
  195. #####################################
  196. sub
  197. CUL_Undef($$)
  198. {
  199. my ($hash, $arg) = @_;
  200. my $name = $hash->{NAME};
  201. foreach my $d (sort keys %defs) {
  202. if(defined($defs{$d}) &&
  203. defined($defs{$d}{IODev}) &&
  204. $defs{$d}{IODev} == $hash)
  205. {
  206. my $lev = ($reread_active ? 4 : 2);
  207. Log3 $name, $lev, "deleting port for $d";
  208. delete $defs{$d}{IODev};
  209. }
  210. }
  211. CUL_SimpleWrite($hash, "X00"); # Switch reception off, it may hang up the CUL
  212. DevIo_CloseDev($hash);
  213. return undef;
  214. }
  215. #####################################
  216. sub
  217. CUL_Shutdown($)
  218. {
  219. my ($hash) = @_;
  220. CUL_SimpleWrite($hash, "X00");
  221. return undef;
  222. }
  223. sub
  224. CUL_RemoveHMPair($)
  225. {
  226. my $hash = shift;
  227. delete($hash->{hmPair});
  228. }
  229. #####################################
  230. sub
  231. CUL_Reopen($)
  232. {
  233. my ($hash) = @_;
  234. DevIo_CloseDev($hash);
  235. DevIo_OpenDev($hash, 1, "CUL_DoInit");
  236. }
  237. #####################################
  238. sub
  239. CUL_Set($@)
  240. {
  241. my ($hash, @a) = @_;
  242. return "\"set CUL\" needs at least one parameter" if(@a < 2);
  243. return "Unknown argument $a[1], choose one of " . join(" ", sort keys %sets)
  244. if(!defined($sets{$a[1]}));
  245. my $name = shift @a;
  246. my $type = shift @a;
  247. my $arg = join("", @a);
  248. return "This command is not valid in the current rfmode"
  249. if($sets{$type} && $sets{$type} ne AttrVal($name, "rfmode", "SlowRF"));
  250. if($type eq "reopen") {
  251. CUL_Reopen($hash);
  252. } elsif($type eq "hmPairForSec") {
  253. return "Usage: set $name hmPairForSec <seconds_active>"
  254. if(!$arg || $arg !~ m/^\d+$/);
  255. $hash->{hmPair} = 1;
  256. InternalTimer(gettimeofday()+$arg, "CUL_RemoveHMPair", $hash, 1);
  257. } elsif($type eq "hmPairSerial") {
  258. return "Usage: set $name hmPairSerial <10-character-serialnumber>"
  259. if(!$arg || $arg !~ m/^.{10}$/);
  260. my $id = AttrVal($hash->{NAME}, "hmId", "F1".$hash->{FHTID});
  261. $hash->{HM_CMDNR} = $hash->{HM_CMDNR} ? ($hash->{HM_CMDNR}+1)%256 : 1;
  262. CUL_SimpleWrite($hash, sprintf("As15%02x8401%s000000010A%s",
  263. $hash->{HM_CMDNR}, $id, unpack('H*', $arg)));
  264. $hash->{hmPairSerial} = $arg;
  265. } elsif($type eq "freq") {
  266. my $f = $arg/26*65536;
  267. my $f2 = sprintf("%02x", $f / 65536);
  268. my $f1 = sprintf("%02x", int($f % 65536) / 256);
  269. my $f0 = sprintf("%02x", $f % 256);
  270. $arg = sprintf("%.3f", (hex($f2)*65536+hex($f1)*256+hex($f0))/65536*26);
  271. Log3 $name, 3, "Setting FREQ2..0 (0D,0E,0F) to $f2 $f1 $f0 = $arg MHz";
  272. CUL_SimpleWrite($hash, "W0F$f2");
  273. CUL_SimpleWrite($hash, "W10$f1");
  274. CUL_SimpleWrite($hash, "W11$f0");
  275. CUL_WriteInit($hash); # Will reprogram the CC1101
  276. } elsif($type eq "bWidth") {
  277. my ($err, $ob);
  278. if(!IsDummy($hash->{NAME})) {
  279. CUL_SimpleWrite($hash, "C10");
  280. ($err, $ob) = CUL_ReadAnswer($hash, $type, 0, "^C10 = .*");
  281. return "Can't get old MDMCFG4 value" if($err || $ob !~ m,/ (.*)\r,);
  282. $ob = $1 & 0x0f;
  283. }
  284. my ($bits, $bw) = (0,0);
  285. for (my $e = 0; $e < 4; $e++) {
  286. for (my $m = 0; $m < 4; $m++) {
  287. $bits = ($e<<6)+($m<<4);
  288. $bw = int(26000/(8 * (4+$m) * (1 << $e))); # KHz
  289. goto GOTBW if($arg >= $bw);
  290. }
  291. }
  292. GOTBW:
  293. $ob = sprintf("%02x", $ob+$bits);
  294. Log3 $name, 3, "Setting MDMCFG4 (10) to $ob = $bw KHz";
  295. CUL_SimpleWrite($hash, "W12$ob");
  296. CUL_WriteInit($hash);
  297. } elsif($type eq "rAmpl") {
  298. return "a numerical value between 24 and 42 is expected"
  299. if($arg !~ m/^\d+$/ || $arg < 24 || $arg > 42);
  300. my ($v, $w);
  301. for($v = 0; $v < @ampllist; $v++) {
  302. last if($ampllist[$v] > $arg);
  303. }
  304. $v = sprintf("%02d", $v-1);
  305. $w = $ampllist[$v];
  306. Log3 $name, 3, "Setting AGCCTRL2 (1B) to $v / $w dB";
  307. CUL_SimpleWrite($hash, "W1D$v");
  308. CUL_WriteInit($hash);
  309. } elsif($type eq "sens") {
  310. return "a numerical value between 4 and 16 is expected"
  311. if($arg !~ m/^\d+$/ || $arg < 4 || $arg > 16);
  312. my $w = int($arg/4)*4;
  313. my $v = sprintf("9%d",$arg/4-1);
  314. Log3 $name, 3, "Setting AGCCTRL0 (1D) to $v / $w dB";
  315. CUL_SimpleWrite($hash, "W1F$v");
  316. CUL_WriteInit($hash);
  317. } elsif( $type eq "ITClock" ) {
  318. my $clock = shift @a;
  319. $clock=250 if($clock eq "");
  320. return "argument $arg is not numeric" if($clock !~ /^\d+$/);
  321. Log3 $name, 3, "set $name $type $clock";
  322. $arg="ic$clock";
  323. CUL_SimpleWrite($hash, $arg);
  324. } else {
  325. return "Expecting a 0-padded hex number"
  326. if((length($arg)&1) == 1 && $type ne "raw");
  327. Log3 $name, 3, "set $name $type $arg";
  328. $arg = "l$arg" if($type eq "led");
  329. $arg = "x$arg" if($type eq "patable");
  330. CUL_SimpleWrite($hash, $arg);
  331. }
  332. return undef;
  333. }
  334. #####################################
  335. sub
  336. CUL_Get($@)
  337. {
  338. my ($hash, @a) = @_;
  339. my $type = $hash->{TYPE};
  340. return "\"get $type\" needs at least one parameter" if(@a < 2);
  341. if(!defined($gets{$a[1]})) {
  342. my @cList = map { $_ =~ m/^(file|raw)$/ ? $_ : "$_:noArg" } sort keys %gets;
  343. return "Unknown argument $a[1], choose one of " . join(" ", @cList);
  344. }
  345. my $arg = ($a[2] ? $a[2] : "");
  346. my ($msg, $err);
  347. my $name = $a[0];
  348. return "No $a[1] for dummies" if(IsDummy($name));
  349. if($a[1] eq "ccconf") {
  350. my %r = ( "0D"=>1,"0E"=>1,"0F"=>1,"10"=>1,"1B"=>1,"1D"=>1 );
  351. foreach my $a (sort keys %r) {
  352. CUL_SimpleWrite($hash, "C$a");
  353. ($err, $msg) = CUL_ReadAnswer($hash, "C$a", 0, "^C.* = .*");
  354. return $err if($err);
  355. my @answ = split(" ", $msg);
  356. $r{$a} = $answ[4];
  357. }
  358. $msg = sprintf("freq:%.3fMHz bWidth:%dKHz rAmpl:%ddB sens:%ddB",
  359. 26*(($r{"0D"}*256+$r{"0E"})*256+$r{"0F"})/65536, #Freq
  360. 26000/(8 * (4+(($r{"10"}>>4)&3)) * (1 << (($r{"10"}>>6)&3))), #Bw
  361. $ampllist[$r{"1B"}&7],
  362. 4+4*($r{"1D"}&3) #Sens
  363. );
  364. } else {
  365. CUL_SimpleWrite($hash, $gets{$a[1]}[0] . $arg);
  366. my $mtch = defined($a[3]) ? $a[3] : $gets{$a[1]}[1]; # optional
  367. ($err, $msg) = CUL_ReadAnswer($hash, $a[1], 0, $mtch);
  368. if(!defined($msg)) {
  369. DevIo_Disconnected($hash);
  370. $msg = "No answer";
  371. } elsif($a[1] eq "cmds") { # nice it up
  372. $msg =~ s/.*Use one of//g;
  373. } elsif($a[1] eq "uptime") { # decode it
  374. $msg =~ s/[\r\n]//g;
  375. $msg = hex($msg)/125;
  376. $msg = sprintf("%d %02d:%02d:%02d",
  377. $msg/86400, ($msg%86400)/3600, ($msg%3600)/60, $msg%60);
  378. } elsif($a[1] eq "credit10ms") {
  379. ($msg) = ($msg =~ /^.. *(\d*)[\r\n]*$/);
  380. }
  381. $msg =~ s/[\r\n]//g;
  382. }
  383. readingsSingleUpdate($hash, $a[1], $msg, 1);
  384. return "$a[0] $a[1] => $msg";
  385. }
  386. sub
  387. CUL_Clear($)
  388. {
  389. my $hash = shift;
  390. # Clear the pipe
  391. $hash->{RA_Timeout} = 0.1;
  392. for(;;) {
  393. my ($err, undef) = CUL_ReadAnswer($hash, "Clear", 0, "wontmatch");
  394. last if($err);
  395. }
  396. delete($hash->{RA_Timeout});
  397. $hash->{PARTIAL} = "";
  398. }
  399. #####################################
  400. sub
  401. CUL_DoInit($)
  402. {
  403. my $hash = shift;
  404. my $name = $hash->{NAME};
  405. my $err;
  406. my $msg = undef;
  407. CUL_Clear($hash);
  408. my ($ver, $try) = ("", 0);
  409. while($try++ < 3 && $ver !~ m/^V/) {
  410. CUL_SimpleWrite($hash, "V");
  411. ($err, $ver) = CUL_ReadAnswer($hash, "Version", 0, "^V");
  412. return "$name: $err" if($err && ($err !~ m/Timeout/ || $try == 3));
  413. $ver = "" if(!$ver);
  414. }
  415. if($ver !~ m/^V/) {
  416. $attr{$name}{dummy} = 1;
  417. $msg = "Not an CUL device, got for V: $ver";
  418. Log3 $name, 1, $msg;
  419. return $msg;
  420. }
  421. $ver =~ s/[\r\n]//g;
  422. $hash->{VERSION} = $ver;
  423. # Cmd-String feststellen
  424. my $cmds = CUL_Get($hash, $name, "cmds", 0);
  425. $cmds =~ s/$name cmds =>//g;
  426. $cmds =~ s/ //g;
  427. $hash->{CMDS} = $cmds;
  428. Log3 $name, 3, "$name: Possible commands: " . $hash->{CMDS};
  429. CUL_WriteInit($hash);
  430. # FHTID
  431. if(defined($hash->{FHTID})) {
  432. my $fhtid;
  433. CUL_SimpleWrite($hash, "T01");
  434. ($err, $fhtid) = CUL_ReadAnswer($hash, "FHTID", 0, undef);
  435. return "$name: $err" if($err);
  436. $fhtid =~ s/[\r\n]//g;
  437. Log3 $name, 5, "GOT CUL fhtid: $fhtid";
  438. if(!defined($fhtid) || $fhtid ne $hash->{FHTID}) {
  439. Log3 $name, 2, "Setting $name fhtid from $fhtid to " . $hash->{FHTID};
  440. CUL_SimpleWrite($hash, "T01" . $hash->{FHTID});
  441. }
  442. }
  443. my $cc = AttrVal($name, "connectCommand", undef);
  444. CUL_SimpleWrite($hash, $cc) if($cc);
  445. readingsSingleUpdate($hash, "state", "Initialized", 1);
  446. # Reset the counter
  447. delete($hash->{XMIT_TIME});
  448. delete($hash->{NR_CMD_LAST_H});
  449. return undef;
  450. }
  451. #####################################
  452. # This is a direct read for commands like get
  453. # Anydata is used by read file to get the filesize
  454. sub
  455. CUL_ReadAnswer($$$$)
  456. {
  457. my ($hash, $arg, $anydata, $regexp) = @_;
  458. my $ohash = $hash;
  459. while($hash && $hash->{TYPE} !~ m/$culNameRe/) {
  460. $hash = $hash->{IODev};
  461. }
  462. return ("No FD", undef)
  463. if(!$hash || ($^O !~ /Win/ && !defined($hash->{FD})));
  464. my ($mculdata, $rin) = ("", '');
  465. my $buf;
  466. my $to = 3; # 3 seconds timeout
  467. $mculdata = $hash->{PARTIAL} if(defined($hash->{PARTIAL}));
  468. $to = $ohash->{RA_Timeout} if($ohash->{RA_Timeout}); # ...or less
  469. for(;;) {
  470. if($^O =~ m/Win/ && $hash->{USBDev}) {
  471. $hash->{USBDev}->read_const_time($to*1000); # set timeout (ms)
  472. # Read anstatt input sonst funzt read_const_time nicht.
  473. $buf = $hash->{USBDev}->read(999);
  474. return ("Timeout reading answer for get $arg", undef)
  475. if(length($buf) == 0);
  476. } else {
  477. return ("Device lost when reading answer for get $arg", undef)
  478. if(!$hash->{FD});
  479. vec($rin, $hash->{FD}, 1) = 1;
  480. my $nfound = select($rin, undef, undef, $to);
  481. if($nfound < 0) {
  482. next if ($! == EAGAIN() || $! == EINTR() || $! == 0);
  483. my $err = $!;
  484. DevIo_Disconnected($hash);
  485. return("CUL_ReadAnswer $arg: $err", undef);
  486. }
  487. return ("Timeout reading answer for get $arg", undef)
  488. if($nfound == 0);
  489. $buf = DevIo_SimpleRead($hash);
  490. return ("No data", undef) if(!defined($buf));
  491. }
  492. if(defined($buf)) {
  493. Log3 $ohash->{NAME}, 5, "CUL/RAW (ReadAnswer): $buf";
  494. $mculdata .= $buf;
  495. }
  496. # Dispatch data in the buffer before the proper answer.
  497. while(($mculdata =~ m/^([^\n]*\n)(.*)/s) || $anydata) {
  498. my $line = ($anydata ? $mculdata : $1);
  499. $mculdata = $2;
  500. $hash->{PARTIAL} = $mculdata; # for recursive calls
  501. (undef, $line) = CUL_prefix(0, $ohash, $line); # Delete prefix
  502. if($regexp && $line !~ m/$regexp/) {
  503. $line =~ s/[\n\r]+//g;
  504. CUL_Parse($ohash, $hash, $ohash->{NAME}, $line) if($init_done);
  505. $mculdata = $hash->{PARTIAL};
  506. } else {
  507. return (undef, $line);
  508. }
  509. }
  510. }
  511. }
  512. #####################################
  513. # Check if the 1% limit is reached and trigger notifies
  514. sub
  515. CUL_XmitLimitCheck($$$)
  516. {
  517. my ($hash,$fn,$now) = @_;
  518. if(!$hash->{XMIT_TIME}) {
  519. $hash->{XMIT_TIME}[0] = $now;
  520. $hash->{NR_CMD_LAST_H} = 1;
  521. return;
  522. }
  523. my $nowM1h = $now-3600;
  524. my @b = grep { $_ > $nowM1h } @{$hash->{XMIT_TIME}};
  525. # Maximum nr of transmissions per hour, but not for HM and MAX
  526. if(@b > 163 && $fn !~ m/^[AZ]/) {
  527. my $name = $hash->{NAME};
  528. Log3 $name, 2, "CUL TRANSMIT LIMIT EXCEEDED";
  529. DoTrigger($name, "TRANSMIT LIMIT EXCEEDED");
  530. } else {
  531. push(@b, $now);
  532. }
  533. $hash->{XMIT_TIME} = \@b;
  534. $hash->{NR_CMD_LAST_H} = int(@b);
  535. }
  536. sub
  537. CUL_XmitDlyHM($$$)
  538. {
  539. my ($hash,$fn,$now) = @_;
  540. my (undef,$mTy,undef,$id) = unpack 'A8A2A6A6',$fn if(length($fn)>19);
  541. if($id &&
  542. $modules{CUL_HM}{defptr}{$id} &&
  543. $modules{CUL_HM}{defptr}{$id}{helper}{io} &&
  544. $modules{CUL_HM}{defptr}{$id}{helper}{io}{nextSend}) {
  545. my $dDly = $modules{CUL_HM}{defptr}{$id}{helper}{io}{nextSend} - $now;
  546. #$dDly -= 0.04 if ($mTy eq "02");# while HM devices need a rest there are
  547. # still some devices that need faster
  548. # reactionfor ack.
  549. # Mode needs to be determined
  550. if ($dDly > 0.01){# wait less then 10 ms will not work
  551. $dDly = 0.1 if($dDly > 0.1);
  552. Log3 $hash->{NAME}, 5, "CUL $id dly:".int($dDly*1000)."ms";
  553. select(undef, undef, undef, $dDly);
  554. }
  555. }
  556. shift(@{$hash->{helper}{$id}{QUEUE}});
  557. InternalTimer($now+0.1, "CUL_XmitDlyHMTo", "$hash->{NAME}:$id", 1)
  558. if (scalar(@{$hash->{helper}{$id}{QUEUE}}));
  559. return 0;
  560. }
  561. sub
  562. CUL_XmitDlyHMTo($)
  563. { # waited long enough - next send for this ID
  564. my ($name,$id) = split(":",$_[0]);
  565. CUL_SendFromQueue($defs{$name}, ${$defs{$name}{helper}{$id}{QUEUE}}[0]);
  566. }
  567. #####################################
  568. # Translate data prepared for an FHZ to CUL syntax, so we can reuse
  569. # the FS20 and FHZ modules.
  570. sub
  571. CUL_WriteTranslate($$$)
  572. {
  573. my ($hash,$fn,$msg) = @_;
  574. ###################
  575. # Rewrite message from FHZ -> CUL
  576. if(length($fn) <= 1) { # CUL Native
  577. ;
  578. } elsif($fn eq "04" && substr($msg,0,6) eq "010101") { # FS20
  579. $fn = "F";
  580. AddDuplicate($hash->{NAME},
  581. "0101a001" . substr($msg, 6, 6) . "00" . substr($msg, 12));
  582. $msg = substr($msg,6);
  583. } elsif($fn eq "04" && substr($msg,0,6) eq "020183") { # FHT
  584. $fn = "T";
  585. $msg = substr($msg,6,4) . substr($msg,10);
  586. } elsif($fn eq "cmd") { # internal command
  587. if($msg eq "speed100") {
  588. $fn = "AR";
  589. } elsif($msg eq "speed10") {
  590. $fn = "Ar";
  591. } else { # by default rewrite init
  592. $fn = $hash->{initString};
  593. }
  594. $msg = "";
  595. } else {
  596. Log3 $hash, 2, "CUL cannot translate $fn $msg";
  597. return (undef, undef);
  598. }
  599. return ($fn, $msg);
  600. }
  601. #####################################
  602. sub
  603. CUL_Write($$$)
  604. {
  605. my ($hash,$fn,$msg) = @_;
  606. ($fn, $msg) = CUL_WriteTranslate($hash, $fn, $msg);
  607. return if(!defined($fn));
  608. my $name = $hash->{NAME};
  609. Log3 $name, 5, "$hash->{NAME} sending $fn$msg";
  610. my $bstring = "$fn$msg";
  611. if($fn eq "F" || # FS20 message
  612. $bstring =~ m/^u....F/ || # FS20 messages sent over an RFR
  613. ($fn eq "" && ($bstring =~ m/^A/ || $bstring =~ m/^Z/ ))) { # AskSin/BidCos/HomeMatic/MAX
  614. CUL_AddSendQueue($hash, $bstring);
  615. } else {
  616. CUL_SimpleWrite($hash, $bstring);
  617. }
  618. }
  619. sub
  620. CUL_SendFromQueue($$)
  621. {
  622. my ($hash, $bstring) = @_;
  623. my $name = $hash->{NAME};
  624. my $hm = ($bstring =~ m/^A/);
  625. my $to = ($hm ? 0.15 : 0.3);
  626. my $now = gettimeofday();
  627. if($bstring ne "") {
  628. my $sp = AttrVal($name, "sendpool", undef);
  629. if($sp) { # Is one of the CUL-fellows sending data?
  630. my @fellows = split(",", $sp);
  631. foreach my $f (@fellows) {
  632. if($f ne $name &&
  633. $defs{$f} &&
  634. $defs{$f}{QUEUE} &&
  635. $defs{$f}{QUEUE}->[0] ne ""){
  636. unshift(@{$hash->{QUEUE}}, "");
  637. InternalTimer($now+$to, "CUL_HandleWriteQueue", $hash, 1);
  638. return;
  639. }
  640. }
  641. }
  642. CUL_XmitLimitCheck($hash, $bstring, $now);
  643. if($hm) {
  644. CUL_SimpleWrite($hash, $bstring) if(!CUL_XmitDlyHM($hash,$bstring,$now));
  645. return;
  646. } else {
  647. CUL_SimpleWrite($hash, $bstring);
  648. }
  649. }
  650. ##############
  651. # Write the next buffer not earlier than 0.23 seconds
  652. # = 3* (12*0.8+1.2+1.0*5*9+0.8+10) = 226.8ms
  653. # else it will be sent too early by the CUL, resulting in a collision
  654. InternalTimer($now+$to, "CUL_HandleWriteQueue", $hash, 1);
  655. }
  656. sub
  657. CUL_AddSendQueue($$)
  658. {
  659. my ($hash, $bstring) = @_;
  660. my $qHash = $hash;
  661. if ($bstring =~ m/^A/){ # HM device
  662. my $id = substr($bstring,16,6);#get HMID destination
  663. $qHash = $hash->{helper}{$id};
  664. }
  665. if(!$qHash->{QUEUE} || 0 == scalar(@{$qHash->{QUEUE}})) {
  666. $qHash->{QUEUE} = [ $bstring ];
  667. CUL_SendFromQueue($hash, $bstring);
  668. } else {
  669. push(@{$qHash->{QUEUE}}, $bstring);
  670. }
  671. }
  672. #####################################
  673. sub
  674. CUL_HandleWriteQueue($)
  675. {
  676. my $hash = shift;
  677. my $arr = $hash->{QUEUE};
  678. if(defined($arr) && @{$arr} > 0) {
  679. shift(@{$arr});
  680. if(@{$arr} == 0) {
  681. delete($hash->{QUEUE});
  682. return;
  683. }
  684. my $bstring = $arr->[0];
  685. if($bstring eq "") {
  686. CUL_HandleWriteQueue($hash);
  687. } else {
  688. CUL_SendFromQueue($hash, $bstring);
  689. }
  690. }
  691. }
  692. #####################################
  693. # called from the global loop, when the select for hash->{FD} reports data
  694. sub
  695. CUL_Read($)
  696. {
  697. my ($hash) = @_;
  698. my $buf = DevIo_SimpleRead($hash);
  699. return "" if(!defined($buf));
  700. my $name = $hash->{NAME};
  701. my $culdata = $hash->{PARTIAL};
  702. Log3 $name, 5, "CUL/RAW: $culdata/$buf";
  703. $culdata .= $buf;
  704. while($culdata =~ m/\n/) {
  705. my $rmsg;
  706. ($rmsg,$culdata) = split("\n", $culdata, 2);
  707. $rmsg =~ s/\r//;
  708. $hash->{PARTIAL} = $culdata; # for recursive calls
  709. CUL_Parse($hash, $hash, $name, $rmsg) if($rmsg);
  710. $culdata = $hash->{PARTIAL};
  711. }
  712. $hash->{PARTIAL} = $culdata;
  713. }
  714. sub
  715. CUL_Parse($$$$@)
  716. {
  717. my ($hash, $iohash, $name, $rmsg, $initstr) = @_;
  718. if($rmsg =~ m/^V/) { # CUN* keepalive
  719. Log3 $name, 4, "CUL_Parse: $name $rmsg";
  720. return;
  721. }
  722. my $rssi;
  723. my $dmsg = $rmsg;
  724. my $dmsgLog = (AttrVal($name,"rfmode","") eq "HomeMatic")
  725. ? join(" ",(unpack'A1A2A2A4A6A6A*',$rmsg))
  726. :$dmsg;
  727. if($dmsg =~ m/^[AFTKEHRStZrib]([A-F0-9][A-F0-9])+$/) { # RSSI
  728. my $l = length($dmsg);
  729. $rssi = hex(substr($dmsg, $l-2, 2));
  730. $dmsg = substr($dmsg, 0, $l-2);
  731. $rssi = ($rssi>=128 ? (($rssi-256)/2-74) : ($rssi/2-74));
  732. Log3 $name, 4, "CUL_Parse: $name $dmsgLog $rssi";
  733. } else {
  734. Log3 $name, 4, "CUL_Parse: $name $dmsgLog";
  735. }
  736. ###########################################
  737. #Translate Message from CUL to FHZ
  738. next if(!$dmsg || length($dmsg) < 1); # Bogus messages
  739. if ($dmsg eq 'SMODE' || $dmsg eq 'TMODE') { # brs/brt returns SMODE/TMODE
  740. Log3 $name, 5, "CUL_Parse: switched to $dmsg";
  741. return;
  742. }
  743. if($dmsg =~ m/^[0-9A-F]{4}U./) { # RF_ROUTER
  744. Dispatch($hash, $dmsg, undef);
  745. return;
  746. }
  747. my $fn = substr($dmsg,0,1);
  748. my $len = length($dmsg);
  749. if($fn eq "F" && $len >= 9) { # Reformat for 10_FS20.pm
  750. CUL_AddSendQueue($iohash, ""); # Delay immediate replies
  751. $dmsg = sprintf("81%02x04xx0101a001%s00%s",
  752. $len/2+7, substr($dmsg,1,6), substr($dmsg,7));
  753. $dmsg = lc($dmsg);
  754. } elsif($fn eq "T") {
  755. if ($len >= 11) { # Reformat for 11_FHT.pm
  756. $dmsg = sprintf("81%02x04xx0909a001%s00%s",
  757. $len/2+7, substr($dmsg,1,6), substr($dmsg,7));
  758. $dmsg = lc($dmsg);
  759. }
  760. } elsif($fn eq "H" && $len >= 13) { # Reformat for 12_HMS.pm
  761. my $type = hex(substr($dmsg,6,1));
  762. my $stat = $type > 1 ? hex(substr($dmsg,7,2)) : hex(substr($dmsg,5,2));
  763. my $prf = $type > 1 ? "02" : "05";
  764. my $bat = $type > 1 ? hex(substr($dmsg,5,1))+1 : 1;
  765. my $HA = substr($dmsg,1,4);
  766. my $values = $type > 1 ? "000000" : substr($dmsg,7);
  767. $dmsg = sprintf("81%02x04xx%s%x%xa001%s0000%02x%s",
  768. $len/2+8, # Packet-Length
  769. $prf, $bat, $type,
  770. $HA, # House-Code
  771. $stat,
  772. $values); # Values
  773. $dmsg = lc($dmsg);
  774. } elsif($fn eq "K" && $len >= 5) {
  775. if($len == 15) { # Reformat for 13_KS300.pm
  776. my @a = split("", $dmsg);
  777. $dmsg = sprintf("81%02x04xx4027a001", $len/2+6);
  778. for(my $i = 1; $i < 14; $i+=2) { # Swap nibbles.
  779. $dmsg .= $a[$i+1] . $a[$i];
  780. }
  781. $dmsg = lc($dmsg);
  782. }
  783. # Other K... Messages ar sent to CUL_WS
  784. } elsif($fn eq "r" && $len >= 23) { # Revolt
  785. $dmsg = lc($dmsg);
  786. } elsif($fn eq "i" && $len >= 7) { # IT
  787. $dmsg = lc($dmsg);
  788. } elsif($fn eq "A" && $len >= 20) { # AskSin/BidCos/HomeMatic
  789. my $src = substr($dmsg,9,6);
  790. if($modules{CUL_HM}{defptr}{$src}){
  791. $modules{CUL_HM}{defptr}{$src}{helper}{io}{nextSend} =
  792. gettimeofday() + 0.100;
  793. }
  794. $dmsg .= "::$rssi:$name" if(defined($rssi));
  795. } elsif($fn eq "Z" && $len >= 21) { # Moritz/Max
  796. ;
  797. } elsif($fn eq "b" && $len >= 24) { # Wireless M-Bus
  798. $dmsg .= "::$rssi" if (defined($rssi));
  799. } elsif($fn eq "t" && $len >= 5) { # TX3
  800. $dmsg = "TX".substr($dmsg,1); # t.* is occupied by FHTTK
  801. }
  802. $hash->{"${name}_MSGCNT"}++;
  803. $hash->{"${name}_TIME"} = TimeNow();
  804. # showtime attribute
  805. readingsSingleUpdate($hash, "state", $hash->{READINGS}{state}{VAL}, 0);
  806. $hash->{RAWMSG} = $rmsg;
  807. my %addvals = (RAWMSG => $dmsg);
  808. if(defined($rssi)) {
  809. $hash->{RSSI} = $rssi;
  810. $addvals{RSSI} = $rssi;
  811. }
  812. Dispatch($hash, $dmsg, \%addvals);
  813. }
  814. #####################################
  815. sub
  816. CUL_Ready($)
  817. {
  818. my ($hash) = @_;
  819. return DevIo_OpenDev($hash, 1, "CUL_DoInit")
  820. if($hash->{STATE} eq "disconnected");
  821. # This is relevant for windows/USB only
  822. my $po = $hash->{USBDev};
  823. my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags);
  824. if($po) {
  825. ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status;
  826. }
  827. return ($InBytes && $InBytes>0);
  828. }
  829. ########################
  830. # Needed for STACKABLE_CC
  831. sub
  832. CUL_WriteInit($)
  833. {
  834. my ($hash) = @_;
  835. foreach my $is (split("\n", $hash->{initString})) {
  836. CUL_SimpleWrite($hash, $is);
  837. }
  838. }
  839. sub
  840. CUL_SimpleWrite(@)
  841. {
  842. my ($hash, $msg, $nonl) = @_;
  843. return if(!$hash);
  844. ($hash, $msg) = CUL_prefix(1, $hash, $msg);
  845. DevIo_SimpleWrite($hash, $msg, 2, !$nonl);
  846. }
  847. sub
  848. CUL_Attr(@)
  849. {
  850. my ($cmd,$name,$aName,$aVal) = @_;
  851. my $hash = $defs{$name};
  852. if($aName eq "rfmode") {
  853. $aVal = "SlowRF" if(!$aVal ||
  854. ($aVal ne "HomeMatic"
  855. && $aVal ne "MAX"
  856. && $aVal ne "WMBus_T"
  857. && $aVal ne "WMBus_S"
  858. && $aVal ne "WMBus_C"
  859. && $aVal ne "KOPP_FC"));
  860. my $msg = $hash->{NAME} . ": Mode $aVal not supported";
  861. if($aVal eq "HomeMatic") {
  862. return if($hash->{initString} =~ m/Ar/);
  863. if($hash->{CMDS} =~ m/A/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  864. $hash->{Clients} = $clientsHomeMatic;
  865. $hash->{MatchList} = \%matchListHomeMatic;
  866. CUL_SimpleWrite($hash, "Zx") if ($hash->{CMDS} =~ m/Z/); # reset Moritz
  867. $hash->{initString} = "X21\nAr"; # X21 is needed for RSSI reporting
  868. CUL_WriteInit($hash);
  869. } else {
  870. Log3 $name, 2, $msg;
  871. return $msg;
  872. }
  873. } elsif($aVal eq "MAX") {
  874. return if($hash->{initString} =~ m/Zr/);
  875. if($hash->{CMDS} =~ m/Z/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  876. $hash->{Clients} = $clientsMAX;
  877. $hash->{MatchList} = \%matchListMAX;
  878. CUL_SimpleWrite($hash, "Ax") if ($hash->{CMDS} =~ m/A/); # reset AskSin
  879. $hash->{initString} = "X21\nZr"; # X21 is needed for RSSI reporting
  880. CUL_WriteInit($hash);
  881. } else {
  882. Log3 $name, 2, $msg;
  883. return $msg;
  884. }
  885. } elsif($aVal eq "WMBus_S") {
  886. return if($hash->{initString} =~ m/brs/);
  887. if($hash->{CMDS} =~ m/b/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  888. $hash->{Clients} = $clientsWMBus;
  889. $hash->{MatchList} = \%matchListWMBus;
  890. $hash->{initString} = "X21\nbrs"; # Use S-Mode
  891. CUL_WriteInit($hash);
  892. } else {
  893. Log3 $name, 2, $msg;
  894. return $msg;
  895. }
  896. } elsif($aVal eq "WMBus_T") {
  897. return if($hash->{initString} =~ m/brt/);
  898. if($hash->{CMDS} =~ m/b/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  899. $hash->{Clients} = $clientsWMBus;
  900. $hash->{MatchList} = \%matchListWMBus;
  901. $hash->{initString} = "X21\nbrt"; # Use T-Mode
  902. CUL_WriteInit($hash);
  903. } else {
  904. Log3 $name, 2, $msg;
  905. return $msg;
  906. }
  907. } elsif($aVal eq "WMBus_C") {
  908. return if($hash->{initString} =~ m/brt/);
  909. if($hash->{CMDS} =~ m/b/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  910. $hash->{Clients} = $clientsWMBus;
  911. $hash->{MatchList} = \%matchListWMBus;
  912. $hash->{initString} = "X21\nbrc"; # Use C-Mode
  913. CUL_WriteInit($hash);
  914. } else {
  915. Log3 $name, 2, $msg;
  916. return $msg;
  917. }
  918. } elsif($aVal eq "KOPP_FC") {
  919. if($hash->{CMDS} =~ m/k/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  920. $hash->{Clients} = $clientsKOPP_FC;
  921. $hash->{MatchList} = \%matchListKOPP_FC;
  922. $hash->{initString} = "krS"; # krS: start Kopp receive Mode
  923. CUL_WriteInit($hash);
  924. } else {
  925. Log3 $name, 2, $msg;
  926. return $msg;
  927. }
  928. } else {
  929. return if($hash->{initString} eq "X21");
  930. $hash->{Clients} = $clientsSlowRF;
  931. $hash->{MatchList} = \%matchListSlowRF;
  932. $hash->{initString} = "X21";
  933. CUL_SimpleWrite($hash, "Ax") if ($hash->{CMDS} =~ m/A/); # reset AskSin
  934. CUL_SimpleWrite($hash, "Zx") if ($hash->{CMDS} =~ m/Z/); # reset Moritz
  935. CUL_SimpleWrite($hash, "brx") if ($hash->{CMDS} =~ m/b/); # reset WMBus
  936. CUL_WriteInit($hash);
  937. }
  938. Log3 $name, 2, "Switched $name rfmode to $aVal";
  939. delete $hash->{".clientArray"};
  940. } elsif($aName eq "hmId"){
  941. if($cmd eq "set") {
  942. return "wrong syntax: hmId must be 6-digit-hex-code (3 byte)"
  943. if($aVal !~ m/^[A-F0-9]{6}$/i);
  944. }
  945. } elsif($aName eq "connectCommand"){
  946. CUL_SimpleWrite($hash, $aVal) if($cmd eq "set");
  947. }
  948. return undef;
  949. }
  950. sub
  951. CUL_prefix($$$)
  952. {
  953. my ($isadd, $hash, $msg) = @_;
  954. while($hash && $hash->{TYPE} !~ m/$culNameRe/) {
  955. $msg = CallFn($hash->{NAME}, $isadd ? "AddPrefix":"DelPrefix", $hash, $msg);
  956. $hash = $hash->{IODev};
  957. last if(!$hash);
  958. }
  959. return ($hash, $msg);
  960. }
  961. 1;
  962. =pod
  963. =item summary connect devices with the culfw Firmware, e.g. Busware CUL
  964. =item summary_DE Anbindung von Geraeten mit dem culfw Firmware, z.Bsp. Busware CUL
  965. =begin html
  966. <a name="CUL"></a>
  967. <h3>CUL</h3>
  968. <ul>
  969. <table>
  970. <tr><td>
  971. The CUL/CUN(O) is a family of RF devices sold by <a
  972. href="http://www.busware.de">busware.de</a>.
  973. With the opensource firmware
  974. <a href="http://culfw.de/culfw.html">culfw</a> they are capable
  975. to receive and send different 433/868 MHz protocols (FS20/FHT/S300/EM/HMS/MAX!).
  976. It is even possible to use these devices as range extenders/routers, see the
  977. <a href="#CUL_RFR">CUL_RFR</a> module for details.
  978. <br> <br>
  979. Some protocols (FS20, FHT and KS300) are converted by this module so that
  980. the same logical device can be used, irrespective if the radio telegram is
  981. received by a CUL or an FHZ device.<br>
  982. Other protocols (S300/EM) need their
  983. own modules. E.g. S300 devices are processed by the CUL_WS module if the
  984. signals are received by the CUL, similarly EMWZ/EMGZ/EMEM is handled by the
  985. CUL_EM module.<br><br>
  986. It is possible to attach more than one device in order to get better
  987. reception, FHEM will filter out duplicate messages.<br><br>
  988. Note: This module may require the <code>Device::SerialPort</code> or
  989. <code>Win32::SerialPort</code> module if you attach the device via USB
  990. and the OS sets strange default parameters for serial devices.<br><br>
  991. </td><td>
  992. <img src="ccc.jpg"/>
  993. </td></tr>
  994. </table>
  995. <a name="CULdefine"></a>
  996. <b>Define</b>
  997. <ul>
  998. <code>define &lt;name&gt; CUL &lt;device&gt; &lt;FHTID&gt;</code> <br>
  999. <br>
  1000. USB-connected devices (CUL/CUN):<br><ul>
  1001. &lt;device&gt; specifies the serial port to communicate with the CUL.
  1002. The name of the serial-device depends on your distribution, under
  1003. linux the cdc_acm kernel module is responsible, and usually a
  1004. /dev/ttyACM0 device will be created. If your distribution does not have a
  1005. cdc_acm module, you can force usbserial to handle the CUL by the
  1006. following command:
  1007. <ul><code>
  1008. modprobe usbserial vendor=0x03eb product=0x204b
  1009. </code></ul>
  1010. In this case the device is most probably /dev/ttyUSB0.<br><br>
  1011. You can also specify a baudrate if the device name contains the @
  1012. character, e.g.: /dev/ttyACM0@38400<br><br>
  1013. If the baudrate is "directio" (e.g.: /dev/ttyACM0@directio), then the
  1014. perl module <code>Device::SerialPort</code> is not needed, and FHEM
  1015. opens the device with simple file io. This might work if the operating
  1016. system uses sane defaults for the serial parameters, e.g. some Linux
  1017. distributions and OSX.<br><br>
  1018. </ul>
  1019. Network-connected devices (CUN(O)):<br><ul>
  1020. &lt;device&gt; specifies the host:port of the device, e.g.
  1021. 192.168.0.244:2323
  1022. </ul>
  1023. <br>
  1024. If the device is called none, then no device will be opened, so you
  1025. can experiment without hardware attached.<br>
  1026. The FHTID is a 4 digit hex number, and it is used when the CUL talks to
  1027. FHT devices or when CUL requests data. Set it to 0000 to avoid answering
  1028. any FHT80b request by the CUL.
  1029. </ul>
  1030. <br>
  1031. <a name="CULset"></a>
  1032. <b>Set </b>
  1033. <ul>
  1034. <li>reopen<br>
  1035. Reopens the connection to the device and reinitializes it.
  1036. </li><br>
  1037. <li>raw<br>
  1038. Issue a CUL firmware command. See the <a
  1039. href="http://culfw.de/commandref.html">this</a> document
  1040. for details on CUL commands.
  1041. </li><br>
  1042. <li>freq / bWidth / rAmpl / sens<br>
  1043. <a href="#rfmode">SlowRF</a> mode only.<br>
  1044. Set the CUL frequency / bandwidth / receiver-amplitude / sensitivity<br>
  1045. Use it with care, it may destroy your hardware and it even may be
  1046. illegal to do so. Note: The parameters used for RFR transmission are
  1047. not affected.<br>
  1048. <ul>
  1049. <li>freq sets both the reception and transmission frequency. Note:
  1050. Although the CC1101 can be set to frequencies between 315 and 915
  1051. MHz, the antenna interface and the antenna of the CUL is tuned for
  1052. exactly one frequency. Default is 868.3 MHz (or 433 MHz)</li>
  1053. <li>bWidth can be set to values between 58 kHz and 812 kHz. Large values
  1054. are susceptible to interference, but make possible to receive
  1055. inaccurately calibrated transmitters. It affects tranmission too.
  1056. Default is 325 kHz.</li>
  1057. <li>rAmpl is receiver amplification, with values between 24 and 42 dB.
  1058. Bigger values allow reception of weak signals. Default is 42.
  1059. </li>
  1060. <li>sens is the decision boundary between the on and off values, and it
  1061. is 4, 8, 12 or 16 dB. Smaller values allow reception of less clear
  1062. signals. Default is 4 dB.</li>
  1063. </ul>
  1064. </li><br>
  1065. <a name="hmPairForSec"></a>
  1066. <li>hmPairForSec<br>
  1067. <a href="#rfmode">HomeMatic</a> mode only.<br>
  1068. Set the CUL in Pairing-Mode for the given seconds. Any HM device set into
  1069. pairing mode in this time will be paired with FHEM.
  1070. </li><br>
  1071. <a name="hmPairSerial"></a>
  1072. <li>hmPairSerial<br>
  1073. <a href="#rfmode">HomeMatic</a> mode only.<br>
  1074. Try to pair with the given device. The argument is a 10 character
  1075. string, usually starting with letters and ending with digits, printed on
  1076. the backside of the device. It is not necessary to put the given device
  1077. in learning mode if it is a receiver.
  1078. </li><br>
  1079. <a name="hmPairForSec"></a>
  1080. <li>led<br>
  1081. Set the CUL led off (00), on (01) or blinking (02).
  1082. </li><br>
  1083. <li>ITClock</br>
  1084. Set the IT clock for Intertechno V1 protocol. Default 250.
  1085. </li><br>
  1086. </ul>
  1087. <a name="CULget"></a>
  1088. <b>Get</b>
  1089. <ul>
  1090. <li>version<br>
  1091. returns the CUL firmware version
  1092. </li><br>
  1093. <li>uptime<br>
  1094. returns the CUL uptime (time since CUL reset)
  1095. </li><br>
  1096. <li>raw<br>
  1097. Issues a CUL firmware command, and waits for one line of data returned by
  1098. the CUL. See the CUL firmware README document for details on CUL
  1099. commands.
  1100. </li><br>
  1101. <li>fhtbuf<br>
  1102. CUL has a message buffer for the FHT. If the buffer is full, then newly
  1103. issued commands will be dropped, and an "EOB" message is issued to the
  1104. FHEM log.
  1105. <code>fhtbuf</code> returns the free memory in this buffer (in hex),
  1106. an empty buffer in the CUL V2 is 74 bytes, in CUL V3/CUN(O) 200 Bytes.
  1107. A message occupies 3 + 2x(number of FHT commands) bytes,
  1108. this is the second reason why sending multiple FHT commands with one
  1109. <a href="#set">set</a> is a good idea. The first reason is, that
  1110. these FHT commands are sent at once to the FHT.
  1111. </li> <br>
  1112. <li>ccconf<br>
  1113. Read some CUL radio-chip (cc1101) registers (frequency, bandwidth, etc.),
  1114. and display them in human readable form.
  1115. </li><br>
  1116. <li>cmds<br>
  1117. Depending on the firmware installed, CULs have a different set of
  1118. possible commands. Please refer to the README of the firmware of your
  1119. CUL to interpret the response of this command. See also the raw command.
  1120. </li><br>
  1121. <li>credit10ms<br>
  1122. One may send for a duration of credit10ms*10 ms before the send limit
  1123. is reached and a LOVF is generated.
  1124. </li><br>
  1125. </ul>
  1126. <a name="CULattr"></a>
  1127. <b>Attributes</b>
  1128. <ul>
  1129. <li><a name="addvaltrigger">addvaltrigger</a><br>
  1130. Create triggers for additional device values. Right now these are RSSI
  1131. and RAWMSG for the CUL family and RAWMSG for the FHZ.
  1132. </li><br>
  1133. <li><a name="connectCommand">connectCommand</a><br>
  1134. raw culfw command sent to the CUL after a (re-)connect of the USB device,
  1135. and sending the usual initialization needed for the configured rfmode.
  1136. </li>
  1137. <li><a href="#do_not_notify">do_not_notify</a></li>
  1138. <li><a href="#attrdummy">dummy</a></li>
  1139. <li><a name="hmId">hmId</a><br>
  1140. Set the HomeMatic ID of this device. If this attribute is absent, the
  1141. ID will be F1&lt;FHTID&gt;. Note 1: After setting or changing this
  1142. attribute you have to relearn all your HomeMatic devices. Note 2: The
  1143. value <b>must</b> be a 6 digit hex number, and 000000 is not valid. FHEM
  1144. won't complain if it is not correct, but the communication won't work.
  1145. </li><br>
  1146. <li><a name="hmProtocolEvents">hmProtocolEvents</a><br>
  1147. Generate events for HomeMatic protocol messages. These are normally
  1148. used for debugging, by activating "inform timer" in a telnet session,
  1149. or looking at the Event Monitor window in the FHEMWEB frontend.<br>
  1150. Example:
  1151. <ul>
  1152. <code>
  1153. 2012-05-17 09:44:22.515 CUL CULHM RCV L:0B N:81 CMD:A258 SRC:......
  1154. DST:...... 0000 (TYPE=88,WAKEMEUP,BIDI,RPTEN)
  1155. </code>
  1156. </ul>
  1157. </li><br>
  1158. <li><a name="longids">longids</a><br>
  1159. Comma separated list of device-types for CUL that should be handled
  1160. using long IDs. This additional ID allows it to differentiate some
  1161. weather sensors, if they are sending on the same channel.
  1162. Therefore a random generated id is added. If you choose to use longids,
  1163. then you'll have to define a different device after battery change.
  1164. Default is not to use long IDs.<br>
  1165. Modules which are using this functionality are for e.g. :
  1166. 14_Hideki, 41_OREGON, 14_CUL_TCM97001, 14_SD_WS07.<br>
  1167. Examples:<br>
  1168. <ul><code>
  1169. # Do not use any long IDs for any devices (this is default):<br>
  1170. attr cul longids 0<br>
  1171. # Use long IDs for all devices:<br>
  1172. attr cul longids 1<br>
  1173. # Use longids for SD_WS07 devices.<br>
  1174. # Will generate devices names like SD_WS07_TH_3 for channel 3.<br>
  1175. attr cul longids SD_WS07
  1176. </code></ul>
  1177. </li><br>
  1178. <li><a href="#model">model</a> (CUL,CUN,etc)</li>
  1179. <li><a name="sendpool">sendpool</a><br>
  1180. If using more than one CUL for covering a large area, sending
  1181. different events by the different CUL's might disturb each other. This
  1182. phenomenon is also known as the Palm-Beach-Resort effect.
  1183. Putting them in a common sendpool will serialize sending the events.
  1184. E.g. if you have three CUN's, you have to specify following
  1185. attributes:<br>
  1186. <code>attr CUN1 sendpool CUN1,CUN2,CUN3<br>
  1187. attr CUN2 sendpool CUN1,CUN2,CUN3<br>
  1188. attr CUN3 sendpool CUN1,CUN2,CUN3</code><br>
  1189. </li><br>
  1190. <li><a name="rfmode">rfmode</a><br>
  1191. Configure the RF Transceiver of the CUL (the CC1101). Available
  1192. arguments are:
  1193. <ul>
  1194. <li>SlowRF<br>
  1195. To communicate with FS20/FHT/HMS/EM1010/S300/Hoermann devices @1 kHz
  1196. datarate. This is the default.</li>
  1197. <li>HomeMatic<br>
  1198. To communicate with HomeMatic type of devices @10 kHz datarate.</li>
  1199. <li>MAX<br>
  1200. To communicate with MAX! type of devices @10 kHz datarate.</li>
  1201. <li>WMBus_S</li>
  1202. <li>WMBus_T</li>
  1203. <li>WMBus_C<br>
  1204. To communicate with Wireless M-Bus devices like water, gas or
  1205. electrical meters. Wireless M-Bus uses three different communication
  1206. modes, S-Mode, T-Mode and C-Mode. While in this mode, no reception of other
  1207. protocols like SlowRF or HomeMatic is possible. See also the WMBUS
  1208. FHEM Module.
  1209. </li>
  1210. </ul>
  1211. </li><br>
  1212. <li><a href="#showtime">showtime</a></li>
  1213. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  1214. </ul>
  1215. <br>
  1216. </ul>
  1217. =end html
  1218. =begin html_DE
  1219. <a name="CUL"></a>
  1220. <h3>CUL</h3>
  1221. <ul>
  1222. <table>
  1223. <tr><td>
  1224. Der CUL/CUN(O) ist eine Familie von Funkempf&auml;ngern, die von der Firma
  1225. <a href="http://www.busware.de">Busware</a> verkauft wird.
  1226. Mit der OpenSource Firmware
  1227. <a href="http://culfw.de/culfw.html">culfw</a> k&ouml;nnen sie verschiedene
  1228. 868 MHz Funkprotokolle empfangen bzw. senden (FS20/FHT/S300/EM/HMS/MAX!).
  1229. Man kann diese Ger&auml;te auch zur Reichweitenverl&auml;ngerung, siehe
  1230. <a href="#CUL_RFR">CUL_RFR</a> einsetzen.
  1231. <br> <br>
  1232. Einige Protokolle (FS20, FHT und KS300) werden von diesem Modul in das FHZ
  1233. Format konvertiert, daher kann dasselbe logische Ger&auml;t verwendet werden,
  1234. egal ob das Funktelegramm von einem CUL oder einem FHZ Ger&auml;t empfangen
  1235. wird.<br>
  1236. Andere Protokolle (S300/EM) ben&ouml;tigen ihre eigenen Module. S300
  1237. Ger&auml;te werden vom Modul CUL_WS verarbeitet, wenn das Signal von einem
  1238. CUL empfangen wurde, &auml;hnliches gilt f&uuml;r EMWZ/EMGZ/EMEM: diese
  1239. werden vom CUL_EM Modul verarbeitet.<br><br>
  1240. Es ist m&ouml;glich mehr als ein Ger&auml;t zu verwenden, um einen besseren
  1241. Empfang zu erhalten, FHEM filtert doppelte Funktelegramme aus.<br><br>
  1242. Bemerkung: Dieses Modul ben&ouml;tigt unter Umst&auml;nden das
  1243. <code>Device::SerialPort</code> bzw. <code>Win32::SerialPort</code> Modul,
  1244. wenn Sie das Ger&auml;t &uuml;ber USB anschlie&szlig;en und das
  1245. Betriebssystem un&uuml;bliche Parameter f&uuml;r serielle Schnittstellen
  1246. setzt.<br><br>
  1247. </td><td>
  1248. <img src="ccc.jpg"/>
  1249. </td></tr>
  1250. </table>
  1251. <a name="CULdefine"></a>
  1252. <b>Define</b>
  1253. <ul>
  1254. <code>define &lt;name&gt; CUL &lt;device&gt; &lt;FHTID&gt;</code> <br>
  1255. <br>
  1256. Ger&auml;te, die an USB angeschlossen sind (CUL/CUN):<br>
  1257. <ul>
  1258. &lt;device&gt; gibt die serielle Schnittstelle an, mit der der CUL
  1259. kommuniziert. Der Name der seriellen Schnittstelle h&auml;ngt von der
  1260. gew&auml;hlten Distribution und USB-Treiber ab, unter Linux ist dies das
  1261. Kernel Modul cdc_acm und &uuml;blicherweise wird die Schnittstelle
  1262. /dev/ttyACM0 genannt. Wenn die Linux Distribution &uuml;ber kein Kernel
  1263. Modul cdc_acm verf&uuml;gt, dann kann die Schnittstelle &uuml;ber
  1264. usbserial mit dem folgenden Befehl erzeugt werden:
  1265. <ul><code>
  1266. modprobe usbserial vendor=0x03eb product=0x204b
  1267. </code></ul>
  1268. In diesem Fall ist diese Schnittstelle dann wahrscheinlich
  1269. /dev/ttyUSB0.<br><br>
  1270. Wenn der Name der Schnittstelle ein @ enth&auml;lt, kann nachfolgend die
  1271. verwendete Baudrate angegeben werden, z.B.: /dev/ttyACM0@38400.<br><br>
  1272. Wenn die Baudrate mit "directio" angegeben wird (z.B.:
  1273. /dev/ttyACM0@directio), wird das Perl Modul
  1274. <code>Device::SerialPort</code> nicht ben&ouml;tigt und FHEM &ouml;ffnet
  1275. die Schnittstelle mit einfachem Dateizugriff. Dies sollte dann
  1276. funktionieren, wenn das Betriebssystem vern&uuml;nftige Standardwerte
  1277. f&uuml;r die serielle Schnittstelle verwendet, wie z.B. einige Linux
  1278. Distributionen oder OSX.<br><br>
  1279. </ul>
  1280. Ger&auml;te, die mit dem Netzwerk verbunden sind (CUN(O)):<br>
  1281. <ul>
  1282. &lt;device&gt; gibt die Hostadresse:Port des Ger&auml;tes an, z.B.
  1283. 192.168.0.244:2323
  1284. </ul>
  1285. <br>
  1286. Wenn das Ger&auml;t mit none bezeichnet wird, wird keine Schnittstelle
  1287. ge&ouml;ffnet und man kann ohne angeschlossene Hardware
  1288. experimentieren.<br>
  1289. Die FHTID ist eine 4-stellige hexadezimale Zahl und wird verwendet, wenn
  1290. der CUL FHT Telegramme sendet bzw. Daten anfragt. Diese sollte als 0000
  1291. gew&auml;hlt werden, wenn man FHT80b Anfragen durch den CUL vermeiden will.
  1292. </ul>
  1293. <br>
  1294. <a name="CULset"></a>
  1295. <b>Set </b>
  1296. <ul>
  1297. <li>reopen<br>
  1298. &Ouml;ffnet die Verbindung zum Ger&auml;t neu und initialisiert es.
  1299. </li><br>
  1300. <li>raw<br>
  1301. Sendet einen CUL Firmware Befehl. Siehe auch
  1302. <a href="http://culfw.de/commandref.html">hier</a> f&uuml;r
  1303. n&auml;here Erl&auml;uterungen der CUL Befehle.
  1304. </li><br>
  1305. <li>freq / bWidth / rAmpl / sens<br>
  1306. Nur in der Betriebsart <a href="#rfmode">SlowRF</a>.<br> Bestimmt die
  1307. CUL Frequenz / Bandbreite / Empf&auml;nger Amplitude /
  1308. Empfindlichkeit<br>
  1309. Bitte mit Vorsicht verwenden, da es die verwendete Hardware
  1310. zerst&ouml;ren kann bzw. es zu illegalen Funkzust&auml;nden kommen
  1311. kann. <br> Bemerkung: Die Parameter f&uuml;r die RFR &Uuml;bermittlung
  1312. werden hierdurch nicht beeinflu&szlig;t.<br>
  1313. <ul>
  1314. <li>freq bestimmt sowohl die Empfangs- als auch die Sendefrequenz.<br>
  1315. Bemerkung: Auch wenn der CC1101 zwischen den Frequenzen 315 und 915
  1316. MHz eingestellt werden kann, ist die Antennenanbindung bzw. die
  1317. Antenne des CUL exakt auf eine Frequenz eingestellt. Standard ist
  1318. 868.3 MHz (bzw. 433 MHz).</li>
  1319. <li>bWidth kann zwischen 58 kHz und 812 kHz variiert werden.
  1320. Gro&szlig;e Werte sind empfindlicher gegen Interferencen, aber
  1321. machen es m&ouml;glich, nicht genau kalbrierte Signale zu
  1322. empfangen. Die Einstellung beeinflusst ebenso die &Uuml;bertragung.
  1323. Standardwert ist 325 kHz.</li>
  1324. <li>rAmpl ist die Verst&auml;rkung des Empf&auml;ngers mit Werten
  1325. zwischen 24 and 42 dB. Gr&ouml;&szlig;ere Werte erlauben den
  1326. Empfang von schwachen Signalen. Standardwert ist 42.</li>
  1327. <li>sens ist die Entscheidungsgrenze zwischen "on" und "off"
  1328. Zust&auml;nden und kann 4, 8, 12 oder 16 dB sein. Kleinere Werte
  1329. erlauben den Empfang von undeutlicheren Signalen. Standard ist 4
  1330. dB.</li>
  1331. </ul>
  1332. </li><br>
  1333. <a name="hmPairForSec"></a>
  1334. <li>hmPairForSec<br>
  1335. Nur in der Betriebsart <a href="#rfmode">HomeMatic</a>.<br> Versetzt den
  1336. CUL f&uuml;r die angegebene Zeit in Sekunden in den Anlern-Modus. Jedes
  1337. HM Ger&auml;t, das sich im Anlern-Modus befindet, wird an FHEM
  1338. angelernt. </li><br>
  1339. <a name="hmPairSerial"></a>
  1340. <li>hmPairSerial<br>
  1341. Nur in der Betriebsart <a href="#rfmode">HomeMatic</a>.<br>
  1342. Versucht, das angegebene Ger&auml;t anzulernen (zu "pairen"). Der
  1343. Parameter ist eine 10-stellige Zeichenfolge, die normalerweise mit
  1344. Buchstaben beginnt und mit Ziffern endet; diese sind auf der
  1345. R&uuml;ckseite der Ger&auml;te aufgedruckt. Wenn das Ger&auml;t ein
  1346. Empf&auml;nger ist, ist es nicht notwendig, das angegebene Ger&auml;t in
  1347. den Anlern-Modus zu versetzen. </li><br>
  1348. <a name="hmPairForSec"></a>
  1349. <li>led<br>
  1350. Schaltet die LED des CUL: aus (00), an (01) oder blinkend (02).
  1351. </li><br>
  1352. <li>ITClock</br>
  1353. Setzt die IT clock f&uuml; Intertechno V1 Protokoll. Default 250.
  1354. </li><br>
  1355. </ul>
  1356. <a name="CULget"></a>
  1357. <b>Get</b>
  1358. <ul>
  1359. <li>version<br>
  1360. gibt die Version der CUL Firmware zur&uuml;ck
  1361. </li><br>
  1362. <li>uptime<br>
  1363. gibt die Betriebszeit des CULs zur&uuml;ck (Zeit seit dem letzten Reset
  1364. des CULs) </li><br>
  1365. <li>raw<br>
  1366. Sendet einen CUL Firmware Befehl und wartet auf eine R&uuml;ckgabe des
  1367. CULs. Siehe auch README der Firmware f&uuml;r n&auml;here
  1368. Erl&auml;uterungen zu den CUL Befehlen. </li><br>
  1369. <li>fhtbuf<br>
  1370. Der CUL hat einen Puffer f&uuml;r Nachrichten f&uuml;r FHT. Wenn der
  1371. Puffer voll ist, werden neu empfangene Telegramme ignoriert und eine
  1372. "EOB" Meldung wird in die FHEM Logdatei geschrieben.
  1373. <code>fhtbuf</code> gibt den freien Speicher dieses Puffers (in hex)
  1374. zur&uuml;ck, ein leerer Puffer im CUL V2 hat 74 Byte, im CUL V3/CUN(O)
  1375. hat 200 Byte. Eine Telegramm ben&ouml;tigt 3 + 2x(Anzahl der FHT
  1376. Befehle) Byte, dies ist ein Grund, warum man mehrere FHT Befehle mit
  1377. einem <a href="#set">set</a> senden sollte. Ein weiterer Grund ist,
  1378. dass diese FHT Befehle in einem "Paket" zum FHT Ger&auml;t gesendet werden.
  1379. </li> <br>
  1380. <li>ccconf<br>
  1381. Liest einige CUL Register des CC1101 (Sende- und Empf&auml;ngerchips)
  1382. aus (Frequenz, Bandbreite, etc.) und stellt diese in lesbarer Form dar.
  1383. </li><br>
  1384. <li>cmds<br>
  1385. In abh&auml;gigkeit der installierten Firmware hat der CUL/CUN(O)
  1386. unterschiedliche Befehlss&auml;tze. N&auml;here Informationen &uuml;ber
  1387. die Befehle bzw. deren Interpretation siehe README Datei der
  1388. verwendeten CUL Firmware. Siehe auch Anmerkungen beim raw Befehl.
  1389. </li><br>
  1390. <li>credit10ms<br>
  1391. Der Funkraum darf f&uuml;r eine Dauer von credit10ms*10 ms belegt
  1392. werden, bevor die gesetzliche 1% Grenze erreicht ist und eine
  1393. LOVF Meldung ausgegeben wird. </li><br> </ul>
  1394. <a name="CULattr"></a>
  1395. <b>Attribute</b>
  1396. <ul>
  1397. <li><a name="addvaltrigger">addvaltrigger</a><br>
  1398. Generiert Trigger f&uuml;r zus&auml;tzliche Werte. Momentan sind dies
  1399. RSSI und RAWMSG f&uuml;r die CUL Familie und RAWMSG f&uuml;r FHZ.
  1400. </li><br>
  1401. <li><a name="connectCommand">connectCommand</a><br>
  1402. culfw Befehl, was nach dem Verbindungsaufbau mit dem USB-Ger&auml;t, nach
  1403. Senden der zum Initialisieren der konfigurierten rfmode ben&ouml;tigten
  1404. Befehle gesendet wird.
  1405. </li>
  1406. <li><a href="#do_not_notify">do_not_notify</a></li>
  1407. <li><a href="#attrdummy">dummy</a></li>
  1408. <li><a name="hmId">hmId</a><br>
  1409. Setzt die HomeMatic ID des Ger&auml;tes. Wenn dieses Attribut fehlt,
  1410. wird die ID zu F1&lt;FHTID&gt; gesetzt. Bemerkung 1: Nach dem Setzen
  1411. bzw. Ver&auml;ndern dieses Attributes m&uuml;ssen alle HomeMatic
  1412. Ger&auml;te neu angelernt werden. Bemerkung 2: Der Wert <b>muss</b>
  1413. eine 6-stellige Hexadezimalzahl sein, 000000 ist ung&uuml;ltig. FHEM
  1414. &uuml;berpr&uuml;ft nicht, ob die ID korrekt ist, im Zweifelsfall
  1415. funktioniert die Kommunikation nicht. </li><br>
  1416. <li><a name="hmProtocolEvents">hmProtocolEvents</a><br>
  1417. Generiert Ereignisse f&uuml;r HomeMatic Telegramme. Diese werden
  1418. normalerweise f&uuml;r die Fehlersuche verwendet, z.B. durch Aktivieren
  1419. von <code>inform timer</code> in einer telnet Sitzung bzw. im
  1420. <code>Event Monitor</code> Fenster im FHEMWEB Frontend.<br>
  1421. Beispiel:
  1422. <ul>
  1423. <code>
  1424. 2012-05-17 09:44:22.515 CUL CULHM RCV L:0B N:81 CMD:A258 SRC:......
  1425. DST:...... 0000 (TYPE=88,WAKEMEUP,BIDI,RPTEN)
  1426. </code>
  1427. </ul>
  1428. </li><br>
  1429. <li><a name="longids">longids</a><br>
  1430. Durch Kommata getrennte Liste von Device-Typen f&uuml;r Empfang von
  1431. langen IDs mit den CUL. Diese zus&auml;tzliche ID erlaubt es
  1432. Wettersensoren, welche auf dem gleichen Kanal senden zu unterscheiden.
  1433. Hierzu wird eine zuf&auml;llig generierte ID hinzugef&uuml;gt. Wenn Sie
  1434. longids verwenden, dann wird in den meisten F&auml;llen nach einem
  1435. Batteriewechsel ein neuer Sensor angelegt.
  1436. Standardm&auml;&szlig;ig werden keine langen IDs verwendet.<br>
  1437. Folgende Module verwenden diese Funktionalit&auml;t:
  1438. 14_Hideki, 41_OREGON, 14_CUL_TCM97001, 14_SD_WS07.<br>
  1439. Beispiele:
  1440. <ul><code>
  1441. # Keine langen IDs verwenden (Default Einstellung):<br>
  1442. attr cul longids 0<br>
  1443. # Immer lange IDs verwenden:<br>
  1444. attr cul longids 1<br>
  1445. # Verwende lange IDs f&uuml;r SD_WS07 Devices.<br>
  1446. # Device Namen sehen z.B. so aus: SD_WS07_TH_3 for channel 3.<br>
  1447. attr cul longids SD_WS07
  1448. </code></ul>
  1449. </li><br>
  1450. <li><a href="#model">model</a> (CUL,CUN)</li><br>
  1451. <li><a name="rfmode">rfmode</a><br>
  1452. Konfiguriert den RF Transceiver des CULs (CC1101). Verf&uuml;gbare
  1453. Argumente sind:
  1454. <ul>
  1455. <li>SlowRF<br>
  1456. F&uuml;r die Kommunikation mit FS20/FHT/HMS/EM1010/S300/Hoermann
  1457. Ger&auml;ten @1 kHz Datenrate (Standardeinstellung).</li>
  1458. <li>HomeMatic<br>
  1459. F&uuml;r die Kommunikation mit HomeMatic Ger&auml;ten @10 kHz
  1460. Datenrate.</li>
  1461. <li>MAX<br>
  1462. F&uuml;r die Kommunikation mit MAX! Ger&auml;ten @10 kHz
  1463. Datenrate.</li>
  1464. <li>WMBus_S</li>
  1465. <li>WMBus_T</li>
  1466. <li>WMBus_C<br>
  1467. F&uuml;r die Kommunikation mit Wireless M-Bus Ger&auml;ten wie
  1468. Wasser-, Gas- oder Elektroz&auml;hlern. Wireless M-Bus verwendet
  1469. drei unterschiedliche Kommunikationsarten, S-Mode, T-Mode und C-Mode. In
  1470. diesem Modus ist der Empfang von anderen Protokollen wie SlowRF
  1471. oder HomeMatic nicht m&ouml;glich.</li>
  1472. </ul>
  1473. </li><br>
  1474. <li><a name="sendpool">sendpool</a><br>
  1475. Wenn mehr als ein CUL verwendet wird, um einen gr&ouml;&szlig;eren
  1476. Bereich abzudecken, k&ouml;nnen diese sich gegenseitig
  1477. beeinflussen. Dieses Ph&auml;nomen wird auch Palm-Beach-Resort Effekt
  1478. genannt. Wenn man diese zu einen gemeinsamen Sende"pool"
  1479. zusammenschlie&szlig;t, wird das Senden der einzelnen Telegramme
  1480. seriell (d.h. hintereinander) durchgef&uuml;hrt.
  1481. Wenn z.B. drei CUN's zur
  1482. Verf&uuml;gung stehen, werden folgende Attribute gesetzt:<br>
  1483. <code>attr CUN1 sendpool CUN1,CUN2,CUN3<br>
  1484. attr CUN2 sendpool CUN1,CUN2,CUN3<br>
  1485. attr CUN3 sendpool CUN1,CUN2,CUN3</code><br>
  1486. </li><br>
  1487. <li><a href="#showtime">showtime</a></li>
  1488. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  1489. </ul>
  1490. <br>
  1491. </ul>
  1492. =end html_DE
  1493. =cut