Hi Danya,<br><br><div class="gmail_quote">2009/8/2 Danya Alexeyevsky <span dir="ltr">&lt;<a href="mailto:me.dendik@gmail.com">me.dendik@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi,<br>
<br>
Thanks to some older discussions on this list I found it quite easy to<br>
eventually track down problem with using USB cable with some more of<br>
Megatec/Q1 UPSes. The trick (which is done in megatec_usb, but not in<br>
blazer_usb) is to read in the junk that somehow gets into read buffers<br>
before sending any commands. (I inserted debug statements so it&#39;s easy<br>
to see that the data read is really junk: in my case it&#39;s most often a<br>
middle piece of previous query and sometimes is appended with some<br>
fragments of /proc/self/environment or something).<br>
<br>
I will appreciate if you apply the patch to fix it (although probably<br>
it&#39;s better to have some such flush function defined in usb wrappers<br>
for every needing driver to use):<br>
<br>
Index: drivers/blazer_usb.c<br>
===================================================================<br>
--- drivers/blazer_usb.c        (revision 1896)<br>
+++ drivers/blazer_usb.c        (working copy)<br>
@@ -94,6 +94,23 @@<br>
 }<br>
<br>
<br>
+static int phoenix_flush_io()<br>
+{<br>
+       static<br>
+       char buf[SMALLBUF+1];<br>
+       int i, ret;<br>
+       upsdebugx(3, &quot;phoenix_flush_io&quot;);<br>
+       for(i = 0; i &lt; 10; i++) {<br>
+               memset(buf, 0, sizeof(buf));<br>
+               /* ret = usb-&gt;get_interrupt(udev, (unsigned char *)buf, 8, 1000); */<br>
+               ret = usb_interrupt_read(udev, 0x81, buf, SMALLBUF, 1000);<br>
+               upsdebugx(4, &quot;flush(%d,%d) &lt;- &#39;%s&#39;&quot;, ret, strlen(buf), buf);<br>
+               if (ret &lt; 1)<br>
+                       break;<br>
+       }<br>
+       return 0;<br>
+}<br>
+<br>
 static int phoenix_command(const char *cmd, char *buf, size_t buflen)<br>
 {<br>
        char    tmp[SMALLBUF];<br>
@@ -103,6 +120,7 @@<br>
        memset(tmp, 0, sizeof(tmp));<br>
        snprintf(tmp, sizeof(tmp), &quot;%s&quot;, cmd);<br>
<br>
+       phoenix_flush_io();<br>
        for (i = 0; i &lt; strlen(tmp); i += ret) {<br>
<br>
                /* Write data in 8-byte chunks */<br>
<br>
After this patch the driver seems to work OK.<br>
</blockquote><div><br>I&#39;ll leave up to Arjen and Alexander (the maintainers of this driver) to approve this patch. <br></div></div><br>I&#39;ve meanwhile added it to our patch tracker on Alioth:<br><a href="https://alioth.debian.org/tracker/index.php?func=detail&amp;aid=311863&amp;group_id=30602&amp;atid=411544">https://alioth.debian.org/tracker/index.php?func=detail&amp;aid=311863&amp;group_id=30602&amp;atid=411544</a><br>
<br>thanks for your contribution,<br>Arnaud<br>-- <br>Linux / Unix Expert R&amp;D - Eaton - <a href="http://www.eaton.com/mgeops">http://www.eaton.com/mgeops</a><br>Network UPS Tools (NUT) Project Leader - <a href="http://www.networkupstools.org/">http://www.networkupstools.org/</a><br>
Debian Developer - <a href="http://www.debian.org">http://www.debian.org</a><br>Free Software Developer - <a href="http://arnaud.quette.free.fr/">http://arnaud.quette.free.fr/</a><br><br>