[Nut-upsdev] USB HID Spec help (passing strings)

Charles Lepple clepple at gmail.com
Fri Aug 28 22:51:15 UTC 2015

On Aug 28, 2015, at 2:21 PM, Rob Groner <rgroner at RTD.com> wrote:
> We’re wrapping up our first version of the UPS we’re making, and so I’m going over the USB code and came across one loose end.  The serial number of the unit (iSerialNumber according to the USB HID doc) is a constant, but it’s of course a different constant for each UPS.

iSerialNumber does not need to be unique per device - it is not very many bits wide.

>   Right now we store that value in the Flash on the device, but the only way I’ve seen to pass the serial number over USB is to encode it as a constant in the code and then reference it as a USB HID String Index.  We aren’t going to rebuild/program for each UPS, so there must be a way to take the value in flash memory and send that as the serial number.  In other words, how do you send a “variable” length string across USB?  Actually, the length can be known ahead of time, but the data itself will be the variable.

NUT and other tools match against the string returned from the "get string descriptor" request (not iSerialNumber itself - the string indexed by it) and the procedure for modifying that is going to be specific to each USB device controller.

Typically the string descriptor table is an array of pointers, and this is often why USB devices cluster the string indexes together starting at 1 (rather than having a sparse array). If you can make the pointer corresponding to the serial number point to RAM, you should be all set (Harvard architecture chips like PICs make this harder, but there is a C __attribute__ or something that you should be able to use). Otherwise, does your USB framework allow callbacks for arbitrary requests?

Charles Lepple
clepple at gmail

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20150828/c101fbe5/attachment.html>

More information about the Nut-upsdev mailing list