@@ -181,6 +181,87 @@ for eventual `exit(EXIT_FAILURE)` and `EF_EXIT_SUCCESS` (`-2`) for
181181`exit(EXIT_SUCCESS)`, which would be handled in the standard driver
182182loop or in `forceshutdown()` method of `main.c`.
183183
184+ addvar, getval and testvar
185+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
186+
187+ NUT drivers can be configured at run-time with optional settings, which
188+ can be passed on command line or via the linkman:ups.conf[5] file.
189+ Such settings broadly fall into two categories: "values" which convey
190+ some specific value (e.g. `port` or `desc` strings), and "flags" which
191+ can be seen as a sort of booleans which are `true` if mentioned and
192+ `false` if not (any assigned value would be ignored, if not rejected
193+ by configuration parser).
194+
195+ Some options are common to all drivers and are handled in `drivers/main.c`
196+ (which also defines and implements most of the methods in this area), while
197+ others may be specific to individual drivers or even their sub-drivers.
198+
199+ The `addvar()` method allows to specify a certain option name, with its
200+ type and a help message string:
201+
202+ addvar(VAR_VALUE, "sdtype", "Specify simple shutdown method (0-6)");
203+
204+ addvar(VAR_FLAG, "wait", "Wait for AC power");
205+
206+ In driver code, these calls should comprise the `upsdrv_makevartable()`
207+ method.
208+
209+ The `getval()` method allows to get the user-provided string value (or
210+ `NULL` -- but it is hard to tell apart if the option was not specified
211+ or no value was assigned). The `testvar()` method allows to check if
212+ the option name was specified (even if without a value), so is better
213+ suited for flags. Internally there is no difference between "values"
214+ and "flags", so historically some flags were "promoted" to values with
215+ boolean-ish strings handled explicitly, in addition to some new features.
216+
217+ NOTE: Internally, the values can also be marked as reloadable (so that a
218+ running driver program may change them when re-reading the configuration
219+ file due to a signal). The implementation may be currently limited to
220+ common options handled by `main.c` itself. In code base this is exposed
221+ with the `addvar_reloadable()` and several `test*_reloadable()` methods.
222+
223+ Since these methods involve a data structure walk to locate (or not) the
224+ entry for each option, they should not be used in data processing loops.
225+ Instead, the driver initialization methods such as `upsdrv_initups()`
226+ should consider all values and flags that can impact the set-up of the
227+ driver, and save them into C variables (typically strings, booleans, or
228+ processed and range/value-checked number types) which are then directly
229+ used in the driver program code.
230+
231+ nut_usb_addvars
232+ ~~~~~~~~~~~~~~~
233+
234+ For consistency between USB-capable NUT drivers, a set of `addvar()`
235+ options related to USB media setup and expected by `nut_libusb_open()`
236+ can be defined by calling the `nut_usb_addvars()` method, which can be
237+ seen in `drivers/libusb{0,1}.c`.
238+
239+ Like `addvar()`, a call to this method belongs in `upsdrv_makevartable()`
240+ (see existing drivers for examples).
241+
242+
243+ nut_ser_addvars
244+ ~~~~~~~~~~~~~~~
245+
246+ WARNING: NOT CURRENTLY IMPLEMENTED.
247+
248+ Issue https://github.com/networkupstools/nut/issues/2748 tracks the idea
249+ to standardize the set and names of options involved in the serial driver
250+ connection set-up (speed, parity, stop-bits, etc.) similarly to the
251+ precedent of `nut_usb_addvars()`. One problem is that many drivers
252+ released during the past decades reinvented this wheel with different
253+ option names.
254+
255+ nut_modbus_addvars
256+ ~~~~~~~~~~~~~~~~~~
257+
258+ WARNING: NOT CURRENTLY IMPLEMENTED.
259+
260+ Issue https://github.com/networkupstools/nut/issues/2419 tracks a similar
261+ idea for Modbus-capable drivers (which may involve or not Serial and/or
262+ USB link and option support, and uniquely TCP/IP RTU support, for example).
263+
264+
184265Data types
185266----------
186267
0 commit comments