<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Am 18. September 2013 21:56 schrieb Andreas Brus <span dir="ltr"><<a href="mailto:andreas@brus.name" target="_blank">andreas@brus.name</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Ich verstehe diese Schleifen bei der Fehlerbehandlung nicht wirklich, aber ich vermute, daß da irgendwas durcheinander gerät.<br>
<br>
Gruß<span class=""><font color="#888888"><br>
Andreas<br></font></span></blockquote><div><br></div><div>Hm, die Schleife macht eigentlich nichts besonderes ...<br><br><pre><div class="" id="LC326"><span class="">double</span> <span class="">ds1820read</span><span class="">(</span><span class="">char</span> <span class="">*</span><span class="">sensorid</span><span class="">)</span> <span class="">{</span></div>
<div class="" id="LC327"><br></div><div class="" id="LC328"> <span class="">FILE</span> <span class="">*</span><span class="">fp</span><span class="">;</span> </div><div class="" id="LC329"><br></div><div class="" id="LC330">
<span class="">sprintf</span><span class="">(</span><span class="">fn</span><span class="">,</span> <span class="">"/sys/bus/w1/devices/%s/w1_slave"</span><span class="">,</span> <span class="">sensorid</span> <span class="">);</span></div>
<div class="" id="LC331"><br></div><div class="" id="LC332"> <span class="">if</span> <span class="">(</span> <span class="">(</span><span class="">fp</span> <span class="">=</span> <span class="">fopen</span> <span class="">(</span> <span class="">fn</span><span class="">,</span> <span class="">"r"</span> <span class="">))</span> <span class="">==</span> <span class="">NULL</span> <span class="">)</span> <span class="">{</span></div>
<div class="" id="LC333"> <span class="">return</span><span class="">(</span><span class="">-</span><span class="">1</span><span class="">);</span></div><div class="" id="LC334"> <span class="">}</span></div><div class="" id="LC335">
<br></div><div class="" id="LC336"> <span class="">else</span> </div><div class="" id="LC337"><br></div><div class="" id="LC338"> <span class="">{</span> </div><div class="" id="LC339"><br></div><div class="" id="LC340"><b> <span class="">fgets</span><span class="">(</span> <span class="">crc_buffer</span><span class="">,</span> <span class="">sizeof</span><span class="">(</span><span class="">crc_buffer</span><span class="">),</span> <span class="">fp</span> <span class="">);</span></b></div>
<div class="" id="LC341"><b> <span class="">if</span> <span class="">(</span> <span class="">!</span><span class="">strstr</span> <span class="">(</span> <span class="">crc_buffer</span><span class="">,</span> <span class="">crc_OK</span> <span class="">)</span> <span class="">)</span> </b></div>
<div class="" id="LC342"><b> <span class="">{</span></b></div><div class="" id="LC343"><b><br></b></div><div class="" id="LC344"><b> <span class="">syslog</span><span class="">(</span><span class="">LOG_INFO</span><span class="">,</span> <span class="">"CRC check failed, SensorID: %s"</span><span class="">,</span> <span class="">sensorid</span><span class="">);</span></b></div>
<div class="" id="LC345"><b><br></b></div><div class="" id="LC346"><b> <span class="">fclose</span> <span class="">(</span> <span class="">fp</span> <span class="">);</span></b></div><div class="" id="LC347"><b> <span class="">return</span><span class="">(</span><span class="">-</span><span class="">1</span><span class="">);</span></b></div>
<div class="" id="LC348"> <span class="">}</span></div><div class="" id="LC349"><br></div><div class="" id="LC350"> <span class="">else</span> </div><div class="" id="LC351"><br></div><div class="" id="LC352"> <span class="">{</span> </div>
<div class="" id="LC353"><br></div><div class="" id="LC354"> <span class="">fgets</span><span class="">(</span> <span class="">temp_buffer</span><span class="">,</span> <span class="">sizeof</span><span class="">(</span><span class="">temp_buffer</span><span class="">),</span> <span class="">fp</span> <span class="">);</span></div>
<div class="" id="LC355"> <span class="">fgets</span><span class="">(</span> <span class="">temp_buffer</span><span class="">,</span> <span class="">sizeof</span><span class="">(</span><span class="">temp_buffer</span><span class="">),</span> <span class="">fp</span> <span class="">);</span></div>
<div class="" id="LC356"><br></div><div class="" id="LC357"> <span class="">char</span> <span class="">*</span><span class="">t</span><span class="">;</span></div><div class="" id="LC358"> <span class="">t</span> <span class="">=</span> <span class="">strndup</span> <span class="">(</span> <span class="">temp_buffer</span> <span class="">+</span><span class="">29</span><span class="">,</span> <span class="">5</span> <span class="">)</span> <span class="">;</span></div>
<div class="" id="LC359"> <span class="">temp</span> <span class="">=</span> <span class="">atof</span><span class="">(</span><span class="">t</span><span class="">)</span><span class="">/</span><span class="">1000</span><span class="">;</span></div>
<div class="" id="LC360"><br></div><div class="" id="LC361"> <span class="">fclose</span> <span class="">(</span> <span class="">fp</span> <span class="">);</span></div><div class="" id="LC362"> <span class="">http_post</span><span class="">(</span><span class="">temp</span><span class="">,</span> <span class="">vzuuid</span><span class="">[</span><span class="">i</span><span class="">][</span><span class="">count</span><span class="">]);</span></div>
<div class="" id="LC363"><br></div><div class="" id="LC364"> <span class="">}</span></div><div class="" id="LC365"><br></div><div class="" id="LC366"> <span class="">}</span></div><div class="" id="LC367"><br></div><div class="" id="LC368">
<span class="">}</span></div></pre><br></div></div>Wenn die Schleife kein CRC_OK lesen kann, haut sie einen Syslogeintrag raus, schliesst den FP und macht return(-1).<br><br><br></div></div>