00_CUL.pm 56 KB

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