00_CUL.pm 56 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732
  1. ##############################################
  2. # $Id: 00_CUL.pm 16907 2018-06-25 09:03:09Z 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,WMBus_C,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 "WMBus_C"
  858. && $aVal ne "KOPP_FC"));
  859. my $msg = $hash->{NAME} . ": Mode $aVal not supported";
  860. if($aVal eq "HomeMatic") {
  861. return if($hash->{initString} =~ m/Ar/);
  862. if($hash->{CMDS} =~ m/A/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  863. $hash->{Clients} = $clientsHomeMatic;
  864. $hash->{MatchList} = \%matchListHomeMatic;
  865. CUL_SimpleWrite($hash, "Zx") if ($hash->{CMDS} =~ m/Z/); # reset Moritz
  866. $hash->{initString} = "X21\nAr"; # X21 is needed for RSSI reporting
  867. CUL_WriteInit($hash);
  868. } else {
  869. Log3 $name, 2, $msg;
  870. return $msg;
  871. }
  872. } elsif($aVal eq "MAX") {
  873. return if($hash->{initString} =~ m/Zr/);
  874. if($hash->{CMDS} =~ m/Z/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  875. $hash->{Clients} = $clientsMAX;
  876. $hash->{MatchList} = \%matchListMAX;
  877. CUL_SimpleWrite($hash, "Ax") if ($hash->{CMDS} =~ m/A/); # reset AskSin
  878. $hash->{initString} = "X21\nZr"; # X21 is needed for RSSI reporting
  879. CUL_WriteInit($hash);
  880. } else {
  881. Log3 $name, 2, $msg;
  882. return $msg;
  883. }
  884. } elsif($aVal eq "WMBus_S") {
  885. return if($hash->{initString} =~ m/brs/);
  886. if($hash->{CMDS} =~ m/b/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  887. $hash->{Clients} = $clientsWMBus;
  888. $hash->{MatchList} = \%matchListWMBus;
  889. $hash->{initString} = "X21\nbrs"; # Use S-Mode
  890. CUL_WriteInit($hash);
  891. } else {
  892. Log3 $name, 2, $msg;
  893. return $msg;
  894. }
  895. } elsif($aVal eq "WMBus_T") {
  896. return if($hash->{initString} =~ m/brt/);
  897. if($hash->{CMDS} =~ m/b/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  898. $hash->{Clients} = $clientsWMBus;
  899. $hash->{MatchList} = \%matchListWMBus;
  900. $hash->{initString} = "X21\nbrt"; # Use T-Mode
  901. CUL_WriteInit($hash);
  902. } else {
  903. Log3 $name, 2, $msg;
  904. return $msg;
  905. }
  906. } elsif($aVal eq "WMBus_C") {
  907. return if($hash->{initString} =~ m/brt/);
  908. if($hash->{CMDS} =~ m/b/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  909. $hash->{Clients} = $clientsWMBus;
  910. $hash->{MatchList} = \%matchListWMBus;
  911. $hash->{initString} = "X21\nbrc"; # Use C-Mode
  912. CUL_WriteInit($hash);
  913. } else {
  914. Log3 $name, 2, $msg;
  915. return $msg;
  916. }
  917. } elsif($aVal eq "KOPP_FC") {
  918. if($hash->{CMDS} =~ m/k/ || IsDummy($hash->{NAME}) || !$hash->{FD}) {
  919. $hash->{Clients} = $clientsKOPP_FC;
  920. $hash->{MatchList} = \%matchListKOPP_FC;
  921. $hash->{initString} = "krS"; # krS: start Kopp receive Mode
  922. CUL_WriteInit($hash);
  923. } else {
  924. Log3 $name, 2, $msg;
  925. return $msg;
  926. }
  927. } else {
  928. return if($hash->{initString} eq "X21");
  929. $hash->{Clients} = $clientsSlowRF;
  930. $hash->{MatchList} = \%matchListSlowRF;
  931. $hash->{initString} = "X21";
  932. CUL_SimpleWrite($hash, "Ax") if ($hash->{CMDS} =~ m/A/); # reset AskSin
  933. CUL_SimpleWrite($hash, "Zx") if ($hash->{CMDS} =~ m/Z/); # reset Moritz
  934. CUL_SimpleWrite($hash, "brx") if ($hash->{CMDS} =~ m/b/); # reset WMBus
  935. CUL_WriteInit($hash);
  936. }
  937. Log3 $name, 2, "Switched $name rfmode to $aVal";
  938. delete $hash->{".clientArray"};
  939. } elsif($aName eq "hmId"){
  940. if($cmd eq "set") {
  941. return "wrong syntax: hmId must be 6-digit-hex-code (3 byte)"
  942. if($aVal !~ m/^[A-F0-9]{6}$/i);
  943. }
  944. } elsif($aName eq "connectCommand"){
  945. CUL_SimpleWrite($hash, $aVal) if($cmd eq "set");
  946. }
  947. return undef;
  948. }
  949. sub
  950. CUL_prefix($$$)
  951. {
  952. my ($isadd, $hash, $msg) = @_;
  953. while($hash && $hash->{TYPE} !~ m/$culNameRe/) {
  954. $msg = CallFn($hash->{NAME}, $isadd ? "AddPrefix":"DelPrefix", $hash, $msg);
  955. $hash = $hash->{IODev};
  956. last if(!$hash);
  957. }
  958. return ($hash, $msg);
  959. }
  960. 1;
  961. =pod
  962. =item summary connect devices with the culfw Firmware, e.g. Busware CUL
  963. =item summary_DE Anbindung von Geraeten mit dem culfw Firmware, z.Bsp. Busware CUL
  964. =begin html
  965. <a name="CUL"></a>
  966. <h3>CUL</h3>
  967. <ul>
  968. <table>
  969. <tr><td>
  970. The CUL/CUN(O) is a family of RF devices sold by <a
  971. href="http://www.busware.de">busware.de</a>.
  972. With the opensource firmware
  973. <a href="http://culfw.de/culfw.html">culfw</a> they are capable
  974. to receive and send different 433/868 MHz protocols (FS20/FHT/S300/EM/HMS/MAX!).
  975. It is even possible to use these devices as range extenders/routers, see the
  976. <a href="#CUL_RFR">CUL_RFR</a> module for details.
  977. <br> <br>
  978. Some protocols (FS20, FHT and KS300) are converted by this module so that
  979. the same logical device can be used, irrespective if the radio telegram is
  980. received by a CUL or an FHZ device.<br>
  981. Other protocols (S300/EM) need their
  982. own modules. E.g. S300 devices are processed by the CUL_WS module if the
  983. signals are received by the CUL, similarly EMWZ/EMGZ/EMEM is handled by the
  984. CUL_EM module.<br><br>
  985. It is possible to attach more than one device in order to get better
  986. reception, FHEM will filter out duplicate messages.<br><br>
  987. Note: This module may require the <code>Device::SerialPort</code> or
  988. <code>Win32::SerialPort</code> module if you attach the device via USB
  989. and the OS sets strange default parameters for serial devices.<br><br>
  990. </td><td>
  991. <img src="ccc.jpg"/>
  992. </td></tr>
  993. </table>
  994. <a name="CULdefine"></a>
  995. <b>Define</b>
  996. <ul>
  997. <code>define &lt;name&gt; CUL &lt;device&gt; &lt;FHTID&gt;</code> <br>
  998. <br>
  999. USB-connected devices (CUL/CUN):<br><ul>
  1000. &lt;device&gt; specifies the serial port to communicate with the CUL.
  1001. The name of the serial-device depends on your distribution, under
  1002. linux the cdc_acm kernel module is responsible, and usually a
  1003. /dev/ttyACM0 device will be created. If your distribution does not have a
  1004. cdc_acm module, you can force usbserial to handle the CUL by the
  1005. following command:
  1006. <ul><code>
  1007. modprobe usbserial vendor=0x03eb product=0x204b
  1008. </code></ul>
  1009. In this case the device is most probably /dev/ttyUSB0.<br><br>
  1010. You can also specify a baudrate if the device name contains the @
  1011. character, e.g.: /dev/ttyACM0@38400<br><br>
  1012. If the baudrate is "directio" (e.g.: /dev/ttyACM0@directio), then the
  1013. perl module <code>Device::SerialPort</code> is not needed, and FHEM
  1014. opens the device with simple file io. This might work if the operating
  1015. system uses sane defaults for the serial parameters, e.g. some Linux
  1016. distributions and OSX.<br><br>
  1017. </ul>
  1018. Network-connected devices (CUN(O)):<br><ul>
  1019. &lt;device&gt; specifies the host:port of the device, e.g.
  1020. 192.168.0.244:2323
  1021. </ul>
  1022. <br>
  1023. If the device is called none, then no device will be opened, so you
  1024. can experiment without hardware attached.<br>
  1025. The FHTID is a 4 digit hex number, and it is used when the CUL talks to
  1026. FHT devices or when CUL requests data. Set it to 0000 to avoid answering
  1027. any FHT80b request by the CUL.
  1028. </ul>
  1029. <br>
  1030. <a name="CULset"></a>
  1031. <b>Set </b>
  1032. <ul>
  1033. <li>reopen<br>
  1034. Reopens the connection to the device and reinitializes it.
  1035. </li><br>
  1036. <li>raw<br>
  1037. Issue a CUL firmware command. See the <a
  1038. href="http://culfw.de/commandref.html">this</a> document
  1039. for details on CUL commands.
  1040. </li><br>
  1041. <li>freq / bWidth / rAmpl / sens<br>
  1042. <a href="#rfmode">SlowRF</a> mode only.<br>
  1043. Set the CUL frequency / bandwidth / receiver-amplitude / sensitivity<br>
  1044. Use it with care, it may destroy your hardware and it even may be
  1045. illegal to do so. Note: The parameters used for RFR transmission are
  1046. not affected.<br>
  1047. <ul>
  1048. <li>freq sets both the reception and transmission frequency. Note:
  1049. Although the CC1101 can be set to frequencies between 315 and 915
  1050. MHz, the antenna interface and the antenna of the CUL is tuned for
  1051. exactly one frequency. Default is 868.3 MHz (or 433 MHz)</li>
  1052. <li>bWidth can be set to values between 58 kHz and 812 kHz. Large values
  1053. are susceptible to interference, but make possible to receive
  1054. inaccurately calibrated transmitters. It affects tranmission too.
  1055. Default is 325 kHz.</li>
  1056. <li>rAmpl is receiver amplification, with values between 24 and 42 dB.
  1057. Bigger values allow reception of weak signals. Default is 42.
  1058. </li>
  1059. <li>sens is the decision boundary between the on and off values, and it
  1060. is 4, 8, 12 or 16 dB. Smaller values allow reception of less clear
  1061. signals. Default is 4 dB.</li>
  1062. </ul>
  1063. </li><br>
  1064. <a name="hmPairForSec"></a>
  1065. <li>hmPairForSec<br>
  1066. <a href="#rfmode">HomeMatic</a> mode only.<br>
  1067. Set the CUL in Pairing-Mode for the given seconds. Any HM device set into
  1068. pairing mode in this time will be paired with FHEM.
  1069. </li><br>
  1070. <a name="hmPairSerial"></a>
  1071. <li>hmPairSerial<br>
  1072. <a href="#rfmode">HomeMatic</a> mode only.<br>
  1073. Try to pair with the given device. The argument is a 10 character
  1074. string, usually starting with letters and ending with digits, printed on
  1075. the backside of the device. It is not necessary to put the given device
  1076. in learning mode if it is a receiver.
  1077. </li><br>
  1078. <a name="hmPairForSec"></a>
  1079. <li>led<br>
  1080. Set the CUL led off (00), on (01) or blinking (02).
  1081. </li><br>
  1082. <li>ITClock</br>
  1083. Set the IT clock for Intertechno V1 protocol. Default 250.
  1084. </li><br>
  1085. </ul>
  1086. <a name="CULget"></a>
  1087. <b>Get</b>
  1088. <ul>
  1089. <li>version<br>
  1090. returns the CUL firmware version
  1091. </li><br>
  1092. <li>uptime<br>
  1093. returns the CUL uptime (time since CUL reset)
  1094. </li><br>
  1095. <li>raw<br>
  1096. Issues a CUL firmware command, and waits for one line of data returned by
  1097. the CUL. See the CUL firmware README document for details on CUL
  1098. commands.
  1099. </li><br>
  1100. <li>fhtbuf<br>
  1101. CUL has a message buffer for the FHT. If the buffer is full, then newly
  1102. issued commands will be dropped, and an "EOB" message is issued to the
  1103. FHEM log.
  1104. <code>fhtbuf</code> returns the free memory in this buffer (in hex),
  1105. an empty buffer in the CUL V2 is 74 bytes, in CUL V3/CUN(O) 200 Bytes.
  1106. A message occupies 3 + 2x(number of FHT commands) bytes,
  1107. this is the second reason why sending multiple FHT commands with one
  1108. <a href="#set">set</a> is a good idea. The first reason is, that
  1109. these FHT commands are sent at once to the FHT.
  1110. </li> <br>
  1111. <li>ccconf<br>
  1112. Read some CUL radio-chip (cc1101) registers (frequency, bandwidth, etc.),
  1113. and display them in human readable form.
  1114. </li><br>
  1115. <li>cmds<br>
  1116. Depending on the firmware installed, CULs have a different set of
  1117. possible commands. Please refer to the README of the firmware of your
  1118. CUL to interpret the response of this command. See also the raw command.
  1119. </li><br>
  1120. <li>credit10ms<br>
  1121. One may send for a duration of credit10ms*10 ms before the send limit
  1122. is reached and a LOVF is generated.
  1123. </li><br>
  1124. </ul>
  1125. <a name="CULattr"></a>
  1126. <b>Attributes</b>
  1127. <ul>
  1128. <li><a name="addvaltrigger">addvaltrigger</a><br>
  1129. Create triggers for additional device values. Right now these are RSSI
  1130. and RAWMSG for the CUL family and RAWMSG for the FHZ.
  1131. </li><br>
  1132. <li><a name="connectCommand">connectCommand</a><br>
  1133. raw culfw command sent to the CUL after a (re-)connect of the USB device,
  1134. and sending the usual initialization needed for the configured rfmode.
  1135. </li>
  1136. <li><a href="#do_not_notify">do_not_notify</a></li>
  1137. <li><a href="#attrdummy">dummy</a></li>
  1138. <li><a name="hmId">hmId</a><br>
  1139. Set the HomeMatic ID of this device. If this attribute is absent, the
  1140. ID will be F1&lt;FHTID&gt;. Note 1: After setting or changing this
  1141. attribute you have to relearn all your HomeMatic devices. Note 2: The
  1142. value <b>must</b> be a 6 digit hex number, and 000000 is not valid. FHEM
  1143. won't complain if it is not correct, but the communication won't work.
  1144. </li><br>
  1145. <li><a name="hmProtocolEvents">hmProtocolEvents</a><br>
  1146. Generate events for HomeMatic protocol messages. These are normally
  1147. used for debugging, by activating "inform timer" in a telnet session,
  1148. or looking at the Event Monitor window in the FHEMWEB frontend.<br>
  1149. Example:
  1150. <ul>
  1151. <code>
  1152. 2012-05-17 09:44:22.515 CUL CULHM RCV L:0B N:81 CMD:A258 SRC:......
  1153. DST:...... 0000 (TYPE=88,WAKEMEUP,BIDI,RPTEN)
  1154. </code>
  1155. </ul>
  1156. </li><br>
  1157. <li><a name="longids">longids</a><br>
  1158. Comma separated list of device-types for CUL that should be handled
  1159. using long IDs. This additional ID allows it to differentiate some
  1160. weather sensors, if they are sending on the same channel.
  1161. Therefore a random generated id is added. If you choose to use longids,
  1162. then you'll have to define a different device after battery change.
  1163. Default is not to use long IDs.<br>
  1164. Modules which are using this functionality are for e.g. :
  1165. 14_Hideki, 41_OREGON, 14_CUL_TCM97001, 14_SD_WS07.<br>
  1166. Examples:<br>
  1167. <ul><code>
  1168. # Do not use any long IDs for any devices (this is default):<br>
  1169. attr cul longids 0<br>
  1170. # Use long IDs for all devices:<br>
  1171. attr cul longids 1<br>
  1172. # Use longids for SD_WS07 devices.<br>
  1173. # Will generate devices names like SD_WS07_TH_3 for channel 3.<br>
  1174. attr cul longids SD_WS07
  1175. </code></ul>
  1176. </li><br>
  1177. <li><a href="#model">model</a> (CUL,CUN,etc)</li>
  1178. <li><a name="sendpool">sendpool</a><br>
  1179. If using more than one CUL for covering a large area, sending
  1180. different events by the different CUL's might disturb each other. This
  1181. phenomenon is also known as the Palm-Beach-Resort effect.
  1182. Putting them in a common sendpool will serialize sending the events.
  1183. E.g. if you have three CUN's, you have to specify following
  1184. attributes:<br>
  1185. <code>attr CUN1 sendpool CUN1,CUN2,CUN3<br>
  1186. attr CUN2 sendpool CUN1,CUN2,CUN3<br>
  1187. attr CUN3 sendpool CUN1,CUN2,CUN3</code><br>
  1188. </li><br>
  1189. <li><a name="rfmode">rfmode</a><br>
  1190. Configure the RF Transceiver of the CUL (the CC1101). Available
  1191. arguments are:
  1192. <ul>
  1193. <li>SlowRF<br>
  1194. To communicate with FS20/FHT/HMS/EM1010/S300/Hoermann devices @1 kHz
  1195. datarate. This is the default.</li>
  1196. <li>HomeMatic<br>
  1197. To communicate with HomeMatic type of devices @10 kHz datarate.</li>
  1198. <li>MAX<br>
  1199. To communicate with MAX! type of devices @10 kHz datarate.</li>
  1200. <li>WMBus_S</li>
  1201. <li>WMBus_T</li>
  1202. <li>WMBus_C<br>
  1203. To communicate with Wireless M-Bus devices like water, gas or
  1204. electrical meters. Wireless M-Bus uses three different communication
  1205. modes, S-Mode, T-Mode and C-Mode. While in this mode, no reception of other
  1206. protocols like SlowRF or HomeMatic is possible. See also the WMBUS
  1207. FHEM Module.
  1208. </li>
  1209. </ul>
  1210. </li><br>
  1211. <li><a href="#showtime">showtime</a></li>
  1212. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  1213. </ul>
  1214. <br>
  1215. </ul>
  1216. =end html
  1217. =begin html_DE
  1218. <a name="CUL"></a>
  1219. <h3>CUL</h3>
  1220. <ul>
  1221. <table>
  1222. <tr><td>
  1223. Der CUL/CUN(O) ist eine Familie von Funkempf&auml;ngern, die von der Firma
  1224. <a href="http://www.busware.de">Busware</a> verkauft wird.
  1225. Mit der OpenSource Firmware
  1226. <a href="http://culfw.de/culfw.html">culfw</a> k&ouml;nnen sie verschiedene
  1227. 868 MHz Funkprotokolle empfangen bzw. senden (FS20/FHT/S300/EM/HMS/MAX!).
  1228. Man kann diese Ger&auml;te auch zur Reichweitenverl&auml;ngerung, siehe
  1229. <a href="#CUL_RFR">CUL_RFR</a> einsetzen.
  1230. <br> <br>
  1231. Einige Protokolle (FS20, FHT und KS300) werden von diesem Modul in das FHZ
  1232. Format konvertiert, daher kann dasselbe logische Ger&auml;t verwendet werden,
  1233. egal ob das Funktelegramm von einem CUL oder einem FHZ Ger&auml;t empfangen
  1234. wird.<br>
  1235. Andere Protokolle (S300/EM) ben&ouml;tigen ihre eigenen Module. S300
  1236. Ger&auml;te werden vom Modul CUL_WS verarbeitet, wenn das Signal von einem
  1237. CUL empfangen wurde, &auml;hnliches gilt f&uuml;r EMWZ/EMGZ/EMEM: diese
  1238. werden vom CUL_EM Modul verarbeitet.<br><br>
  1239. Es ist m&ouml;glich mehr als ein Ger&auml;t zu verwenden, um einen besseren
  1240. Empfang zu erhalten, FHEM filtert doppelte Funktelegramme aus.<br><br>
  1241. Bemerkung: Dieses Modul ben&ouml;tigt unter Umst&auml;nden das
  1242. <code>Device::SerialPort</code> bzw. <code>Win32::SerialPort</code> Modul,
  1243. wenn Sie das Ger&auml;t &uuml;ber USB anschlie&szlig;en und das
  1244. Betriebssystem un&uuml;bliche Parameter f&uuml;r serielle Schnittstellen
  1245. setzt.<br><br>
  1246. </td><td>
  1247. <img src="ccc.jpg"/>
  1248. </td></tr>
  1249. </table>
  1250. <a name="CULdefine"></a>
  1251. <b>Define</b>
  1252. <ul>
  1253. <code>define &lt;name&gt; CUL &lt;device&gt; &lt;FHTID&gt;</code> <br>
  1254. <br>
  1255. Ger&auml;te, die an USB angeschlossen sind (CUL/CUN):<br>
  1256. <ul>
  1257. &lt;device&gt; gibt die serielle Schnittstelle an, mit der der CUL
  1258. kommuniziert. Der Name der seriellen Schnittstelle h&auml;ngt von der
  1259. gew&auml;hlten Distribution und USB-Treiber ab, unter Linux ist dies das
  1260. Kernel Modul cdc_acm und &uuml;blicherweise wird die Schnittstelle
  1261. /dev/ttyACM0 genannt. Wenn die Linux Distribution &uuml;ber kein Kernel
  1262. Modul cdc_acm verf&uuml;gt, dann kann die Schnittstelle &uuml;ber
  1263. usbserial mit dem folgenden Befehl erzeugt werden:
  1264. <ul><code>
  1265. modprobe usbserial vendor=0x03eb product=0x204b
  1266. </code></ul>
  1267. In diesem Fall ist diese Schnittstelle dann wahrscheinlich
  1268. /dev/ttyUSB0.<br><br>
  1269. Wenn der Name der Schnittstelle ein @ enth&auml;lt, kann nachfolgend die
  1270. verwendete Baudrate angegeben werden, z.B.: /dev/ttyACM0@38400.<br><br>
  1271. Wenn die Baudrate mit "directio" angegeben wird (z.B.:
  1272. /dev/ttyACM0@directio), wird das Perl Modul
  1273. <code>Device::SerialPort</code> nicht ben&ouml;tigt und FHEM &ouml;ffnet
  1274. die Schnittstelle mit einfachem Dateizugriff. Dies sollte dann
  1275. funktionieren, wenn das Betriebssystem vern&uuml;nftige Standardwerte
  1276. f&uuml;r die serielle Schnittstelle verwendet, wie z.B. einige Linux
  1277. Distributionen oder OSX.<br><br>
  1278. </ul>
  1279. Ger&auml;te, die mit dem Netzwerk verbunden sind (CUN(O)):<br>
  1280. <ul>
  1281. &lt;device&gt; gibt die Hostadresse:Port des Ger&auml;tes an, z.B.
  1282. 192.168.0.244:2323
  1283. </ul>
  1284. <br>
  1285. Wenn das Ger&auml;t mit none bezeichnet wird, wird keine Schnittstelle
  1286. ge&ouml;ffnet und man kann ohne angeschlossene Hardware
  1287. experimentieren.<br>
  1288. Die FHTID ist eine 4-stellige hexadezimale Zahl und wird verwendet, wenn
  1289. der CUL FHT Telegramme sendet bzw. Daten anfragt. Diese sollte als 0000
  1290. gew&auml;hlt werden, wenn man FHT80b Anfragen durch den CUL vermeiden will.
  1291. </ul>
  1292. <br>
  1293. <a name="CULset"></a>
  1294. <b>Set </b>
  1295. <ul>
  1296. <li>reopen<br>
  1297. &Ouml;ffnet die Verbindung zum Ger&auml;t neu und initialisiert es.
  1298. </li><br>
  1299. <li>raw<br>
  1300. Sendet einen CUL Firmware Befehl. Siehe auch
  1301. <a href="http://culfw.de/commandref.html">hier</a> f&uuml;r
  1302. n&auml;here Erl&auml;uterungen der CUL Befehle.
  1303. </li><br>
  1304. <li>freq / bWidth / rAmpl / sens<br>
  1305. Nur in der Betriebsart <a href="#rfmode">SlowRF</a>.<br> Bestimmt die
  1306. CUL Frequenz / Bandbreite / Empf&auml;nger Amplitude /
  1307. Empfindlichkeit<br>
  1308. Bitte mit Vorsicht verwenden, da es die verwendete Hardware
  1309. zerst&ouml;ren kann bzw. es zu illegalen Funkzust&auml;nden kommen
  1310. kann. <br> Bemerkung: Die Parameter f&uuml;r die RFR &Uuml;bermittlung
  1311. werden hierdurch nicht beeinflu&szlig;t.<br>
  1312. <ul>
  1313. <li>freq bestimmt sowohl die Empfangs- als auch die Sendefrequenz.<br>
  1314. Bemerkung: Auch wenn der CC1101 zwischen den Frequenzen 315 und 915
  1315. MHz eingestellt werden kann, ist die Antennenanbindung bzw. die
  1316. Antenne des CUL exakt auf eine Frequenz eingestellt. Standard ist
  1317. 868.3 MHz (bzw. 433 MHz).</li>
  1318. <li>bWidth kann zwischen 58 kHz und 812 kHz variiert werden.
  1319. Gro&szlig;e Werte sind empfindlicher gegen Interferencen, aber
  1320. machen es m&ouml;glich, nicht genau kalbrierte Signale zu
  1321. empfangen. Die Einstellung beeinflusst ebenso die &Uuml;bertragung.
  1322. Standardwert ist 325 kHz.</li>
  1323. <li>rAmpl ist die Verst&auml;rkung des Empf&auml;ngers mit Werten
  1324. zwischen 24 and 42 dB. Gr&ouml;&szlig;ere Werte erlauben den
  1325. Empfang von schwachen Signalen. Standardwert ist 42.</li>
  1326. <li>sens ist die Entscheidungsgrenze zwischen "on" und "off"
  1327. Zust&auml;nden und kann 4, 8, 12 oder 16 dB sein. Kleinere Werte
  1328. erlauben den Empfang von undeutlicheren Signalen. Standard ist 4
  1329. dB.</li>
  1330. </ul>
  1331. </li><br>
  1332. <a name="hmPairForSec"></a>
  1333. <li>hmPairForSec<br>
  1334. Nur in der Betriebsart <a href="#rfmode">HomeMatic</a>.<br> Versetzt den
  1335. CUL f&uuml;r die angegebene Zeit in Sekunden in den Anlern-Modus. Jedes
  1336. HM Ger&auml;t, das sich im Anlern-Modus befindet, wird an FHEM
  1337. angelernt. </li><br>
  1338. <a name="hmPairSerial"></a>
  1339. <li>hmPairSerial<br>
  1340. Nur in der Betriebsart <a href="#rfmode">HomeMatic</a>.<br>
  1341. Versucht, das angegebene Ger&auml;t anzulernen (zu "pairen"). Der
  1342. Parameter ist eine 10-stellige Zeichenfolge, die normalerweise mit
  1343. Buchstaben beginnt und mit Ziffern endet; diese sind auf der
  1344. R&uuml;ckseite der Ger&auml;te aufgedruckt. Wenn das Ger&auml;t ein
  1345. Empf&auml;nger ist, ist es nicht notwendig, das angegebene Ger&auml;t in
  1346. den Anlern-Modus zu versetzen. </li><br>
  1347. <a name="hmPairForSec"></a>
  1348. <li>led<br>
  1349. Schaltet die LED des CUL: aus (00), an (01) oder blinkend (02).
  1350. </li><br>
  1351. <li>ITClock</br>
  1352. Setzt die IT clock f&uuml; Intertechno V1 Protokoll. Default 250.
  1353. </li><br>
  1354. </ul>
  1355. <a name="CULget"></a>
  1356. <b>Get</b>
  1357. <ul>
  1358. <li>version<br>
  1359. gibt die Version der CUL Firmware zur&uuml;ck
  1360. </li><br>
  1361. <li>uptime<br>
  1362. gibt die Betriebszeit des CULs zur&uuml;ck (Zeit seit dem letzten Reset
  1363. des CULs) </li><br>
  1364. <li>raw<br>
  1365. Sendet einen CUL Firmware Befehl und wartet auf eine R&uuml;ckgabe des
  1366. CULs. Siehe auch README der Firmware f&uuml;r n&auml;here
  1367. Erl&auml;uterungen zu den CUL Befehlen. </li><br>
  1368. <li>fhtbuf<br>
  1369. Der CUL hat einen Puffer f&uuml;r Nachrichten f&uuml;r FHT. Wenn der
  1370. Puffer voll ist, werden neu empfangene Telegramme ignoriert und eine
  1371. "EOB" Meldung wird in die FHEM Logdatei geschrieben.
  1372. <code>fhtbuf</code> gibt den freien Speicher dieses Puffers (in hex)
  1373. zur&uuml;ck, ein leerer Puffer im CUL V2 hat 74 Byte, im CUL V3/CUN(O)
  1374. hat 200 Byte. Eine Telegramm ben&ouml;tigt 3 + 2x(Anzahl der FHT
  1375. Befehle) Byte, dies ist ein Grund, warum man mehrere FHT Befehle mit
  1376. einem <a href="#set">set</a> senden sollte. Ein weiterer Grund ist,
  1377. dass diese FHT Befehle in einem "Paket" zum FHT Ger&auml;t gesendet werden.
  1378. </li> <br>
  1379. <li>ccconf<br>
  1380. Liest einige CUL Register des CC1101 (Sende- und Empf&auml;ngerchips)
  1381. aus (Frequenz, Bandbreite, etc.) und stellt diese in lesbarer Form dar.
  1382. </li><br>
  1383. <li>cmds<br>
  1384. In abh&auml;gigkeit der installierten Firmware hat der CUL/CUN(O)
  1385. unterschiedliche Befehlss&auml;tze. N&auml;here Informationen &uuml;ber
  1386. die Befehle bzw. deren Interpretation siehe README Datei der
  1387. verwendeten CUL Firmware. Siehe auch Anmerkungen beim raw Befehl.
  1388. </li><br>
  1389. <li>credit10ms<br>
  1390. Der Funkraum darf f&uuml;r eine Dauer von credit10ms*10 ms belegt
  1391. werden, bevor die gesetzliche 1% Grenze erreicht ist und eine
  1392. LOVF Meldung ausgegeben wird. </li><br> </ul>
  1393. <a name="CULattr"></a>
  1394. <b>Attribute</b>
  1395. <ul>
  1396. <li><a name="addvaltrigger">addvaltrigger</a><br>
  1397. Generiert Trigger f&uuml;r zus&auml;tzliche Werte. Momentan sind dies
  1398. RSSI und RAWMSG f&uuml;r die CUL Familie und RAWMSG f&uuml;r FHZ.
  1399. </li><br>
  1400. <li><a name="connectCommand">connectCommand</a><br>
  1401. culfw Befehl, was nach dem Verbindungsaufbau mit dem USB-Ger&auml;t, nach
  1402. Senden der zum Initialisieren der konfigurierten rfmode ben&ouml;tigten
  1403. Befehle gesendet wird.
  1404. </li>
  1405. <li><a href="#do_not_notify">do_not_notify</a></li>
  1406. <li><a href="#attrdummy">dummy</a></li>
  1407. <li><a name="hmId">hmId</a><br>
  1408. Setzt die HomeMatic ID des Ger&auml;tes. Wenn dieses Attribut fehlt,
  1409. wird die ID zu F1&lt;FHTID&gt; gesetzt. Bemerkung 1: Nach dem Setzen
  1410. bzw. Ver&auml;ndern dieses Attributes m&uuml;ssen alle HomeMatic
  1411. Ger&auml;te neu angelernt werden. Bemerkung 2: Der Wert <b>muss</b>
  1412. eine 6-stellige Hexadezimalzahl sein, 000000 ist ung&uuml;ltig. FHEM
  1413. &uuml;berpr&uuml;ft nicht, ob die ID korrekt ist, im Zweifelsfall
  1414. funktioniert die Kommunikation nicht. </li><br>
  1415. <li><a name="hmProtocolEvents">hmProtocolEvents</a><br>
  1416. Generiert Ereignisse f&uuml;r HomeMatic Telegramme. Diese werden
  1417. normalerweise f&uuml;r die Fehlersuche verwendet, z.B. durch Aktivieren
  1418. von <code>inform timer</code> in einer telnet Sitzung bzw. im
  1419. <code>Event Monitor</code> Fenster im FHEMWEB Frontend.<br>
  1420. Beispiel:
  1421. <ul>
  1422. <code>
  1423. 2012-05-17 09:44:22.515 CUL CULHM RCV L:0B N:81 CMD:A258 SRC:......
  1424. DST:...... 0000 (TYPE=88,WAKEMEUP,BIDI,RPTEN)
  1425. </code>
  1426. </ul>
  1427. </li><br>
  1428. <li><a name="longids">longids</a><br>
  1429. Durch Kommata getrennte Liste von Device-Typen f&uuml;r Empfang von
  1430. langen IDs mit den CUL. Diese zus&auml;tzliche ID erlaubt es
  1431. Wettersensoren, welche auf dem gleichen Kanal senden zu unterscheiden.
  1432. Hierzu wird eine zuf&auml;llig generierte ID hinzugef&uuml;gt. Wenn Sie
  1433. longids verwenden, dann wird in den meisten F&auml;llen nach einem
  1434. Batteriewechsel ein neuer Sensor angelegt.
  1435. Standardm&auml;&szlig;ig werden keine langen IDs verwendet.<br>
  1436. Folgende Module verwenden diese Funktionalit&auml;t:
  1437. 14_Hideki, 41_OREGON, 14_CUL_TCM97001, 14_SD_WS07.<br>
  1438. Beispiele:
  1439. <ul><code>
  1440. # Keine langen IDs verwenden (Default Einstellung):<br>
  1441. attr cul longids 0<br>
  1442. # Immer lange IDs verwenden:<br>
  1443. attr cul longids 1<br>
  1444. # Verwende lange IDs f&uuml;r SD_WS07 Devices.<br>
  1445. # Device Namen sehen z.B. so aus: SD_WS07_TH_3 for channel 3.<br>
  1446. attr cul longids SD_WS07
  1447. </code></ul>
  1448. </li><br>
  1449. <li><a href="#model">model</a> (CUL,CUN)</li><br>
  1450. <li><a name="rfmode">rfmode</a><br>
  1451. Konfiguriert den RF Transceiver des CULs (CC1101). Verf&uuml;gbare
  1452. Argumente sind:
  1453. <ul>
  1454. <li>SlowRF<br>
  1455. F&uuml;r die Kommunikation mit FS20/FHT/HMS/EM1010/S300/Hoermann
  1456. Ger&auml;ten @1 kHz Datenrate (Standardeinstellung).</li>
  1457. <li>HomeMatic<br>
  1458. F&uuml;r die Kommunikation mit HomeMatic Ger&auml;ten @10 kHz
  1459. Datenrate.</li>
  1460. <li>MAX<br>
  1461. F&uuml;r die Kommunikation mit MAX! Ger&auml;ten @10 kHz
  1462. Datenrate.</li>
  1463. <li>WMBus_S</li>
  1464. <li>WMBus_T</li>
  1465. <li>WMBus_C<br>
  1466. F&uuml;r die Kommunikation mit Wireless M-Bus Ger&auml;ten wie
  1467. Wasser-, Gas- oder Elektroz&auml;hlern. Wireless M-Bus verwendet
  1468. drei unterschiedliche Kommunikationsarten, S-Mode, T-Mode und C-Mode. In
  1469. diesem Modus ist der Empfang von anderen Protokollen wie SlowRF
  1470. oder HomeMatic nicht m&ouml;glich.</li>
  1471. </ul>
  1472. </li><br>
  1473. <li><a name="sendpool">sendpool</a><br>
  1474. Wenn mehr als ein CUL verwendet wird, um einen gr&ouml;&szlig;eren
  1475. Bereich abzudecken, k&ouml;nnen diese sich gegenseitig
  1476. beeinflussen. Dieses Ph&auml;nomen wird auch Palm-Beach-Resort Effekt
  1477. genannt. Wenn man diese zu einen gemeinsamen Sende"pool"
  1478. zusammenschlie&szlig;t, wird das Senden der einzelnen Telegramme
  1479. seriell (d.h. hintereinander) durchgef&uuml;hrt.
  1480. Wenn z.B. drei CUN's zur
  1481. Verf&uuml;gung stehen, werden folgende Attribute gesetzt:<br>
  1482. <code>attr CUN1 sendpool CUN1,CUN2,CUN3<br>
  1483. attr CUN2 sendpool CUN1,CUN2,CUN3<br>
  1484. attr CUN3 sendpool CUN1,CUN2,CUN3</code><br>
  1485. </li><br>
  1486. <li><a href="#showtime">showtime</a></li>
  1487. <li><a href="#readingFnAttributes">readingFnAttributes</a></li>
  1488. </ul>
  1489. <br>
  1490. </ul>
  1491. =end html_DE
  1492. =cut