Python Library Stringtools
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

index.html 57KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  1. <!DOCTYPE html>
  2. <html class="writer-html4" lang="en" >
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Welcome to stringtools’s documentation! &mdash; stringtools documentation</title>
  7. <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  8. <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  9. <!--[if lt IE 9]>
  10. <script src="_static/js/html5shiv.min.js"></script>
  11. <![endif]-->
  12. <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
  13. <script type="text/javascript" src="_static/jquery.js"></script>
  14. <script type="text/javascript" src="_static/underscore.js"></script>
  15. <script type="text/javascript" src="_static/doctools.js"></script>
  16. <script type="text/javascript" src="_static/language_data.js"></script>
  17. <script type="text/javascript" src="_static/js/theme.js"></script>
  18. <link rel="index" title="Index" href="genindex.html" />
  19. <link rel="search" title="Search" href="search.html" />
  20. </head>
  21. <body class="wy-body-for-nav">
  22. <div class="wy-grid-for-nav">
  23. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  24. <div class="wy-side-scroll">
  25. <div class="wy-side-nav-search" >
  26. <a href="#" class="icon icon-home" alt="Documentation Home"> stringtools
  27. </a>
  28. <div role="search">
  29. <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
  30. <input type="text" name="q" placeholder="Search docs" />
  31. <input type="hidden" name="check_keywords" value="yes" />
  32. <input type="hidden" name="area" value="default" />
  33. </form>
  34. </div>
  35. </div>
  36. <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
  37. <!-- Local TOC -->
  38. <div class="local-toc"><ul>
  39. <li><a class="reference internal" href="#">Welcome to stringtools’s documentation!</a><ul>
  40. <li><a class="reference internal" href="#stringtools-stringtools">stringtools (Stringtools)</a></li>
  41. <li><a class="reference internal" href="#csp-carriage-return-seperation-protocol">csp (Carriage-Return seperation protocol)</a></li>
  42. <li><a class="reference internal" href="#stp-serial-transfer-protocol">stp (Serial transfer protocol)</a></li>
  43. </ul>
  44. </li>
  45. <li><a class="reference internal" href="#indices-and-tables">Indices and tables</a></li>
  46. </ul>
  47. </div>
  48. </div>
  49. </div>
  50. </nav>
  51. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
  52. <nav class="wy-nav-top" aria-label="top navigation">
  53. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  54. <a href="#">stringtools</a>
  55. </nav>
  56. <div class="wy-nav-content">
  57. <div class="rst-content">
  58. <div role="navigation" aria-label="breadcrumbs navigation">
  59. <ul class="wy-breadcrumbs">
  60. <li><a href="#" class="icon icon-home"></a> &raquo;</li>
  61. <li>Welcome to stringtools’s documentation!</li>
  62. <li class="wy-breadcrumbs-aside">
  63. <a href="_sources/index.rst.txt" rel="nofollow"> View page source</a>
  64. </li>
  65. </ul>
  66. <hr/>
  67. </div>
  68. <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
  69. <div itemprop="articleBody">
  70. <div class="section" id="module-stringtools">
  71. <span id="welcome-to-stringtools-s-documentation"></span><h1>Welcome to stringtools’s documentation!<a class="headerlink" href="#module-stringtools" title="Permalink to this headline">¶</a></h1>
  72. <div class="section" id="stringtools-stringtools">
  73. <h2>stringtools (Stringtools)<a class="headerlink" href="#stringtools-stringtools" title="Permalink to this headline">¶</a></h2>
  74. <p><strong>Author:</strong></p>
  75. <ul class="simple">
  76. <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>
  77. </ul>
  78. <p><strong>Description:</strong></p>
  79. <blockquote>
  80. <div>This Module supports functionality around string operations.</div></blockquote>
  81. <p><strong>Submodules:</strong></p>
  82. <ul class="simple">
  83. <li><a class="reference internal" href="#module-stringtools.csp" title="stringtools.csp"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stringtools.csp</span></code></a></li>
  84. <li><a class="reference internal" href="#module-stringtools.stp" title="stringtools.stp"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stringtools.stp</span></code></a></li>
  85. <li><a class="reference internal" href="#stringtools.gzip_compress" title="stringtools.gzip_compress"><code class="xref py py-func docutils literal notranslate"><span class="pre">gzip_compress()</span></code></a></li>
  86. <li><a class="reference internal" href="#stringtools.gzip_extract" title="stringtools.gzip_extract"><code class="xref py py-func docutils literal notranslate"><span class="pre">gzip_extract()</span></code></a></li>
  87. <li><a class="reference internal" href="#stringtools.hexlify" title="stringtools.hexlify"><code class="xref py py-func docutils literal notranslate"><span class="pre">hexlify()</span></code></a></li>
  88. </ul>
  89. <p><strong>Unittest:</strong></p>
  90. <blockquote>
  91. <div>See also the <a class="reference download internal" download="" href="_downloads/412e50d5e5a6e9ca1556b611fbae3c9c/unittest.pdf"><code class="xref download docutils literal notranslate"><span class="pre">unittest</span></code></a> documentation.</div></blockquote>
  92. <p><strong>Module Documentation:</strong></p>
  93. <dl class="function">
  94. <dt id="stringtools.gzip_compress">
  95. <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>
  96. <dd><p>Method to compress a stream of bytes.</p>
  97. <table class="docutils field-list" frame="void" rules="none">
  98. <col class="field-name" />
  99. <col class="field-body" />
  100. <tbody valign="top">
  101. <tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
  102. <li><strong>s</strong> (<em>str</em>) – The bytestream (string) to be compressed</li>
  103. <li><strong>compresslevel</strong> (<em>int</em>) – An optional compressionn level (default is 9)</li>
  104. </ul>
  105. </td>
  106. </tr>
  107. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first">The compressed bytestream</p>
  108. </td>
  109. </tr>
  110. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">str</p>
  111. </td>
  112. </tr>
  113. </tbody>
  114. </table>
  115. <p><strong>Example:</strong></p>
  116. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">stringtools</span>
  117. <span class="kn">import</span> <span class="nn">report</span>
  118. <span class="n">report</span><span class="o">.</span><span class="n">stdoutLoggingConfigure</span><span class="p">(</span><span class="n">log_name_lvl</span><span class="o">=</span><span class="p">[(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">logger_name</span><span class="p">,</span> <span class="s1">&#39;DEBUG&#39;</span><span class="p">),</span> <span class="p">])</span>
  119. <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>
  120. </pre></div>
  121. </div>
  122. <p>Will result to the following output:</p>
  123. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">45</span><span class="p">:</span><span class="mi">24</span><span class="p">,</span><span class="mi">558</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">GZIP</span><span class="p">:</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>
  124. <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">64</span> <span class="mi">9</span><span class="n">d</span> <span class="mi">30</span> <span class="mi">5</span><span class="n">e</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>
  125. </pre></div>
  126. </div>
  127. </dd></dl>
  128. <dl class="function">
  129. <dt id="stringtools.gzip_extract">
  130. <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>
  131. <dd><p>Method to extract data from a compress stream of bytes.</p>
  132. <table class="docutils field-list" frame="void" rules="none">
  133. <col class="field-name" />
  134. <col class="field-body" />
  135. <tbody valign="top">
  136. <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>
  137. </tr>
  138. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The extracted data</td>
  139. </tr>
  140. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
  141. </tr>
  142. </tbody>
  143. </table>
  144. <p><strong>Example:</strong></p>
  145. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">stringtools</span>
  146. <span class="kn">import</span> <span class="nn">report</span>
  147. <span class="n">report</span><span class="o">.</span><span class="n">stdoutLoggingConfigure</span><span class="p">(</span><span class="n">log_name_lvl</span><span class="o">=</span><span class="p">[(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">logger_name</span><span class="p">,</span> <span class="s1">&#39;DEBUG&#39;</span><span class="p">),</span> <span class="p">])</span>
  148. <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>
  149. </pre></div>
  150. </div>
  151. <p>Will result to the following output:</p>
  152. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">45</span><span class="p">:</span><span class="mi">39</span><span class="p">,</span><span class="mi">899</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">GZIP</span><span class="p">:</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>
  153. <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>
  154. </pre></div>
  155. </div>
  156. </dd></dl>
  157. <dl class="function">
  158. <dt id="stringtools.hexlify">
  159. <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>
  160. <dd><p>Method to hexlify a string.</p>
  161. <table class="docutils field-list" frame="void" rules="none">
  162. <col class="field-name" />
  163. <col class="field-body" />
  164. <tbody valign="top">
  165. <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>
  166. </tr>
  167. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The hexlified string</td>
  168. </tr>
  169. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
  170. </tr>
  171. </tbody>
  172. </table>
  173. <p><strong>Example:</strong></p>
  174. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">stringtools</span>
  175. <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>
  176. </pre></div>
  177. </div>
  178. <p>Will result to the following output:</p>
  179. <div class="highlight-default notranslate"><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>
  180. </pre></div>
  181. </div>
  182. </dd></dl>
  183. </div>
  184. <span class="target" id="module-stringtools.csp"></span><div class="section" id="csp-carriage-return-seperation-protocol">
  185. <h2>csp (Carriage-Return seperation protocol)<a class="headerlink" href="#csp-carriage-return-seperation-protocol" title="Permalink to this headline">¶</a></h2>
  186. <p><strong>Author:</strong></p>
  187. <ul class="simple">
  188. <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>
  189. </ul>
  190. <p><strong>Description:</strong></p>
  191. <blockquote>
  192. <div>This module is a submodule of <a class="reference internal" href="#module-stringtools" title="stringtools"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stringtools</span></code></a> and creates an frame to transmit and receive messages via an serial interface.</div></blockquote>
  193. <p><strong>Submodules:</strong></p>
  194. <ul class="simple">
  195. <li><a class="reference internal" href="#stringtools.csp.csp" title="stringtools.csp.csp"><code class="xref py py-class docutils literal notranslate"><span class="pre">stringtools.csp.csp</span></code></a></li>
  196. <li><a class="reference internal" href="#stringtools.csp.build_frame" title="stringtools.csp.build_frame"><code class="xref py py-func docutils literal notranslate"><span class="pre">stringtools.csp.build_frame()</span></code></a></li>
  197. </ul>
  198. <dl class="function">
  199. <dt id="stringtools.csp.build_frame">
  200. <code class="descclassname">stringtools.csp.</code><code class="descname">build_frame</code><span class="sig-paren">(</span><em>msg</em>, <em>seperator=b'\n'</em><span class="sig-paren">)</span><a class="headerlink" href="#stringtools.csp.build_frame" title="Permalink to this definition">¶</a></dt>
  201. <dd><p>This Method builds an “csp-frame” to be transfered via a stream.</p>
  202. <table class="docutils field-list" frame="void" rules="none">
  203. <col class="field-name" />
  204. <col class="field-body" />
  205. <tbody valign="top">
  206. <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>
  207. </tr>
  208. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The “csp-framed” message to be sent</td>
  209. </tr>
  210. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
  211. </tr>
  212. </tbody>
  213. </table>
  214. <p><strong>Example:</strong></p>
  215. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">stringtools</span>
  216. <span class="n">data</span> <span class="o">=</span> <span class="sa">b</span><span class="s1">&#39;message&#39;</span>
  217. <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>
  218. <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>
  219. </pre></div>
  220. </div>
  221. <p>Will result to the following output:</p>
  222. <div class="highlight-default notranslate"><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>
  223. <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>
  224. </pre></div>
  225. </div>
  226. </dd></dl>
  227. <dl class="class">
  228. <dt id="stringtools.csp.csp">
  229. <em class="property">class </em><code class="descclassname">stringtools.csp.</code><code class="descname">csp</code><span class="sig-paren">(</span><em>seperator=b'n'</em><span class="sig-paren">)</span><a class="headerlink" href="#stringtools.csp.csp" title="Permalink to this definition">¶</a></dt>
  230. <dd><p>This class extracts messages from an “csp-stream”.</p>
  231. <p><strong>Example:</strong></p>
  232. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">report</span>
  233. <span class="kn">import</span> <span class="nn">stringtools</span>
  234. <span class="n">report</span><span class="o">.</span><span class="n">stdoutLoggingConfigure</span><span class="p">(</span><span class="n">log_name_lvl</span><span class="o">=</span><span class="p">[(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">logger_name</span><span class="p">,</span> <span class="s1">&#39;DEBUG&#39;</span><span class="p">),</span> <span class="p">])</span>
  235. <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>
  236. <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>
  237. <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="nb">bytes</span><span class="p">([</span><span class="n">byte</span><span class="p">]))</span>
  238. <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
  239. <span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
  240. </pre></div>
  241. </div>
  242. <p>Will result to the following output:</p>
  243. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">31</span><span class="p">:</span><span class="mi">22</span><span class="p">,</span><span class="mi">093</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Leaving</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">buffer</span> <span class="p">(</span><span class="n">to</span> <span class="n">be</span> <span class="n">processed</span> <span class="nb">next</span> <span class="n">time</span><span class="p">):</span> <span class="p">(</span><span class="mi">5</span><span class="p">):</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span>
  244. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">31</span><span class="p">:</span><span class="mi">22</span><span class="p">,</span><span class="mi">094</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Leaving</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">buffer</span> <span class="p">(</span><span class="n">to</span> <span class="n">be</span> <span class="n">processed</span> <span class="nb">next</span> <span class="n">time</span><span class="p">):</span> <span class="p">(</span><span class="mi">10</span><span class="p">):</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">65</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span>
  245. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">31</span><span class="p">:</span><span class="mi">22</span><span class="p">,</span><span class="mi">094</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Leaving</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">buffer</span> <span class="p">(</span><span class="n">to</span> <span class="n">be</span> <span class="n">processed</span> <span class="nb">next</span> <span class="n">time</span><span class="p">):</span> <span class="p">(</span><span class="mi">15</span><span class="p">):</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">65</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span>
  246. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">31</span><span class="p">:</span><span class="mi">22</span><span class="p">,</span><span class="mi">095</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Leaving</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">buffer</span> <span class="p">(</span><span class="n">to</span> <span class="n">be</span> <span class="n">processed</span> <span class="nb">next</span> <span class="n">time</span><span class="p">):</span> <span class="p">(</span><span class="mi">20</span><span class="p">):</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">65</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span>
  247. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">31</span><span class="p">:</span><span class="mi">22</span><span class="p">,</span><span class="mi">095</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Leaving</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">buffer</span> <span class="p">(</span><span class="n">to</span> <span class="n">be</span> <span class="n">processed</span> <span class="nb">next</span> <span class="n">time</span><span class="p">):</span> <span class="p">(</span><span class="mi">25</span><span class="p">):</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">65</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">61</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span>
  248. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">31</span><span class="p">:</span><span class="mi">22</span><span class="p">,</span><span class="mi">095</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Leaving</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">buffer</span> <span class="p">(</span><span class="n">to</span> <span class="n">be</span> <span class="n">processed</span> <span class="nb">next</span> <span class="n">time</span><span class="p">):</span> <span class="p">(</span><span class="mi">30</span><span class="p">):</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">65</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">61</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">67</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span>
  249. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">31</span><span class="p">:</span><span class="mi">22</span><span class="p">,</span><span class="mi">096</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Leaving</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">buffer</span> <span class="p">(</span><span class="n">to</span> <span class="n">be</span> <span class="n">processed</span> <span class="nb">next</span> <span class="n">time</span><span class="p">):</span> <span class="p">(</span><span class="mi">35</span><span class="p">):</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">65</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">61</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">67</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">65</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span>
  250. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">31</span><span class="p">:</span><span class="mi">22</span><span class="p">,</span><span class="mi">096</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">CSP</span><span class="p">:</span> <span class="n">Leaving</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">buffer</span> <span class="p">(</span><span class="n">to</span> <span class="n">be</span> <span class="n">processed</span> <span class="nb">next</span> <span class="n">time</span><span class="p">):</span> <span class="p">(</span><span class="mi">41</span><span class="p">):</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">6</span><span class="n">d</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">65</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">73</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">61</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">67</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">65</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span> <span class="mi">5</span><span class="n">b</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">c</span> <span class="mi">6</span><span class="n">e</span> <span class="mi">27</span> <span class="mi">5</span><span class="n">d</span>
  251. </pre></div>
  252. </div>
  253. <dl class="method">
  254. <dt id="stringtools.csp.csp.process">
  255. <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>
  256. <dd><p>This processes a byte out of a “stp-stream”.</p>
  257. <table class="docutils field-list" frame="void" rules="none">
  258. <col class="field-name" />
  259. <col class="field-body" />
  260. <tbody valign="top">
  261. <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>
  262. </tr>
  263. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">A list of the extracted message(s)</td>
  264. </tr>
  265. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">list</td>
  266. </tr>
  267. </tbody>
  268. </table>
  269. </dd></dl>
  270. </dd></dl>
  271. </div>
  272. <span class="target" id="module-stringtools.stp"></span><div class="section" id="stp-serial-transfer-protocol">
  273. <h2>stp (Serial transfer protocol)<a class="headerlink" href="#stp-serial-transfer-protocol" title="Permalink to this headline">¶</a></h2>
  274. <p><strong>Author:</strong></p>
  275. <ul class="simple">
  276. <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>
  277. </ul>
  278. <p><strong>Description:</strong></p>
  279. <blockquote>
  280. <div>This module is a submodule of <a class="reference internal" href="#module-stringtools" title="stringtools"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stringtools</span></code></a> and creates an serial frame to transmit and receive messages via an serial interface.</div></blockquote>
  281. <p><strong>Submodules:</strong></p>
  282. <ul class="simple">
  283. <li><a class="reference internal" href="#stringtools.stp.stp" title="stringtools.stp.stp"><code class="xref py py-class docutils literal notranslate"><span class="pre">stringtools.stp.stp</span></code></a></li>
  284. <li><a class="reference internal" href="#stringtools.stp.build_frame" title="stringtools.stp.build_frame"><code class="xref py py-func docutils literal notranslate"><span class="pre">stringtools.stp.build_frame()</span></code></a></li>
  285. </ul>
  286. <dl class="data">
  287. <dt id="stringtools.stp.DATA_CLEAR_BUFFER">
  288. <code class="descclassname">stringtools.stp.</code><code class="descname">DATA_CLEAR_BUFFER</code><em class="property"> = b'&lt;'</em><a class="headerlink" href="#stringtools.stp.DATA_CLEAR_BUFFER" title="Permalink to this definition">¶</a></dt>
  289. <dd><p>The clear buffer byte (‘\x3a\x3c’ -&gt; start of message)</p>
  290. </dd></dl>
  291. <dl class="data">
  292. <dt id="stringtools.stp.DATA_STORE_SYNC_VALUE">
  293. <code class="descclassname">stringtools.stp.</code><code class="descname">DATA_STORE_SYNC_VALUE</code><em class="property"> = b'='</em><a class="headerlink" href="#stringtools.stp.DATA_STORE_SYNC_VALUE" title="Permalink to this definition">¶</a></dt>
  294. <dd><p>The store sync value byte (‘\x3a\x3d’ -&gt; ‘\x3a’ inside a message)</p>
  295. </dd></dl>
  296. <dl class="data">
  297. <dt id="stringtools.stp.DATA_SYNC">
  298. <code class="descclassname">stringtools.stp.</code><code class="descname">DATA_SYNC</code><em class="property"> = b':'</em><a class="headerlink" href="#stringtools.stp.DATA_SYNC" title="Permalink to this definition">¶</a></dt>
  299. <dd><p>The data sync byte</p>
  300. </dd></dl>
  301. <dl class="data">
  302. <dt id="stringtools.stp.DATA_VALID_MSG">
  303. <code class="descclassname">stringtools.stp.</code><code class="descname">DATA_VALID_MSG</code><em class="property"> = b'&gt;'</em><a class="headerlink" href="#stringtools.stp.DATA_VALID_MSG" title="Permalink to this definition">¶</a></dt>
  304. <dd><p>The valid message byte (‘\x3a\x3e’ -&gt; end of message)</p>
  305. </dd></dl>
  306. <dl class="data">
  307. <dt id="stringtools.stp.STP_STATE_ESCAPE_1">
  308. <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>
  309. <dd><p>Escape 1 state definition (‘\x3a\x3c’ found)</p>
  310. </dd></dl>
  311. <dl class="data">
  312. <dt id="stringtools.stp.STP_STATE_ESCAPE_2">
  313. <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>
  314. <dd><p>Escape 2 state definition (‘\x3a’ found inside a message)</p>
  315. </dd></dl>
  316. <dl class="data">
  317. <dt id="stringtools.stp.STP_STATE_IDLE">
  318. <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>
  319. <dd><p>Idle state definition (default)</p>
  320. </dd></dl>
  321. <dl class="data">
  322. <dt id="stringtools.stp.STP_STATE_STORE_DATA">
  323. <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>
  324. <dd><p>Store data state definition (start of message found; data will be stored)</p>
  325. </dd></dl>
  326. <dl class="function">
  327. <dt id="stringtools.stp.build_frame">
  328. <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>
  329. <dd><p>This Method builds an “stp-frame” to be transfered via a stream.</p>
  330. <table class="docutils field-list" frame="void" rules="none">
  331. <col class="field-name" />
  332. <col class="field-body" />
  333. <tbody valign="top">
  334. <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>
  335. </tr>
  336. <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">The “stp-framed” message to be sent</td>
  337. </tr>
  338. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
  339. </tr>
  340. </tbody>
  341. </table>
  342. <p><strong>Example:</strong></p>
  343. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">stringtools</span>
  344. <span class="nb">print</span><span class="p">(</span><span class="nb">repr</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>
  345. </pre></div>
  346. </div>
  347. <p>Will result to the following output:</p>
  348. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="sa">b</span><span class="s1">&#39;:&lt;:=message:=:&gt;&#39;</span>
  349. </pre></div>
  350. </div>
  351. </dd></dl>
  352. <dl class="class">
  353. <dt id="stringtools.stp.stp">
  354. <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>
  355. <dd><p>This class extracts messages from an “stp-stream”.</p>
  356. <p><strong>Example:</strong></p>
  357. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">report</span>
  358. <span class="kn">import</span> <span class="nn">stringtools</span>
  359. <span class="n">report</span><span class="o">.</span><span class="n">stdoutLoggingConfigure</span><span class="p">(</span><span class="n">log_name_lvl</span><span class="o">=</span><span class="p">[(</span><span class="n">stringtools</span><span class="o">.</span><span class="n">logger_name</span><span class="p">,</span> <span class="s1">&#39;DEBUG&#39;</span><span class="p">),</span> <span class="p">])</span>
  360. <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>
  361. <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>
  362. <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="nb">bytes</span><span class="p">([</span><span class="n">byte</span><span class="p">]))</span>
  363. <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
  364. <span class="nb">print</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
  365. </pre></div>
  366. </div>
  367. <p>Will result to the following output:</p>
  368. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">38</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">329</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</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>
  369. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">38</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">329</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">start</span> <span class="n">pattern</span> <span class="p">(</span><span class="mi">3</span><span class="n">a</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>
  370. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">38</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">329</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</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>
  371. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">38</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">329</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</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">pattern</span> <span class="p">(</span><span class="mi">3</span><span class="n">a</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>
  372. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">38</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">329</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</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>
  373. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">38</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">329</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</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">pattern</span> <span class="p">(</span><span class="mi">3</span><span class="n">a</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>
  374. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">38</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">329</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</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>
  375. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">38</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">329</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">DEBUG</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">end</span> <span class="n">pattern</span> <span class="p">(</span><span class="mi">3</span><span class="n">a</span> <span class="mi">3</span><span class="n">e</span><span class="p">)</span> <span class="n">received</span> <span class="o">=&gt;</span> <span class="n">storing</span> <span class="n">message</span> <span class="ow">and</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>
  376. <span class="mi">2020</span><span class="o">-</span><span class="mi">01</span><span class="o">-</span><span class="mi">28</span> <span class="mi">21</span><span class="p">:</span><span class="mi">38</span><span class="p">:</span><span class="mi">27</span><span class="p">,</span><span class="mi">329</span><span class="p">:</span> <span class="n">STRINGTOOLS</span> <span class="o">-</span> <span class="n">INFO</span> <span class="o">-</span> <span class="n">STP</span><span class="p">:</span> <span class="n">message</span> <span class="n">identified</span> <span class="o">-</span> <span class="p">(</span><span class="mi">9</span><span class="p">):</span> <span class="mi">3</span><span class="n">a</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">3</span><span class="n">a</span>
  377. <span class="p">[</span><span class="sa">b</span><span class="s1">&#39;:message:&#39;</span><span class="p">]</span>
  378. </pre></div>
  379. </div>
  380. <dl class="method">
  381. <dt id="stringtools.stp.stp.process">
  382. <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>
  383. <dd><p>This processes a byte out of a “stp-stream”.</p>
  384. <table class="docutils field-list" frame="void" rules="none">
  385. <col class="field-name" />
  386. <col class="field-body" />
  387. <tbody valign="top">
  388. <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>
  389. </tr>
  390. <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>
  391. </tr>
  392. <tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body">str</td>
  393. </tr>
  394. </tbody>
  395. </table>
  396. </dd></dl>
  397. </dd></dl>
  398. </div>
  399. <div class="toctree-wrapper compound">
  400. </div>
  401. </div>
  402. <div class="section" id="indices-and-tables">
  403. <h1>Indices and tables<a class="headerlink" href="#indices-and-tables" title="Permalink to this headline">¶</a></h1>
  404. <ul class="simple">
  405. <li><a class="reference internal" href="genindex.html"><span class="std std-ref">Index</span></a></li>
  406. <li><a class="reference internal" href="py-modindex.html"><span class="std std-ref">Module Index</span></a></li>
  407. <li><a class="reference internal" href="search.html"><span class="std std-ref">Search Page</span></a></li>
  408. </ul>
  409. </div>
  410. </div>
  411. </div>
  412. <footer>
  413. <hr/>
  414. <div role="contentinfo">
  415. <p>
  416. &copy; Copyright 2021, Dirk Alders
  417. </p>
  418. </div>
  419. Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a
  420. <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a>
  421. provided by <a href="https://readthedocs.org">Read the Docs</a>.
  422. </footer>
  423. </div>
  424. </div>
  425. </section>
  426. </div>
  427. <script type="text/javascript">
  428. jQuery(function () {
  429. SphinxRtdTheme.Navigation.enable(true);
  430. });
  431. </script>
  432. </body>
  433. </html>