[Nut-upsdev] [nut-commits] svn commit r1136 - in trunk: . drivers

Arjen de Korte nut+devel at de-korte.org
Wed Oct 3 10:20:07 UTC 2007

>> 3) Something you're probably not responsible for, but if flushing the
>> input buffers is needed, this is something that should be done in main
>> driver body (megatec.c). The driver doesn't flush I/O buffers, so the
>> implementation of the Megatec protocol is apparently robust enough to
>> tolerate occasional garbage characters in the buffers.
> I can do this in "megatec.c" if necessary, just say the word.

Well, this is really not something I can decide, it largely depends on the
UPS (and protocol) if this is desireable/needed. For instance, the UPS for
which I wrote the 'safenet' driver a couple of years ago, spits out some
garbage characters a few seconds after you open a connection to it (an
unsollicited serial PnP reply string). It really benefits from flushing
the I/O buffers before *every* command. If the same holds for the
'megatec' driver, I don't know. From the below, it looks like it does.

> And yes, the implementation has to be robust against garbage because
> the hardware itself sometimes goes crazy and returns crap.

Generally speaking, it doesn't hurt to flush the buffers with the
ser_flush_io(upsfd) command before sending a command. Under the hood it is
a single ioctl() call which takes virtually no time at all to execute (no
actual data is read). Only if your UPS is really slow to respond, it may
hurt (since it won't allow to read the result of a query from the previous
upsdrv_updateinfo() call).

Best regards, Arjen

More information about the Nut-upsdev mailing list