[Nut-upsdev] Dynamix 650 VA USB - broken, have rough fix

Brian R. Smith bsmith at furbium.com
Sat Sep 25 02:25:51 UTC 2010


On Sep 24, 2010, at 9:43 PM, Arjen de Korte wrote:

> Citeren "Brian R. Smith" <bsmith at furbium.com>:
> 
>> Should megatec_usb.c/set_data_krauler just skip the "usb" subdriver function table and go straight for usb_get_string?  Or should the usb subdriver be extended with a call that doesn't go through usb_get_string_simple?
> 
> The 'megatec_usb' driver is no longer maintained and has been replaced by the 'blazer_usb' driver. This uses direct calls to the libusb library, so the fix you recommend should be much easier to implement. Please post some debug output before and after making these changes by running the driver with -DDD enabled (not more).

Ah, thanks for that.  Yes, blazer_usb is a better place for the change.  Sorry I didn't notice it earlier.

Here's debug output, from before:
====================================================================
Network UPS Tools - Megatec/Q1 protocol USB driver 0.03 (2.4.3)
   0.000000	debug level is '3'
   0.118093	Checking device (1D6B/0001) (005/001)
   0.118164	- VendorID: 1d6b
   0.118177	- ProductID: 0001
   0.118188	- Manufacturer: Linux 2.6.32-24-generic uhci_hcd
   0.118199	- Product: UHCI Host Controller
   0.118209	- Serial Number: 0000:00:1d.3
   0.118220	- Bus: 005
   0.118230	Trying to match device
   0.118256	Device does not match - skipping
   0.118273	Checking device (1D6B/0001) (004/001)
   0.118317	- VendorID: 1d6b
   0.118328	- ProductID: 0001
   0.118339	- Manufacturer: Linux 2.6.32-24-generic uhci_hcd
   0.118350	- Product: UHCI Host Controller
   0.118362	- Serial Number: 0000:00:1d.2
   0.118372	- Bus: 004
   0.118383	Trying to match device
   0.118395	Device does not match - skipping
   0.118411	Checking device (1D6B/0001) (003/001)
   0.118453	- VendorID: 1d6b
   0.118465	- ProductID: 0001
   0.118476	- Manufacturer: Linux 2.6.32-24-generic uhci_hcd
   0.118487	- Product: UHCI Host Controller
   0.118498	- Serial Number: 0000:00:1d.1
   0.118508	- Bus: 003
   0.118519	Trying to match device
   0.118531	Device does not match - skipping
   0.118546	Checking device (0001/0000) (002/002)
   0.124522	- VendorID: 0001
   0.124540	- ProductID: 0000
   0.124550	- Manufacturer: unknown
   0.124561	- Product: unknown
   0.124572	- Serial Number: unknown
   0.124583	- Bus: 002
   0.124594	Trying to match device
   0.124633	Device matches
   0.127542	Trying megatec protocol...
   0.127559	send: Q1
   0.130530	read: error sending control message: Broken pipe
   0.133511	Stall condition cleared
   0.133523	blazer_status: short reply
   0.133536	Status read 1 failed
   0.133547	send: Q1
   0.149536	read: error sending control message: Broken pipe
   0.152559	Stall condition cleared
   0.152600	blazer_status: short reply
   0.152617	Status read 2 failed
   0.152634	send: Q1
   0.155557	read: error sending control message: Broken pipe
   0.158531	Stall condition cleared
   0.158553	blazer_status: short reply
   0.158565	Status read 3 failed
   0.158576	Trying mustek protocol...
   0.158587	send: QS
   0.158599	read: QS
   0.158609	blazer_status: short reply
   0.158620	Status read 1 failed
   0.158631	send: QS
   0.158641	read: QS
   0.158652	blazer_status: short reply
   0.158663	Status read 2 failed
   0.158674	send: QS
   0.158685	read: QS
   0.158696	blazer_status: short reply
   0.158707	Status read 3 failed
   0.158717	Trying megatec/old protocol...
   0.158728	send: D
   0.158738	read: D
   0.158749	blazer_status: short reply
   0.158760	Status read 1 failed
   0.158771	send: D
   0.158781	read: D
   0.158792	blazer_status: short reply
   0.158803	Status read 2 failed
   0.158814	send: D
   0.158824	read: D
   0.158835	blazer_status: short reply
   0.158846	Status read 3 failed
   0.158857	No supported UPS detected
====================================================================

