@@ -58,6 +58,8 @@ | |||
<span class="kn">import</span> <span class="nn">time</span> | |||
<span class="kn">import</span> <span class="nn">re</span> | |||
<span class="kn">from</span> <span class="nn">builtins</span> <span class="kn">import</span> <span class="nb">chr</span> | |||
<span class="kn">from</span> <span class="nn">.event</span> <span class="kn">import</span> <span class="n">event</span> | |||
<span class="kn">from</span> <span class="nn">.util</span> <span class="kn">import</span> <span class="n">InvalidMessageError</span> | |||
<span class="kn">from</span> <span class="nn">.messages</span> <span class="kn">import</span> <span class="n">Message</span><span class="p">,</span> <span class="n">ExpanderMessage</span><span class="p">,</span> <span class="n">RFMessage</span><span class="p">,</span> <span class="n">LRRMessage</span> | |||
@@ -100,15 +102,15 @@ | |||
<span class="n">on_write</span> <span class="o">=</span> <span class="n">event</span><span class="o">.</span><span class="n">Event</span><span class="p">(</span><span class="s">"This event is called when data has been written to the device.</span><span class="se">\n\n</span><span class="s">**Callback definition:** *def callback(device, data)*"</span><span class="p">)</span> | |||
<span class="c"># Constants</span> | |||
<span class="n">KEY_F1</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
<span class="n">KEY_F1</span> <span class="o">=</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
<span class="sd">"""Represents panel function key #1"""</span> | |||
<span class="n">KEY_F2</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> | |||
<span class="n">KEY_F2</span> <span class="o">=</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> | |||
<span class="sd">"""Represents panel function key #2"""</span> | |||
<span class="n">KEY_F3</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> | |||
<span class="n">KEY_F3</span> <span class="o">=</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span> | |||
<span class="sd">"""Represents panel function key #3"""</span> | |||
<span class="n">KEY_F4</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> | |||
<span class="n">KEY_F4</span> <span class="o">=</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> | |||
<span class="sd">"""Represents panel function key #4"""</span> | |||
<span class="n">KEY_PANIC</span> <span class="o">=</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> <span class="o">+</span> <span class="nb">unichr</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> | |||
<span class="n">KEY_PANIC</span> <span class="o">=</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> <span class="o">+</span> <span class="nb">chr</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span> | |||
<span class="sd">"""Represents a panic keypress"""</span> | |||
<span class="n">BATTERY_TIMEOUT</span> <span class="o">=</span> <span class="mi">30</span> | |||
@@ -123,9 +125,9 @@ | |||
<span class="sd">"""The configuration bits set on the device."""</span> | |||
<span class="n">address_mask</span> <span class="o">=</span> <span class="mh">0xFFFFFFFF</span> | |||
<span class="sd">"""The address mask configured on the device."""</span> | |||
<span class="n">emulate_zone</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)]</span> | |||
<span class="n">emulate_zone</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">))]</span> | |||
<span class="sd">"""List containing the devices zone emulation status."""</span> | |||
<span class="n">emulate_relay</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)]</span> | |||
<span class="n">emulate_relay</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">))]</span> | |||
<span class="sd">"""List containing the devices relay emulation status."""</span> | |||
<span class="n">emulate_lrr</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="sd">"""The status of the devices LRR emulation."""</span> | |||
@@ -134,6 +136,14 @@ | |||
<span class="n">mode</span> <span class="o">=</span> <span class="n">ADEMCO</span> | |||
<span class="sd">"""The panel mode that the AlarmDecoder is in. Currently supports ADEMCO and DSC."""</span> | |||
<span class="c">#Version Information</span> | |||
<span class="n">serial_number</span> <span class="o">=</span> <span class="mh">0xFFFFFFFF</span> | |||
<span class="sd">"""The device serial number"""</span> | |||
<span class="n">version_number</span> <span class="o">=</span> <span class="s">'Unknown'</span> | |||
<span class="sd">"""The device firmware version"""</span> | |||
<span class="n">version_flags</span> <span class="o">=</span> <span class="s">""</span> | |||
<span class="sd">"""Device flags enabled"""</span> | |||
<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">device</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Constructor</span> | |||
@@ -153,19 +163,23 @@ | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_armed_status</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_fire_status</span> <span class="o">=</span> <span class="p">(</span><span class="bp">False</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_battery_status</span> <span class="o">=</span> <span class="p">(</span><span class="bp">False</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_panic_status</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_panic_status</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_relay_status</span> <span class="o">=</span> <span class="p">{}</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_internal_address_mask</span> <span class="o">=</span> <span class="mh">0xFFFFFFFF</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">address</span> <span class="o">=</span> <span class="mi">18</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">configbits</span> <span class="o">=</span> <span class="mh">0xFF00</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">address_mask</span> <span class="o">=</span> <span class="mh">0x00000000</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_zone</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)]</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_relay</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)]</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">address_mask</span> <span class="o">=</span> <span class="mh">0xFFFFFFFF</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_zone</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">))]</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_relay</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">x</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">))]</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_lrr</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">deduplicate</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">mode</span> <span class="o">=</span> <span class="n">ADEMCO</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span> <span class="o">=</span> <span class="mh">0xFFFFFFFF</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">version_number</span> <span class="o">=</span> <span class="s">'Unknown'</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">version_flags</span> <span class="o">=</span> <span class="s">""</span> | |||
<span class="k">def</span> <span class="nf">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Support for context manager __enter__.</span> | |||
@@ -280,7 +294,7 @@ | |||
<span class="sd"> """</span> | |||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">data</span><span class="p">))</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="nb">str</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="n">data</span><span class="p">))</span> | |||
</div> | |||
<div class="viewcode-block" id="AlarmDecoder.get_config"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.decoder.AlarmDecoder.get_config">[docs]</a> <span class="k">def</span> <span class="nf">get_config</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
@@ -292,7 +306,9 @@ | |||
<span class="sd">"""</span> | |||
<span class="sd"> Sets configuration entries on the device.</span> | |||
<span class="sd"> """</span> | |||
<span class="n">config_string</span> <span class="o">=</span> <span class="s">''</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="s">"C{0}</span><span class="se">\r</span><span class="s">"</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">get_config_string</span><span class="p">()))</span> | |||
</div> | |||
<div class="viewcode-block" id="AlarmDecoder.get_config_string"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.decoder.AlarmDecoder.get_config_string">[docs]</a> <span class="k">def</span> <span class="nf">get_config_string</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="n">config_entries</span> <span class="o">=</span> <span class="p">[]</span> | |||
<span class="c"># HACK: This is ugly.. but I can't think of an elegant way of doing it.</span> | |||
@@ -305,11 +321,17 @@ | |||
<span class="s">''</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">'Y'</span> <span class="k">if</span> <span class="n">r</span> <span class="k">else</span> <span class="s">'N'</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">emulate_relay</span><span class="p">])))</span> | |||
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">'LRR'</span><span class="p">,</span> <span class="s">'Y'</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">emulate_lrr</span> <span class="k">else</span> <span class="s">'N'</span><span class="p">))</span> | |||
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">'DEDUPLICATE'</span><span class="p">,</span> <span class="s">'Y'</span> <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">deduplicate</span> <span class="k">else</span> <span class="s">'N'</span><span class="p">))</span> | |||
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">'MODE'</span><span class="p">,</span> <span class="n">PANEL_TYPES</span><span class="o">.</span><span class="n">keys</span><span class="p">()[</span><span class="n">PANEL_TYPES</span><span class="o">.</span><span class="n">values</span><span class="p">()</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="p">)]))</span> | |||
<span class="n">config_entries</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="s">'MODE'</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="n">PANEL_TYPES</span><span class="p">)[</span><span class="nb">list</span><span class="p">(</span><span class="n">PANEL_TYPES</span><span class="o">.</span><span class="n">values</span><span class="p">())</span><span class="o">.</span><span class="n">index</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mode</span><span class="p">)]))</span> | |||
<span class="n">config_string</span> <span class="o">=</span> <span class="s">'&'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">'='</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">config_entries</span><span class="p">])</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="s">"C{0}</span><span class="se">\r</span><span class="s">"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">config_string</span><span class="p">))</span> | |||
<span class="k">return</span> <span class="s">'&'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">'='</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">t</span><span class="p">)</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">config_entries</span><span class="p">])</span> | |||
</div> | |||
<div class="viewcode-block" id="AlarmDecoder.get_version"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.decoder.AlarmDecoder.get_version">[docs]</a> <span class="k">def</span> <span class="nf">get_version</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Retrieves the version string from the device. Called automatically by :py:meth:`_on_open`.</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">send</span><span class="p">(</span><span class="s">"V</span><span class="se">\r</span><span class="s">"</span><span class="p">)</span> | |||
</div> | |||
<div class="viewcode-block" id="AlarmDecoder.reboot"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.decoder.AlarmDecoder.reboot">[docs]</a> <span class="k">def</span> <span class="nf">reboot</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
@@ -370,6 +392,8 @@ | |||
<span class="sd"> :returns: :py:class:`~alarmdecoder.messages.Message`</span> | |||
<span class="sd"> """</span> | |||
<span class="n">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s">'utf-8'</span><span class="p">)</span> | |||
<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> | |||
<span class="n">data</span> <span class="o">=</span> <span class="n">data</span><span class="o">.</span><span class="n">lstrip</span><span class="p">(</span><span class="s">'</span><span class="se">\0</span><span class="s">'</span><span class="p">)</span> | |||
@@ -397,6 +421,9 @@ | |||
<span class="k">elif</span> <span class="n">data</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">'!CONFIG'</span><span class="p">):</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_handle_config</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> | |||
<span class="k">elif</span> <span class="n">data</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">'!VER'</span><span class="p">):</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_handle_version</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> | |||
<span class="k">elif</span> <span class="n">data</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">'!Sending'</span><span class="p">):</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_handle_sending</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> | |||
@@ -475,6 +502,21 @@ | |||
<span class="k">return</span> <span class="n">msg</span> | |||
<span class="k">def</span> <span class="nf">_handle_version</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Handles received version data.</span> | |||
<span class="sd"> </span> | |||
<span class="sd"> :param data: Version string to parse</span> | |||
<span class="sd"> :type data: string</span> | |||
<span class="sd"> """</span> | |||
<span class="n">_</span><span class="p">,</span> <span class="n">version_string</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">':'</span><span class="p">)</span> | |||
<span class="n">version_parts</span> <span class="o">=</span> <span class="n">version_string</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s">','</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">serial_number</span> <span class="o">=</span> <span class="n">version_parts</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">version_number</span> <span class="o">=</span> <span class="n">version_parts</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">version_flags</span> <span class="o">=</span> <span class="n">version_parts</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span> | |||
<span class="k">def</span> <span class="nf">_handle_config</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Handles received configuration data.</span> | |||
@@ -493,9 +535,9 @@ | |||
<span class="k">elif</span> <span class="n">key</span> <span class="o">==</span> <span class="s">'MASK'</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">address_mask</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">val</span><span class="p">,</span> <span class="mi">16</span><span class="p">)</span> | |||
<span class="k">elif</span> <span class="n">key</span> <span class="o">==</span> <span class="s">'EXP'</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_zone</span> <span class="o">=</span> <span class="p">[</span><span class="n">val</span><span class="p">[</span><span class="n">z</span><span class="p">]</span> <span class="o">==</span> <span class="s">'Y'</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">)]</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_zone</span> <span class="o">=</span> <span class="p">[</span><span class="n">val</span><span class="p">[</span><span class="n">z</span><span class="p">]</span> <span class="o">==</span> <span class="s">'Y'</span> <span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">5</span><span class="p">))]</span> | |||
<span class="k">elif</span> <span class="n">key</span> <span class="o">==</span> <span class="s">'REL'</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_relay</span> <span class="o">=</span> <span class="p">[</span><span class="n">val</span><span class="p">[</span><span class="n">r</span><span class="p">]</span> <span class="o">==</span> <span class="s">'Y'</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)]</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_relay</span> <span class="o">=</span> <span class="p">[</span><span class="n">val</span><span class="p">[</span><span class="n">r</span><span class="p">]</span> <span class="o">==</span> <span class="s">'Y'</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">))]</span> | |||
<span class="k">elif</span> <span class="n">key</span> <span class="o">==</span> <span class="s">'LRR'</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">emulate_lrr</span> <span class="o">=</span> <span class="p">(</span><span class="n">val</span> <span class="o">==</span> <span class="s">'Y'</span><span class="p">)</span> | |||
<span class="k">elif</span> <span class="n">key</span> <span class="o">==</span> <span class="s">'DEDUPLICATE'</span><span class="p">:</span> | |||
@@ -699,6 +741,8 @@ | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">get_config</span><span class="p">()</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">get_version</span><span class="p">()</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">on_open</span><span class="p">()</span> | |||
<span class="k">def</span> <span class="nf">_on_close</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sender</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |||
@@ -69,10 +69,13 @@ | |||
<span class="kn">import</span> <span class="nn">serial</span> | |||
<span class="kn">import</span> <span class="nn">serial.tools.list_ports</span> | |||
<span class="kn">import</span> <span class="nn">socket</span> | |||
<span class="kn">import</span> <span class="nn">select</span> | |||
<span class="kn">from</span> <span class="nn">builtins</span> <span class="kn">import</span> <span class="nb">bytes</span> | |||
<span class="kn">from</span> <span class="nn">.util</span> <span class="kn">import</span> <span class="n">CommError</span><span class="p">,</span> <span class="n">TimeoutError</span><span class="p">,</span> <span class="n">NoDeviceError</span><span class="p">,</span> <span class="n">InvalidMessageError</span> | |||
<span class="kn">from</span> <span class="nn">.event</span> <span class="kn">import</span> <span class="n">event</span> | |||
<span class="n">have_pyftdi</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="kn">from</span> <span class="nn">pyftdi.pyftdi.ftdi</span> <span class="kn">import</span> <span class="n">Ftdi</span><span class="p">,</span> <span class="n">FtdiError</span> | |||
<span class="kn">import</span> <span class="nn">usb.core</span> | |||
@@ -81,7 +84,15 @@ | |||
<span class="n">have_pyftdi</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span> | |||
<span class="n">have_pyftdi</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="kn">from</span> <span class="nn">pyftdi.ftdi</span> <span class="kn">import</span> <span class="n">Ftdi</span><span class="p">,</span> <span class="n">FtdiError</span> | |||
<span class="kn">import</span> <span class="nn">usb.core</span> | |||
<span class="kn">import</span> <span class="nn">usb.util</span> | |||
<span class="n">have_pyftdi</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span> | |||
<span class="n">have_pyftdi</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="kn">from</span> <span class="nn">OpenSSL</span> <span class="kn">import</span> <span class="n">SSL</span><span class="p">,</span> <span class="n">crypto</span> | |||
@@ -89,8 +100,16 @@ | |||
<span class="n">have_openssl</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span> | |||
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">namedtuple</span> | |||
<span class="n">SSL</span> <span class="o">=</span> <span class="n">namedtuple</span><span class="p">(</span><span class="s">'SSL'</span><span class="p">,</span> <span class="p">[</span><span class="s">'Error'</span><span class="p">,</span> <span class="s">'WantReadError'</span><span class="p">,</span> <span class="s">'SysCallError'</span><span class="p">])</span> | |||
<span class="k">class</span> <span class="nc">SSL</span><span class="p">:</span> | |||
<span class="k">class</span> <span class="nc">Error</span><span class="p">(</span><span class="ne">BaseException</span><span class="p">):</span> | |||
<span class="k">pass</span> | |||
<span class="k">class</span> <span class="nc">WantReadError</span><span class="p">(</span><span class="ne">BaseException</span><span class="p">):</span> | |||
<span class="k">pass</span> | |||
<span class="k">class</span> <span class="nc">SysCallError</span><span class="p">(</span><span class="ne">BaseException</span><span class="p">):</span> | |||
<span class="k">pass</span> | |||
<span class="n">have_openssl</span> <span class="o">=</span> <span class="bp">False</span> | |||
@@ -110,7 +129,7 @@ | |||
<span class="sd"> Constructor</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_id</span> <span class="o">=</span> <span class="s">''</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="s">''</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="n">b</span><span class="s">''</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_read_thread</span> <span class="o">=</span> <span class="bp">None</span> | |||
@@ -220,10 +239,10 @@ | |||
<span class="k">except</span> <span class="n">SSL</span><span class="o">.</span><span class="n">WantReadError</span><span class="p">:</span> | |||
<span class="k">pass</span> | |||
<span class="k">except</span> <span class="n">CommError</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="n">CommError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> | |||
<span class="k">except</span> <span class="ne">Exception</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_running</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="k">raise</span> | |||
@@ -275,7 +294,7 @@ | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="n">cls</span><span class="o">.</span><span class="n">__devices</span> <span class="o">=</span> <span class="n">Ftdi</span><span class="o">.</span><span class="n">find_all</span><span class="p">(</span><span class="n">query</span><span class="p">,</span> <span class="n">nocache</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">)</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error enumerating AD2USB devices: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">return</span> <span class="n">cls</span><span class="o">.</span><span class="n">__devices</span> | |||
@@ -482,10 +501,10 @@ | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_id</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_serial_number</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">)</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">NoDeviceError</span><span class="p">(</span><span class="s">'Error opening device: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="ne">KeyError</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="ne">KeyError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">NoDeviceError</span><span class="p">(</span><span class="s">'Unsupported device. ({0:04x}:{1:04x}) You probably need a newer version of pyftdi.'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">err</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">0</span><span class="p">],</span> <span class="n">err</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="mi">1</span><span class="p">]))</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
@@ -527,7 +546,7 @@ | |||
<span class="bp">self</span><span class="o">.</span><span class="n">on_write</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="n">FtdiError</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="n">FtdiError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error writing to device: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span> | |||
</div> | |||
<div class="viewcode-block" id="USBDevice.read"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.devices.USBDevice.read">[docs]</a> <span class="k">def</span> <span class="nf">read</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
@@ -542,7 +561,7 @@ | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">read_data</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">)</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error reading from device: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">return</span> <span class="n">ret</span> | |||
@@ -567,7 +586,7 @@ | |||
<span class="n">timeout_event</span><span class="o">.</span><span class="n">reading</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="k">if</span> <span class="n">purge_buffer</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="s">''</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="n">b</span><span class="s">''</span> | |||
<span class="n">got_line</span><span class="p">,</span> <span class="n">ret</span> <span class="o">=</span> <span class="bp">False</span><span class="p">,</span> <span class="bp">None</span> | |||
@@ -579,11 +598,11 @@ | |||
<span class="k">while</span> <span class="n">timeout_event</span><span class="o">.</span><span class="n">reading</span><span class="p">:</span> | |||
<span class="n">buf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">read_data</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">!=</span> <span class="s">''</span><span class="p">:</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">!=</span> <span class="n">b</span><span class="s">''</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">+=</span> <span class="n">buf</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">==</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s">"</span><span class="se">\r\n</span><span class="s">"</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">==</span> <span class="n">b</span><span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="n">b</span><span class="s">"</span><span class="se">\r\n</span><span class="s">"</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">)</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> | |||
<span class="n">got_line</span> <span class="o">=</span> <span class="bp">True</span> | |||
@@ -591,12 +610,12 @@ | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">usb</span><span class="o">.</span><span class="n">core</span><span class="o">.</span><span class="n">USBError</span><span class="p">,</span> <span class="n">FtdiError</span><span class="p">)</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error reading from device: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="k">if</span> <span class="n">got_line</span><span class="p">:</span> | |||
<span class="n">ret</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">,</span> <span class="s">''</span> | |||
<span class="n">ret</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">,</span> <span class="n">b</span><span class="s">''</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">on_read</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">ret</span><span class="p">)</span> | |||
@@ -607,6 +626,12 @@ | |||
<span class="n">timer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span> | |||
<span class="k">return</span> <span class="n">ret</span> | |||
</div> | |||
<div class="viewcode-block" id="USBDevice.purge"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.devices.USBDevice.purge">[docs]</a> <span class="k">def</span> <span class="nf">purge</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Purges read/write buffers.</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">purge_buffers</span><span class="p">()</span> | |||
</div> | |||
<span class="k">def</span> <span class="nf">_get_serial_number</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
@@ -702,7 +727,7 @@ | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">devices</span> <span class="o">=</span> <span class="n">serial</span><span class="o">.</span><span class="n">tools</span><span class="o">.</span><span class="n">list_ports</span><span class="o">.</span><span class="n">comports</span><span class="p">()</span> | |||
<span class="k">except</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error enumerating serial devices: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">return</span> <span class="n">devices</span> | |||
@@ -773,7 +798,7 @@ | |||
<span class="c"># all issues with it.</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">baudrate</span> <span class="o">=</span> <span class="n">baudrate</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="ne">OSError</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">,</span> <span class="ne">ValueError</span><span class="p">,</span> <span class="ne">OSError</span><span class="p">)</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">NoDeviceError</span><span class="p">(</span><span class="s">'Error opening device on {0}.'</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">_port</span><span class="p">),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
@@ -813,7 +838,7 @@ | |||
<span class="k">except</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialTimeoutException</span><span class="p">:</span> | |||
<span class="k">pass</span> | |||
<span class="k">except</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error writing to device.'</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
@@ -831,7 +856,7 @@ | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="n">ret</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error reading from device: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">return</span> <span class="n">ret</span> | |||
@@ -856,7 +881,7 @@ | |||
<span class="n">timeout_event</span><span class="o">.</span><span class="n">reading</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="k">if</span> <span class="n">purge_buffer</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="s">''</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="n">b</span><span class="s">''</span> | |||
<span class="n">got_line</span><span class="p">,</span> <span class="n">ret</span> <span class="o">=</span> <span class="bp">False</span><span class="p">,</span> <span class="bp">None</span> | |||
@@ -869,11 +894,11 @@ | |||
<span class="n">buf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
<span class="c"># NOTE: AD2SERIAL apparently sends down \xFF on boot.</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">!=</span> <span class="s">''</span> <span class="ow">and</span> <span class="n">buf</span> <span class="o">!=</span> <span class="s">"</span><span class="se">\xff</span><span class="s">"</span><span class="p">:</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">!=</span> <span class="n">b</span><span class="s">''</span> <span class="ow">and</span> <span class="n">buf</span> <span class="o">!=</span> <span class="n">b</span><span class="s">"</span><span class="se">\xff</span><span class="s">"</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">+=</span> <span class="n">buf</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">==</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s">"</span><span class="se">\r\n</span><span class="s">"</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">==</span> <span class="n">b</span><span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="n">b</span><span class="s">"</span><span class="se">\r\n</span><span class="s">"</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">)</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> | |||
<span class="n">got_line</span> <span class="o">=</span> <span class="bp">True</span> | |||
@@ -881,12 +906,12 @@ | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="ne">OSError</span><span class="p">,</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="ne">OSError</span><span class="p">,</span> <span class="n">serial</span><span class="o">.</span><span class="n">SerialException</span><span class="p">)</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error reading from device: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="k">if</span> <span class="n">got_line</span><span class="p">:</span> | |||
<span class="n">ret</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">,</span> <span class="s">''</span> | |||
<span class="n">ret</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">,</span> <span class="n">b</span><span class="s">''</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">on_read</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">ret</span><span class="p">)</span> | |||
@@ -897,6 +922,13 @@ | |||
<span class="n">timer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span> | |||
<span class="k">return</span> <span class="n">ret</span> | |||
</div> | |||
<div class="viewcode-block" id="SerialDevice.purge"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.devices.SerialDevice.purge">[docs]</a> <span class="k">def</span> <span class="nf">purge</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Purges read/write buffers.</span> | |||
<span class="sd"> """</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">flushInput</span><span class="p">()</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">flushOutput</span><span class="p">()</span> | |||
</div></div> | |||
<div class="viewcode-block" id="SocketDevice"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.devices.SocketDevice">[docs]</a><span class="k">class</span> <span class="nc">SocketDevice</span><span class="p">(</span><span class="n">Device</span><span class="p">):</span> | |||
@@ -1038,7 +1070,6 @@ | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_init_ssl</span><span class="p">()</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">connect</span><span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">_host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span><span class="p">))</span> | |||
<span class="c">#self._device.setblocking(1)</span> | |||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">_use_ssl</span><span class="p">:</span> | |||
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span> | |||
@@ -1050,7 +1081,7 @@ | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_id</span> <span class="o">=</span> <span class="s">'{0}:{1}'</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">_host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">NoDeviceError</span><span class="p">(</span><span class="s">'Error opening device at {0}:{1}'</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">_host</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_port</span><span class="p">),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
@@ -1103,7 +1134,7 @@ | |||
<span class="bp">self</span><span class="o">.</span><span class="n">on_write</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">SSL</span><span class="o">.</span><span class="n">Error</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span><span class="p">),</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="p">(</span><span class="n">SSL</span><span class="o">.</span><span class="n">Error</span><span class="p">,</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span><span class="p">)</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error writing to device.'</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">return</span> <span class="n">data_sent</span> | |||
@@ -1118,9 +1149,12 @@ | |||
<span class="n">data</span> <span class="o">=</span> <span class="bp">None</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
<span class="n">read_ready</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">select</span><span class="o">.</span><span class="n">select</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="p">],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="mi">0</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">read_ready</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">):</span> | |||
<span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error while reading from device: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">return</span> <span class="n">data</span> | |||
@@ -1145,7 +1179,7 @@ | |||
<span class="n">timeout_event</span><span class="o">.</span><span class="n">reading</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="k">if</span> <span class="n">purge_buffer</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="s">''</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="n">b</span><span class="s">''</span> | |||
<span class="n">got_line</span><span class="p">,</span> <span class="n">ret</span> <span class="o">=</span> <span class="bp">False</span><span class="p">,</span> <span class="bp">None</span> | |||
@@ -1155,24 +1189,31 @@ | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="k">while</span> <span class="n">timeout_event</span><span class="o">.</span><span class="n">reading</span><span class="p">:</span> | |||
<span class="n">read_ready</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="n">select</span><span class="o">.</span><span class="n">select</span><span class="p">([</span><span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="p">],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="mi">0</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">read_ready</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">):</span> | |||
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span> | |||
<span class="k">continue</span> | |||
<span class="n">buf</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">!=</span> <span class="s">''</span><span class="p">:</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">!=</span> <span class="n">b</span><span class="s">''</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">+=</span> <span class="n">buf</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">==</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="s">"</span><span class="se">\r\n</span><span class="s">"</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">buf</span> <span class="o">==</span> <span class="n">b</span><span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="o">.</span><span class="n">rstrip</span><span class="p">(</span><span class="n">b</span><span class="s">"</span><span class="se">\r\n</span><span class="s">"</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">)</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> | |||
<span class="n">got_line</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="k">break</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.01</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error reading from device: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">)),</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="n">SSL</span><span class="o">.</span><span class="n">SysCallError</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="n">SSL</span><span class="o">.</span><span class="n">SysCallError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="n">errno</span><span class="p">,</span> <span class="n">msg</span> <span class="o">=</span> <span class="n">err</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'SSL error while reading from device: {0} ({1})'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="n">errno</span><span class="p">))</span> | |||
@@ -1181,7 +1222,7 @@ | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="k">if</span> <span class="n">got_line</span><span class="p">:</span> | |||
<span class="n">ret</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">,</span> <span class="s">''</span> | |||
<span class="n">ret</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_buffer</span><span class="p">,</span> <span class="n">b</span><span class="s">''</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">on_read</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">ret</span><span class="p">)</span> | |||
@@ -1192,6 +1233,19 @@ | |||
<span class="n">timer</span><span class="o">.</span><span class="n">cancel</span><span class="p">()</span> | |||
<span class="k">return</span> <span class="n">ret</span> | |||
</div> | |||
<div class="viewcode-block" id="SocketDevice.purge"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.devices.SocketDevice.purge">[docs]</a> <span class="k">def</span> <span class="nf">purge</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Purges read/write buffers.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">setblocking</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> | |||
<span class="k">while</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">recv</span><span class="p">(</span><span class="mi">1</span><span class="p">)):</span> | |||
<span class="k">pass</span> | |||
<span class="k">except</span> <span class="n">socket</span><span class="o">.</span><span class="n">error</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">pass</span> | |||
<span class="k">finally</span><span class="p">:</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="o">.</span><span class="n">setblocking</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
</div> | |||
<span class="k">def</span> <span class="nf">_init_ssl</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
@@ -1226,7 +1280,7 @@ | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_device</span> <span class="o">=</span> <span class="n">SSL</span><span class="o">.</span><span class="n">Connection</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">_device</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="n">SSL</span><span class="o">.</span><span class="n">Error</span><span class="p">,</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="n">SSL</span><span class="o">.</span><span class="n">Error</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">CommError</span><span class="p">(</span><span class="s">'Error setting up SSL connection.'</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">_verify_ssl_callback</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">connection</span><span class="p">,</span> <span class="n">x509</span><span class="p">,</span> <span class="n">errnum</span><span class="p">,</span> <span class="n">errdepth</span><span class="p">,</span> <span class="n">ok</span><span class="p">):</span> | |||
@@ -64,6 +64,8 @@ | |||
<span class="kn">import</span> <span class="nn">re</span> | |||
<span class="kn">import</span> <span class="nn">datetime</span> | |||
<span class="kn">from</span> <span class="nn">reprlib</span> <span class="kn">import</span> <span class="nb">repr</span> | |||
<span class="kn">from</span> <span class="nn">.util</span> <span class="kn">import</span> <span class="n">InvalidMessageError</span> | |||
<span class="kn">from</span> <span class="nn">.panels</span> <span class="kn">import</span> <span class="n">PANEL_TYPES</span><span class="p">,</span> <span class="n">ADEMCO</span><span class="p">,</span> <span class="n">DSC</span> | |||
@@ -185,7 +187,7 @@ | |||
<span class="sd"> :raises: :py:class:`~alarmdecoder.util.InvalidMessageError`</span> | |||
<span class="sd"> """</span> | |||
<span class="n">match</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> | |||
<span class="n">match</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="nb">str</span><span class="p">(</span><span class="n">data</span><span class="p">))</span> | |||
<span class="k">if</span> <span class="n">match</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">InvalidMessageError</span><span class="p">(</span><span class="s">'Received invalid message: {0}'</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">data</span><span class="p">))</span> | |||
@@ -212,13 +214,13 @@ | |||
<span class="bp">self</span><span class="o">.</span><span class="n">check_zone</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">15</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">perimeter_only</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">16</span><span class="p">)</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">system_fault</span> <span class="o">=</span> <span class="n">is_bit_set</span><span class="p">(</span><span class="mi">17</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">18</span><span class="p">]</span> <span class="ow">in</span> <span class="n">PANEL_TYPES</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span> | |||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bitfield</span><span class="p">[</span><span class="mi">18</span><span class="p">]</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="n">PANEL_TYPES</span><span class="p">):</span> | |||
<span class="bp">self</span><span class="o">.</span><span class="n">panel_type</span> <span class="o">=</span> <span class="n">PANEL_TYPES</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">18</span><span class="p">]]</span> | |||
<span class="c"># pos 20-21 - Unused.</span> | |||
<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">'"'</span><span class="p">)</span> | |||
<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> | |||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">panel_type</span> <span class="o">==</span> <span class="n">ADEMCO</span><span class="p">:</span> | |||
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">panel_type</span> <span class="ow">in</span> <span class="p">(</span><span class="n">ADEMCO</span><span class="p">,</span> <span class="n">DSC</span><span class="p">):</span> | |||
<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">&</span> <span class="mh">0x01</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> | |||
<span class="c"># Current cursor location on the alpha display.</span> | |||
<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">panel_data</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> | |||
@@ -340,7 +342,7 @@ | |||
<span class="sd">"""Low battery indication"""</span> | |||
<span class="n">supervision</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="sd">"""Supervision required indication"""</span> | |||
<span class="n">loop</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">)]</span> | |||
<span class="n">loop</span> <span class="o">=</span> <span class="p">[</span><span class="bp">False</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="nb">range</span><span class="p">(</span><span class="mi">4</span><span class="p">))]</span> | |||
<span class="sd">"""Loop indicators"""</span> | |||
<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> | |||
@@ -57,6 +57,7 @@ | |||
<span class="kn">import</span> <span class="nn">time</span> | |||
<span class="kn">import</span> <span class="nn">threading</span> | |||
<span class="kn">from</span> <span class="nn">io</span> <span class="kn">import</span> <span class="nb">open</span> | |||
<div class="viewcode-block" id="NoDeviceError"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.util.NoDeviceError">[docs]</a><span class="k">class</span> <span class="nc">NoDeviceError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span> | |||
@@ -86,6 +87,20 @@ | |||
<span class="sd"> """</span> | |||
<span class="k">pass</span> | |||
</div> | |||
<div class="viewcode-block" id="UploadError"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.util.UploadError">[docs]</a><span class="k">class</span> <span class="nc">UploadError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Generic firmware upload error.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">pass</span> | |||
</div> | |||
<div class="viewcode-block" id="UploadChecksumError"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.util.UploadChecksumError">[docs]</a><span class="k">class</span> <span class="nc">UploadChecksumError</span><span class="p">(</span><span class="n">UploadError</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> The firmware upload failed due to a checksum error.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">pass</span> | |||
</div> | |||
<div class="viewcode-block" id="Firmware"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.util.Firmware">[docs]</a><span class="k">class</span> <span class="nc">Firmware</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
@@ -99,10 +114,12 @@ | |||
<span class="n">STAGE_LOAD</span> <span class="o">=</span> <span class="mi">3</span> | |||
<span class="n">STAGE_UPLOADING</span> <span class="o">=</span> <span class="mi">4</span> | |||
<span class="n">STAGE_DONE</span> <span class="o">=</span> <span class="mi">5</span> | |||
<span class="n">STAGE_ERROR</span> <span class="o">=</span> <span class="mi">98</span> | |||
<span class="n">STAGE_DEBUG</span> <span class="o">=</span> <span class="mi">99</span> | |||
<span class="c"># FIXME: Rewrite this monstrosity.</span> | |||
<span class="nd">@staticmethod</span> | |||
<div class="viewcode-block" id="Firmware.upload"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.util.Firmware.upload">[docs]</a> <span class="k">def</span> <span class="nf">upload</span><span class="p">(</span><span class="n">dev</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">progress_callback</span><span class="o">=</span><span class="bp">None</span><span class="p">):</span> | |||
<div class="viewcode-block" id="Firmware.upload"><a class="viewcode-back" href="../../alarmdecoder.html#alarmdecoder.util.Firmware.upload">[docs]</a> <span class="k">def</span> <span class="nf">upload</span><span class="p">(</span><span class="n">dev</span><span class="p">,</span> <span class="n">filename</span><span class="p">,</span> <span class="n">progress_callback</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">debug</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span> | |||
<span class="sd">"""</span> | |||
<span class="sd"> Uploads firmware to an `AlarmDecoder`_ device.</span> | |||
@@ -119,15 +136,29 @@ | |||
<span class="sd"> Perform the actual firmware upload to the device.</span> | |||
<span class="sd"> """</span> | |||
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span> <span class="k">as</span> <span class="n">upload_file</span><span class="p">:</span> | |||
<span class="n">line_cnt</span> <span class="o">=</span> <span class="mi">0</span> | |||
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">upload_file</span><span class="p">:</span> | |||
<span class="n">line_cnt</span> <span class="o">+=</span> <span class="mi">1</span> | |||
<span class="n">line</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">rstrip</span><span class="p">()</span> | |||
<span class="k">if</span> <span class="n">line</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">==</span> <span class="s">':'</span><span class="p">:</span> | |||
<span class="n">dev</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span> <span class="o">+</span> <span class="s">"</span><span class="se">\r</span><span class="s">"</span><span class="p">)</span> | |||
<span class="n">dev</span><span class="o">.</span><span class="n">read_line</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="mf">10.0</span><span class="p">)</span> | |||
<span class="n">response</span> <span class="o">=</span> <span class="n">dev</span><span class="o">.</span><span class="n">read_line</span><span class="p">(</span><span class="n">timeout</span><span class="o">=</span><span class="mf">5.0</span><span class="p">,</span> <span class="n">purge_buffer</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">debug</span><span class="p">:</span> | |||
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_DEBUG</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="s">"line={0} - line={1} response={2}"</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">line_cnt</span><span class="p">,</span> <span class="n">line</span><span class="p">,</span> <span class="n">response</span><span class="p">));</span> | |||
<span class="k">if</span> <span class="s">'!ce'</span> <span class="ow">in</span> <span class="n">response</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">UploadChecksumError</span><span class="p">(</span><span class="s">"Checksum error on line "</span> <span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">line_cnt</span><span class="p">)</span> <span class="o">+</span> <span class="s">" of "</span> <span class="o">+</span> <span class="n">filename</span><span class="p">);</span> | |||
<span class="k">elif</span> <span class="s">'!no'</span> <span class="ow">in</span> <span class="n">response</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">UploadError</span><span class="p">(</span><span class="s">"Incorrect data sent to bootloader."</span><span class="p">)</span> | |||
<span class="k">elif</span> <span class="s">'!ok'</span> <span class="ow">in</span> <span class="n">response</span><span class="p">:</span> | |||
<span class="k">break</span> | |||
<span class="k">if</span> <span class="n">progress_callback</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="n">progress_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_UPLOADING</span><span class="p">)</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="k">if</span> <span class="n">progress_callback</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="n">progress_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_UPLOADING</span><span class="p">)</span> | |||
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.0</span><span class="p">)</span> | |||
@@ -149,6 +180,8 @@ | |||
<span class="n">position</span> <span class="o">=</span> <span class="mi">0</span> | |||
<span class="n">dev</span><span class="o">.</span><span class="n">purge</span><span class="p">()</span> | |||
<span class="k">while</span> <span class="n">timeout_event</span><span class="o">.</span><span class="n">reading</span><span class="p">:</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="n">char</span> <span class="o">=</span> <span class="n">dev</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> | |||
@@ -161,7 +194,7 @@ | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">position</span> <span class="o">=</span> <span class="mi">0</span> | |||
<span class="k">except</span> <span class="ne">Exception</span><span class="p">:</span> | |||
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="k">pass</span> | |||
<span class="k">if</span> <span class="n">timer</span><span class="p">:</span> | |||
@@ -170,10 +203,10 @@ | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">TimeoutError</span><span class="p">(</span><span class="s">'Timeout while waiting for line terminator.'</span><span class="p">)</span> | |||
<span class="k">def</span> <span class="nf">stage_callback</span><span class="p">(</span><span class="n">stage</span><span class="p">):</span> | |||
<span class="k">def</span> <span class="nf">stage_callback</span><span class="p">(</span><span class="n">stage</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span> | |||
<span class="sd">"""Callback to update progress for the specified stage."""</span> | |||
<span class="k">if</span> <span class="n">progress_callback</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="n">progress_callback</span><span class="p">(</span><span class="n">stage</span><span class="p">)</span> | |||
<span class="n">progress_callback</span><span class="p">(</span><span class="n">stage</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">dev</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span> | |||
<span class="k">raise</span> <span class="n">NoDeviceError</span><span class="p">(</span><span class="s">'No device specified for firmware upload.'</span><span class="p">)</span> | |||
@@ -186,24 +219,39 @@ | |||
<span class="n">dev</span><span class="o">.</span><span class="n">stop_reader</span><span class="p">()</span> | |||
<span class="k">while</span> <span class="n">dev</span><span class="o">.</span><span class="n">_read_thread</span><span class="o">.</span><span class="n">is_alive</span><span class="p">():</span> | |||
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_WAITING</span><span class="p">)</span> | |||
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span> | |||
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> | |||
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mf">0.5</span><span class="p">)</span> | |||
<span class="c"># Reboot the device and wait for the boot loader.</span> | |||
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_BOOT</span><span class="p">)</span> | |||
<span class="n">dev</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">"="</span><span class="p">)</span> | |||
<span class="n">read_until</span><span class="p">(</span><span class="s">'......'</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">15.0</span><span class="p">)</span> | |||
<span class="c"># Get ourselves into the boot loader and wait for indication</span> | |||
<span class="c"># that it's ready for the firmware upload.</span> | |||
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_LOAD</span><span class="p">)</span> | |||
<span class="n">dev</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">"="</span><span class="p">)</span> | |||
<span class="n">read_until</span><span class="p">(</span><span class="s">'!load'</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">15.0</span><span class="p">)</span> | |||
<span class="n">retry</span> <span class="o">=</span> <span class="mi">3</span> | |||
<span class="n">found_loader</span> <span class="o">=</span> <span class="bp">False</span> | |||
<span class="k">while</span> <span class="n">retry</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_BOOT</span><span class="p">)</span> | |||
<span class="n">dev</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">"="</span><span class="p">)</span> | |||
<span class="n">read_until</span><span class="p">(</span><span class="s">'!boot'</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">15.0</span><span class="p">)</span> | |||
<span class="c"># Get ourselves into the boot loader and wait for indication</span> | |||
<span class="c"># that it's ready for the firmware upload.</span> | |||
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_LOAD</span><span class="p">)</span> | |||
<span class="n">dev</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s">"="</span><span class="p">)</span> | |||
<span class="n">read_until</span><span class="p">(</span><span class="s">'!load'</span><span class="p">,</span> <span class="n">timeout</span><span class="o">=</span><span class="mf">15.0</span><span class="p">)</span> | |||
<span class="k">except</span> <span class="n">TimeoutError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="n">retry</span> <span class="o">-=</span> <span class="mi">1</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">retry</span> <span class="o">=</span> <span class="mi">0</span> | |||
<span class="n">found_loader</span> <span class="o">=</span> <span class="bp">True</span> | |||
<span class="c"># And finally do the upload.</span> | |||
<span class="n">do_upload</span><span class="p">()</span> | |||
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_DONE</span><span class="p">)</span></div></div> | |||
<span class="k">if</span> <span class="n">found_loader</span><span class="p">:</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="n">do_upload</span><span class="p">()</span> | |||
<span class="k">except</span> <span class="n">UploadError</span> <span class="k">as</span> <span class="n">err</span><span class="p">:</span> | |||
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_ERROR</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="nb">str</span><span class="p">(</span><span class="n">err</span><span class="p">))</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_DONE</span><span class="p">)</span> | |||
<span class="k">else</span><span class="p">:</span> | |||
<span class="n">stage_callback</span><span class="p">(</span><span class="n">Firmware</span><span class="o">.</span><span class="n">STAGE_ERROR</span><span class="p">,</span> <span class="n">error</span><span class="o">=</span><span class="s">"Error entering bootloader."</span><span class="p">)</span></div></div> | |||
</pre></div> | |||
</div> | |||
@@ -226,7 +226,7 @@ | |||
<span class="bp">self</span><span class="o">.</span><span class="n">_last_zone_fault</span> <span class="o">=</span> <span class="mi">0</span> | |||
<span class="c"># Process fault</span> | |||
<span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">check_zone</span> <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">"FAULT"</span><span class="p">):</span> | |||
<span class="k">elif</span> <span class="n">message</span><span class="o">.</span><span class="n">check_zone</span> <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">"FAULT"</span><span class="p">)</span> <span class="ow">or</span> <span class="n">message</span><span class="o">.</span><span class="n">text</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s">"ALARM"</span><span class="p">):</span> | |||
<span class="c"># Apparently this representation can be both base 10</span> | |||
<span class="c"># or base 16, depending on where the message came</span> | |||
<span class="c"># from.</span> | |||
@@ -307,7 +307,7 @@ | |||
<span class="n">it</span> <span class="o">=</span> <span class="nb">iter</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_zones_faulted</span><span class="p">)</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="k">while</span> <span class="ow">not</span> <span class="n">found_last_faulted</span><span class="p">:</span> | |||
<span class="n">z</span> <span class="o">=</span> <span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> | |||
<span class="n">z</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="n">it</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">z</span> <span class="o">==</span> <span class="bp">self</span><span class="o">.</span><span class="n">_last_zone_fault</span><span class="p">:</span> | |||
<span class="n">found_last_faulted</span> <span class="o">=</span> <span class="bp">True</span> | |||
@@ -320,7 +320,7 @@ | |||
<span class="c"># between to our clear list.</span> | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="k">while</span> <span class="ow">not</span> <span class="n">at_end</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">found_current</span><span class="p">:</span> | |||
<span class="n">z</span> <span class="o">=</span> <span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> | |||
<span class="n">z</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="n">it</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">z</span> <span class="o">==</span> <span class="n">zone</span><span class="p">:</span> | |||
<span class="n">found_current</span> <span class="o">=</span> <span class="bp">True</span> | |||
@@ -338,7 +338,7 @@ | |||
<span class="k">try</span><span class="p">:</span> | |||
<span class="k">while</span> <span class="ow">not</span> <span class="n">found_current</span><span class="p">:</span> | |||
<span class="n">z</span> <span class="o">=</span> <span class="n">it</span><span class="o">.</span><span class="n">next</span><span class="p">()</span> | |||
<span class="n">z</span> <span class="o">=</span> <span class="nb">next</span><span class="p">(</span><span class="n">it</span><span class="p">)</span> | |||
<span class="k">if</span> <span class="n">z</span> <span class="o">==</span> <span class="n">zone</span><span class="p">:</span> | |||
<span class="n">found_current</span> <span class="o">=</span> <span class="bp">True</span> | |||
@@ -359,7 +359,7 @@ | |||
<span class="sd"> """</span> | |||
<span class="n">zones</span> <span class="o">=</span> <span class="p">[]</span> | |||
<span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">_zones</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span> | |||
<span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="nb">list</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">_zones</span><span class="o">.</span><span class="n">keys</span><span class="p">()):</span> | |||
<span class="n">zones</span> <span class="o">+=</span> <span class="p">[</span><span class="n">z</span><span class="p">]</span> | |||
<span class="k">for</span> <span class="n">z</span> <span class="ow">in</span> <span class="n">zones</span><span class="p">:</span> | |||
@@ -309,6 +309,24 @@ | |||
<dd><p>The panel mode that the AlarmDecoder is in. Currently supports ADEMCO and DSC.</p> | |||
</dd></dl> | |||
<dl class="attribute"> | |||
<dt id="alarmdecoder.decoder.AlarmDecoder.serial_number"> | |||
<tt class="descname">serial_number</tt><em class="property"> = 4294967295</em><a class="headerlink" href="#alarmdecoder.decoder.AlarmDecoder.serial_number" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>The device serial number</p> | |||
</dd></dl> | |||
<dl class="attribute"> | |||
<dt id="alarmdecoder.decoder.AlarmDecoder.version_number"> | |||
<tt class="descname">version_number</tt><em class="property"> = 'Unknown'</em><a class="headerlink" href="#alarmdecoder.decoder.AlarmDecoder.version_number" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>The device firmware version</p> | |||
</dd></dl> | |||
<dl class="attribute"> | |||
<dt id="alarmdecoder.decoder.AlarmDecoder.version_flags"> | |||
<tt class="descname">version_flags</tt><em class="property"> = ''</em><a class="headerlink" href="#alarmdecoder.decoder.AlarmDecoder.version_flags" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>Device flags enabled</p> | |||
</dd></dl> | |||
<dl class="attribute"> | |||
<dt id="alarmdecoder.decoder.AlarmDecoder.id"> | |||
<tt class="descname">id</tt><a class="reference internal" href="_modules/alarmdecoder/decoder.html#AlarmDecoder.id"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.decoder.AlarmDecoder.id" title="Permalink to this definition">¶</a></dt> | |||
@@ -416,6 +434,17 @@ thread should be started.</li> | |||
<dd><p>Sets configuration entries on the device.</p> | |||
</dd></dl> | |||
<dl class="method"> | |||
<dt id="alarmdecoder.decoder.AlarmDecoder.get_config_string"> | |||
<tt class="descname">get_config_string</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/alarmdecoder/decoder.html#AlarmDecoder.get_config_string"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.decoder.AlarmDecoder.get_config_string" title="Permalink to this definition">¶</a></dt> | |||
<dd></dd></dl> | |||
<dl class="method"> | |||
<dt id="alarmdecoder.decoder.AlarmDecoder.get_version"> | |||
<tt class="descname">get_version</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/alarmdecoder/decoder.html#AlarmDecoder.get_version"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.decoder.AlarmDecoder.get_version" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>Retrieves the version string from the device. Called automatically by <tt class="xref py py-meth docutils literal"><span class="pre">_on_open()</span></tt>.</p> | |||
</dd></dl> | |||
<dl class="method"> | |||
<dt id="alarmdecoder.decoder.AlarmDecoder.reboot"> | |||
<tt class="descname">reboot</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/alarmdecoder/decoder.html#AlarmDecoder.reboot"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.decoder.AlarmDecoder.reboot" title="Permalink to this definition">¶</a></dt> | |||
@@ -813,6 +842,12 @@ reading.</li> | |||
</table> | |||
</dd></dl> | |||
<dl class="method"> | |||
<dt id="alarmdecoder.devices.USBDevice.purge"> | |||
<tt class="descname">purge</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/alarmdecoder/devices.html#USBDevice.purge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.devices.USBDevice.purge" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>Purges read/write buffers.</p> | |||
</dd></dl> | |||
<dl class="class"> | |||
<dt id="alarmdecoder.devices.USBDevice.DetectThread"> | |||
<em class="property">class </em><tt class="descname">DetectThread</tt><big>(</big><em>on_attached=None</em>, <em>on_detached=None</em><big>)</big><a class="reference internal" href="_modules/alarmdecoder/devices.html#USBDevice.DetectThread"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.devices.USBDevice.DetectThread" title="Permalink to this definition">¶</a></dt> | |||
@@ -981,6 +1016,12 @@ reading.</li> | |||
</table> | |||
</dd></dl> | |||
<dl class="method"> | |||
<dt id="alarmdecoder.devices.SerialDevice.purge"> | |||
<tt class="descname">purge</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/alarmdecoder/devices.html#SerialDevice.purge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.devices.SerialDevice.purge" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>Purges read/write buffers.</p> | |||
</dd></dl> | |||
</dd></dl> | |||
<dl class="class"> | |||
@@ -1152,6 +1193,12 @@ reading.</li> | |||
</table> | |||
</dd></dl> | |||
<dl class="method"> | |||
<dt id="alarmdecoder.devices.SocketDevice.purge"> | |||
<tt class="descname">purge</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/alarmdecoder/devices.html#SocketDevice.purge"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.devices.SocketDevice.purge" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>Purges read/write buffers.</p> | |||
</dd></dl> | |||
</dd></dl> | |||
</div> | |||
@@ -1656,6 +1703,20 @@ devices.</p> | |||
<p>The format of the panel message was invalid.</p> | |||
</dd></dl> | |||
<dl class="exception"> | |||
<dt id="alarmdecoder.util.UploadError"> | |||
<em class="property">exception </em><tt class="descclassname">alarmdecoder.util.</tt><tt class="descname">UploadError</tt><a class="reference internal" href="_modules/alarmdecoder/util.html#UploadError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.util.UploadError" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>Bases: <tt class="xref py py-class docutils literal"><span class="pre">exceptions.Exception</span></tt></p> | |||
<p>Generic firmware upload error.</p> | |||
</dd></dl> | |||
<dl class="exception"> | |||
<dt id="alarmdecoder.util.UploadChecksumError"> | |||
<em class="property">exception </em><tt class="descclassname">alarmdecoder.util.</tt><tt class="descname">UploadChecksumError</tt><a class="reference internal" href="_modules/alarmdecoder/util.html#UploadChecksumError"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.util.UploadChecksumError" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>Bases: <a class="reference internal" href="#alarmdecoder.util.UploadError" title="alarmdecoder.util.UploadError"><tt class="xref py py-class docutils literal"><span class="pre">alarmdecoder.util.UploadError</span></tt></a></p> | |||
<p>The firmware upload failed due to a checksum error.</p> | |||
</dd></dl> | |||
<dl class="class"> | |||
<dt id="alarmdecoder.util.Firmware"> | |||
<em class="property">class </em><tt class="descclassname">alarmdecoder.util.</tt><tt class="descname">Firmware</tt><a class="reference internal" href="_modules/alarmdecoder/util.html#Firmware"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.util.Firmware" title="Permalink to this definition">¶</a></dt> | |||
@@ -1691,9 +1752,19 @@ devices.</p> | |||
<tt class="descname">STAGE_DONE</tt><em class="property"> = 5</em><a class="headerlink" href="#alarmdecoder.util.Firmware.STAGE_DONE" title="Permalink to this definition">¶</a></dt> | |||
<dd></dd></dl> | |||
<dl class="attribute"> | |||
<dt id="alarmdecoder.util.Firmware.STAGE_ERROR"> | |||
<tt class="descname">STAGE_ERROR</tt><em class="property"> = 98</em><a class="headerlink" href="#alarmdecoder.util.Firmware.STAGE_ERROR" title="Permalink to this definition">¶</a></dt> | |||
<dd></dd></dl> | |||
<dl class="attribute"> | |||
<dt id="alarmdecoder.util.Firmware.STAGE_DEBUG"> | |||
<tt class="descname">STAGE_DEBUG</tt><em class="property"> = 99</em><a class="headerlink" href="#alarmdecoder.util.Firmware.STAGE_DEBUG" title="Permalink to this definition">¶</a></dt> | |||
<dd></dd></dl> | |||
<dl class="staticmethod"> | |||
<dt id="alarmdecoder.util.Firmware.upload"> | |||
<em class="property">static </em><tt class="descname">upload</tt><big>(</big><em>dev</em>, <em>filename</em>, <em>progress_callback=None</em><big>)</big><a class="reference internal" href="_modules/alarmdecoder/util.html#Firmware.upload"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.util.Firmware.upload" title="Permalink to this definition">¶</a></dt> | |||
<em class="property">static </em><tt class="descname">upload</tt><big>(</big><em>dev</em>, <em>filename</em>, <em>progress_callback=None</em>, <em>debug=False</em><big>)</big><a class="reference internal" href="_modules/alarmdecoder/util.html#Firmware.upload"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#alarmdecoder.util.Firmware.upload" title="Permalink to this definition">¶</a></dt> | |||
<dd><p>Uploads firmware to an <a class="reference external" href="http://www.alarmdecoder.com">AlarmDecoder</a> device.</p> | |||
<table class="docutils field-list" frame="void" rules="none"> | |||
<col class="field-name" /> | |||
@@ -467,6 +467,16 @@ | |||
<dt><a href="alarmdecoder.html#alarmdecoder.decoder.AlarmDecoder.get_config">get_config() (alarmdecoder.decoder.AlarmDecoder method)</a> | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.decoder.AlarmDecoder.get_config_string">get_config_string() (alarmdecoder.decoder.AlarmDecoder method)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.decoder.AlarmDecoder.get_version">get_version() (alarmdecoder.decoder.AlarmDecoder method)</a> | |||
</dt> | |||
</dl></td> | |||
</tr></table> | |||
@@ -771,12 +781,12 @@ | |||
<dt><a href="alarmdecoder.html#alarmdecoder.messages.LRRMessage.partition">partition (alarmdecoder.messages.LRRMessage attribute)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.messages.Message.perimeter_only">perimeter_only (alarmdecoder.messages.Message attribute)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.devices.USBDevice.PRODUCT_IDS">PRODUCT_IDS (alarmdecoder.devices.USBDevice attribute)</a> | |||
</dt> | |||
@@ -785,6 +795,20 @@ | |||
<dt><a href="alarmdecoder.html#alarmdecoder.messages.Message.programming_mode">programming_mode (alarmdecoder.messages.Message attribute)</a> | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.devices.SerialDevice.purge">purge() (alarmdecoder.devices.SerialDevice method)</a> | |||
</dt> | |||
<dd><dl> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.devices.SocketDevice.purge">(alarmdecoder.devices.SocketDevice method)</a> | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.devices.USBDevice.purge">(alarmdecoder.devices.USBDevice method)</a> | |||
</dt> | |||
</dl></dd> | |||
</dl></td> | |||
</tr></table> | |||
@@ -874,11 +898,15 @@ | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.devices.USBDevice.serial_number">serial_number (alarmdecoder.devices.USBDevice attribute)</a> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.decoder.AlarmDecoder.serial_number">serial_number (alarmdecoder.decoder.AlarmDecoder attribute)</a> | |||
</dt> | |||
<dd><dl> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.devices.USBDevice.serial_number">(alarmdecoder.devices.USBDevice attribute)</a> | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.messages.RFMessage.serial_number">(alarmdecoder.messages.RFMessage attribute)</a> | |||
</dt> | |||
@@ -912,16 +940,24 @@ | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.util.Firmware.STAGE_DEBUG">STAGE_DEBUG (alarmdecoder.util.Firmware attribute)</a> | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.util.Firmware.STAGE_DONE">STAGE_DONE (alarmdecoder.util.Firmware attribute)</a> | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.util.Firmware.STAGE_LOAD">STAGE_LOAD (alarmdecoder.util.Firmware attribute)</a> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.util.Firmware.STAGE_ERROR">STAGE_ERROR (alarmdecoder.util.Firmware attribute)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.util.Firmware.STAGE_LOAD">STAGE_LOAD (alarmdecoder.util.Firmware attribute)</a> | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.util.Firmware.STAGE_START">STAGE_START (alarmdecoder.util.Firmware attribute)</a> | |||
</dt> | |||
@@ -1015,9 +1051,17 @@ | |||
<dt><a href="alarmdecoder.html#alarmdecoder.util.Firmware.upload">upload() (alarmdecoder.util.Firmware static method)</a> | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.util.UploadChecksumError">UploadChecksumError</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.util.UploadError">UploadError</a> | |||
</dt> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.devices.USBDevice">USBDevice (class in alarmdecoder.devices)</a> | |||
</dt> | |||
@@ -1041,6 +1085,16 @@ | |||
</dt> | |||
</dl></dd> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.decoder.AlarmDecoder.version_flags">version_flags (alarmdecoder.decoder.AlarmDecoder attribute)</a> | |||
</dt> | |||
</dl></td> | |||
<td style="width: 33%" valign="top"><dl> | |||
<dt><a href="alarmdecoder.html#alarmdecoder.decoder.AlarmDecoder.version_number">version_number (alarmdecoder.decoder.AlarmDecoder attribute)</a> | |||
</dt> | |||
</dl></td> | |||
</tr></table> | |||
@@ -14,12 +14,12 @@ if sys.version_info < (3,): | |||
extra_requirements.append('future==0.14.3') | |||
setup(name='alarmdecoder', | |||
version='0.10.3', | |||
version='0.11.0', | |||
description='Python interface for the AlarmDecoder (AD2) family ' | |||
'of alarm devices which includes the AD2USB, AD2SERIAL and AD2PI.', | |||
long_description=readme(), | |||
classifiers=[ | |||
'Development Status :: 4 - Beta', | |||
'Development Status :: 5 - Production/Stable', | |||
'License :: OSI Approved :: MIT License', | |||
'Programming Language :: Python :: 2.7', | |||
'Topic :: Software Development :: Libraries :: Python Modules', | |||