|
28 | 28 |
|
29 | 29 | #include <ctype.h> /* isdigit() */ |
30 | 30 |
|
31 | | -#define POWERCOM_HID_VERSION "PowerCOM HID 0.73" |
| 31 | +#define POWERCOM_HID_VERSION "PowerCOM HID 0.74" |
32 | 32 | /* FIXME: experimental flag to be put in upsdrv_info */ |
33 | 33 |
|
34 | 34 | /* PowerCOM */ |
@@ -97,11 +97,23 @@ static const char *powercom_startup_fun(double value) |
97 | 97 | static double powercom_startup_nuf(const char *value) |
98 | 98 | { |
99 | 99 | const char *s = dstate_getinfo("ups.delay.start"); |
| 100 | + const char *cfg = getval("ondelay"); |
100 | 101 | uint32_t val, command; |
101 | 102 | int iv; |
102 | 103 |
|
103 | | - /* Start with seconds "as is" - convert into whole minutes */ |
104 | | - iv = atoi(value ? value : s) / 60; /* minutes */ |
| 104 | + /* Priority: 1) command value, 2) config ondelay, 3) UPS current, 4) default |
| 105 | + * Note we start with seconds "as is" - convert into whole minutes for the device protocol |
| 106 | + */ |
| 107 | + if (value && *value) { |
| 108 | + iv = atoi(value) / 60; |
| 109 | + } else if (cfg && *cfg) { |
| 110 | + iv = atoi(cfg) / 60; |
| 111 | + } else if (s && *s) { |
| 112 | + iv = atoi(s) / 60; |
| 113 | + } else { |
| 114 | + iv = 2; /* Default: 2 minutes (120 seconds) */ |
| 115 | + } |
| 116 | + |
105 | 117 | #if (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_PUSH_POP) && ( (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TYPE_LIMITS) || (defined HAVE_PRAGMA_GCC_DIAGNOSTIC_IGNORED_TAUTOLOGICAL_CONSTANT_OUT_OF_RANGE_COMPARE) ) |
106 | 118 | # pragma GCC diagnostic push |
107 | 119 | #endif |
@@ -165,10 +177,23 @@ static const char *powercom_shutdown_fun(double value) |
165 | 177 | static double powercom_shutdown_nuf(const char *value) |
166 | 178 | { |
167 | 179 | const char *s = dstate_getinfo("ups.delay.shutdown"); |
| 180 | + const char *cfg = getval("offdelay"); |
168 | 181 | uint16_t val, command; |
169 | 182 | int iv; |
170 | 183 |
|
171 | | - iv = atoi(value ? value : s); /* seconds */ |
| 184 | + /* Priority: 1) command value, 2) config offdelay, 3) UPS current, 4) default |
| 185 | + * Note we start with seconds "as is" - convert into magic numbers for the device protocol below |
| 186 | + */ |
| 187 | + if (value && *value) { |
| 188 | + iv = atoi(value); |
| 189 | + } else if (cfg && *cfg) { |
| 190 | + iv = atoi(cfg); |
| 191 | + } else if (s && *s) { |
| 192 | + iv = atoi(s); |
| 193 | + } else { |
| 194 | + iv = 60; /* Default: 60 seconds */ |
| 195 | + } |
| 196 | + |
172 | 197 | if (iv < 0 || (intmax_t)iv > (intmax_t)UINT16_MAX) { |
173 | 198 | upsdebugx(0, "%s: value = %d is not in uint16_t range", __func__, iv); |
174 | 199 | return 0; |
@@ -219,11 +244,24 @@ static info_lkp_t powercom_shutdown_info[] = { |
219 | 244 | static double powercom_stayoff_nuf(const char *value) |
220 | 245 | { |
221 | 246 | const char *s = dstate_getinfo("ups.delay.shutdown"); |
| 247 | + const char *cfg = getval("offdelay"); |
222 | 248 | uint16_t val, command; |
223 | 249 | int iv; |
224 | 250 |
|
225 | 251 | /* FIXME: Anything for powercom_sdcmd_discrete_delay? */ |
226 | | - iv = atoi(value ? value : s); |
| 252 | + /* Priority: 1) command value, 2) config offdelay, 3) UPS current, 4) default |
| 253 | + * Note we start with seconds "as is" - convert into magic numbers for the device protocol below |
| 254 | + */ |
| 255 | + if (value && *value) { |
| 256 | + iv = atoi(value); |
| 257 | + } else if (cfg && *cfg) { |
| 258 | + iv = atoi(cfg); |
| 259 | + } else if (s && *s) { |
| 260 | + iv = atoi(s); |
| 261 | + } else { |
| 262 | + iv = 60; /* Default: 60 seconds */ |
| 263 | + } |
| 264 | + |
227 | 265 | if (iv < 0 || (intmax_t)iv > (intmax_t)UINT16_MAX) { |
228 | 266 | upsdebugx(0, "%s: value = %d is not in uint16_t range", __func__, iv); |
229 | 267 | return 0; |
|
0 commit comments