[Nut-upsdev] Patch for the bestfortress driver 0.02

J. Thomsen list at jth.net
Mon Apr 19 11:24:10 UTC 2010


I could not make the bestfortress driver 0.02 work for my Best Fortress LI675VA,
so I have made a patch for the driver.
The reason was, that all responses are preceded and terminated by CR LF, but the driver would discard everything after the first CR
LF.

The following patch discards everything up to the first LF.
It also adds a debugging feature of displaying the accepted data  (level 5 i.e. -D -D -D -D -D -D)

/Jørgen Thomsen

--- 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