00_TCM.pm 61 KB

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