And after:
====================================================================
Network UPS Tools - Megatec/Q1 protocol USB driver 0.03 (2.4.3)
   0.000000	debug level is '3'
   0.118088	Checking device (1D6B/0001) (005/001)
   0.118160	- VendorID: 1d6b
   0.118172	- ProductID: 0001
   0.118182	- Manufacturer: Linux 2.6.32-24-generic uhci_hcd
   0.118193	- Product: UHCI Host Controller
   0.118204	- Serial Number: 0000:00:1d.3
   0.118219	- Bus: 005
   0.118232	Trying to match device
   0.118257	Device does not match - skipping
   0.118275	Checking device (1D6B/0001) (004/001)
   0.118319	- VendorID: 1d6b
   0.118331	- ProductID: 0001
   0.118342	- Manufacturer: Linux 2.6.32-24-generic uhci_hcd
   0.118353	- Product: UHCI Host Controller
   0.118364	- Serial Number: 0000:00:1d.2
   0.118374	- Bus: 004
   0.118385	Trying to match device
   0.118397	Device does not match - skipping
   0.118413	Checking device (1D6B/0001) (003/001)
   0.118455	- VendorID: 1d6b
   0.118467	- ProductID: 0001
   0.118477	- Manufacturer: Linux 2.6.32-24-generic uhci_hcd
   0.118488	- Product: UHCI Host Controller
   0.118499	- Serial Number: 0000:00:1d.1
   0.118510	- Bus: 003
   0.118520	Trying to match device
   0.118532	Device does not match - skipping
   0.118548	Checking device (0001/0000) (002/002)
   0.124095	- VendorID: 0001
   0.124115	- ProductID: 0000
   0.124126	- Manufacturer: unknown
   0.124136	- Product: unknown
   0.124147	- Serial Number: unknown
   0.124158	- Bus: 002
   0.124168	Trying to match device
   0.124208	Device matches
   0.127113	Trying megatec protocol...
   0.127131	send: Q1
   0.133087	blazer_status: short reply
   0.133104	Status read 1 failed
   0.133116	send: Q1
   0.414304	Status read in 2 tries
   0.414328	Supported UPS detected with megatec protocol
   0.414340	send: F
   0.571288	Ratings read in 1 tries
   0.571313	send: I
   0.774349	Vendor information read in 1 tries
   0.774377	Battery runtime will not be calculated (runtimecal not set)
   0.774402	send: Q1
   1.054571	dstate_init: sock /var/state/ups/blazer_usb-DynamixUPS open on fd 5
   1.054609	send: Q1
   1.059418	read: timeout
   1.059432	blazer_status: short reply
   1.059444	Communications with UPS lost: status read failed!
   3.056628	send: Q1
   3.336276	Communications with UPS re-established
   5.058367	send: Q1
   7.060107	send: Q1
   7.064567	read: timeout
   7.064582	blazer_status: short reply
   7.064593	Communications with UPS lost: status read failed!
   9.062118	send: Q1
   9.342426	Communications with UPS re-established
  11.062258	send: Q1
  13.063998	send: Q1
  15.065761	send: Q1
  17.067520	send: Q1
  17.072148	read: timeout
  17.072163	blazer_status: short reply
  17.072175	Communications with UPS lost: status read failed!
  19.069533	send: Q1
  19.326997	Communications with UPS re-established
  21.071296	send: Q1
  23.073059	send: Q1
  25.074820	send: Q1
  27.076584	send: Q1
  29.078351	send: Q1
  31.080117	send: Q1
  33.081884	send: Q1
  35.083655	send: Q1
  37.085429	send: Q1
  39.087206	send: Q1
  41.088984	send: Q1
  43.090759	send: Q1
  43.339563	blazer_status: non numerical value [27.0]
  45.092528	send: Q1
  47.094300	send: Q1
  49.096050	send: Q1
  51.097802	send: Q1
  53.099556	send: Q1
  55.101309	send: Q1
  57.103065	send: Q1
  57.107474	read: timeout
  57.107489	blazer_status: short reply
  57.107501	Communications with UPS lost: status read failed!
  59.105087	send: Q1
  59.391341	Communications with UPS re-established
  61.106825	send: Q1
^C  63.022253	Signal 2: exiting
====================================================================

The communication gets lost/restored often, but it works.

The diffs aren't complicated - it's the guts of usb_get_string_simple repurposed:
====================================================================
*** blazer_usb.c.orig	2010-02-12 10:43:23.000000000 +1300
--- blazer_usb.c	2010-09-25 13:43:09.523546405 +1200
***************
*** 233,238 ****
--- 233,239 ----
  	};
  
  	int	i;
+ 	char tbuf[255];	/* Some devices choke on size > 255 */
  
  	upsdebugx(3, "send: %.*s", (int)strcspn(cmd, "\r"), cmd);
  
***************
*** 244,257 ****
  		}
  
  		for (retry = 0; retry < 10; retry++) {
! 			int	ret;
! 
! 			ret = usb_get_string_simple(udev, command[i].index, buf, buflen);
  
  			if (ret <= 0) {
  				upsdebugx(3, "read: %s", ret ? usb_strerror() : "timeout");
  				return ret;
  			}
  
  			/* "UPS No Ack" has a special meaning */
  			if (!strcasecmp(buf, "UPS No Ack")) {
--- 245,279 ----
  		}
  
  		for (retry = 0; retry < 10; retry++) {
! 			int	ret, di, si;
! 	
! 			//ret = usb_get_string_simple(udev, command[i].index, buf, buflen);
! 			// Most of the guts of usb_get_string_simple, but eliminated
! 			// request for languages - seems to confuse stoopid UPS
! 			ret = usb_get_string(udev, command[i].index, 0x0409, tbuf, sizeof(tbuf));
  
  			if (ret <= 0) {
  				upsdebugx(3, "read: %s", ret ? usb_strerror() : "timeout");
  				return ret;
  			}
+ 			if (tbuf[1] != USB_DT_STRING)
+ 				return -EIO;
+ 			
+ 			if (tbuf[0] > ret)
+ 				return -EFBIG;
+ 		    
+ 			for (di = 0, si = 2; si < tbuf[0]; si += 2)
+ 			{
+ 				if (di >= (buflen - 1))
+ 					break;
+ 		
+ 				if (tbuf[si + 1])	/* high byte */
+ 					buf[di++] = '?';
+ 				else
+ 					buf[di++] = tbuf[si];
+ 			}
+ 		
+ 			buf[di] = 0;
  
  			/* "UPS No Ack" has a special meaning */
  			if (!strcasecmp(buf, "UPS No Ack")) {
====================================================================

Take care,
--
Brian R. Smith
bsmith at furbium.com






More information about the Nut-upsdev mailing list