<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">On Sep 2, 2015, at 8:54 AM, Rob Groner <<a href="mailto:rgroner@RTD.com" class="">rgroner@RTD.com</a>> wrote:<br class=""><div><blockquote type="cite" class=""><br class="Apple-interchange-newline"><div class="">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" class="">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)" class="">
<style class=""><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.apple-style-span
{mso-style-name:apple-style-span;}
span.EmailStyle18
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div lang="EN-US" link="blue" vlink="purple" class="">
<div class="WordSection1"><p class="MsoNormal"><o:p class=""> </o:p></p>
<div class=""><p class="MsoNormal" style="text-indent:.5in">No, just as a variable string descriptor.<o:p class=""></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt" class="">
<div class="">
<div class=""><p class="MsoNormal"><span style="color:#1F497D" class=""> </span></p><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class="">By “variable string descriptor”, do you mean what is contained in the example in the App Note? I’m just asking for clarification, in
case variable string descriptor is something different than shown there.</span></p></div></div></blockquote></div></div></div></blockquote><div><br class=""></div><div>By "variable" I mean "not const". Although they did not explicitly mark any of the structs "const", their code does not change any of the string descriptors at runtime.</div><br class=""><blockquote type="cite" class=""><div class=""><div lang="EN-US" link="blue" vlink="purple" class=""><div class="WordSection1"><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt" class=""><div class=""><div class=""><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class=""><o:p class=""></o:p></span></p><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class=""> </span></p><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class="">The way they do the string descriptors in the example is how I have mine now. They return a size and address, but it is to something
that was defined at compile time. I guess I’ve been fixated on that, so I don’t know if I can simply pass a different string that what was defined before. And I don’t know how to handle something of an unknown size (though in my case, the MAX size of the
serial number can be defined)</span></p></div></div></blockquote></div></div></div></blockquote>Because the structs are not const, you should be able to write new values into them at runtime. (It's up to you to do this before the string is actually requested, but since string descriptors are not requested often, you could do it in something like GetStringDescriptor() just before it returns.)</div><div><br class=""></div><div>You would need to change the "sizeof()" to be the actual length of that struct at runtime. It's a little tricky, because the base struct is sizeof(USB_STRING_DESCRIPTOR), and then you need to add 2*strlen(serial_number) if your copy of the serial number from EEPROM is ASCII. (Note that the ['M', 'i', 'c', 'r', 'o'...] initialization is for a WORD[] rather than char[]. USB strings are 16-bit little-endian Unicode.)</div><div><br class=""></div><div>Dragging in a copy of sprintf() might be overkill, but you could have a loop that reads in the bytes of the serial number, adds '0' (0x30) to each 4-bit hex digit, and writes that into the string descriptor.</div><div><blockquote type="cite" class=""><div class=""><div lang="EN-US" link="blue" vlink="purple" class=""><div class="WordSection1"><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt" class=""><div class=""><div class=""><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class=""><o:p class=""></o:p></span></p><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class=""> </span></p><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class="">That’s why I was asking about the variable string descriptor...it sounds more like something where you can pass a string of any size
and address, which would definitely be what I’m looking for.</span></p></div></div></blockquote></div></div></div></blockquote>GetStringDescriptor() is returning a pointer via "return", and a length passed by reference ("*length = ..."), so as long as you construct the string descriptor to look the same as the statically-initialized ones, you should be all set.<br class=""><blockquote type="cite" class=""><div class=""><div lang="EN-US" link="blue" vlink="purple" class=""><div class="WordSection1"><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt" class=""><div class=""><div class=""><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class=""><o:p class=""></o:p></span></p><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class=""> </span></p><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class="">Looking at the data being passed, I realized that battery.type is something else that I possibly won’t know until the code is running.
Our UPS can use different attached batteries, and will be able to discern what it is at runtime, and that’s when it would be able to report battery.type.</span></p></div></div></blockquote></div></div></div></blockquote><div>For returning one choice from a limited set, you might want to create one const string descriptor for each battery type string, and choose one pointer/length pair at runtime.</div><blockquote type="cite" class=""><div lang="EN-US" link="blue" vlink="purple" class=""><div class="WordSection1"><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt" class=""><div class=""><div class=""><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class=""><o:p class=""></o:p></span></p><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class=""> </span></p><p class="MsoNormal" style="margin-right:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class="">Thanks for the help Charles…that is a very good link to the Appnote considering you haven’t done PIC32 work.
</span><span style="font-size:11.0pt;font-family:Wingdings;color:#1F497D" class="">J</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D" class=""> My google skills failed me.<o:p class=""></o:p></span></p><p class="MsoNormal" style="margin-right:.5in"><br class=""></p></div>
</div>
</blockquote>
</div>
</div>
</blockquote>No problem. Using the standard string descriptors means fewer special cases in our source code :-)</div><div><br class=""></div><div>Note that you should be able to test reading the string descriptors by simply using "lsusb -v -d <i class="">VID</i>:" on your device (might need to be run as root, depending on permissions). Next to the iSerialNumber value, it will try to fetch the corresponding string descriptor and print it.</div><br class=""><div class="">
<span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px;"><div class="">-- </div><div class="">Charles Lepple</div><div class="">clepple@gmail</div><div class=""><br class=""></div></span><br class="Apple-interchange-newline">
</div>
<br class=""></body></html>