[Nut-upsdev] apc-hid.c: watts_to_av_conversion

Arjen de Korte nut+devel at de-korte.org
Sat Aug 11 08:57:32 UTC 2007


Peter,

Looking through the usbhid-ups subdrivers, I came across the following
function in apc-hid.c, presumably added by you about two years ago (if
not, my apologies):

41 	/* returns statically allocated string - must not use it again before
42 	   done with result! */
43 	static char *watts_to_av_conversion_fun(long value) {
44 	        static char buf[20];
45
46 	        snprintf(buf, sizeof(buf), "%.0f", value * 1.4142136);
47 	        return buf;
48 	}
49
50 	static info_lkp_t watts_to_av_conversion[] = {
51 	        { 0, NULL, watts_to_av_conversion_fun }
52 	};

Being a power electronics engineer, the name of it made me wonder what the
heck was going on. As far as I know, there is no way to convert between AV
and W without knowing the phase relation between RMS voltage and -current.
Could it be that for this particular UPS this works out to be correct by
coincidence? Now that we have "ups.realpower.nominal", I think we should
change line 215

	{ "ups.power.nominal", 0, 0, "UPS.Output.ConfigActivePower", NULL, "%s",
HU_FLAG_OK, watts_to_av_conversion }, /* CyberPower */

to

	{ "ups.realpower.nominal", 0, 0, "UPS.Output.ConfigActivePower", NULL,
"%.0f", HU_FLAG_OK, NULL }, /* CyberPower */

Chances are, it also supports

	{ "ups.power.nominal", 0, 0, "UPS.Output.ConfigApparentPower", NULL,
"%.0f", HU_FLAG_OK, NULL }, /* CyberPower */

so that may be worthwhile adding too.

Best regards, Arjen
-- 
Eindhoven - The Netherlands
Key fingerprint - 66 4E 03 2C 9D B5 CB 9B  7A FE 7E C1 EE 88 BC 57




More information about the Nut-upsdev mailing list