00_TCM.pm 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501
  1. ##############################################
  2. # $Id: 00_TCM.pm 12434 2016-10-26 11:10:15Z klaus-schauer $
  3. # by r.koenig at koeniglich.de
  4. #
  5. # This modules handles the communication with a TCM 120 or TCM 310 / TCM 400J EnOcean
  6. # transceiver chip. As the protocols are radically different, this is actually 2
  7. # drivers in one.
  8. # See also:
  9. # TCM_120_User_Manual_V1.53_02.pdf
  10. # EnOcean Serial Protocol 3 (ESP3) (for the TCM 310, TCM 400J)
  11. # TODO:
  12. # Check BSC Temp
  13. # Check Stick Temp
  14. # Check Stick WriteRadio
  15. # Check Stick RSS
  16. package main;
  17. use strict;
  18. use warnings;
  19. use Time::HiRes qw(gettimeofday usleep);
  20. if( $^O =~ /Win/ ) {
  21. require Win32::SerialPort;
  22. } else {
  23. require Device::SerialPort;
  24. }
  25. sub TCM_Read($);
  26. sub TCM_ReadAnswer($$);
  27. sub TCM_Ready($);
  28. sub TCM_Write($$$);
  29. sub TCM_Parse120($$$);
  30. sub TCM_Parse310($$$);
  31. sub TCM_CRC8($);
  32. sub TCM_CSUM($);
  33. sub
  34. TCM_Initialize($)
  35. {
  36. my ($hash) = @_;
  37. require "$attr{global}{modpath}/FHEM/DevIo.pm";
  38. # Provider
  39. $hash->{ReadFn} = "TCM_Read";
  40. $hash->{WriteFn} = "TCM_Write";
  41. $hash->{ReadyFn} = "TCM_Ready";
  42. $hash->{Clients} = ":EnOcean:";
  43. my %matchList= (
  44. "1:EnOcean" => "^EnOcean:",
  45. );
  46. $hash->{MatchList} = \%matchList;
  47. # Normal devices
  48. $hash->{DefFn} = "TCM_Define";
  49. $hash->{UndefFn} = "TCM_Undef";
  50. $hash->{GetFn} = "TCM_Get";
  51. $hash->{SetFn} = "TCM_Set";
  52. $hash->{NotifyFn} = "TCM_Notify";
  53. $hash->{AttrFn} = "TCM_Attr";
  54. $hash->{AttrList} = "baseID blockSenderID:own,no comModeUTE:auto,biDir,uniDir comType:TCM,RS485 do_not_notify:1,0 " .
  55. "dummy:1,0 learningMode:always,demand,nearfield " .
  56. "sendInterval:0,25,40,50,100,150,200,250 smartAckMailboxMax:slider,0,1,20 " .
  57. "smartAckLearnMode:simple,advance,advanceSelectRep";
  58. }
  59. # Define
  60. sub TCM_Define($$)
  61. {
  62. my ($hash, $def) = @_;
  63. my @a = split("[ \t][ \t]*", $def);
  64. my $name = $a[0];
  65. my $model = $a[2];
  66. return "TCM: wrong syntax, correct is: define <name> TCM [ESP2|ESP3] ".
  67. "{devicename[\@baudrate]|ip:port|none}"
  68. if(@a != 4 || $model !~ m/^(ESP2|ESP3|120|310)$/);
  69. $hash->{NOTIFYDEV} = "global";
  70. DevIo_CloseDev($hash);
  71. my $dev = $a[3];
  72. $hash->{DeviceName} = $dev;
  73. # old model names replaced
  74. $model = "ESP2" if ($model eq "120");
  75. $model = "ESP3" if ($model eq "310");
  76. $hash->{MODEL} = $model;
  77. $hash->{BaseID} = "00000000";
  78. $hash->{LastID} = "00000000";
  79. if($dev eq "none") {
  80. Log3 undef, 1, "TCM $name device is none, commands will be echoed only";
  81. $attr{$name}{dummy} = 1;
  82. return undef;
  83. }
  84. my $ret = DevIo_OpenDev($hash, 0, undef);
  85. return $ret;
  86. }
  87. # Initialize serial communication
  88. sub
  89. TCM_InitSerialCom($)
  90. {
  91. my ($hash) = @_;
  92. my $name = $hash->{NAME};
  93. if ($hash->{STATE} eq "disconnected") {
  94. Log3 $name, 2, "TCM $name not initialized";
  95. return undef;
  96. }
  97. my $attrVal;
  98. my $comType = AttrVal($name, "comType", "TCM");
  99. my $setCmdVal = "";
  100. my @setCmd = ("set", "reset", $setCmdVal);
  101. # read and discard receive buffer, modem reset
  102. if ($hash->{MODEL} eq "ESP2") {
  103. if ($comType eq "TCM") {
  104. TCM_ReadAnswer($hash, "set reset");
  105. #TCM_Read($hash);
  106. $hash->{PARTIAL} = '';
  107. TCM_Set($hash, @setCmd);
  108. }
  109. } else {
  110. #TCM_ReadAnswer($hash, "set reset");
  111. #TCM_Read($hash);
  112. #$hash->{PARTIAL} = '';
  113. delete $hash->{helper}{awaitCmdResp};
  114. TCM_Set($hash, @setCmd);
  115. }
  116. # default attributes
  117. my %setAttrInit;
  118. if ($comType eq "RS485" || $hash->{DeviceName} eq "none") {
  119. %setAttrInit = (sendInterval => {ESP2 => 100, ESP3 => 0},
  120. learningMode => {ESP2 => "always", ESP3 => "always"}
  121. );
  122. }else {
  123. %setAttrInit = ("sendInterval" => {ESP2 => 100, ESP3 => 0});
  124. }
  125. foreach(keys %setAttrInit) {
  126. $attrVal = AttrVal($name, $_, undef);
  127. if(!defined $attrVal && defined $setAttrInit{$_}{$hash->{MODEL}}) {
  128. $attr{$name}{$_} = $setAttrInit{$_}{$hash->{MODEL}};
  129. Log3 $name, 2, "TCM $name Attribute $_ $setAttrInit{$_}{$hash->{MODEL}} initialized";
  130. }
  131. }
  132. # 500 ms pause
  133. usleep(500 * 1000);
  134. # read transceiver IDs
  135. my $baseID = AttrVal($name, "baseID", undef);
  136. if (defined($baseID)) {
  137. $hash->{BaseID} = $baseID;
  138. $hash->{LastID} = sprintf "%08X", (hex $baseID) + 127;
  139. } elsif ($comType ne "RS485" && $hash->{DeviceName} ne "none") {
  140. my @getBaseID = ("get", "baseID");
  141. if (TCM_Get($hash, @getBaseID) =~ /[Ff]{2}[\dA-Fa-f]{6}/) {
  142. $hash->{BaseID} = sprintf "%08X", hex $&;
  143. $hash->{LastID} = sprintf "%08X", (hex $&) + 127;
  144. } else {
  145. $hash->{BaseID} = "00000000";
  146. $hash->{LastID} = "00000000";
  147. }
  148. }
  149. if ($hash->{MODEL} eq "ESP3" && $comType ne "RS485" && $hash->{DeviceName} ne "none") {
  150. # get chipID
  151. my @getChipID = ('get', 'version');
  152. if (TCM_Get($hash, @getChipID) =~ m/ChipID:.([\dA-Fa-f]{8})/) {
  153. $hash->{ChipID} = sprintf "%08X", hex $1;
  154. }
  155. }
  156. # default transceiver parameter
  157. if ($comType ne "RS485" && $hash->{DeviceName} ne "none") {
  158. my %setCmdRestore = (mode => "00",
  159. maturity => "01",
  160. repeater => "RepEnable: 00 RepLevel: 00",
  161. smartAckMailboxMax => 0
  162. );
  163. foreach(keys %setCmdRestore) {
  164. $setCmdVal = ReadingsVal($name, $_, AttrVal($name, $_, undef));
  165. if (defined $setCmdVal) {
  166. if ($_ eq "repeater") {
  167. $setCmdVal = substr($setCmdVal, 11, 2) . substr($setCmdVal, 24, 2);
  168. $setCmdVal = "0000" if ($setCmdVal eq "0001");
  169. }
  170. @setCmd = ("set", $_, $setCmdVal);
  171. TCM_Set($hash, @setCmd);
  172. Log3 $name, 2, "TCM $name $_ $setCmdVal restored";
  173. } else {
  174. if ($hash->{MODEL} eq "ESP2") {
  175. } else {
  176. if ($_ eq "repeater") {
  177. $setCmdVal = substr($setCmdRestore{$_}, 11, 2) . substr($setCmdRestore{$_}, 24, 2);
  178. } else {
  179. $setCmdVal = $setCmdRestore{$_};
  180. }
  181. @setCmd = ("set", $_, $setCmdVal);
  182. my $msg = TCM_Set($hash, @setCmd);
  183. Log3 $name, 2, "TCM $name $_ $setCmdVal initialized" if ($msg eq "");
  184. }
  185. }
  186. }
  187. }
  188. #CommandSave(undef, undef);
  189. readingsSingleUpdate($hash, "state", "initialized", 1);
  190. Log3 $name, 2, "TCM $name initialized";
  191. return undef;
  192. }
  193. # Write
  194. # Input is header and data (HEX), without CRC
  195. sub
  196. TCM_Write($$$)
  197. {
  198. my ($hash,$fn,$msg) = @_;
  199. my $name = $hash->{NAME};
  200. return if (!defined($fn));
  201. my $bstring;
  202. if ($hash->{MODEL} eq "ESP2") {
  203. # TCM 120 (ESP2)
  204. if (!$fn) {
  205. # command with ESP2 format
  206. $bstring = $msg;
  207. } else {
  208. # command with ESP3 format
  209. my $packetType = hex(substr($fn, 6, 2));
  210. if ($packetType != 1) {
  211. Log3 $name, 1, "TCM $name Packet Type not supported.";
  212. return;
  213. }
  214. my $odataLen = hex(substr($fn, 4, 2));
  215. if ($odataLen != 0) {
  216. Log3 $name, 1, "TCM $name Radio Telegram with optional Data not supported.";
  217. return;
  218. }
  219. #my $mdataLen = hex(substr($fn, 0, 4));
  220. my $rorg = substr ($msg, 0, 2);
  221. # translate the RORG to ORG
  222. my %rorgmap = ("F6"=>"05",
  223. "D5"=>"06",
  224. "A5"=>"07",
  225. );
  226. if($rorgmap{$rorg}) {
  227. $rorg = $rorgmap{$rorg};
  228. } else {
  229. Log3 $name, 1, "TCM $name unknown RORG mapping for $rorg";
  230. }
  231. if ($rorg eq "05" || $rorg eq "06") {
  232. $bstring = "6B" . $rorg . substr ($msg, 2, 2) . "000000" . substr ($msg, 4);
  233. } else {
  234. $bstring = "6B" . $rorg . substr ($msg, 2);
  235. }
  236. }
  237. $bstring = "A55A" . $bstring . TCM_CSUM($bstring);
  238. } else {
  239. # TCM 310 (ESP3)
  240. $bstring = "55" . $fn . TCM_CRC8($fn) . $msg . TCM_CRC8($msg);
  241. if (exists($hash->{helper}{telegramSentTimeLast}) && $hash->{helper}{telegramSentTimeLast} < gettimeofday() - 6) {
  242. # clear outdated response control list
  243. delete $hash->{helper}{awaitCmdResp};
  244. }
  245. $hash->{helper}{telegramSentTimeLast} = gettimeofday();
  246. if (exists $hash->{helper}{SetAwaitCmdResp}) {
  247. push(@{$hash->{helper}{awaitCmdResp}}, 1);
  248. delete $hash->{helper}{SetAwaitCmdResp};
  249. } else {
  250. push(@{$hash->{helper}{awaitCmdResp}}, 0);
  251. }
  252. #Log3 $name, 5, "TCM $name awaitCmdResp: " . join(' ', @{$hash->{helper}{awaitCmdResp}});
  253. }
  254. Log3 $name, 5, "TCM $name sent ESP: $bstring";
  255. DevIo_SimpleWrite($hash, $bstring, 1);
  256. # next commands will be sent with a delay
  257. usleep(int(AttrVal($name, "sendInterval", 100)) * 1000);
  258. }
  259. # ESP2 CRC
  260. # Used in the TCM120
  261. sub
  262. TCM_CSUM($)
  263. {
  264. my $msg = shift;
  265. my $ml = length($msg);
  266. my @data;
  267. for(my $i = 0; $i < $ml; $i += 2) {
  268. push(@data, ord(pack('H*', substr($msg, $i, 2))));
  269. }
  270. my $sum = 0;
  271. map { $sum += $_; } @data;
  272. return sprintf("%02X", $sum & 0xFF);
  273. }
  274. # ESP3 CRC-Table
  275. my @u8CRC8Table = (
  276. 0x00, 0x07, 0x0e, 0x09, 0x1c, 0x1b, 0x12, 0x15, 0x38, 0x3f, 0x36, 0x31, 0x24,
  277. 0x23, 0x2a, 0x2d, 0x70, 0x77, 0x7e, 0x79, 0x6c, 0x6b, 0x62, 0x65, 0x48, 0x4f,
  278. 0x46, 0x41, 0x54, 0x53, 0x5a, 0x5d, 0xe0, 0xe7, 0xee, 0xe9, 0xfc, 0xfb, 0xf2,
  279. 0xf5, 0xd8, 0xdf, 0xd6, 0xd1, 0xc4, 0xc3, 0xca, 0xcd, 0x90, 0x97, 0x9e, 0x99,
  280. 0x8c, 0x8b, 0x82, 0x85, 0xa8, 0xaf, 0xa6, 0xa1, 0xb4, 0xb3, 0xba, 0xbd, 0xc7,
  281. 0xc0, 0xc9, 0xce, 0xdb, 0xdc, 0xd5, 0xd2, 0xff, 0xf8, 0xf1, 0xf6, 0xe3, 0xe4,
  282. 0xed, 0xea, 0xb7, 0xb0, 0xb9, 0xbe, 0xab, 0xac, 0xa5, 0xa2, 0x8f, 0x88, 0x81,
  283. 0x86, 0x93, 0x94, 0x9d, 0x9a, 0x27, 0x20, 0x29, 0x2e, 0x3b, 0x3c, 0x35, 0x32,
  284. 0x1f, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0d, 0x0a, 0x57, 0x50, 0x59, 0x5e, 0x4b,
  285. 0x4c, 0x45, 0x42, 0x6f, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7d, 0x7a, 0x89, 0x8e,
  286. 0x87, 0x80, 0x95, 0x92, 0x9b, 0x9c, 0xb1, 0xb6, 0xbf, 0xb8, 0xad, 0xaa, 0xa3,
  287. 0xa4, 0xf9, 0xfe, 0xf7, 0xf0, 0xe5, 0xe2, 0xeb, 0xec, 0xc1, 0xc6, 0xcf, 0xc8,
  288. 0xdd, 0xda, 0xd3, 0xd4, 0x69, 0x6e, 0x67, 0x60, 0x75, 0x72, 0x7b, 0x7c, 0x51,
  289. 0x56, 0x5f, 0x58, 0x4d, 0x4a, 0x43, 0x44, 0x19, 0x1e, 0x17, 0x10, 0x05, 0x02,
  290. 0x0b, 0x0c, 0x21, 0x26, 0x2f, 0x28, 0x3d, 0x3a, 0x33, 0x34, 0x4e, 0x49, 0x40,
  291. 0x47, 0x52, 0x55, 0x5c, 0x5b, 0x76, 0x71, 0x78, 0x7f, 0x6A, 0x6d, 0x64, 0x63,
  292. 0x3e, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2c, 0x2b, 0x06, 0x01, 0x08, 0x0f, 0x1a,
  293. 0x1d, 0x14, 0x13, 0xae, 0xa9, 0xa0, 0xa7, 0xb2, 0xb5, 0xbc, 0xbb, 0x96, 0x91,
  294. 0x98, 0x9f, 0x8a, 0x8D, 0x84, 0x83, 0xde, 0xd9, 0xd0, 0xd7, 0xc2, 0xc5, 0xcc,
  295. 0xcb, 0xe6, 0xe1, 0xe8, 0xef, 0xfa, 0xfd, 0xf4, 0xf3 );
  296. # ESP3 CRC
  297. # Used in the TCM310
  298. sub
  299. TCM_CRC8($)
  300. {
  301. my $msg = shift;
  302. my $ml = length($msg);
  303. my @data;
  304. for(my $i = 0; $i < $ml; $i += 2) {
  305. push(@data, ord(pack('H*', substr($msg, $i, 2))));
  306. }
  307. my $crc = 0;
  308. map { $crc = $u8CRC8Table[$crc ^ $_]; } @data;
  309. return sprintf("%02X", $crc);
  310. }
  311. # Read
  312. # called from the global loop, when the select for hash->{FD} reports data
  313. sub
  314. TCM_Read($)
  315. {
  316. my ($hash) = @_;
  317. my $buf = DevIo_SimpleRead($hash);
  318. return "" if(!defined($buf));
  319. my $name = $hash->{NAME};
  320. my $blockSenderID = AttrVal($name, "blockSenderID", "own");
  321. my $chipID = exists($hash->{ChipID}) ? hex $hash->{ChipID} : 0;
  322. my $baseID = exists($hash->{BaseID}) ? hex $hash->{BaseID} : 0;
  323. my $lastID = exists($hash->{LastID}) ? hex $hash->{LastID} : 0;
  324. my $data = $hash->{PARTIAL} . uc(unpack('H*', $buf));
  325. Log3 $name, 5, "TCM $name received ESP: $data";
  326. if($hash->{MODEL} eq "ESP2") {
  327. # TCM 120
  328. while($data =~ m/^A55A(.B.{20})(..)/) {
  329. my ($net, $crc) = ($1, $2);
  330. my $mycrc = TCM_CSUM($net);
  331. my $rest = substr($data, 28);
  332. if($crc ne $mycrc) {
  333. Log3 $name, 2, "TCM $name wrong checksum: got $crc, computed $mycrc" ;
  334. $data = $rest;
  335. next;
  336. }
  337. if($net =~ m/^0B(..)(........)(........)(..)/) {
  338. # Receive Radio Telegram (RRT)
  339. my ($org, $d1,$id,$status) = ($1, $2, $3, $4);
  340. my $packetType = 1;
  341. # Re-translate the ORG to RadioORG / TCM310 equivalent
  342. my %orgmap = ("05"=>"F6", "06"=>"D5", "07"=>"A5", );
  343. if($orgmap{$org}) {
  344. $org = $orgmap{$org};
  345. } else {
  346. Log3 $name, 2, "TCM $name unknown ORG mapping for $org";
  347. }
  348. if ($org ne "A5") {
  349. # extract db_0
  350. $d1 = substr($d1, 0, 2);
  351. }
  352. if ($blockSenderID eq "own" && ((hex($id) >= $baseID && hex($id) <= $lastID) || $chipID == hex($id))) {
  353. Log3 $name, 4, "TCM $name own telegram from $id blocked.";
  354. } else {
  355. Dispatch($hash, "EnOcean:$packetType:$org:$d1:$id:$status:01FFFFFFFF0000", undef);
  356. }
  357. } else {
  358. # Receive Message Telegram (RMT)
  359. my $msg = TCM_Parse120($hash, $net, 1);
  360. if (($msg eq 'OK') && ($net =~ m/^8B(..)(........)(........)(..)/)){
  361. my ($org, $d1,$id,$status) = ($1, $2, $3, $4);
  362. my $packetType = 1;
  363. # Re-translate the ORG to RadioORG / TCM310 equivalent
  364. my %orgmap = ("05" => "F6", "06" => "D5", "07" => "A5");
  365. if($orgmap{$org}) {
  366. $org = $orgmap{$org};
  367. } else {
  368. Log3 $name, 2, "TCM $name unknown ORG mapping for $org";
  369. }
  370. if ($org ne "A5") {
  371. # extract db_0
  372. $d1 = substr($d1, 0, 2);
  373. }
  374. if ($blockSenderID eq "own" && ((hex($id) >= $baseID && hex($id) <= $lastID) || $chipID == hex($id))) {
  375. Log3 $name, 4, "TCM $name own telegram from $id blocked.";
  376. } else {
  377. Dispatch($hash, "EnOcean:$packetType:$org:$d1:$id:$status:01FFFFFFFF0000", undef);
  378. }
  379. }
  380. }
  381. $data = $rest;
  382. }
  383. if(length($data) >= 4) {
  384. $data =~ s/.*A55A/A55A/ if($data !~ m/^A55A/);
  385. $data = "" if($data !~ m/^A55A/);
  386. }
  387. } else {
  388. # TCM310 / ESP3
  389. while($data =~ m/^55(....)(..)(..)(..)/) {
  390. my ($ldata, $lodata, $packetType, $crc) = (hex($1), hex($2), hex($3), $4);
  391. my $tlen = 2*(7+$ldata+$lodata);
  392. # data telegram incomplete
  393. last if(length($data) < $tlen);
  394. my $rest = substr($data, $tlen);
  395. $data = substr($data, 0, $tlen);
  396. my $hdr = substr($data, 2, 8);
  397. my $mdata = substr($data, 12, $ldata * 2);
  398. my $odata = substr($data, 12 + $ldata * 2, $lodata * 2);
  399. my $mycrc = TCM_CRC8($hdr);
  400. if($mycrc ne $crc) {
  401. Log3 $name, 2, "TCM $name wrong header checksum: got $crc, computed $mycrc" ;
  402. $data = $rest;
  403. next;
  404. }
  405. $mycrc = TCM_CRC8($mdata . $odata);
  406. $crc = substr($data, -2);
  407. if($mycrc ne $crc) {
  408. Log3 $name, 2, "TCM $name wrong data checksum: got $crc, computed $mycrc" ;
  409. $data = $rest;
  410. next;
  411. }
  412. if ($packetType == 1) {
  413. # packet type RADIO
  414. $mdata =~ m/^(..)(.*)(........)(..)$/;
  415. my ($org, $d1, $id, $status) = ($1,$2,$3,$4);
  416. my $repeatingCounter = hex substr($status, 1, 1);
  417. $odata =~ m/^(..)(........)(..)(..)$/;
  418. my ($RSSI, $receivingQuality) = (hex($3), "excellent");
  419. if ($RSSI > 87) {
  420. $receivingQuality = "bad";
  421. } elsif ($RSSI > 75) {
  422. $receivingQuality = "good";
  423. }
  424. my %addvals = (
  425. PacketType => $packetType,
  426. SubTelNum => hex($1),
  427. DestinationID => $2,
  428. RSSI => -$RSSI,
  429. ReceivingQuality => $receivingQuality,
  430. RepeatingCounter => $repeatingCounter,
  431. );
  432. $hash->{RSSI} = -$RSSI;
  433. if ($blockSenderID eq "own" && ((hex($id) >= $baseID && hex($id) <= $lastID) || $chipID == hex($id))) {
  434. Log3 $name, 4, "TCM $name own telegram from $id blocked.";
  435. } else {
  436. #EnOcean:PacketType:RORG:MessageData:SourceID:Status:OptionalData
  437. Dispatch($hash, "EnOcean:$packetType:$org:$d1:$id:$status:$odata", \%addvals);
  438. }
  439. } elsif ($packetType == 2) {
  440. # packet type RESPONSE
  441. if (defined $hash->{helper}{awaitCmdResp}[0] && $hash->{helper}{awaitCmdResp}[0]) {
  442. # do not execute if transceiver command answer is expected
  443. $data .= $rest;
  444. last;
  445. }
  446. shift(@{$hash->{helper}{awaitCmdResp}});
  447. $mdata =~ m/^(..)(.*)$/;
  448. my $rc = $1;
  449. my %codes = (
  450. "00" => "OK",
  451. "01" => "ERROR",
  452. "02" => "NOT_SUPPORTED",
  453. "03" => "WRONG_PARAM",
  454. "04" => "OPERATION_DENIED",
  455. "05" => "LOCK_SET",
  456. "82" => "FLASH_HW_ERROR",
  457. "90" => "BASEID_OUT_OF_RANGE",
  458. "91" => "BASEID_MAX_REACHED",
  459. );
  460. my $rcTxt = $codes{$rc} if($codes{$rc});
  461. Log3 $name, $rc eq "00" ? 5 : 2, "TCM $name RESPONSE: $rcTxt";
  462. #$packetType = sprintf "%01X", $packetType;
  463. #EnOcean:PacketType:ResposeCode:MessageData:OptionalData
  464. #Dispatch($hash, "EnOcean:$packetType:$1:$2:$odata", undef);
  465. } elsif ($packetType == 3) {
  466. # packet type RADIO_SUB_TEL
  467. Log3 $name, 2, "TCM $name packet type RADIO_SUB_TEL not supported: $data";
  468. } elsif ($packetType == 4) {
  469. # packet type EVENT
  470. $mdata =~ m/^(..)(.*)$/;
  471. $packetType = sprintf "%01X", $packetType;
  472. #EnOcean:PacketType:eventCode:MessageData
  473. Dispatch($hash, "EnOcean:$packetType:$1:$2", undef);
  474. } elsif ($packetType == 5) {
  475. # packet type COMMON_COMMAND
  476. Log3 $name, 2, "TCM $name packet type COMMON_COMMAND not supported: $data";
  477. } elsif ($packetType == 6) {
  478. # packet type SMART_ACK_COMMAND
  479. $mdata =~ m/^(..)(.*)$/;
  480. $packetType = sprintf "%01X", $packetType;
  481. #EnOcean:PacketType:smartAckCode:MessageData
  482. Dispatch($hash, "EnOcean:$packetType:$1:$2", undef);
  483. } elsif ($packetType == 7) {
  484. # packet type REMOTE_MAN_COMMAND
  485. $mdata =~ m/^(....)(....)(.*)$/;
  486. my ($function, $manufID, $messageData) = ($1, $2, $3);
  487. $odata =~ m/^(........)(........)(..)(..)$/;
  488. my ($RSSI, $receivingQuality) = ($3, "excellent");
  489. if (hex($RSSI) > 87) {
  490. $receivingQuality = "bad";
  491. } elsif (hex($RSSI) > 75) {
  492. $receivingQuality = "good";
  493. }
  494. my %addvals = (
  495. PacketType => $packetType,
  496. DestinationID => $1,
  497. RSSI => -hex($RSSI),
  498. ReceivingQuality => $receivingQuality,
  499. );
  500. $hash->{RSSI} = -hex($RSSI);
  501. $packetType = sprintf "%01X", $packetType;
  502. if ($blockSenderID eq "own" && ((hex($2) >= $baseID && hex($2) <= $lastID) || $chipID == hex($2))) {
  503. Log3 $name, 4, "TCM $name own telegram from $2 blocked.";
  504. } else {
  505. #EnOcean:PacketType:RORG:MessageData:SourceID:DestinationID:FunctionNumber:ManufacturerID:RSSI:Delay
  506. Dispatch($hash, "EnOcean:$packetType:C5:$messageData:$2:$1:$function:$manufID:$RSSI:$4", \%addvals);
  507. }
  508. } elsif ($packetType == 9) {
  509. # packet type RADIO_MESSAGE
  510. Log3 $name, 2, "TCM: $name packet type RADIO_MESSAGE not supported: $data";
  511. } elsif ($packetType == 10) {
  512. # packet type RADIO_ADVANCED
  513. Log3 $name, 2, "TCM $name packet type RADIO_ADVANCED not supported: $data";
  514. } else {
  515. Log3 $name, 2, "TCM $name unknown packet type $packetType: $data";
  516. }
  517. $data = $rest;
  518. }
  519. if(length($data) >= 4) {
  520. $data =~ s/.*55/55/ if($data !~ m/^55/);
  521. $data = "" if($data !~ m/^55/);
  522. }
  523. }
  524. $hash->{PARTIAL} = $data;
  525. }
  526. # Parse Table TCM 120
  527. my %parsetbl120 = (
  528. "8B05" => { msg=>"OK" },
  529. "8B06" => { msg=>"OK" },
  530. "8B07" => { msg=>"OK" },
  531. "8B08" => { msg=>"ERR_SYNTAX_H_SEQ" },
  532. "8B09" => { msg=>"ERR_SYNTAX_LENGTH" },
  533. "8B0A" => { msg=>"ERR_SYNTAX_CHKSUM" },
  534. "8B0B" => { msg=>"ERR_SYNTAX_ORG" },
  535. "8B0C" => { msg=>"ERR_MODEM_DUP_ID" },
  536. "8B19" => { msg=>"ERR" },
  537. "8B1A" => { msg=>"ERR_IDRANGE" },
  538. "8B22" => { msg=>"ERR_TX_IDRANGE" },
  539. "8B28" => { msg=>"ERR_MODEM_NOTWANTEDACK" },
  540. "8B29" => { msg=>"ERR_MODEM_NOTACK" },
  541. "8B58" => { msg=>"OK" },
  542. "8B8C" => { msg=>"INF_SW_VER", expr=>'"$a[2].$a[3].$a[4].$a[5]"' },
  543. "8B88" => { msg=>"INF_RX_SENSIVITY", expr=>'$a[2] ? "High (01)":"Low (00)"' },
  544. "8B89" => { msg=>"INFO", expr=>'substr($rawstr,2,9)' },
  545. "8B98" => { msg=>"INF_IDBASE",
  546. expr=>'sprintf("%02x%02x%02x%02x", $a[2], $a[3], $a[4], $a[5])' },
  547. "8BA8" => { msg=>"INF_MODEM_STATUS",
  548. expr=>'sprintf("%s, ID:%02x%02x", $a[2]?"on":"off", $a[3], $a[4])' },
  549. );
  550. # Parse TCM 120
  551. sub
  552. TCM_Parse120($$$)
  553. {
  554. my ($hash,$rawmsg,$ret) = @_;
  555. my $name = $hash->{NAME};
  556. Log3 $name, 5, "TCM $name Parse $rawmsg";
  557. my $msg = "";
  558. my $cmd = $parsetbl120{substr($rawmsg, 0, 4)};
  559. if(!$cmd) {
  560. $msg ="Unknown command: $rawmsg";
  561. } else {
  562. if($cmd->{expr}) {
  563. $msg = $cmd->{msg}." " if(!$ret);
  564. my $rawstr = pack('H*', $rawmsg);
  565. $rawstr =~ s/[\r\n]//g;
  566. my @a = map { ord($_) } split("", $rawstr);
  567. $msg .= eval $cmd->{expr};
  568. } else {
  569. return "" if($cmd ->{msg} eq "OK" && !$ret); # SKIP Ok
  570. $msg = $cmd->{msg};
  571. }
  572. }
  573. Log3 $name, 2, "TCM $name RESPONSE: $msg" if(!$ret);
  574. return $msg;
  575. }
  576. # Parse Table TCM 310
  577. my %rc310 = (
  578. "00" => "OK",
  579. "01" => "ERROR",
  580. "02" => "NOT_SUPPORTED",
  581. "03" => "WRONG_PARAM",
  582. "04" => "OPERATION_DENIED",
  583. "05" => "LOCK_SET",
  584. "82" => "FLASH_HW_ERROR",
  585. "90" => "BASEID_OUT_OF_RANGE",
  586. "91" => "BASEID_MAX_REACHED",
  587. );
  588. # Parse TCM 310
  589. sub
  590. TCM_Parse310($$$)
  591. {
  592. my ($hash,$rawmsg,$ptr) = @_;
  593. my $name = $hash->{NAME};
  594. Log3 $name, 5, "TCM_Parse $rawmsg";
  595. my $rc = substr($rawmsg, 0, 2);
  596. my $msg = "";
  597. if($rc ne "00") {
  598. $msg = $rc310{$rc};
  599. $msg = "Unknown return code $rc" if(!$msg);
  600. } else {
  601. my @ans;
  602. foreach my $k (sort keys %{$ptr}) {
  603. next if($k eq "cmd" || $k eq "arg" || $k eq "packetType");
  604. my ($off, $len, $type) = split(",", $ptr->{$k});
  605. my $data;
  606. if ($len == 0) {
  607. $data = substr($rawmsg, $off*2);
  608. } else {
  609. $data = substr($rawmsg, $off*2, $len*2);
  610. }
  611. if($type) {
  612. if ($type eq "STR") {
  613. $data = pack('H*', $data);
  614. ####
  615. # remove trailing 0x00
  616. #$data =~ s/[^A-Za-z0-9#\.\-_]//g;
  617. $data =~ tr/A-Za-z0-9#.-_//cd;
  618. } else {
  619. my $dataLen = length($data);
  620. my $dataOut = '';
  621. my ($part1, $part2, $part3) = split(":", $type);
  622. $part1 *= 2;
  623. $part2 *= 2;
  624. if (defined $part3) {
  625. $part3 *= 2;
  626. while ($dataLen > 0) {
  627. $data =~ m/^(.{$part1})(.{$part2})(.{$part3})(.*)$/;
  628. $dataOut .= $1 . ':' . $2 . ':' . $3 . ' ';
  629. $data = $4;
  630. $dataLen -= $part1 + $part2 + $part3;
  631. }
  632. } else {
  633. while ($dataLen > 0) {
  634. $data =~ m/^(.{$part1})(.{$part2})(.*)$/;
  635. $dataOut .= $1 . ':' . $2 . ' ';
  636. $data = $3;
  637. $dataLen -= $part1 + $part2;
  638. }
  639. }
  640. chop($dataOut);
  641. $data = $dataOut;
  642. }
  643. }
  644. push @ans, "$k: $data";
  645. }
  646. $msg = join(" ", @ans);
  647. }
  648. if ($msg eq "") {
  649. Log3 $name, 2, "TCM $name RESPONSE: OK";
  650. } else {
  651. Log3 $name, 2, "TCM $name RESPONSE: $msg";
  652. }
  653. return $msg;
  654. }
  655. # Ready
  656. sub
  657. TCM_Ready($)
  658. {
  659. my ($hash) = @_;
  660. return DevIo_OpenDev($hash, 1, undef)
  661. # if($hash->{STATE} ne "opened");
  662. if($hash->{STATE} eq "disconnected");
  663. # This is relevant for windows/USB only
  664. my $po = $hash->{USBDev};
  665. return undef if(!$po);
  666. my ($BlockingFlags, $InBytes, $OutBytes, $ErrorFlags) = $po->status;
  667. return ($InBytes>0);
  668. }
  669. # Get commands TCM 120
  670. my %gets120 = (
  671. "sensitivity" => "AB48",
  672. "baseID" => "AB58",
  673. "modem_status" => "AB68",
  674. "version" => "AB4B",
  675. );
  676. # Get commands TCM 310
  677. my %gets310 = (
  678. "baseID" => {packetType => 5, cmd => "08", BaseID => "1,4", RemainingWriteCycles => "5,1"},
  679. "filter" => {packetType => 5, cmd => "0F", "Type:Value" => "1,0,1:4"},
  680. "numSecureDevicesIn" => {packetType => 5, cmd => "1D00", Number => "1,1"},
  681. "numSecureDevicesOut" => {packetType => 5, cmd => "1D01", Number => "1,1"},
  682. "repeater" => {packetType => 5, cmd => "0A", RepEnable => "1,1", RepLevel => "2,1"},
  683. "frequencyInfo" => {packetType => 5, cmd => "25", Frequency => "1,1", Protocol => "2,1"},
  684. "stepCode" => {packetType => 5, cmd => "27", HWRevision => "1,1", Stepcode => "2,1"},
  685. "smartAckLearnMode" => {packetType => 6, cmd => "02", Enable => "1,1", Extended => "2,1"},
  686. "smartAckLearnedClients" => {packetType => 6, cmd => "06", "ClientID:CtrlID:Mailbox" => "1,0,4:4:1"},
  687. "version" => {packetType => 5, cmd => "03", APPVersion => "1,4", APIVersion => "5,4", ChipID => "9,4", ChipVersion => "13,4", Desc => "17,16,STR"},
  688. );
  689. # Get
  690. sub
  691. TCM_Get($@)
  692. {
  693. my ($hash, @a) = @_;
  694. my $name = $hash->{NAME};
  695. return if (AttrVal($name, "comType", "TCM") eq "RS485" || $hash->{DeviceName} eq "none");
  696. return "\"get $name\" needs one parameter" if(@a != 2);
  697. my $cmd = $a[1];
  698. my ($err, $msg, $packetType);
  699. if($hash->{MODEL} eq "ESP2") {
  700. # TCM 120
  701. my $rawcmd = $gets120{$cmd};
  702. return "Unknown argument $cmd, choose one of " . join(':noArg ', sort keys %gets120) . ':noArg' if(!defined($rawcmd));
  703. Log3 $name, 3, "TCM get $name $cmd";
  704. $rawcmd .= "000000000000000000";
  705. TCM_Write($hash, "", $rawcmd);
  706. ($err, $msg) = TCM_ReadAnswer($hash, "get $cmd");
  707. $msg = TCM_Parse120($hash, $msg, 1) if(!$err);
  708. } else {
  709. # TCM 310
  710. my $cmdhash = $gets310{$cmd};
  711. return "Unknown argument $cmd, choose one of " . join(':noArg ', sort keys %gets310) . ':noArg' if(!defined($cmdhash));
  712. Log3 $name, 3, "TCM get $name $cmd";
  713. my $cmdHex = $cmdhash->{cmd};
  714. $hash->{helper}{SetAwaitCmdResp} = 1;
  715. TCM_Write($hash, sprintf("%04X00%02X", length($cmdHex)/2, $cmdhash->{packetType}), $cmdHex);
  716. ($err, $msg) = TCM_ReadAnswer($hash, "get $cmd");
  717. $msg = TCM_Parse310($hash, $msg, $cmdhash) if(!$err);
  718. }
  719. if($err) {
  720. Log3 undef, 2, "TCM $name $err";
  721. return $err;
  722. }
  723. readingsSingleUpdate($hash, $cmd, $msg, 1);
  724. return $msg;
  725. }
  726. # clear teach in flag
  727. sub TCM_ClearTeach($)
  728. {
  729. my $hash = shift;
  730. delete($hash->{Teach});
  731. }
  732. # clear Smart ACK teach in flag
  733. sub TCM_ClearSmartAckLearn($)
  734. {
  735. my $hash = shift;
  736. delete($hash->{SmartAckLearn});
  737. readingsSingleUpdate($hash, "smartAckLearnMode", "Enable: 00 Extended: 00", 1);
  738. }
  739. # Set commands TCM 120
  740. my %sets120 = ( # Name, Data to send to the CUL, Regexp for the answer
  741. "teach" => {cmd => "AB18", arg => "\\d+"},
  742. "baseID" => {cmd => "AB18", arg => "FF[8-9A-F][0-9A-F]{5}"},
  743. "sensitivity" => {cmd => "AB08", arg => "0[01]"},
  744. "sleep" => {cmd => "AB09"},
  745. "wake" => {cmd => ""}, # Special
  746. "reset" => {cmd => "AB0A"},
  747. "modem_on" => {cmd => "AB28", arg => "[0-9A-F]{4}"},
  748. "modem_off" => {cmd => "AB2A"},
  749. );
  750. # Set commands TCM 310
  751. my %sets310 = (
  752. "init" => {},
  753. "teach" => {packetType => 5, arg=> "\\d+"},
  754. "sleep" => {packetType => 5, cmd => "01", arg => "00[0-9A-F]{6}"},
  755. "reset" => {packetType => 5, cmd => "02"},
  756. "bist" => {packetType => 5, cmd => "06", BIST_Result => "1,1"},
  757. "baseID" => {packetType => 5, cmd => "07", arg => "FF[8-9A-F][0-9A-F]{5}"},
  758. "repeater" => {packetType => 5, cmd => "09", arg => "0[0-1]0[0-2]"},
  759. "filterAdd" => {packetType => 5, cmd => "0B", arg => "0[0-3][0-9A-F]{8}[048C]0"},
  760. "filterDel" => {packetType => 5, cmd => "0C", arg => "0[0-3][0-9A-F]{8}"},
  761. "filterDelAll" => {packetType => 5, cmd => "0D"},
  762. "filterEnable" => {packetType => 5, cmd => "0E", arg => "0[01]0[0189]"},
  763. "maturity" => {packetType => 5, cmd => "10", arg => "0[0-1]"},
  764. "subtel" => {packetType => 5, cmd => "11", arg => "0[0-1]"},
  765. "mode" => {packetType => 5, cmd => "1C", arg => "0[0-1]"},
  766. "baudrate" => {packetType => 5, cmd => "24", arg => "0[0-3]"},
  767. "smartAckLearn" => {packetType => 6, cmd => "01", arg => "\\d+"},
  768. "smartAckMailboxMax" => {packetType => 6, cmd => "08", arg => "\\d+"},
  769. );
  770. # Set
  771. sub TCM_Set($@)
  772. {
  773. my ($hash, @a) = @_;
  774. my $name = $hash->{NAME};
  775. return if (AttrVal($name, "comType", "TCM") eq "RS485" || $hash->{DeviceName} eq "none");
  776. return "\"set $name\" needs at least one parameter" if(@a < 2);
  777. my $cmd = $a[1];
  778. my $arg = $a[2];
  779. my ($err, $msg);
  780. my $chash = ($hash->{MODEL} eq "ESP2" ? \%sets120 : \%sets310);
  781. my $cmdhash = $chash->{$cmd};
  782. return "Unknown argument $cmd, choose one of ".join(" ",sort keys %{$chash})
  783. if(!defined($cmdhash));
  784. my $cmdHex = $cmdhash->{cmd};
  785. my $argre = $cmdhash->{arg};
  786. my $logArg = defined($arg) ? $arg : '';
  787. if($argre) {
  788. return "Argument needed for set $name $cmd ($argre)" if (!defined($arg));
  789. return "Argument does not match the regexp ($argre)" if ($arg !~ m/$argre/i);
  790. if ($cmd eq "smartAckLearn") {
  791. if (($arg + 0) >= 0 && ($arg + 0) <= 4294967) {
  792. if ($arg == 0) {
  793. $arg = '0' x 12;
  794. readingsSingleUpdate($hash, "smartAckLearnMode", "Enable: 00 Extended: 00", 1);
  795. } else {
  796. my $smartAckLearnMode = AttrVal($name, "smartAckLearnMode", "simple");
  797. my %smartAckLearnMode = (simple => 0, advance => 1, advanceSelectRep => 2);
  798. $arg = sprintf "01%02X%08X", $smartAckLearnMode{$smartAckLearnMode}, $arg * 1000;
  799. readingsSingleUpdate($hash, "smartAckLearnMode", "Enable: 01 Extended: " . sprintf("%02X", $smartAckLearnMode{$smartAckLearnMode}), 1);
  800. }
  801. } else {
  802. return "Argument wrong, choose 0...4294967";
  803. }
  804. } elsif ($cmd eq "smartAckMailboxMax") {
  805. if (($arg + 0) >= 0 && ($arg + 0) <= 20) {
  806. $attr{$name}{smartAckMailboxMax} = $arg;
  807. $arg = sprintf "%02X", $arg;
  808. } else {
  809. return "Argument wrong, choose 0...20";
  810. }
  811. }
  812. $cmdHex .= $arg;
  813. }
  814. Log3 $name, 3, "TCM set $name $cmd $logArg";
  815. if($cmd eq "teach") {
  816. if ($arg == 0) {
  817. RemoveInternalTimer($hash, "TCM_ClearTeach");
  818. delete $hash->{Teach};
  819. return;
  820. } else {
  821. RemoveInternalTimer($hash, "TCM_ClearTeach");
  822. InternalTimer(gettimeofday() + $arg, "TCM_ClearTeach", $hash, 1);
  823. $hash->{Teach} = 1;
  824. return;
  825. }
  826. }
  827. if($hash->{MODEL} eq "ESP2") {
  828. # TCM 120
  829. if($cmdHex eq "") { # wake is very special
  830. DevIo_SimpleWrite($hash, "AA", 1);
  831. return "";
  832. }
  833. $cmdHex .= "0"x(22-length($cmdHex)); # Padding with 0
  834. TCM_Write($hash, "", $cmdHex);
  835. ($err, $msg) = TCM_ReadAnswer($hash, "get $cmd");
  836. $msg = TCM_Parse120($hash, $msg, 1) if(!$err);
  837. } else {
  838. # TCM310
  839. if($cmd eq "init") {
  840. TCM_InitSerialCom($hash);
  841. return;
  842. }
  843. $hash->{helper}{SetAwaitCmdResp} = 1;
  844. TCM_Write($hash, sprintf("%04X00%02X", length($cmdHex)/2, $cmdhash->{packetType}), $cmdHex);
  845. ($err, $msg) = TCM_ReadAnswer($hash, "set $cmd");
  846. if(!$err) {
  847. $msg = TCM_Parse310($hash, $msg, $cmdhash);
  848. if ($cmd eq "smartAckLearn") {
  849. if (substr($arg, 0, 2) eq '00') {
  850. # end Smart ACK learnmode
  851. RemoveInternalTimer($hash, "TCM_ClearSmartAckLearn");
  852. delete $hash->{SmartAckLearn};
  853. } else {
  854. RemoveInternalTimer($hash, "TCM_ClearSmartAckLearn");
  855. InternalTimer(gettimeofday() + hex(substr($arg, 4, 8)) * 0.001, "TCM_ClearSmartAckLearn", $hash, 1);
  856. $hash->{SmartAckLearn} = 1;
  857. }
  858. }
  859. }
  860. }
  861. if($err) {
  862. Log3 undef, 2, "TCM $name $err";
  863. return $err;
  864. }
  865. my @setCmdReadingsUpdate = ("repeater", "maturity", "mode");
  866. foreach(@setCmdReadingsUpdate) {
  867. if ($_ eq $cmd && $msg eq "") {
  868. if ($_ eq "repeater") {
  869. $arg = "RepEnable: " . substr($arg, 0, 2) . " RepLevel: " . substr($arg, 2, 2);
  870. }
  871. readingsSingleUpdate($hash, $cmd, $arg, 1);
  872. }
  873. }
  874. return $msg;
  875. }
  876. # read command response data
  877. sub TCM_ReadAnswer($$)
  878. {
  879. my ($hash, $arg) = @_;
  880. return ("No FD", undef) if(!$hash || ($^O !~ /Win/ && !defined($hash->{FD})));
  881. my $name = $hash->{NAME};
  882. my $blockSenderID = AttrVal($name, "blockSenderID", "own");
  883. my $chipID = exists($hash->{ChipID}) ? hex $hash->{ChipID} : 0;
  884. my $baseID = exists($hash->{BaseID}) ? hex $hash->{BaseID} : 0;
  885. my $lastID = exists($hash->{LastID}) ? hex $hash->{LastID} : 0;
  886. my ($data, $rin, $buf) = ($hash->{PARTIAL}, "", "");
  887. # 2 seconds timeout
  888. my $to = 2;
  889. for (;;) {
  890. if ($^O =~ m/Win/ && $hash->{USBDev}) {
  891. $hash->{USBDev}->read_const_time($to*1000); # set timeout (ms)
  892. # Read anstatt input sonst funzt read_const_time nicht.
  893. $buf = $hash->{USBDev}->read(999);
  894. if (length($buf) == 0) {
  895. if (length($data) == 0) {
  896. shift(@{$hash->{helper}{awaitCmdResp}});
  897. return ("Timeout reading answer for $arg", undef);
  898. }
  899. } else {
  900. $data .= uc(unpack('H*', $buf));
  901. }
  902. } else {
  903. if (!$hash->{FD}) {
  904. shift(@{$hash->{helper}{awaitCmdResp}});
  905. return ("Device lost when reading answer for $arg", undef);
  906. }
  907. vec($rin, $hash->{FD}, 1) = 1;
  908. my $nfound = select($rin, undef, undef, $to);
  909. if ($nfound < 0) {
  910. next if ($! == EAGAIN() || $! == EINTR() || $! == 0);
  911. my $err = $!;
  912. DevIo_Disconnected($hash);
  913. shift(@{$hash->{helper}{awaitCmdResp}});
  914. return("Device error: $err", undef);
  915. } elsif ($nfound == 0) {
  916. if (length($data) == 0) {
  917. shift(@{$hash->{helper}{awaitCmdResp}});
  918. return ("Timeout reading response for $arg", undef);
  919. }
  920. } else {
  921. $buf = DevIo_SimpleRead($hash);
  922. if(!defined($buf)) {
  923. shift(@{$hash->{helper}{awaitCmdResp}});
  924. return ("No response data for $arg", undef);
  925. }
  926. $data .= uc(unpack('H*', $buf));
  927. }
  928. }
  929. if (length($data) > 4) {
  930. Log3 $name, 5, "TCM $name received ESP: $data";
  931. if ($hash->{MODEL} eq "ESP2") {
  932. # TCM 120
  933. if (length($data) >= 28) {
  934. if ($data !~ m/^A55A(.B.{20})(..)/) {
  935. $hash->{PARTIAL} = '';
  936. return ("$arg: Bogus answer received: $data", undef);
  937. }
  938. my ($net, $crc) = ($1, $2);
  939. my $mycrc = TCM_CSUM($net);
  940. $hash->{PARTIAL} = substr($data, 28);
  941. if ($crc ne $mycrc) {
  942. return ("wrong checksum: got $crc, computed $mycrc", undef);
  943. }
  944. return (undef, $net);
  945. }
  946. } else {
  947. # TCM 310
  948. if($data !~ m/^55/) {
  949. $data =~ s/.*55/55/;
  950. if ($data !~ m/^55/) {
  951. #$data = '';
  952. $hash->{PARTIAL} = '';
  953. shift(@{$hash->{helper}{awaitCmdResp}});
  954. return ("$arg: Bogus answer received: $data", undef);
  955. }
  956. $hash->{PARTIAL} = $data;
  957. }
  958. next if ($data !~ m/^55(....)(..)(..)(..)/);
  959. my ($ldata, $lodata, $packetType, $crc) = (hex($1), hex($2), hex($3), $4);
  960. my $tlen = 2 * (7 + $ldata + $lodata);
  961. # data telegram incomplete
  962. next if (length($data) < $tlen);
  963. my $rest = substr($data, $tlen);
  964. $data = substr($data, 0, $tlen);
  965. my $hdr = substr($data, 2, 8);
  966. my $mdata = substr($data, 12, $ldata * 2);
  967. my $odata = substr($data, 12 + $ldata * 2, $lodata * 2);
  968. my $mycrc = TCM_CRC8($hdr);
  969. if ($crc ne $mycrc) {
  970. $hash->{PARTIAL} = $rest;
  971. shift(@{$hash->{helper}{awaitCmdResp}});
  972. return ("wrong header checksum: got $crc, computed $mycrc", undef);
  973. }
  974. $mycrc = TCM_CRC8($mdata . $odata);
  975. $crc = substr($data, -2);
  976. if ($crc ne $mycrc) {
  977. $hash->{PARTIAL} = $rest;
  978. shift(@{$hash->{helper}{awaitCmdResp}});
  979. return ("wrong data checksum: got $crc, computed $mycrc", undef);
  980. }
  981. if ($packetType == 1) {
  982. # packet type RADIO
  983. $mdata =~ m/^(..)(.*)(........)(..)$/;
  984. my ($org, $d1, $id, $status) = ($1, $2, $3, $4);
  985. my $repeatingCounter = hex substr($status, 1, 1);
  986. $odata =~ m/^(..)(........)(..)(..)$/;
  987. my ($RSSI, $receivingQuality) = (hex($3), "excellent");
  988. if ($RSSI > 87) {
  989. $receivingQuality = "bad";
  990. } elsif ($RSSI > 75) {
  991. $receivingQuality = "good";
  992. }
  993. my %addvals = (
  994. PacketType => $packetType,
  995. SubTelNum => hex($1),
  996. DestinationID => $2,
  997. RSSI => -$RSSI,
  998. ReceivingQuality => $receivingQuality,
  999. RepeatingCounter => $repeatingCounter,
  1000. );
  1001. $hash->{RSSI} = -$RSSI;
  1002. if ($blockSenderID eq "own" && ((hex($id) >= $baseID && hex($id) <= $lastID) || $chipID == hex($id))) {
  1003. Log3 $name, 4, "TCM $name own telegram from $id blocked.";
  1004. } else {
  1005. #EnOcean:PacketType:RORG:MessageData:SourceID:Status:OptionalData
  1006. Dispatch($hash, "EnOcean:$packetType:$org:$d1:$id:$status:$odata", \%addvals);
  1007. }
  1008. $data = $rest;
  1009. $hash->{PARTIAL} = $rest;
  1010. next;
  1011. } elsif($packetType == 2) {
  1012. # packet type RESPONSE
  1013. $hash->{PARTIAL} = $rest;
  1014. if (defined $hash->{helper}{awaitCmdResp}[0] && $hash->{helper}{awaitCmdResp}[0]) {
  1015. shift(@{$hash->{helper}{awaitCmdResp}});
  1016. return (undef, $mdata . $odata);
  1017. } else {
  1018. shift(@{$hash->{helper}{awaitCmdResp}});
  1019. $mdata =~ m/^(..)(.*)$/;
  1020. my $rc = $1;
  1021. my %codes = (
  1022. "00" => "OK",
  1023. "01" => "ERROR",
  1024. "02" => "NOT_SUPPORTED",
  1025. "03" => "WRONG_PARAM",
  1026. "04" => "OPERATION_DENIED",
  1027. "05" => "LOCK_SET",
  1028. "82" => "FLASH_HW_ERROR",
  1029. "90" => "BASEID_OUT_OF_RANGE",
  1030. "91" => "BASEID_MAX_REACHED",
  1031. );
  1032. my $rcTxt = $codes{$rc} if($codes{$rc});
  1033. Log3 $name, $rc eq "00" ? 5 : 2, "TCM $name RESPONSE: $rcTxt";
  1034. #$packetType = sprintf "%01X", $packetType;
  1035. #EnOcean:PacketType:ResposeCode:MessageData:OptionalData
  1036. #Dispatch($hash, "EnOcean:$packetType:$1:$2:$odata", undef);
  1037. $data = $rest;
  1038. next;
  1039. }
  1040. } else {
  1041. return ("Evaluation of the command $arg aborted because the received data telegram is not supported.", undef)
  1042. }
  1043. }
  1044. }
  1045. }
  1046. }
  1047. #
  1048. sub TCM_Attr(@) {
  1049. my ($cmd, $name, $attrName, $attrVal) = @_;
  1050. my $hash = $defs{$name};
  1051. # return if attribute list is incomplete
  1052. return undef if (!$init_done);
  1053. if ($attrName eq "blockSenderID") {
  1054. if (!defined $attrVal) {
  1055. } elsif ($attrVal !~ m/^own|no$/) {
  1056. Log3 $name, 2, "EnOcean $name attribute-value [$attrName] = $attrVal wrong";
  1057. CommandDeleteAttr(undef, "$name $attrName");
  1058. }
  1059. } elsif ($attrName eq "baseID") {
  1060. if (!defined $attrVal){
  1061. } elsif ($attrVal !~ m/^[Ff]{2}[\dA-Fa-f]{6}$/) {
  1062. Log3 $name, 2, "EnOcean $name attribute-value [$attrName] = $attrVal wrong";
  1063. CommandDeleteAttr(undef, "$name $attrName");
  1064. } else {
  1065. $hash->{BaseID} = $attrVal;
  1066. $hash->{LastID} = sprintf "%08X", (hex $attrVal) + 127;
  1067. }
  1068. } elsif ($attrName eq "comModeUTE") {
  1069. if (!defined $attrVal){
  1070. } elsif ($attrVal !~ m/^auto|biDir|uniDir$/) {
  1071. Log3 $name, 2, "EnOcean $name attribute-value [$attrName] = $attrVal wrong";
  1072. CommandDeleteAttr(undef, "$name $attrName");
  1073. }
  1074. } elsif ($attrName eq "comType") {
  1075. if (!defined $attrVal){
  1076. } elsif ($attrVal !~ m/^TCM|RS485$/) {
  1077. Log3 $name, 2, "EnOcean $name attribute-value [$attrName] = $attrVal wrong";
  1078. CommandDeleteAttr(undef, "$name $attrName");
  1079. }
  1080. } elsif ($attrName eq "learningMode") {
  1081. if (!defined $attrVal){
  1082. } elsif ($attrVal !~ m/^always|demand|nearfield$/) {
  1083. Log3 $name, 2, "EnOcean $name attribute-value [$attrName] = $attrVal wrong";
  1084. CommandDeleteAttr(undef, "$name $attrName");
  1085. }
  1086. } elsif ($attrName eq "sendInterval") {
  1087. if (!defined $attrVal){
  1088. } elsif (($attrVal + 0) < 0 || ($attrVal + 0) > 250) {
  1089. Log3 $name, 2, "EnOcean $name attribute-value [$attrName] = $attrVal wrong or out of range";
  1090. CommandDeleteAttr(undef, "$name $attrName");
  1091. }
  1092. } elsif ($attrName eq "smartAckLearnMode") {
  1093. if (!defined $attrVal){
  1094. } elsif ($attrVal !~ m/^simple|advance|advanceSelectRep$/) {
  1095. Log3 $name, 2, "EnOcean $name attribute-value [$attrName] = $attrVal wrong";
  1096. CommandDeleteAttr(undef, "$name $attrName");
  1097. }
  1098. } elsif ($attrName eq "smartAckMailboxMax") {
  1099. if (!defined $attrVal){
  1100. } elsif (($attrVal + 0) >= 0 && ($attrVal + 0) <= 20) {
  1101. TCM_Set($hash, ("set", "smartAckMailboxMax", $attrVal));
  1102. } else {
  1103. Log3 $name, 2, "EnOcean $name attribute-value [$attrName] = $attrVal wrong or out of range";
  1104. CommandDeleteAttr(undef, "$name $attrName");
  1105. }
  1106. }
  1107. return undef;
  1108. }
  1109. #
  1110. sub TCM_Notify(@) {
  1111. my ($hash, $dev) = @_;
  1112. if ($dev->{NAME} eq "global" && grep (m/^INITIALIZED|REREADCFG$/, @{$dev->{CHANGED}})){
  1113. TCM_InitSerialCom($hash);
  1114. }
  1115. return undef;
  1116. }
  1117. # Undef
  1118. sub
  1119. TCM_Undef($$)
  1120. {
  1121. my ($hash, $arg) = @_;
  1122. my $name = $hash->{NAME};
  1123. foreach my $d (sort keys %defs) {
  1124. if(defined($defs{$d}) &&
  1125. defined($defs{$d}{IODev}) &&
  1126. $defs{$d}{IODev} == $hash)
  1127. {
  1128. my $lev = ($reread_active ? 4 : 2);
  1129. Log3 $name, $lev, "TCM deleting port for $d";
  1130. delete $defs{$d}{IODev};
  1131. }
  1132. }
  1133. DevIo_CloseDev($hash);
  1134. return undef;
  1135. }
  1136. 1;
  1137. =pod
  1138. =item summary EnOcean Serial Protocol Inferface (ESP2/ESP3)
  1139. =item summary_DE EnOcean Serial Protocol Interface (ESP2/ESP3)
  1140. =begin html
  1141. <a name="TCM"></a>
  1142. <h3>TCM</h3>
  1143. <ul>
  1144. The TCM module serves an USB or TCP/IP connected TCM 120 or TCM 310x, TCM 410J
  1145. EnOcean Transceiver module. These are mostly packaged together with a serial to USB
  1146. chip and an antenna, e.g. the BSC BOR contains the TCM 120, the <a
  1147. href="http://www.enocean.com/de/enocean_module/usb-300-oem/">USB 300</a> from
  1148. EnOcean and the EUL from busware contains a TCM 310. See also the datasheet
  1149. available from <a href="http://www.enocean.com">www.enocean.com</a>.
  1150. <br>
  1151. As the TCM 120 and the TCM 310, TCM 410J speak completely different protocols, this
  1152. module implements 2 drivers in one. It is the "physical" part for the <a
  1153. href="#EnOcean">EnOcean</a> module.<br><br>
  1154. Please note that EnOcean repeaters also send Fhem data telegrams again. Use
  1155. <code>attr &lt;name&gt; <a href="#blockSenderID">blockSenderID</a> own</code>
  1156. to block receiving telegrams with TCM SenderIDs.<br>
  1157. The address range used by your transceiver module, can be found in the
  1158. parameters BaseID and LastID.
  1159. <br><br>
  1160. The transceiver moduls do not always support all commands. The supported range
  1161. of commands depends on the hardware and the firmware version. A firmware update
  1162. is usually not provided.
  1163. <br><br>
  1164. The TCM module enables also a wired connection to Eltako actuators over the
  1165. Eltako RS485 bus in the switchboard or distribution box via Eltako FGW14 RS232-RS485
  1166. gateway modules. These actuators are linked to an associated wireless antenna module
  1167. (FAM14) on the bus. The FAM14 device frequently polls the actuator status of all
  1168. associated devices if the FAM14 operating mode rotary switch is on position 4.
  1169. Therefore, actuator states can be retrieved more reliable, even after any fhem downtime,
  1170. when switch events or actuator confirmations could not have been tracked during the
  1171. downtime. As all actuators are polled approx. every 1-2 seconds, it should be avoided to
  1172. use event-on-update-reading. Use instead either event-on-change-reading or
  1173. event-min-interval.
  1174. The Eltako bus uses the EnOcean Serial Protocol version 2 (ESP2). For this reason,
  1175. a FGW14 can be configured as a ESP2. The attribute <a href="#TCM_comType">comType</a>
  1176. must be set to RS485.<br><br>
  1177. <a name="TCMdefine"></a>
  1178. <b>Define</b>
  1179. <ul>
  1180. <code>define &lt;name&gt; TCM [ESP2|ESP3] &lt;device&gt;</code> <br>
  1181. <br>
  1182. First you have to specify the type of the EnOcean Transceiver Chip, i.e
  1183. either ESP2 for the TCM 120 or ESP3 for the TCM 310x, TCM 410J, USB 300, USB400J.<br><br>
  1184. <code>device</code> can take the same parameters (@baudrate, @directio,
  1185. TCP/IP, none) like the <a href="#CULdefine">CUL</a>, but you probably have
  1186. to specify the baudrate: the TCM 120 should be opened with 9600 Baud, the
  1187. TCM 310 with 57600 baud. For Eltako FGW14 devices, type has to be set to 120 and
  1188. the baudrate has to be set to 57600 baud if the FGW14 operating mode
  1189. rotary switch is on position 6.<br><br>
  1190. Example:
  1191. <ul><code>
  1192. define BscBor TCM ESP2 /dev/ttyACM0@9600<br>
  1193. define FGW14 TCM ESP2 /dev/ttyS3@57600<br>
  1194. define TCM310 TCM ESP3 /dev/ttyACM0@57600<br>
  1195. define TCM310 TCM ESP3 COM1@57600 (Windows)<br>
  1196. </code></ul>
  1197. </ul>
  1198. <br>
  1199. <a name="TCMset"></a>
  1200. <b>Set</b><br>
  1201. <ul><b>ESP2 (TCM 120)</b><br>
  1202. <li>baseID [FF800000 ... FFFFFF80]<br>
  1203. Set the BaseID.<br>
  1204. Note: The firmware executes this command only up to then times to prevent misuse.</li>
  1205. <li>modem_off<br>
  1206. Deactivates TCM modem functionality</li>
  1207. <li>modem_on [0000 ... FFFF]<br>
  1208. Activates TCM modem functionality and sets the modem ID</li>
  1209. <li>teach &lt;t/s&gt;<br>
  1210. Set Fhem in learning mode, see <a href="#TCM_learningMode">learningMode</a>.<br>
  1211. The command is always required for UTE and to teach-in bidirectional actuators
  1212. e. g. EEP 4BS (RORG A5-20-XX),
  1213. see <a href="#EnOcean_teach-in">Teach-In / Teach-Out</a>.</li>
  1214. <li>reset<br>
  1215. Reset the device</li>
  1216. <li>sensitivity [00|01]<br>
  1217. Set the TCM radio sensitivity: low = 00, high = 01</li>
  1218. <li>sleep<br>
  1219. Enter the energy saving mode</li>
  1220. <li>wake<br>
  1221. Wakes up from sleep mode</li>
  1222. <br>
  1223. For details see the TCM 120 User Manual available from <a href="http://www.enocean.com">www.enocean.com</a>.
  1224. <br><br>
  1225. </ul>
  1226. <ul><b>ESP3 (TCM 310x, TCM 410J, USB 300, USB400J)</b><br>
  1227. <li>baseID [FF800000 ... FFFFFF80]<br>
  1228. Set the BaseID.<br>
  1229. Note: The firmware executes this command only up to then times to prevent misuse.</li>
  1230. <li>baudrate [00|01|02|03]<br>
  1231. Modifies the baud rate of the EnOcean device.<br>
  1232. baudrate = 00: 56700 baud (default)<br>
  1233. baudrate = 01: 115200 baud<br>
  1234. baudrate = 02: 230400 baud<br>
  1235. baudrate = 03: 460800 baud</li>
  1236. <li>bist<br>
  1237. Perform Flash BIST operation (Built-in-self-test).</li>
  1238. <li>filterAdd &lt;FilterType&gt;&lt;FilterValue&gt;&lt;FilterKind&gt;<br>
  1239. Add filter to filter list. Description of the filter parameters and examples, see
  1240. <a href="https://www.enocean.com/esp">EnOcean Serial Protocol 3 (ESP3)</a></li>
  1241. <li>filterDel &lt;FilterType&gt;&lt;FilterValue&gt;<br>
  1242. Del filter from filter list. Description of the filter parameters, see
  1243. <a href="https://www.enocean.com/esp">EnOcean Serial Protocol 3 (ESP3)</a></li>
  1244. <li>filterDelAll<br>
  1245. Del all filter from filter list.</li>
  1246. <li>filterEnable &lt;FilterON/OFF&gt;&lt;FilterOperator&gt;<br>
  1247. Enable/Disable all supplied filters. Description of the filter parameters, see
  1248. <a href="https://www.enocean.com/esp">EnOcean Serial Protocol 3 (ESP3)</a></li>
  1249. <li>init<br>
  1250. Initialize serial communication and transceiver configuration</li>
  1251. <li>maturity [00|01]<br>
  1252. Waiting till end of maturity time before received radio telegrams will transmit:
  1253. radio telegrams are send immediately = 00, after the maturity time is elapsed = 01</li>
  1254. <li>mode [00|01]<br>
  1255. mode = 00: Compatible mode - ERP1 - gateway uses Packet Type 1 to transmit and receive radio telegrams<br>
  1256. mode = 01: Advanced mode - ERP2 - gateway uses Packet Type 10 to transmit and receive radio telegrams
  1257. (for FSK products with advanced protocol)</li>
  1258. <li>smartAckLearn &lt;t/s&gt;<br>
  1259. Set Fhem in Smart Ack learning mode.<br>
  1260. The post master fuctionality must be activated using the command <code>smartAckMailboxMax</code> in advance.<br>
  1261. The simple learnmode is supported, see <a href="#TCM_smartAckLearnMode">smartAckLearnMode</a><br>
  1262. A device, which is then also put in this state is to paired with
  1263. Fhem. Bidirectional learn in for 4BS, UTE and Generic Profiles are supported.<br>
  1264. <code>t/s</code> is the time for the learning period.</li>
  1265. <li>smartAckMailboxMax 0..20<br>
  1266. Enable the post master fuctionality and set amount of mailboxes available, 0 = disable post master functionality.
  1267. Maximum 28 mailboxes can be created. This upper limit is for each firmware restricted and may be smaller.</li>
  1268. <li>teach &lt;t/s&gt;<br>
  1269. Set Fhem in learning mode for RBS, 1BS, 4BS, GP, STE and UTE teach-in / teach-out, see <a href="#TCM_learningMode">learningMode</a>.<br>
  1270. The command is always required for STE, GB, UTE and to teach-in bidirectional actuators
  1271. e. g. EEP 4BS (RORG A5-20-XX)</li>
  1272. <li>reset<br>
  1273. Reset the device</li>
  1274. <li>repeater [0000|0101|0102]<br>
  1275. Set Repeater Level: off = 0000, 1 = 0101, 2 = 0102.</li>
  1276. <li>sleep &lt;t/10 ms&gt; (Range: 00000000 ... 00FFFFFF)<br>
  1277. Enter the energy saving mode</li>
  1278. <li>subtel [00|01]<br>
  1279. Transmitting additional subtelegram info: Enable = 01, Disable = 00</li>
  1280. <br>
  1281. For details see the EnOcean Serial Protocol 3 (ESP3) available from
  1282. <a href="http://www.enocean.com">www.enocean.com</a>.
  1283. <br><br>
  1284. </ul>
  1285. <a name="TCMget"></a>
  1286. <b>Get</b><br>
  1287. <ul><b>TCM 120</b><br>
  1288. <li>baseID<br>
  1289. Get the BaseID. You need this command in order to control EnOcean devices,
  1290. see the <a href="#EnOceandefine">EnOcean</a> paragraph.
  1291. </li>
  1292. <li>modem_status<br>
  1293. Requests the current modem status.</li>
  1294. <li>sensitivity<br>
  1295. Get the TCM radio sensitivity, low = 00, high = 01</li>
  1296. <li>version<br>
  1297. Read the device SW version / HW version, chip-ID, etc.</li>
  1298. <br>
  1299. For details see the TCM 120 User Manual available from <a href="http://www.enocean.com">www.enocean.com</a>.
  1300. <br><br>
  1301. </ul>
  1302. <ul><b>TCM 310</b><br>
  1303. <li>baseID<br>
  1304. Get the BaseID. You need this command in order to control EnOcean devices,
  1305. see the <a href="#EnOceandefine">EnOcean</a> paragraph.</li>
  1306. <li>filter<br>
  1307. Get supplied filters. Description of the filter parameters, see
  1308. <a href="https://www.enocean.com/esp">EnOcean Serial Protocol 3 (ESP3)</a></li>
  1309. <li>freqencyInfo<br>
  1310. Reads Frequency and protocol of the Device, see
  1311. <a href="https://www.enocean.com/esp">EnOcean Serial Protocol 3 (ESP3)</a></li>
  1312. <li>numSecureDev<br>
  1313. Read number of teached in secure devices.</li>
  1314. <li>repeater<br>
  1315. Read Repeater Level: off = 0000, 1 = 0101, 2 = 0102.</li>
  1316. <li>smartAckLearnMode<br>
  1317. Get current smart ack learn mode<br>
  1318. Enable: 00|01 = off|on<br>
  1319. Extended: 00|01|02 = simple|advance|advanceSelectRep</li>
  1320. <li>smartAckLearnedClients<br>
  1321. Get information about the learned smart ack clients</li>
  1322. <li>stepCode<br>
  1323. Reads Hardware Step code and Revision of the Device, see
  1324. <a href="https://www.enocean.com/esp">EnOcean Serial Protocol 3 (ESP3)</a></li>
  1325. <li>version<br>
  1326. Read the device SW version / HW version, chip-ID, etc.</li>
  1327. <br>
  1328. For details see the EnOcean Serial Protocol 3 (ESP3) available from
  1329. <a href="http://www.enocean.com">www.enocean.com</a>.
  1330. <br><br>
  1331. </ul>
  1332. <a name="TCMattr"></a>
  1333. <b>Attributes</b>
  1334. <ul>
  1335. <li><a name="TCM_blockSenderID">blockSenderID</a> &lt;own|no&gt;,
  1336. [blockSenderID] = own is default.<br>
  1337. Block receiving telegrams with a TCM SenderID sent by repeaters.
  1338. </li>
  1339. <li><a href="#attrdummy">dummy</a></li>
  1340. <li><a name="TCM_baseID">baseID</a> &lt;FF800000 ... FFFFFF80&gt;,
  1341. [baseID] = <none> is default.<br>
  1342. Set Transceiver baseID and override automatic allocation. Use this attribute only if the IODev does not allow automatic allocation.
  1343. </li>
  1344. <li><a name="TCM_comModeUTE">comModeUTE</a> &lt;auto|biDir|uniDir&gt;,
  1345. [comModeUTE] = auto is default.<br>
  1346. Presetting the communication method of actuators that be taught using the UTE teach-in. The automatic selection of the
  1347. communication method should only be overwrite manually, if this is explicitly required in the operating instructions of
  1348. the actuator. The parameters should then be immediately re-set to "auto".
  1349. </li>
  1350. <li><a name="TCM_comType">comType</a> &lt;TCM|RS485&gt;,
  1351. [comType] = TCM is default.<br>
  1352. Type of communication device
  1353. </li>
  1354. <li><a href="#do_not_notify">do_not_notify</a></li>
  1355. <li><a name="TCM_learningMode">learningMode</a> &lt;always|demand|nearfield&gt;,
  1356. [learningMode] = demand is default.<br>
  1357. Learning method for automatic setup of EnOcean devices:<br>
  1358. [learningMode] = always: Teach-In/Teach-Out telegrams always accepted, with the exception of bidirectional devices<br>
  1359. [learningMode] = demand: Teach-In/Teach-Out telegrams accepted if Fhem is in learning mode, see also <code>set &lt;IODev&gt; teach &lt;t/s&gt;</code><br>
  1360. [learningMode] = nearfield: Teach-In/Teach-Out telegrams accepted if Fhem is in learning mode and the signal strength RSSI >= -60 dBm.<be>
  1361. </li>
  1362. <li><a name="TCM_sendInterval">sendInterval</a> &lt;0 ... 250&gt;<br>
  1363. ESP2: [sendInterval] = 100 ms is default.<br>
  1364. ESP3: [sendInterval] = 0 ms is default.<br>
  1365. Smallest interval between two sending telegrams
  1366. </li>
  1367. <li><a name="TCM_smartAckLearnMode">smartAckLearnMode</a> &lt;simple|advance|advanceSelectRep&gt;<br>
  1368. select Smart Ack learn mode; only simple supported by Fhem
  1369. </li>
  1370. <li><a name="TCM_smartAckMailboxMax">smartAckMailboxMax</a> &lt;0 ... 28&gt;<br>
  1371. Amount of mailboxes available, 0 = disable post master functionality.
  1372. Maximum 28 mailboxes can be created. This upper limit is for each firmware restricted and may be smaller.
  1373. </li>
  1374. <li><a href="#verbose">verbose</a></li>
  1375. <br><br>
  1376. </ul>
  1377. <a name="TCMevents"></a>
  1378. <b>Generated events</b>
  1379. <ul>
  1380. <li>baseID &lt;transceiver response&gt;</li>
  1381. <li>maturity 00|01</li>
  1382. <li>modem_status &lt;transceiver response&gt;</li>
  1383. <li>numSecureDev &lt;transceiver response&gt;</li>
  1384. <li>repeater 0000|0101|0102</li>
  1385. <li>sensitivity 00|01</li>
  1386. <li>version &lt;transceiver response&gt;</li>
  1387. <li>state: opend|initialized</li>
  1388. <br><br>
  1389. </ul>
  1390. </ul>
  1391. =end html
  1392. =cut