[Nut-upsdev] Driver fix for Ippon BCP800 (06da/0003), blazer_usb.c

Arnaud Quette aquette.dev at gmail.com
Mon Aug 3 14:53:50 UTC 2009


Hi Danya,

2009/8/2 Danya Alexeyevsky <me.dendik at gmail.com>

> Hi,
>
> Thanks to some older discussions on this list I found it quite easy to
> eventually track down problem with using USB cable with some more of
> Megatec/Q1 UPSes. The trick (which is done in megatec_usb, but not in
> blazer_usb) is to read in the junk that somehow gets into read buffers
> before sending any commands. (I inserted debug statements so it's easy
> to see that the data read is really junk: in my case it's most often a
> middle piece of previous query and sometimes is appended with some
> fragments of /proc/self/environment or something).
>
> I will appreciate if you apply the patch to fix it (although probably
> it's better to have some such flush function defined in usb wrappers
> for every needing driver to use):
>
> Index: drivers/blazer_usb.c
> ===================================================================
> --- drivers/blazer_usb.c        (revision 1896)
> +++ drivers/blazer_usb.c        (working copy)
> @@ -94,6 +94,23 @@
>  }
>
>
> +static int phoenix_flush_io()
> +{
> +       static
> +       char buf[SMALLBUF+1];
> +       int i, ret;
> +       upsdebugx(3, "phoenix_flush_io");
> +       for(i = 0; i < 10; i++) {
> +               memset(buf, 0, sizeof(buf));
> +               /* ret = usb->get_interrupt(udev, (unsigned char *)buf, 8,
> 1000); */
> +               ret = usb_interrupt_read(udev, 0x81, buf, SMALLBUF, 1000);
> +               upsdebugx(4, "flush(%d,%d) <- '%s'", ret, strlen(buf),
> buf);
> +               if (ret < 1)
> +                       break;
> +       }
> +       return 0;
> +}
> +
>  static int phoenix_command(const char *cmd, char *buf, size_t buflen)
>  {
>        char    tmp[SMALLBUF];
> @@ -103,6 +120,7 @@
>        memset(tmp, 0, sizeof(tmp));
>        snprintf(tmp, sizeof(tmp), "%s", cmd);
>
> +       phoenix_flush_io();
>        for (i = 0; i < strlen(tmp); i += ret) {
>
>                /* Write data in 8-byte chunks */
>
> After this patch the driver seems to work OK.
>

I'll leave up to Arjen and Alexander (the maintainers of this driver) to
approve this patch.

I've meanwhile added it to our patch tracker on Alioth:
https://alioth.debian.org/tracker/index.php?func=detail&aid=311863&group_id=30602&atid=411544

thanks for your contribution,
Arnaud
-- 
Linux / Unix Expert R&D - Eaton - http://www.eaton.com/mgeops
Network UPS Tools (NUT) Project Leader - http://www.networkupstools.org/
Debian Developer - http://www.debian.org
Free Software Developer - http://arnaud.quette.free.fr/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20090803/439da355/attachment.htm>


More information about the Nut-upsdev mailing list