[Nut-upsdev] NUT and libhid

Arjen de Korte nut+devel at de-korte.org
Tue Aug 14 12:28:19 UTC 2007

> I think the differences between NUT HID and libhid are probably
> considerable at this point, as I've spent some time last year updating
> the former.
> - the report buffer,

Thanks for reminding me, so it is you I should nag with questions about
the report buffering, not Charles.

> - introduced a data structure to store the parsed report descriptor,
>   rather than re-parsing it each time it is used,
> - much improved conversion functions for physical and logical units,
> - cleaned up many parts of the code, eliminated global variables where
>   possible,

Regarding the latter, do you have any particular reason for dynamically
allocating the report buffer 'rbuf'? As far as I can see, we always have
one (and exactly one), which is used by all functions that operate on the
report buffer. Instead of free'ing and allocating it each time we
(re)connect to the UPS, I can imagine that it is less hassle to make this
a global variable and just invalidate the timestamps (by zero'ing them).
In that case, instead of calling free_report_buffer() and
new_report_buffer(), we call

static reportbuf_t	rbuf;


void HIDClearReportBuffer(void)
	int i;

	for (i=0; i<256; i++) {
		rbuf.ts[i] = 0;

This would satisfy my need for a way to invalidate the contents of the
report buffer, so that after a successful instcmd() and setvar() we would
just call HIDClearReportBuffer() and all is well again.

> - and probably more.
> I don't know how many changes you made to libhid since the fork;
> perhaps it's easier to keep improving NUT's HID?

The latter would be a lot easier IMHO...

Best regards, Arjen

More information about the Nut-upsdev mailing list