Skip to content

Commit

Permalink
Merge pull request #2802 from dvdesolve/q2_bruntime
Browse files Browse the repository at this point in the history
Fix battery runtime calculation for Q2 protocol
  • Loading branch information
jimklimov authored Feb 14, 2025
2 parents 4cdf3fd + 7c4642e commit caf8d1e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
13 changes: 13 additions & 0 deletions drivers/nutdrv_qx.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,19 @@ int qx_multiply_x1000(item_t *item, char *value, const size_t valuelen) {
return 0;
}

/* Convert minutes to seconds */
int qx_multiply_m2s(item_t *item, char *value, const size_t valuelen) {
float s = 0;

if (sscanf(item->value, "%f", &s) != 1) {
upsdebugx(2, "unparsable ss.ss %s", item->value);
return -1;
}

snprintf(value, valuelen, "%.0f", s * 60.0);
return 0;
}

/* Fill batt.volt.act and guesstimate the battery charge
* if it isn't already available. */
static int qx_battery(void)
Expand Down
3 changes: 3 additions & 0 deletions drivers/nutdrv_qx.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,9 @@ int qx_multiply_battvolt(item_t *item, char *value, const size_t valuelen);
/* Convert kilo-values to their full representation */
int qx_multiply_x1000(item_t *item, char *value, const size_t valuelen);

/* Convert minutes to seconds */
int qx_multiply_m2s(item_t *item, char *value, const size_t valuelen);

/* Data for processing status values */
#define STATUS(x) ((unsigned int)1U<<x)

Expand Down
2 changes: 1 addition & 1 deletion drivers/nutdrv_qx_q2.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ static item_t q2_qx2nut[] = {
{ "output.L3.load", 0, NULL, "Q2\r", "", 118, '(', "", 51, 53, "%.0f", 0, NULL, NULL, NULL },
{ "ups.temperature", 0, NULL, "Q2\r", "", 118, '(', "", 66, 69, "%.1f", 0, NULL, NULL, NULL },
{ "battery.voltage", 0, NULL, "Q2\r", "", 118, '(', "", 60, 64, "%.1f", 0, NULL, NULL, qx_multiply_battvolt },
{ "battery.runtime", 0, NULL, "Q2\r", "", 118, '(', "", 80, 85, "%.0f", 0, NULL, NULL, NULL },
{ "battery.runtime", 0, NULL, "Q2\r", "", 118, '(', "", 80, 85, "%.2f", 0, NULL, NULL, qx_multiply_m2s },
{ "battery.charge", 0, NULL, "Q2\r", "", 118, '(', "", 87, 89, "%.0f", 0, NULL, NULL, NULL },
{ "experimental.input.topology", 0, NULL, "Q2\r", "", 118, '(', "", 115, 115, "%s", QX_FLAG_STATIC, NULL, NULL, q2_process_topology_bits }, /* Input transformer topology */
{ "experimental.output.topology", 0, NULL, "Q2\r", "", 118, '(', "", 116, 116, "%s", QX_FLAG_STATIC, NULL, NULL, q2_process_topology_bits }, /* Output transformer topology */
Expand Down

0 comments on commit caf8d1e

Please sign in to comment.