[Nut-upsdev] CyberPower CP825AVR-G battery scale

Ariel asnutups at dsgml.com
Fri Dec 30 11:49:59 UTC 2011


On Thu, 29 Dec 2011, Charles Lepple wrote:

> On Dec 28, 2011, at 9:16 AM, Ariel wrote:

>> On Wed, 28 Dec 2011, Charles Lepple wrote:

>>> Is it possible that UPS.PowerSummary.Voltage is really an output 
>>> voltage divided by 10? (This has happened on other devices.)

>> Well, I have two 12 volt batteries, so 24 volts makes sense, 240 doesn't.

> I meant AC output voltage, not DC.

No, I'm in the US, so 120 volts.

>> I agree - I think the scaling should be configured in ups.conf, and be 
>> general for any field. To make it very easy support +-*/ without 
>> precedence - operations are done strictly left to right. Perhaps 3 
>> fields: operation, min, max (min/max are applied after scaling, not 
>> before).

> We will need to think about this a bit more to bound the scaling/offset 
> problem.

In case you wish to do it, I wrote some functions to parse and execute a 
scale/offset/min/max calculation.

The code pre-parses a text specification, then there is a function to run 
the calculation on a specific value.

I did not try to integrate it into the code since I'm not very familiar 
with it, but I would expect that instead of things like:

{ "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%s", 0, cps_battvolt },

You would have:

{ "battery.voltage", 0, 0, "UPS.PowerSummary.Voltage", NULL, "%s", 0, "* 0.667" },

i.e. just a textual specification of the scaling/offset, and the driver 
could read in user specified options that would override the default 
(either on the command line or in ups.conf).

Or the divide_by_10_conversion_fun() function would be replaced by a 
default scaling (that can be overridden by the user - which is the main 
point of doing it in text), and then just a single generic output 
function.

I attached the files with the code.

An example of usage:

#include <stdio.h>
#include "str_math.h"

int main(void) {
   struct str_math spec;
   /* minus 6 times 3 divide by 8, min value 1, max 20 */
   printf(init_str_math(&spec, " - 6 * 3  /  8,  1, 20") ? "valid spec\n" : "invalid spec\n");

   printf("%f\n", str_math(&spec, 500));

   free_str_math(&spec);
   return 0;
}

 	-Ariel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: str_math.h
Type: text/x-chdr
Size: 1136 bytes
Desc: 
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20111230/9ada86c6/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: str_math.c
Type: text/x-csrc
Size: 4259 bytes
Desc: 
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20111230/9ada86c6/attachment.c>


More information about the Nut-upsdev mailing list