A clone of: https://github.com/nutechsoftware/alarmdecoder This is requires as they dropped support for older firmware releases w/o building in backward compatibility code, and they had previously hardcoded pyserial to a python2 only version.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

289 lines
33 KiB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>pyad2usb.messages &mdash; pyad2usb documentation</title>
  7. <link rel="stylesheet" href="../../_static/default.css" type="text/css" />
  8. <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
  9. <script type="text/javascript">
  10. var DOCUMENTATION_OPTIONS = {
  11. URL_ROOT: '../../',
  12. VERSION: '',
  13. COLLAPSE_INDEX: false,
  14. FILE_SUFFIX: '.html',
  15. HAS_SOURCE: true
  16. };
  17. </script>
  18. <script type="text/javascript" src="../../_static/jquery.js"></script>
  19. <script type="text/javascript" src="../../_static/underscore.js"></script>
  20. <script type="text/javascript" src="../../_static/doctools.js"></script>
  21. <link rel="top" title="pyad2usb documentation" href="../../index.html" />
  22. <link rel="up" title="Module code" href="../index.html" />
  23. </head>
  24. <body>
  25. <div class="related">
  26. <h3>Navigation</h3>
  27. <ul>
  28. <li class="right" style="margin-right: 10px">
  29. <a href="../../genindex.html" title="General Index"
  30. accesskey="I">index</a></li>
  31. <li class="right" >
  32. <a href="../../py-modindex.html" title="Python Module Index"
  33. >modules</a> |</li>
  34. <li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
  35. <li><a href="../index.html" accesskey="U">Module code</a> &raquo;</li>
  36. </ul>
  37. </div>
  38. <div class="document">
  39. <div class="documentwrapper">
  40. <div class="bodywrapper">
  41. <div class="body">
  42. <h1>Source code for pyad2usb.messages</h1><div class="highlight"><pre>
  43. <span class="sd">&quot;&quot;&quot;</span>
  44. <span class="sd">Message representations received from the panel through the AD2USB.</span>
  45. <span class="sd">&quot;&quot;&quot;</span>
  46. <span class="kn">import</span> <span class="nn">re</span>
  47. <div class="viewcode-block" id="Message"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.Message">[docs]</a><span class="k">class</span> <span class="nc">Message</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
  48. <span class="sd">&quot;&quot;&quot;</span>
  49. <span class="sd"> Represents a message from the alarm panel.</span>
  50. <span class="sd"> &quot;&quot;&quot;</span>
  51. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
  52. <span class="sd">&quot;&quot;&quot;</span>
  53. <span class="sd"> Constructor</span>
  54. <span class="sd"> &quot;&quot;&quot;</span>
  55. <span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="o">=</span> <span class="bp">False</span>
  56. <span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">=</span> <span class="bp">False</span>
  57. <span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="o">=</span> <span class="bp">False</span>
  58. <span class="bp">self</span><span class="o">.</span><span class="n">backlight_on</span> <span class="o">=</span> <span class="bp">False</span>
  59. <span class="bp">self</span><span class="o">.</span><span class="n">programming_mode</span> <span class="o">=</span> <span class="bp">False</span>
  60. <span class="bp">self</span><span class="o">.</span><span class="n">beeps</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
  61. <span class="bp">self</span><span class="o">.</span><span class="n">zone_bypassed</span> <span class="o">=</span> <span class="bp">False</span>
  62. <span class="bp">self</span><span class="o">.</span><span class="n">ac_power</span> <span class="o">=</span> <span class="bp">False</span>
  63. <span class="bp">self</span><span class="o">.</span><span class="n">chime_on</span> <span class="o">=</span> <span class="bp">False</span>
  64. <span class="bp">self</span><span class="o">.</span><span class="n">alarm_event_occurred</span> <span class="o">=</span> <span class="bp">False</span>
  65. <span class="bp">self</span><span class="o">.</span><span class="n">alarm_sounding</span> <span class="o">=</span> <span class="bp">False</span>
  66. <span class="bp">self</span><span class="o">.</span><span class="n">battery_low</span> <span class="o">=</span> <span class="bp">False</span>
  67. <span class="bp">self</span><span class="o">.</span><span class="n">entry_delay_off</span> <span class="o">=</span> <span class="bp">False</span>
  68. <span class="bp">self</span><span class="o">.</span><span class="n">fire_alarm</span> <span class="o">=</span> <span class="bp">False</span>
  69. <span class="bp">self</span><span class="o">.</span><span class="n">check_zone</span> <span class="o">=</span> <span class="bp">False</span>
  70. <span class="bp">self</span><span class="o">.</span><span class="n">perimeter_only</span> <span class="o">=</span> <span class="bp">False</span>
  71. <span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
  72. <span class="bp">self</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
  73. <span class="bp">self</span><span class="o">.</span><span class="n">cursor_location</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span>
  74. <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
  75. <span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
  76. <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
  77. <span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span> <span class="o">=</span> <span class="s">&quot;&quot;</span>
  78. <span class="bp">self</span><span class="o">.</span><span class="n">_regex</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">&#39;(&quot;(?:[^&quot;]|&quot;&quot;)*&quot;|[^,]*),(&quot;(?:[^&quot;]|&quot;&quot;)*&quot;|[^,]*),(&quot;(?:[^&quot;]|&quot;&quot;)*&quot;|[^,]*),(&quot;(?:[^&quot;]|&quot;&quot;)*&quot;|[^,]*)&#39;</span><span class="p">)</span>
  79. <span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
  80. <span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
  81. <span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
  82. <span class="sd">&quot;&quot;&quot;</span>
  83. <span class="sd"> Parse the message from the device.</span>
  84. <span class="sd"> &quot;&quot;&quot;</span>
  85. <span class="n">m</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_regex</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
  86. <span class="k">if</span> <span class="n">m</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
  87. <span class="k">raise</span> <span class="n">util</span><span class="o">.</span><span class="n">InvalidMessageError</span><span class="p">(</span><span class="s">&#39;Received invalid message: {0}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>
  88. <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">,</span> <span class="n">alpha</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="p">)</span>
  89. <span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">3</span><span class="o">+</span><span class="mi">8</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span>
  90. <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="n">data</span>
  91. <span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">1</span><span class="p">:</span><span class="mi">2</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  92. <span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">2</span><span class="p">:</span><span class="mi">3</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  93. <span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">3</span><span class="p">:</span><span class="mi">4</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  94. <span class="bp">self</span><span class="o">.</span><span class="n">backlight_on</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">5</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  95. <span class="bp">self</span><span class="o">.</span><span class="n">programming_mode</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">5</span><span class="p">:</span><span class="mi">6</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  96. <span class="bp">self</span><span class="o">.</span><span class="n">beeps</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">7</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span>
  97. <span class="bp">self</span><span class="o">.</span><span class="n">zone_bypassed</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">7</span><span class="p">:</span><span class="mi">8</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  98. <span class="bp">self</span><span class="o">.</span><span class="n">ac_power</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">8</span><span class="p">:</span><span class="mi">9</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  99. <span class="bp">self</span><span class="o">.</span><span class="n">chime_on</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">9</span><span class="p">:</span><span class="mi">10</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  100. <span class="bp">self</span><span class="o">.</span><span class="n">alarm_event_occurred</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">10</span><span class="p">:</span><span class="mi">11</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  101. <span class="bp">self</span><span class="o">.</span><span class="n">alarm_sounding</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">11</span><span class="p">:</span><span class="mi">12</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  102. <span class="bp">self</span><span class="o">.</span><span class="n">battery_low</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">12</span><span class="p">:</span><span class="mi">13</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  103. <span class="bp">self</span><span class="o">.</span><span class="n">entry_delay_off</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">13</span><span class="p">:</span><span class="mi">14</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  104. <span class="bp">self</span><span class="o">.</span><span class="n">fire_alarm</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">14</span><span class="p">:</span><span class="mi">15</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  105. <span class="bp">self</span><span class="o">.</span><span class="n">check_zone</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">15</span><span class="p">:</span><span class="mi">16</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  106. <span class="bp">self</span><span class="o">.</span><span class="n">perimeter_only</span> <span class="o">=</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">16</span><span class="p">:</span><span class="mi">17</span><span class="p">]</span> <span class="o">==</span> <span class="s">&quot;0&quot;</span>
  107. <span class="c"># bits 17-20 unused.</span>
  108. <span class="bp">self</span><span class="o">.</span><span class="n">text</span> <span class="o">=</span> <span class="n">alpha</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s">&#39;&quot;&#39;</span><span class="p">)</span>
  109. <span class="k">if</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">panel_data</span><span class="p">[</span><span class="mi">19</span><span class="p">:</span><span class="mi">21</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span> <span class="o">&amp;</span> <span class="mh">0x01</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
  110. <span class="bp">self</span><span class="o">.</span><span class="n">cursor_location</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">21</span><span class="p">:</span><span class="mi">23</span><span class="p">],</span> <span class="mi">16</span><span class="p">)</span> <span class="c"># Alpha character index that the cursor is on.</span>
  111. <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  112. <span class="sd">&quot;&quot;&quot;</span>
  113. <span class="sd"> String conversion operator.</span>
  114. <span class="sd"> &quot;&quot;&quot;</span>
  115. <span class="k">return</span> <span class="s">&#39;msg &gt; {0:0&lt;9} [{1}{2}{3}] -- ({4}) {5}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">hex</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mask</span><span class="p">),</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">ready</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">armed_away</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">1</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">armed_home</span> <span class="k">else</span> <span class="mi">0</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">numeric_code</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
  116. </div>
  117. <div class="viewcode-block" id="ExpanderMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.ExpanderMessage">[docs]</a><span class="k">class</span> <span class="nc">ExpanderMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
  118. <span class="sd">&quot;&quot;&quot;</span>
  119. <span class="sd"> Represents a message from a zone or relay expansion module.</span>
  120. <span class="sd"> &quot;&quot;&quot;</span>
  121. <span class="n">ZONE</span> <span class="o">=</span> <span class="mi">0</span>
  122. <span class="n">RELAY</span> <span class="o">=</span> <span class="mi">1</span>
  123. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
  124. <span class="sd">&quot;&quot;&quot;</span>
  125. <span class="sd"> Constructor</span>
  126. <span class="sd"> &quot;&quot;&quot;</span>
  127. <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="bp">None</span>
  128. <span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="bp">None</span>
  129. <span class="bp">self</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="bp">None</span>
  130. <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="bp">None</span>
  131. <span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span>
  132. <span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
  133. <span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
  134. <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  135. <span class="sd">&quot;&quot;&quot;</span>
  136. <span class="sd"> String conversion operator.</span>
  137. <span class="sd"> &quot;&quot;&quot;</span>
  138. <span class="n">expander_type</span> <span class="o">=</span> <span class="s">&#39;UNKWN&#39;</span>
  139. <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">ZONE</span><span class="p">:</span>
  140. <span class="n">expander_type</span> <span class="o">=</span> <span class="s">&#39;ZONE&#39;</span>
  141. <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">==</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">RELAY</span><span class="p">:</span>
  142. <span class="n">expander_type</span> <span class="o">=</span> <span class="s">&#39;RELAY&#39;</span>
  143. <span class="k">return</span> <span class="s">&#39;exp &gt; [{0: &lt;5}] {1}/{2} -- {3}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">expander_type</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">address</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">channel</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
  144. <span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
  145. <span class="sd">&quot;&quot;&quot;</span>
  146. <span class="sd"> Parse the raw message from the device.</span>
  147. <span class="sd"> &quot;&quot;&quot;</span>
  148. <span class="n">header</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
  149. <span class="n">address</span><span class="p">,</span> <span class="n">channel</span><span class="p">,</span> <span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>
  150. <span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>
  151. <span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="n">address</span>
  152. <span class="bp">self</span><span class="o">.</span><span class="n">channel</span> <span class="o">=</span> <span class="n">channel</span>
  153. <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">value</span>
  154. <span class="k">if</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!EXP&#39;</span><span class="p">:</span>
  155. <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">ZONE</span>
  156. <span class="k">elif</span> <span class="n">header</span> <span class="o">==</span> <span class="s">&#39;!REL&#39;</span><span class="p">:</span>
  157. <span class="bp">self</span><span class="o">.</span><span class="n">type</span> <span class="o">=</span> <span class="n">ExpanderMessage</span><span class="o">.</span><span class="n">RELAY</span>
  158. </div>
  159. <div class="viewcode-block" id="RFMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.RFMessage">[docs]</a><span class="k">class</span> <span class="nc">RFMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
  160. <span class="sd">&quot;&quot;&quot;</span>
  161. <span class="sd"> Represents a message from an RF receiver.</span>
  162. <span class="sd"> &quot;&quot;&quot;</span>
  163. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
  164. <span class="sd">&quot;&quot;&quot;</span>
  165. <span class="sd"> Constructor</span>
  166. <span class="sd"> &quot;&quot;&quot;</span>
  167. <span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span>
  168. <span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span> <span class="o">=</span> <span class="bp">None</span>
  169. <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="bp">None</span>
  170. <span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
  171. <span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
  172. <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  173. <span class="sd">&quot;&quot;&quot;</span>
  174. <span class="sd"> String conversion operator.</span>
  175. <span class="sd"> &quot;&quot;&quot;</span>
  176. <span class="k">return</span> <span class="s">&#39;rf &gt; {0}: {1}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
  177. <span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
  178. <span class="sd">&quot;&quot;&quot;</span>
  179. <span class="sd"> Parses the raw message from the device.</span>
  180. <span class="sd"> &quot;&quot;&quot;</span>
  181. <span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>
  182. <span class="n">_</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
  183. <span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">value</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span>
  184. </div>
  185. <div class="viewcode-block" id="LRRMessage"><a class="viewcode-back" href="../../pyad2usb.html#pyad2usb.messages.LRRMessage">[docs]</a><span class="k">class</span> <span class="nc">LRRMessage</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
  186. <span class="sd">&quot;&quot;&quot;</span>
  187. <span class="sd"> Represent a message from a Long Range Radio.</span>
  188. <span class="sd"> &quot;&quot;&quot;</span>
  189. <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span>
  190. <span class="sd">&quot;&quot;&quot;</span>
  191. <span class="sd"> Constructor</span>
  192. <span class="sd"> &quot;&quot;&quot;</span>
  193. <span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="bp">None</span>
  194. <span class="bp">self</span><span class="o">.</span><span class="n">_event_data</span> <span class="o">=</span> <span class="bp">None</span>
  195. <span class="bp">self</span><span class="o">.</span><span class="n">_partition</span> <span class="o">=</span> <span class="bp">None</span>
  196. <span class="bp">self</span><span class="o">.</span><span class="n">_event_type</span> <span class="o">=</span> <span class="bp">None</span>
  197. <span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
  198. <span class="bp">self</span><span class="o">.</span><span class="n">_parse_message</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
  199. <span class="k">def</span> <span class="nf">__str__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
  200. <span class="sd">&quot;&quot;&quot;</span>
  201. <span class="sd"> String conversion operator.</span>
  202. <span class="sd"> &quot;&quot;&quot;</span>
  203. <span class="k">return</span> <span class="s">&#39;lrr &gt; {0} @ {1} -- {2}&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">()</span>
  204. <span class="k">def</span> <span class="nf">_parse_message</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
  205. <span class="sd">&quot;&quot;&quot;</span>
  206. <span class="sd"> Parses the raw message from the device.</span>
  207. <span class="sd"> &quot;&quot;&quot;</span>
  208. <span class="bp">self</span><span class="o">.</span><span class="n">raw</span> <span class="o">=</span> <span class="n">data</span>
  209. <span class="n">_</span><span class="p">,</span> <span class="n">values</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;:&#39;</span><span class="p">)</span>
  210. <span class="bp">self</span><span class="o">.</span><span class="n">_event_data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_partition</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_event_type</span> <span class="o">=</span> <span class="n">values</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">&#39;,&#39;</span><span class="p">)</span></div>
  211. </pre></div>
  212. </div>
  213. </div>
  214. </div>
  215. <div class="sphinxsidebar">
  216. <div class="sphinxsidebarwrapper">
  217. <div id="searchbox" style="display: none">
  218. <h3>Quick search</h3>
  219. <form class="search" action="../../search.html" method="get">
  220. <input type="text" name="q" />
  221. <input type="submit" value="Go" />
  222. <input type="hidden" name="check_keywords" value="yes" />
  223. <input type="hidden" name="area" value="default" />
  224. </form>
  225. <p class="searchtip" style="font-size: 90%">
  226. Enter search terms or a module, class or function name.
  227. </p>
  228. </div>
  229. <script type="text/javascript">$('#searchbox').show(0);</script>
  230. </div>
  231. </div>
  232. <div class="clearer"></div>
  233. </div>
  234. <div class="related">
  235. <h3>Navigation</h3>
  236. <ul>
  237. <li class="right" style="margin-right: 10px">
  238. <a href="../../genindex.html" title="General Index"
  239. >index</a></li>
  240. <li class="right" >
  241. <a href="../../py-modindex.html" title="Python Module Index"
  242. >modules</a> |</li>
  243. <li><a href="../../index.html">pyad2usb documentation</a> &raquo;</li>
  244. <li><a href="../index.html" >Module code</a> &raquo;</li>
  245. </ul>
  246. </div>
  247. <div class="footer">
  248. &copy; Copyright 2013, Author.
  249. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2b1.
  250. </div>
  251. </body>
  252. </html>