<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p style="margin-top:0;margin-bottom:0"></p>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
Dear Daniele,</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
i understand perfectly, i'd like to explain you why we choosed to clone the blazer_usb driver:</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
some of our devices uses Voltronic Q1 protocol and we tried the Krauler Subdriver (it was the one with the right "commands", Q1, F, etc.), but the issues were 2:</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
- first: the Krauler Subdriver expects a different number of bytes in answer because in debug i see "Short Reply" (if i send Q1 to the UPS it will answer with 47 Bytes, CR terminated), from what i understand there is something wrong with the last byte that
 somewhere is not counted (because if i use a serial terminal and send Q1 the UPS answer correctly with the number of bytes required)</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
- second: the battery voltage low and high (estimated) were not acceptable for our UPSs because the % level will never reach the 100% and the voltage estimation was wrong.</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
- third: we have products with VID and PID: FFFF 0000, this is a problem because the combination is occuped by Krauler and in this way it will match each time with the wrong subdriver (krauler instead of our).</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
<br>
</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
now the question i've for you: can we create a clone of nutdrv_qx, but with the differences shown before? do you have other solutions? </div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
thanks for the support!</div>
<div style="font-family: Calibri, Helvetica, sans-serif; font-size: 16px; margin-top: 0px; margin-bottom: 0px;">
<br>
</div>
<p></p>
<div id="Signature">
<div id="divtagdefaultwrapper" dir="ltr" style="">
<p style="color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif; font-size:12pt">
Best Regards,</p>
<p style=""><span style="font-size:11pt"><u>Gabriele Taormina</u></span><span style="font-size:11pt"> </span><span style="font-size:11pt"> </span><span style="font-size:11pt"></span></p>
<p style=""><span style="font-size:11pt"></span><span style="font-size:11pt">UPS </span><span style="font-size:11pt">Strategic Business Unit</span></p>
<p style=""><span style="font-size:11pt"></span><span style="font-size:11pt">Field Application Engineer</span></p>
<p style=""><span style="font-size:11pt"></span><span style="font-size:11pt">Phone:     +39 0522/207046</span></p>
<p style=""><span style="font-size:11pt"></span><span style="font-size:11pt">Fax:           +39 0522/207005</span></p>
<p style=""><span style="font-size:11pt"></span><span style="font-size:11pt">Address:  Via Rodano 1 - Reggio Emilia - 42124 - Italy</span></p>
<p style=""><span style="font-size:11pt"></span><span style="font-size:11pt">Email:       </span><span style="font-size:11pt"><a href="mailto:gabriele.taormina@legrand.com" class="OWAAutoLink" style="font-size:12pt" id="LPNoLP">gabriele.taormina@legrand.com</a></span></p>
<p style=""><span style="font-size:11pt"><a href="mailto:gabriele.taormina@legrand.com" class="OWAAutoLink" style="font-size:12pt" id="LPNoLP"></a></span><span style="font-size:11pt">Website:  </span><span style="font-size:11pt"><a href="http://www.ups.legrand.com/" target="_blank" rel="noopener noreferrer" class="x_OWAAutoLink" id="LPNoLP" style="font-size:12pt">www.ups.legrand.com</a></span></p>
<p style=""><span style="font-size:11pt"></span><span style="font-size:11pt">Website:  </span><a href="http://www.legrand.com/" target="_blank" rel="noopener noreferrer" class="x_OWAAutoLink" id="LPNoLP" style="font-size:12pt"><span style="font-size:11pt">www.legrand.com</span></a></p>
<span style="font-size:11pt"></span>
<div style="color:rgb(0,0,0); font-family:Calibri,Arial,Helvetica,sans-serif,serif,EmojiFont; font-size:16px">
<span style="font-size:11pt"></span><font size="2" style="font-family:Arial,Helvetica,sans-serif,serif,EmojiFont"><img class="EmojiInsert" alt="1506322600142_legrand-vector-logo.png" style="" data-outlook-trace="F:1|T:1" src="cid:45766636-8d75-405f-9451-3ce8872733c5"><br>
</font></div>
<br>
<p style="color:rgb(0,0,0); font-family:Calibri,Helvetica,sans-serif; font-size:12pt">
</p>
</div>
</div>
</div>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>Da:</b> Daniele Pezzini <hyouko@gmail.com><br>
<b>Inviato:</b> sabato 21 luglio 2018 02:48:25<br>
<b>A:</b> Gabriele TAORMINA<br>
<b>Cc:</b> nut-upsdev@alioth-lists.debian.net; Thierry DESTRUEL; Stefano PONGILUPPI<br>
<b>Oggetto:</b> Re: [Nut-upsdev] Adding drivers to NUT?</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">aehm.. the innards of nutdrv_qx are not exactly well documented (and<br>
vars have somewhat confusing names) -- my fault, sorry.<br>
This is another thing that has been on my todo list for a while...<br>
<br>
Briefly, at the moment, in nutdrv_qx, there are actually two kinds of<br>
subdrivers:<br>
- 'protocols', which are communication-type-agnostic (i.e. they do not<br>
fiddle with serial or USB operations, and are not restrained by them),<br>
only map the protocol used by the device to the protocol used by NUT,<br>
and are implemented in their own files using (and exposing only) the<br>
`subdriver_t` format (for more info on this type, see the chapter of<br>
the developer guide I mentioned before, 'nutdrv_qx.h' or the various<br>
'nutdrv_qx_<name-of-the-protocol>.c' files),<br>
- 'USB subdrivers', which only deal with USB I/O operations, and,<br>
conversely, are implemented entirely in 'nutdrv_qx.c'.<br>
<br>
With regard to 'protocols', nutdrv_qx works like this:<br>
- 'nutdrv_qx.c''s `subdriver_list` lists the various (#include'd)<br>
'protocols' the driver supports.<br>
- Once nutdrv_qx has set up the communication with a supported device<br>
in `upsdrv_initups()` (see below, for serial or USB devices), it gives<br>
all (unless otherwise instructed by the user) 'protocols' in<br>
`subdriver_list` a few tries by calling their 'claim()' function<br>
(which usually tries to read some vars from the device to see if it's<br>
actually 'speaking' that protocol): the first one to successfully<br>
claim (i.e. the 'claim()' function returns 1) the device wins.<br>
- From then on, nutdrv_qx uses that 'protocol' when communicating<br>
(e.g. updating the vars, sending instant commands, ...) with the<br>
device: the mapping in the 'qx2nut' table, the 'accepted'/'rejected'<br>
strings, etc.<br>
<br>
Now, onto communications (entirely in 'nutdrv_qx.c')...<br>
<br>
For serial devices:<br>
- given that, so far, all supported devices shared similar settings<br>
and I/O modus operandi, operations are done directly without much<br>
fanfare...<br>
- setup is done directly in `upsdrv_initups()`,<br>
- ditto for subsequent communications, in `qx_command()`.<br>
<br>
For USB devices:<br>
- `qx_usb_id` lists the various VID:PID pairs (with, optionally and<br>
only if needed, the iManufacturer and iProduct strings) of each<br>
supported device, coupled with a function ('fun()' from now on) that<br>
will set `subdriver_command` to point to the function ('command()'<br>
from now on) later used to communicate with the device.<br>
- When nutdrv_qx starts, in `upsdrv_initups()`, it will either pick<br>
the USB subdriver (whose name must be mapped to its relative<br>
'command()' in the `usbsubdriver` list) directly if it was explicitly<br>
provided by the user or, for each available USB device, traverse the<br>
`qx_usb_id` lists, until it finds a match (VID:PID +<br>
iManufacturer/iProduct) and then call its 'fun()' function -- in both<br>
cases, the result is that, if a supported device is found,<br>
`subdriver_command` points to the right 'command()' function.<br>
- Later, every time nutdrv_qx needs to send anything to the device and<br>
to get a reply from it (i.e. in the `qx_command()` function), it will<br>
call the function ('command()') pointed to by `subdriver_command`:<br>
this 'command()' function will receive a null-terminated byte string,<br>
a buffer and its size, and will do all the needed things to a) send<br>
the string to the device and b) get the reply from the device and<br>
store it in the buffer (for example, sending the string verbatim to a<br>
control endpoint and then reading the reply, or mapping the string it<br>
gets to the index of a string descriptor, that, once retrieved, will<br>
hold the reply).<br>
<br>
A couple of examples worth a thousand words:<br>
- adding a 'protocol':<br>
<a href="https://github.com/networkupstools/nut/commit/dc1e0799277008dcd2c2fad6bc3f59455b242d14">https://github.com/networkupstools/nut/commit/dc1e0799277008dcd2c2fad6bc3f59455b242d14</a><br>
- adding a 'USB subdriver':<br>
<a href="https://github.com/networkupstools/nut/commit/3370bbf3ca2d8f95346487938895c494e363186f">https://github.com/networkupstools/nut/commit/3370bbf3ca2d8f95346487938895c494e363186f</a><br>
<br>
Clearer, now?<br>
</div>
</span></font></div>
<br>
<hr>
<font face="Tahoma" size="2">
<p>Ce message, ainsi que tous les fichiers joints à ce message, peuvent contenir des informations sensibles et/ ou confidentielles ne devant pas être divulguées. Si vous n'êtes pas le destinataire de ce message (ou que vous recevez ce message par erreur), nous
 vous remercions de le notifier immédiatement à son expéditeur, et de détruire ce message. Toute copie, divulgation, modification, utilisation ou diffusion, non autorisée, directe ou indirecte, de tout ou partie de ce message, est strictement interdite.
</p>
<br>
<p>This e-mail, and any document attached hereby, may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized,
 direct or indirect, copying, disclosure, distribution or other use of the material or parts thereof is strictly forbidden.</p>
</font>
</body>
</html>