[Nut-upsdev] Patch for the bestfortress driver 0.02

Stuart D Gathman stuart at bmsi.com
Fri May 25 20:09:18 UTC 2012


Applied this to nut-2.6.3 on fedora, and bestfortress seems to still
work.  The patch seems reasonable as well.  As to why it isn't needed
for me, I suspect it has to do with serial IO buffering.  Driver was
depending on upsflushin() to empty the input buffer before triggering
another status update.  That doesn't always kill everything (I was
getting occasional misreads on a server), and the patch simply skips to
just after '\n' before and after reading a status line.

Long ago, Nostradamus foresaw that on 05/25/2012 10:31 AM, Arnaud Quette
would write:
> Hi Jørgen, Oliver and Stuart,
>
> I'm not forgetting you...
> while looking again at bestfortress, I realized I completely missed
> Jørgen's patch!
>
> 2010/4/19 J. Thomsen <list at jth.net>:
>> --- nut-2.4.3/drivers/bestfortress.c    2010-02-11 22:43:23.000000000 +0100
>> +++ nut-2.4.3j/drivers/bestfortress.c   2010-04-19 12:17:07.929852889 +0200
>> @@ -34,7 +34,7 @@
>>  #endif
>>
>>  #define DRIVER_NAME             "Best Fortress UPS driver"
>> -#define DRIVER_VERSION  "0.02"
>> +#define DRIVER_VERSION  "0.03"
>>
>>  /* driver description structure */
>>  upsdrv_info_t   upsdrv_info = {
>> @@ -203,20 +203,26 @@
>>        int loadva;
>>        int len;
>>        int retry;
>> +       char ch;
>>
>>        int checksum_ok, is_online=1, is_off, low_batt, trimming, boosting;
>>
>>        for (retry = 0; retry < 5; ++retry) {
>>                upsflushin (0, 0, "\r ");
>>                upssend ("f\r");
>> +               while (ser_get_char(upsfd, &ch, 0, UPSDELAY) > 0 && ch != '\n'); // response starts with \r\n
>> +               temp[2] = 0;
>>                do {
>> -                       if (upsrecv (temp+2, sizeof temp - 2, ENDCHAR, IGNCHARS) <= 0) {
>> +                       if ((len = upsrecv (temp+2, sizeof temp - 2, ENDCHAR, IGNCHARS)) <= 0) {
>>                                upsflushin (0, 0, "\r ");
>>                                upssend ("f\r");
>> +                               while (ser_get_char(upsfd, &ch, 0, UPSDELAY) > 0 && ch != '\n'); // response starts with \r\n
>>                        }
>>                } while (temp[2] == 0);
>>
>> -               /*syslog (LOG_DAEMON | LOG_NOTICE,"ups: got '%s'\n", p);*/
>> +               /* syslog (LOG_DAEMON | LOG_NOTICE,"ups: got %d chars '%s'\n", len, temp + 2); */
>> +
>> +               upsdebugx(5, "data from UPS: len=%d '%s'", len, &temp[2]);
>>                /* status example:
>>                   000000000001000000000000012201210000001200014500000280600000990025000000000301BE
>>                   000000000001000000000000012401230000001200014800000280600000990025000000000301B7
>




More information about the Nut-upsdev mailing list