46_TRX_ELSE.pm 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. # $Id: 46_TRX_ELSE.pm 16542 2018-04-02 22:10:20Z KernSani $
  2. #################################################################################
  3. # 46_TRX_ELSE.pm
  4. #
  5. # FHEM module unkown RFXtrx433 messages
  6. #
  7. # Copyright (C) 2012-2016 Willi Herzig
  8. # Maintenance since 2018 by KernSani
  9. #
  10. # This program is free software; you can redistribute it and/or
  11. # modify it under the terms of the GNU General Public License
  12. # as published by the Free Software Foundation; either version 2
  13. # of the License, or (at your option) any later version.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License
  21. # along with this program; if not, write to the Free Software
  22. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  23. #
  24. # The GNU General Public License may also be found at http://www.gnu.org/licenses/gpl-2.0.html .
  25. ###################################
  26. #
  27. # values for "set global verbose"
  28. # 4: log unknown protocols
  29. # 5: log decoding hexlines for debugging
  30. #
  31. ##############################################################################
  32. #
  33. # CHANGELOG
  34. #
  35. # 02.04.2018 support for vair CO2 sensors (forum #67734) -Thanks to vbs
  36. # 29.03.2018 Summary for Commandref
  37. #
  38. #
  39. ##############################################################################package main;
  40. use strict;
  41. use warnings;
  42. my $time_old = 0;
  43. my $DOT = q{_};
  44. sub
  45. TRX_ELSE_Initialize($)
  46. {
  47. my ($hash) = @_;
  48. $hash->{Match} = "^..(0[0-9a-f]|1[a-f]|2[1-9a-f]|3[0-9a-f]|4[1-9a-d]|4f|53|59|5e|5f|6[0-9a-f]|70|7[2-9a-f]|[8-9a-f][0-9a-f]).*";
  49. $hash->{DefFn} = "TRX_ELSE_Define";
  50. $hash->{UndefFn} = "TRX_ELSE_Undef";
  51. $hash->{ParseFn} = "TRX_ELSE_Parse";
  52. $hash->{AttrList} = "IODev ignore:1,0 do_not_notify:1,0 ".
  53. $readingFnAttributes;
  54. Log3 $hash, 5, "TRX_ELSE_Initialize() Initialize";
  55. }
  56. #####################################
  57. sub
  58. TRX_ELSE_Define($$)
  59. {
  60. my ($hash, $def) = @_;
  61. my @a = split("[ \t][ \t]*", $def);
  62. my $a = int(@a);
  63. return "wrong syntax: define <name> TRX_ELSE code" if(int(@a) != 3);
  64. my $name = $a[0];
  65. my $code = $a[2];
  66. my $device_name = "TRX_UNKNOWN".$DOT.$code;
  67. $hash->{CODE} = $code;
  68. $modules{TRX_ELSE}{defptr}{$device_name} = $hash;
  69. AssignIoPort($hash);
  70. return undef;
  71. }
  72. #####################################
  73. sub
  74. TRX_ELSE_Undef($$)
  75. {
  76. my ($hash, $name) = @_;
  77. delete($modules{TRX_ELSE}{defptr}{$name});
  78. return undef;
  79. }
  80. sub
  81. TRX_ELSE_Parse($$)
  82. {
  83. my ($hash, $msg) = @_;
  84. my $time = time();
  85. if ($time_old ==0) {
  86. Log3 $hash, 5, "TRX_ELSE_Parse() decoding delay=0 hex=$msg";
  87. } else {
  88. my $time_diff = $time - $time_old ;
  89. Log3 $hash, 5, "TRX_ELSE_Parse() decoding delay=$time_diff hex=$msg";
  90. }
  91. $time_old = $time;
  92. # convert to binary
  93. my $bin_msg = pack('H*', $msg);
  94. Log3 $hash, 5, "TRX_ELSE_Parse() 2 hex=$msg";
  95. # convert string to array of bytes. Skip length byte
  96. my @rfxcom_data_array = ();
  97. foreach (split(//, substr($bin_msg,1))) {
  98. push (@rfxcom_data_array, ord($_) );
  99. }
  100. my $num_bytes = ord(substr($bin_msg,0,1));
  101. if ($num_bytes < 4) {
  102. return;
  103. }
  104. my $type = $rfxcom_data_array[0];
  105. Log3 $hash, 5, "TRX_ELSE_Parse() num_bytes=$num_bytes hex=$msg type=$type";
  106. my $res = "";
  107. if ($type == 0x02) {
  108. my $subtype = $rfxcom_data_array[1];
  109. my $msg = $rfxcom_data_array[3];
  110. if (($msg != 0x00) && ($msg != 0x01)) {
  111. Log3 $hash, 1, "TRX_ELSE_Parse() error transmit NACK=".sprintf("%02x",$msg);
  112. }
  113. return "";
  114. }
  115. my $type_hex = sprintf("%02x", $type);
  116. my $device_name = "TRX".$DOT."UNKNOWN".$DOT.$type_hex;
  117. my $def = $modules{TRX_ELSE}{defptr}{$device_name};
  118. if (!$def) {
  119. Log3 $hash, 3, "TRX_ELSE: Unknown device $device_name, please define it";
  120. return "UNDEFINED $device_name TRX_ELSE $type_hex";
  121. }
  122. my $name = $def->{NAME};
  123. return "" if(IsIgnored($name));
  124. readingsBeginUpdate($def);
  125. my $current = $msg;
  126. #my $sensor = "hexline";
  127. #readingsBulkUpdate($def, $sensor, $current);
  128. readingsBulkUpdate($def, "state", $current);
  129. readingsEndUpdate($def, 1);
  130. return $name;
  131. }
  132. 1;
  133. =pod
  134. =item device
  135. =item summary unhandled messages from TRX
  136. =item summary_DE unbekannte Nachrichten von TRX
  137. =begin html
  138. <a name="TRX_ELSE"></a>
  139. <h3>TRX_ELSE</h3>
  140. <ul>
  141. The TRX_ELSE module is invoked by TRX if a code is received by RFXCOM RFXtrx433 RF receiver that is currently not handled by a TRX_-Module. You need to define an RFXtrx433 receiver first.
  142. See <a href="#TRX">TRX</a>.
  143. <br>
  144. <a name="TRX_SECURITYdefine"></a>
  145. <br>
  146. <b>Define</b>
  147. <ul>
  148. <code>define &lt;name&gt; TRX_ELSE &lt;hextype&gt;</code> <br>
  149. <br>
  150. <code>&lt;hextype&gt;</code>
  151. <ul>
  152. specifies the hexvalue (00 - ff) of the type received by the RFXtrx433 transceiver. <br>
  153. </ul>
  154. <br>
  155. Example: <br>
  156. <code>define TRX_UNKNOWN_9A TRX_ELSE 9A</code>
  157. <br>
  158. </ul>
  159. <br>
  160. </ul>
  161. =end html
  162. =cut