Hi Heinz,
2010/5/30 heinz
> Thank you for your nut-2.4.3 system. I had big troubles getting it to work
> with the UPSONIC PROFFICE 650 UPS in USB mode.
>
> I had to rewrite the get_data_phoenix() function in drivers/megatec_usb.c
> file.
> It now appears to be working correctly. I have attached the source of the
> modified function in case you might want to add it to a future version.
>
first, thanks for your report. Though it's always better to report to the
NUT list ;-)
code changes are also better using patch (ie diff against the original
code).
so I've generated one, attached.
that being said, you should give a try to blazer_usb, the successor of the
megatec_usb driver.
we will be interested in a debug output (ie /path/to/blazer_usb -DDDDD -a
<upsname>
along with the output of "lsusb -v" excerpt of your device.
now, since I don't know much about these drivers, I'll let Arjen comment on
the patch itself.
cheers,
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/
--- /tmp/get_data.c.orig 2010-06-30 22:52:40.000000000 +0200
+++ /tmp/get_data.c 2010-06-30 22:50:54.000000000 +0200
@@ -1,6 +1,8 @@
static int get_data_phoenix(char *buffer, int buffer_size)
{
- int count;
+ int count = 0;
+ int chunk = 8;
+ int rxbytes = 0;
memset(buffer, '\0', buffer_size);
@@ -10,13 +12,18 @@
return strlen(buffer);
}
- for (count = 8; count <= buffer_size; count += 8) {
-
- /* Read data in 8-byte chunks, break on a timeout */
- if (usb->get_interrupt(udev, (unsigned char *)&buffer[count-8], 8, 1000) < 0) {
- return count-8;
+ while ( count < (buffer_size - 1) ) {
+ /* Read data in a chunk, break on a timeout */
+ rxbytes = usb->get_interrupt(udev, (unsigned char *)&buffer[count], chunk, 1000);
+ if ( rxbytes <= 0) {
+ return count; // Exhausted data channel
}
-
+ count += rxbytes; // Got some more valid bytes
+ // If we got a CR somewhere in that mess, then the UPS has finished with us
+ if ( strchr(&(buffer[count - rxbytes]), (int) '\r') ) {
+ return count;
+ }
+
upsdebugx(3, "get_data_phoenix: got so far [%s]", buffer);
upsdebug_hex(4, "get_data_phoenix", (unsigned char *)buffer, count);
}
_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev