stringtools/_docs_/index.html

463 lines
46 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to stringtoolss documentation! &#8212; stringtools documentation</title>
<link rel="stylesheet" href="_static/alabaster.css" type="text/css" />
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: './',
VERSION: '',
COLLAPSE_INDEX: false,
FILE_SUFFIX: '.html',
HAS_SOURCE: true,
SOURCELINK_SUFFIX: '.txt'
};
</script>
<script type="text/javascript" src="_static/jquery.js"></script>
<script type="text/javascript" src="_static/underscore.js"></script>
<script type="text/javascript" src="_static/doctools.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="stylesheet" href="_static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
</head>
<body>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="section" id="module-stringtools">
<span id="welcome-to-stringtools-s-documentation"></span><h1>Welcome to stringtoolss documentation!<a class="headerlink" href="#module-stringtools" title="Permalink to this headline"></a></h1>
<div class="section" id="stringtools-stringtools">
<h2>stringtools (Stringtools)<a class="headerlink" href="#stringtools-stringtools" title="Permalink to this headline"></a></h2>
<p><strong>Author:</strong></p>
<ul class="simple">
<li>Dirk Alders &lt;<a class="reference external" href="mailto:sudo-dirk&#37;&#52;&#48;mount-mockery&#46;de">sudo-dirk<span>&#64;</span>mount-mockery<span>&#46;</span>de</a>&gt;</li>
</ul>
<p><strong>Description:</strong></p>
<blockquote>
<div>This Module supports functionality around string operations.</div></blockquote>
<p><strong>Submodules:</strong></p>
<ul class="simple">
<li><a class="reference internal" href="#module-stringtools.csp" title="stringtools.csp"><code class="xref py py-mod docutils literal"><span class="pre">stringtools.csp</span></code></a></li>
<li><a class="reference internal" href="#module-stringtools.stp" title="stringtools.stp"><code class="xref py py-mod docutils literal"><span class="pre">stringtools.stp</span></code></a></li>
<li><a class="reference internal" href="#stringtools.gzip_compress" title="stringtools.gzip_compress"><code class="xref py py-func docutils literal"><span class="pre">gzip_compress()</span></code></a></li>
<li><a class="reference internal" href="#stringtools.gzip_extract" title="stringtools.gzip_extract"><code class="xref py py-func docutils literal"><span class="pre">gzip_extract()</span></code></a></li>
<li><a class="reference internal" href="#stringtools.hexlify" title="stringtools.hexlify"><code class="xref py py-func docutils literal"><span class="pre">hexlify()</span></code></a></li>
</ul>
<p><strong>Unittest:</strong></p>
<blockquote>
<div>See also the <a class="reference download internal" href="_downloads/unittest.pdf" download=""><code class="xref download docutils literal"><span class="pre">unittest</span></code></a> documentation.</div></blockquote>
<p><strong>Module Documentation:</strong></p>
<dl class="function">
<dt id="stringtools.gzip_compress">
<code class="descclassname">stringtools.</code><code class="descname">gzip_compress</code><span class="sig-paren">(</span><em>s</em>, <em>compresslevel=9</em><span class="sig-paren">)</span><a class="headerlink" href="#stringtools.gzip_compress" title="Permalink to this definition"></a></dt>
<dd><p>Method to compress a stream of bytes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>s</strong> (<em>str</em>) The bytestream (string) to be compressed</li>
<li><strong>compresslevel</strong> (<em>int</em>) An optional compressionn level (default is 9)</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The compressed bytestream</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">str</p>
</td>
</tr>
</tbody>
</table>
<p><strong>Example:</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">stringtools</span>
<span class="kn">import</span> <span class="nn">report</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="n">logger</span> <span class="o">=</span> <span class="n">report</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;example&#39;</span><span class="p">,</span> <span class="p">[(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">,</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">))],</span> <span class="n">report</span><span class="o">.</span><span class="n">SHORT_FMT</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">gzip_compress</span><span class="p">(</span><span class="mi">15</span> <span class="o">*</span> <span class="sa">b</span><span class="s1">&#39;</span><span class="se">\x00</span><span class="s1">&#39;</span> <span class="o">+</span> <span class="mi">15</span> <span class="o">*</span> <span class="sa">b</span><span class="s1">&#39;</span><span class="se">\xff</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">logger</span><span class="o">=</span><span class="n">logger</span><span class="p">)))</span>
</pre></div>
</div>
<p>Will result to the following output:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">19</span><span class="p">:</span><span class="mi">14</span><span class="p">:</span><span class="mi">02</span><span class="p">,</span><span class="mi">852</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">Finished</span> <span class="n">to</span> <span class="n">compress</span> <span class="n">a</span> <span class="n">string</span> <span class="p">(</span><span class="n">compression_rate</span><span class="o">=</span><span class="mf">0.867</span><span class="p">,</span> <span class="n">consumed_time</span><span class="o">=</span><span class="mf">0.0</span><span class="n">s</span><span class="p">)</span><span class="o">.</span>
<span class="p">(</span><span class="mi">26</span><span class="p">):</span> <span class="mi">1</span><span class="n">f</span> <span class="mi">8</span><span class="n">b</span> <span class="mi">08</span> <span class="mi">00</span> <span class="mi">5</span><span class="n">a</span> <span class="mi">83</span> <span class="n">e5</span> <span class="mi">5</span><span class="n">c</span> <span class="mi">02</span> <span class="n">ff</span> <span class="mi">63</span> <span class="mi">60</span> <span class="mi">40</span> <span class="mi">01</span> <span class="n">ff</span> <span class="mi">51</span> <span class="mi">01</span> <span class="mi">00</span> <span class="mi">2</span><span class="n">d</span> <span class="mi">8</span><span class="n">a</span> <span class="mi">7</span><span class="n">d</span> <span class="n">de</span> <span class="mi">1</span><span class="n">e</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="stringtools.gzip_extract">
<code class="descclassname">stringtools.</code><code class="descname">gzip_extract</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#stringtools.gzip_extract" title="Permalink to this definition"></a></dt>
<dd><p>Method to extract data from a compress stream of bytes.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>s</strong> (<em>str</em>) The compressed bytestream (string) to be extracted</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The extracted data</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
</tr>
</tbody>
</table>
<p><strong>Example:</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">stringtools</span>
<span class="kn">import</span> <span class="nn">report</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="n">logger</span> <span class="o">=</span> <span class="n">report</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;example&#39;</span><span class="p">,</span> <span class="p">[(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">,</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">))],</span> <span class="n">report</span><span class="o">.</span><span class="n">SHORT_FMT</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">gzip_extract</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;</span><span class="se">\x1f\x8b\x08\x00\xd0\x82\xe5\x5c\x02\xff\x63\x60\x40\x01\xff\x51\x01\x00\x2d\x8a\x7d\xde\x1e\x00\x00\x00</span><span class="s1">&#39;</span><span class="p">,</span> <span class="n">logger</span><span class="o">=</span><span class="n">logger</span><span class="p">)))</span>
</pre></div>
</div>
<p>Will result to the following output:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">19</span><span class="p">:</span><span class="mi">14</span><span class="p">:</span><span class="mi">09</span><span class="p">,</span><span class="mi">390</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">Finished</span> <span class="n">to</span> <span class="n">extract</span> <span class="n">a</span> <span class="n">string</span> <span class="p">(</span><span class="n">compression_rate</span><span class="o">=</span><span class="mf">0.867</span><span class="p">,</span> <span class="n">consumed_time</span><span class="o">=</span><span class="mf">0.0</span><span class="n">s</span><span class="p">)</span><span class="o">.</span>
<span class="p">(</span><span class="mi">30</span><span class="p">):</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="mi">00</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span> <span class="n">ff</span>
</pre></div>
</div>
</dd></dl>
<dl class="function">
<dt id="stringtools.hexlify">
<code class="descclassname">stringtools.</code><code class="descname">hexlify</code><span class="sig-paren">(</span><em>s</em><span class="sig-paren">)</span><a class="headerlink" href="#stringtools.hexlify" title="Permalink to this definition"></a></dt>
<dd><p>Method to hexlify a string.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>s</strong> (<em>str</em>) A string including the bytes to be hexlified.</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The hexlified string</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
</tr>
</tbody>
</table>
<p><strong>Example:</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">stringtools</span>
<span class="nb">print</span><span class="p">(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;A stringexample with non printable characters like </span><span class="se">\x12</span><span class="s1">&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>Will result to the following output:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">(</span><span class="mi">52</span><span class="p">):</span> <span class="mi">41</span> <span class="mi">20</span> <span class="mi">73</span> <span class="mi">74</span> <span class="mi">72</span> <span class="mi">69</span> <span class="mi">6</span><span class="n">e</span> <span class="mi">67</span> <span class="mi">65</span> <span class="mi">78</span> <span class="mi">61</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">70</span> <span class="mi">6</span><span class="n">c</span> <span class="mi">65</span> <span class="mi">20</span> <span class="mi">77</span> <span class="mi">69</span> <span class="mi">74</span> <span class="mi">68</span> <span class="mi">20</span> <span class="mi">6</span><span class="n">e</span> <span class="mi">6</span><span class="n">f</span> <span class="mi">6</span><span class="n">e</span> <span class="mi">20</span> <span class="mi">70</span> <span class="mi">72</span> <span class="mi">69</span> <span class="mi">6</span><span class="n">e</span> <span class="mi">74</span> <span class="mi">61</span> <span class="mi">62</span> <span class="mi">6</span><span class="n">c</span> <span class="mi">65</span> <span class="mi">20</span> <span class="mi">63</span> <span class="mi">68</span> <span class="mi">61</span> <span class="mi">72</span> <span class="mi">61</span> <span class="mi">63</span> <span class="mi">74</span> <span class="mi">65</span> <span class="mi">72</span> <span class="mi">73</span> <span class="mi">20</span> <span class="mi">6</span><span class="n">c</span> <span class="mi">69</span> <span class="mi">6</span><span class="n">b</span> <span class="mi">65</span> <span class="mi">20</span> <span class="mi">12</span>
</pre></div>
</div>
</dd></dl>
</div>
<span class="target" id="module-stringtools.csp"></span><div class="section" id="csp-carriage-return-seperation-protocol">
<h2>csp (Carriage-Return seperation protocol)<a class="headerlink" href="#csp-carriage-return-seperation-protocol" title="Permalink to this headline"></a></h2>
<p><strong>Author:</strong></p>
<ul class="simple">
<li>Dirk Alders &lt;<a class="reference external" href="mailto:sudo-dirk&#37;&#52;&#48;mount-mockery&#46;de">sudo-dirk<span>&#64;</span>mount-mockery<span>&#46;</span>de</a>&gt;</li>
</ul>
<p><strong>Description:</strong></p>
<blockquote>
<div>This module is a submodule of <a class="reference internal" href="#module-stringtools" title="stringtools"><code class="xref py py-mod docutils literal"><span class="pre">stringtools</span></code></a> and creates an frame to transmit and receive messages via an serial interface.</div></blockquote>
<p><strong>Submodules:</strong></p>
<ul class="simple">
<li><a class="reference internal" href="#stringtools.csp.csp" title="stringtools.csp.csp"><code class="xref py py-class docutils literal"><span class="pre">stringtools.csp.csp</span></code></a></li>
<li><a class="reference internal" href="#stringtools.csp.build_frame" title="stringtools.csp.build_frame"><code class="xref py py-func docutils literal"><span class="pre">stringtools.csp.build_frame()</span></code></a></li>
</ul>
<dl class="function">
<dt id="stringtools.csp.build_frame">
<code class="descclassname">stringtools.csp.</code><code class="descname">build_frame</code><span class="sig-paren">(</span><em>msg</em>, <em>seperator='\n'</em><span class="sig-paren">)</span><a class="headerlink" href="#stringtools.csp.build_frame" title="Permalink to this definition"></a></dt>
<dd><p>This Method builds an “csp-frame” to be transfered via a stream.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> (<em>str</em>) A String (Bytes) to be framed</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The “csp-framed” message to be sent</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
</tr>
</tbody>
</table>
<p><strong>Example:</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">stringtools</span>
<span class="n">data</span> <span class="o">=</span> <span class="sa">b</span><span class="s1">&#39;message&#39;</span>
<span class="nb">print</span><span class="p">(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="n">data</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">hexlify</span><span class="p">(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">csp</span><span class="o">.</span><span class="n">build_frame</span><span class="p">(</span><span class="n">data</span><span class="p">)))</span>
</pre></div>
</div>
<p>Will result to the following output:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="p">(</span><span class="mi">7</span><span class="p">):</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">65</span> <span class="mi">73</span> <span class="mi">73</span> <span class="mi">61</span> <span class="mi">67</span> <span class="mi">65</span>
<span class="p">(</span><span class="mi">8</span><span class="p">):</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">65</span> <span class="mi">73</span> <span class="mi">73</span> <span class="mi">61</span> <span class="mi">67</span> <span class="mi">65</span> <span class="mi">0</span><span class="n">a</span>
</pre></div>
</div>
</dd></dl>
<dl class="class">
<dt id="stringtools.csp.csp">
<em class="property">class </em><code class="descclassname">stringtools.csp.</code><code class="descname">csp</code><span class="sig-paren">(</span><em>seperator='n'</em><span class="sig-paren">)</span><a class="headerlink" href="#stringtools.csp.csp" title="Permalink to this definition"></a></dt>
<dd><p>This class extracts messages from an “csp-stream”.</p>
<p><strong>Example:</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">report</span>
<span class="kn">import</span> <span class="nn">stringtools</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="n">logger</span> <span class="o">=</span> <span class="n">report</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;example&#39;</span><span class="p">,</span> <span class="p">[(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">,</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">))],</span> <span class="n">report</span><span class="o">.</span><span class="n">SHORT_FMT</span><span class="p">)</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">stringtools</span><span class="o">.</span><span class="n">csp</span><span class="o">.</span><span class="n">csp</span><span class="p">()</span>
<span class="k">for</span> <span class="n">byte</span> <span class="ow">in</span> <span class="sa">b</span><span class="s1">&#39;message</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">byte</span><span class="p">,</span> <span class="n">logger</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="kc">None</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<p>Will result to the following output:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">41</span><span class="p">:</span><span class="mi">54</span><span class="p">,</span><span class="mi">305</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Adding</span> <span class="sa">b</span><span class="s1">&#39;m&#39;</span> <span class="n">to</span> <span class="n">buffer</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">41</span><span class="p">:</span><span class="mi">54</span><span class="p">,</span><span class="mi">305</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Adding</span> <span class="sa">b</span><span class="s1">&#39;e&#39;</span> <span class="n">to</span> <span class="n">buffer</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">41</span><span class="p">:</span><span class="mi">54</span><span class="p">,</span><span class="mi">305</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Adding</span> <span class="sa">b</span><span class="s1">&#39;s&#39;</span> <span class="n">to</span> <span class="n">buffer</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">41</span><span class="p">:</span><span class="mi">54</span><span class="p">,</span><span class="mi">305</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Adding</span> <span class="sa">b</span><span class="s1">&#39;s&#39;</span> <span class="n">to</span> <span class="n">buffer</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">41</span><span class="p">:</span><span class="mi">54</span><span class="p">,</span><span class="mi">305</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Adding</span> <span class="sa">b</span><span class="s1">&#39;a&#39;</span> <span class="n">to</span> <span class="n">buffer</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">41</span><span class="p">:</span><span class="mi">54</span><span class="p">,</span><span class="mi">305</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Adding</span> <span class="sa">b</span><span class="s1">&#39;g&#39;</span> <span class="n">to</span> <span class="n">buffer</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">41</span><span class="p">:</span><span class="mi">54</span><span class="p">,</span><span class="mi">305</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Adding</span> <span class="sa">b</span><span class="s1">&#39;e&#39;</span> <span class="n">to</span> <span class="n">buffer</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">41</span><span class="p">:</span><span class="mi">54</span><span class="p">,</span><span class="mi">305</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Message</span> <span class="n">identified</span> <span class="n">by</span> <span class="n">seperator</span> <span class="mi">0</span><span class="n">a</span>
<span class="sa">b</span><span class="s1">&#39;message&#39;</span>
</pre></div>
</div>
<dl class="method">
<dt id="stringtools.csp.csp.process">
<code class="descname">process</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#stringtools.csp.csp.process" title="Permalink to this definition"></a></dt>
<dd><p>This processes a byte out of a “stp-stream”.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> (<em>bytes</em>) A byte stream</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">A list of the extracted message(s)</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
<span class="target" id="module-stringtools.stp"></span><div class="section" id="stp-serial-transfer-protocol">
<h2>stp (Serial transfer protocol)<a class="headerlink" href="#stp-serial-transfer-protocol" title="Permalink to this headline"></a></h2>
<p><strong>Author:</strong></p>
<ul class="simple">
<li>Dirk Alders &lt;<a class="reference external" href="mailto:sudo-dirk&#37;&#52;&#48;mount-mockery&#46;de">sudo-dirk<span>&#64;</span>mount-mockery<span>&#46;</span>de</a>&gt;</li>
</ul>
<p><strong>Description:</strong></p>
<blockquote>
<div>This module is a submodule of <a class="reference internal" href="#module-stringtools" title="stringtools"><code class="xref py py-mod docutils literal"><span class="pre">stringtools</span></code></a> and creates an serial frame to transmit and receive messages via an serial interface.</div></blockquote>
<p><strong>Submodules:</strong></p>
<ul class="simple">
<li><a class="reference internal" href="#stringtools.stp.stp" title="stringtools.stp.stp"><code class="xref py py-class docutils literal"><span class="pre">stringtools.stp.stp</span></code></a></li>
<li><a class="reference internal" href="#stringtools.stp.build_frame" title="stringtools.stp.build_frame"><code class="xref py py-func docutils literal"><span class="pre">stringtools.stp.build_frame()</span></code></a></li>
</ul>
<dl class="data">
<dt id="stringtools.stp.DATA_CLEAR_BUFFER">
<code class="descclassname">stringtools.stp.</code><code class="descname">DATA_CLEAR_BUFFER</code><em class="property"> = '&lt;'</em><a class="headerlink" href="#stringtools.stp.DATA_CLEAR_BUFFER" title="Permalink to this definition"></a></dt>
<dd><p>The clear buffer byte (\x3a\x3c -&gt; start of message)</p>
</dd></dl>
<dl class="data">
<dt id="stringtools.stp.DATA_STORE_SYNC_VALUE">
<code class="descclassname">stringtools.stp.</code><code class="descname">DATA_STORE_SYNC_VALUE</code><em class="property"> = '='</em><a class="headerlink" href="#stringtools.stp.DATA_STORE_SYNC_VALUE" title="Permalink to this definition"></a></dt>
<dd><p>The store sync value byte (\x3a\x3d -&gt; \x3a inside a message)</p>
</dd></dl>
<dl class="data">
<dt id="stringtools.stp.DATA_SYNC">
<code class="descclassname">stringtools.stp.</code><code class="descname">DATA_SYNC</code><em class="property"> = ':'</em><a class="headerlink" href="#stringtools.stp.DATA_SYNC" title="Permalink to this definition"></a></dt>
<dd><p>The data sync byte</p>
</dd></dl>
<dl class="data">
<dt id="stringtools.stp.DATA_VALID_MSG">
<code class="descclassname">stringtools.stp.</code><code class="descname">DATA_VALID_MSG</code><em class="property"> = '&gt;'</em><a class="headerlink" href="#stringtools.stp.DATA_VALID_MSG" title="Permalink to this definition"></a></dt>
<dd><p>The valid message byte (\x3a\x3e -&gt; end of message)</p>
</dd></dl>
<dl class="data">
<dt id="stringtools.stp.STP_STATE_ESCAPE_1">
<code class="descclassname">stringtools.stp.</code><code class="descname">STP_STATE_ESCAPE_1</code><em class="property"> = 1</em><a class="headerlink" href="#stringtools.stp.STP_STATE_ESCAPE_1" title="Permalink to this definition"></a></dt>
<dd><p>Escape 1 state definition (\x3a\x3c found)</p>
</dd></dl>
<dl class="data">
<dt id="stringtools.stp.STP_STATE_ESCAPE_2">
<code class="descclassname">stringtools.stp.</code><code class="descname">STP_STATE_ESCAPE_2</code><em class="property"> = 2</em><a class="headerlink" href="#stringtools.stp.STP_STATE_ESCAPE_2" title="Permalink to this definition"></a></dt>
<dd><p>Escape 2 state definition (\x3a found inside a message)</p>
</dd></dl>
<dl class="data">
<dt id="stringtools.stp.STP_STATE_IDLE">
<code class="descclassname">stringtools.stp.</code><code class="descname">STP_STATE_IDLE</code><em class="property"> = 0</em><a class="headerlink" href="#stringtools.stp.STP_STATE_IDLE" title="Permalink to this definition"></a></dt>
<dd><p>Idle state definition (default)</p>
</dd></dl>
<dl class="data">
<dt id="stringtools.stp.STP_STATE_STORE_DATA">
<code class="descclassname">stringtools.stp.</code><code class="descname">STP_STATE_STORE_DATA</code><em class="property"> = 3</em><a class="headerlink" href="#stringtools.stp.STP_STATE_STORE_DATA" title="Permalink to this definition"></a></dt>
<dd><p>Store data state definition (start of message found; data will be stored)</p>
</dd></dl>
<dl class="function">
<dt id="stringtools.stp.build_frame">
<code class="descclassname">stringtools.stp.</code><code class="descname">build_frame</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#stringtools.stp.build_frame" title="Permalink to this definition"></a></dt>
<dd><p>This Method builds an “stp-frame” to be transfered via a stream.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> (<em>str</em>) A String (Bytes) to be framed</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The “stp-framed” message to be sent</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
</tr>
</tbody>
</table>
<p><strong>Example:</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">stringtools</span>
<span class="nb">print</span><span class="p">(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">stp</span><span class="o">.</span><span class="n">build_frame</span><span class="p">(</span><span class="sa">b</span><span class="s1">&#39;:message:&#39;</span><span class="p">))</span>
</pre></div>
</div>
<p>Will result to the following output:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="sa">b</span><span class="s1">&#39;:&lt;:=message:=:&gt;&#39;</span>
</pre></div>
</div>
</dd></dl>
<dl class="class">
<dt id="stringtools.stp.stp">
<em class="property">class </em><code class="descclassname">stringtools.stp.</code><code class="descname">stp</code><a class="headerlink" href="#stringtools.stp.stp" title="Permalink to this definition"></a></dt>
<dd><p>This class extracts messages from an “stp-stream”.</p>
<p><strong>Example:</strong></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">report</span>
<span class="kn">import</span> <span class="nn">stringtools</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="n">logger</span> <span class="o">=</span> <span class="n">report</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="s1">&#39;example&#39;</span><span class="p">,</span> <span class="p">[(</span><span class="n">logging</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">,</span> <span class="n">logging</span><span class="o">.</span><span class="n">StreamHandler</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdout</span><span class="p">))],</span> <span class="n">report</span><span class="o">.</span><span class="n">SHORT_FMT</span><span class="p">)</span>
<span class="n">s</span> <span class="o">=</span> <span class="n">stringtools</span><span class="o">.</span><span class="n">stp</span><span class="o">.</span><span class="n">stp</span><span class="p">()</span>
<span class="k">for</span> <span class="n">byte</span> <span class="ow">in</span> <span class="sa">b</span><span class="s1">&#39;:&lt;:=message:=:&gt;&#39;</span><span class="p">:</span>
<span class="n">data</span> <span class="o">=</span> <span class="n">s</span><span class="o">.</span><span class="n">process</span><span class="p">(</span><span class="n">byte</span><span class="p">,</span> <span class="n">logger</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="kc">None</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>
</div>
<p>Will result to the following output:</p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">43</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">476</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">data</span> <span class="n">sync</span> <span class="p">(</span><span class="mi">3</span><span class="n">a</span><span class="p">)</span> <span class="n">received</span> <span class="o">=&gt;</span> <span class="n">changing</span> <span class="n">state</span> <span class="n">STP_STATE_IDLE</span> <span class="o">-&gt;</span> <span class="n">STP_STATE_ESCAPE_1</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">43</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">476</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">clear</span> <span class="n">buffer</span> <span class="p">(</span><span class="mi">3</span><span class="n">c</span><span class="p">)</span> <span class="n">received</span> <span class="o">=&gt;</span> <span class="n">changing</span> <span class="n">state</span> <span class="n">STP_STATE_ESCAPE_1</span> <span class="o">-&gt;</span> <span class="n">STP_STATE_STORE_DATA</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">43</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">476</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">data</span> <span class="n">sync</span> <span class="p">(</span><span class="mi">3</span><span class="n">a</span><span class="p">)</span> <span class="n">received</span> <span class="o">=&gt;</span> <span class="n">changing</span> <span class="n">state</span> <span class="n">STP_STATE_STORE_DATA</span> <span class="o">-&gt;</span> <span class="n">STP_STATE_ESCAPE_2</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">43</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">476</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">store</span> <span class="n">sync</span> <span class="n">value</span> <span class="p">(</span><span class="mi">3</span><span class="n">d</span><span class="p">)</span> <span class="n">received</span> <span class="o">=&gt;</span> <span class="n">changing</span> <span class="n">state</span> <span class="n">STP_STATE_ESCAPE_2</span> <span class="o">-&gt;</span> <span class="n">STP_STATE_STORE_DATA</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">43</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">476</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">data</span> <span class="n">sync</span> <span class="p">(</span><span class="mi">3</span><span class="n">a</span><span class="p">)</span> <span class="n">received</span> <span class="o">=&gt;</span> <span class="n">changing</span> <span class="n">state</span> <span class="n">STP_STATE_STORE_DATA</span> <span class="o">-&gt;</span> <span class="n">STP_STATE_ESCAPE_2</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">43</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">476</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">store</span> <span class="n">sync</span> <span class="n">value</span> <span class="p">(</span><span class="mi">3</span><span class="n">d</span><span class="p">)</span> <span class="n">received</span> <span class="o">=&gt;</span> <span class="n">changing</span> <span class="n">state</span> <span class="n">STP_STATE_ESCAPE_2</span> <span class="o">-&gt;</span> <span class="n">STP_STATE_STORE_DATA</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">43</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">476</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">data</span> <span class="n">sync</span> <span class="p">(</span><span class="mi">3</span><span class="n">a</span><span class="p">)</span> <span class="n">received</span> <span class="o">=&gt;</span> <span class="n">changing</span> <span class="n">state</span> <span class="n">STP_STATE_STORE_DATA</span> <span class="o">-&gt;</span> <span class="n">STP_STATE_ESCAPE_2</span>
<span class="mi">2019</span><span class="o">-</span><span class="mi">05</span><span class="o">-</span><span class="mi">22</span> <span class="mi">18</span><span class="p">:</span><span class="mi">43</span><span class="p">:</span><span class="mi">14</span><span class="p">,</span><span class="mi">476</span><span class="p">:</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">message</span> <span class="n">completed</span> <span class="p">(</span><span class="mi">3</span><span class="n">e</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="n">changing</span> <span class="n">state</span> <span class="n">STP_STATE_ESCAPE_2</span> <span class="o">-&gt;</span> <span class="n">STP_STATE_IDLE</span>
<span class="sa">b</span><span class="s1">&#39;:message:&#39;</span>
</pre></div>
</div>
<dl class="method">
<dt id="stringtools.stp.stp.process">
<code class="descname">process</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="headerlink" href="#stringtools.stp.stp.process" title="Permalink to this definition"></a></dt>
<dd><p>This processes a byte out of a “stp-stream”.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> (<em>bytes</em>) A byte stream</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The extracted message or None, if no message is identified yet</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
</tr>
</tbody>
</table>
</dd></dl>
</dd></dl>
</div>
<div class="toctree-wrapper compound">
</div>
</div>
<div class="section" id="indices-and-tables">
<h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline"></a></h1>
<ul class="simple">
<li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
<li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
<li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
</ul>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper"><div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="#">Documentation overview</a><ul>
</ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<form class="search" action="search.html" method="get">
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="footer">
&copy;2019, Dirk Alders.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.6.7</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.8</a>
|
<a href="_sources/index.rst.txt"
rel="nofollow">Page source</a>
</div>
</body>
</html>