[Nut-upsdev] Driver fix for Ippon BCP800 (06da/0003), blazer_usb.c
Danya Alexeyevsky
me.dendik at gmail.com
Sun Aug 2 07:53:56 UTC 2009
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.
Cheers,
-- Danya
More information about the Nut-upsdev
mailing list