Danya Alexeyevsky
2009-Aug-02 07:53 UTC
[Nut-upsdev] Driver fix for Ippon BCP800 (06da/0003), blazer_usb.c
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
Arnaud Quette
2009-Aug-03 14:53 UTC
[Nut-upsdev] Driver fix for Ippon BCP800 (06da/0003), blazer_usb.c
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>
Arjen de Korte
2009-Aug-24 14:52 UTC
[Nut-upsdev] Driver fix for Ippon BCP800 (06da/0003), blazer_usb.c
Citeren Danya Alexeyevsky <me.dendik op gmail.com>:> 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).Thanks for this report. I have slightly modified your patch, but it should work out the same.> 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):The fact that we need to flush the IO buffers, really means that the USB to serial implementation is broken, so I'd prefer to do this explicitly in the driver. Best regards, Arjen -- Please keep list traffic on the list
Reasonably Related Threads
- Ippon BackComfoPro (06da:0003 Phoenixtec Power)
- Fwd: Re: megatec_usb: Ippon BackComfoPro (06da:0003 Phoenixtec Power)
- megatec_usb: Ippon BackComfoPro (06da:0003 Phoenixtec Power)
- blazer_usb vs. Ippon Smart Power Pro 1400
- [nut-commits] svn commit r2839 - branches/windows_port/scripts/Windows