00_TCM.pm 55 KB

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