Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NEWS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ https://github.com/networkupstools/nut/milestone/12
Tested on A1000 and A2000 units. [#3181]
* Hides QX_FLAG_NONUT variables from syslog unless the debug level
is raised. [issue #3190, PR #3198]
* Added support for battery.charge in hunnox subdriver. [#3254]

- `powerp-bin` and `powerp-txt` driver updates:
* Their `upsdrv_initinfo()` methods did not explicitly reference the
Expand Down
1 change: 1 addition & 0 deletions drivers/nutdrv_qx.c
Original file line number Diff line number Diff line change
Expand Up @@ -1433,6 +1433,7 @@ static int hunnox_command(const char *cmd, size_t cmdlen, char *buf, size_t bufl
{ "I\r", 0x0c, }, /* Vendor infos */
{ "Q\r", 0x07, }, /* Beeper toggle */
{ "C\r", 0x0a, }, /* Cancel shutdown/Load on [0x(0..F)A]*/
{ "BL\r", 0xf3, }, /* Battery charge */
{ NULL, 0 }
};
int i, ret, index = 0;
Expand Down
33 changes: 32 additions & 1 deletion drivers/nutdrv_qx_hunnox.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,29 @@

#include "nutdrv_qx_hunnox.h"

#define HUNNOX_VERSION "Hunnox 0.02"
#define HUNNOX_VERSION "Hunnox 0.03"

/* Parse BL response: BL100, BL50, BL0, etc. */
static int hunnox_battery_charge(item_t *item, char *value, const size_t valuelen)
{
char *response = item->answer;
int percent;

if (strncmp(response, "BL", 2) != 0) {
upsdebugx(2, "%s: invalid response [%s]", __func__, response);
return -1;
}

percent = atoi(response + 2);

if (percent < 0 || percent > 100) {
upsdebugx(2, "%s: invalid percentage [%d]", __func__, percent);
return -1;
}

snprintf(value, valuelen, "%d", percent);
return 0;
}

/* qx2nut lookup table */
static item_t hunnox_qx2nut[] = {
Expand Down Expand Up @@ -77,6 +99,14 @@ static item_t hunnox_qx2nut[] = {
{ "device.model", 0, NULL, "FW?\r", "", 39, '#', "", 17, 26, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL },
{ "ups.firmware", 0, NULL, "FW?\r", "", 39, '#', "", 28, 37, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL },

/*
* > [BL\r]
* < [BL100\r]
* 01234
* 0
*/
{ "battery.charge", 0, NULL, "BL\r", "", 6, 'B', "", 0, 0, "%.0f", QX_FLAG_QUICK_POLL, NULL, NULL, hunnox_battery_charge },

/* Instant commands */
{ "beeper.toggle", 0, NULL, "Q\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL },
{ "load.off", 0, NULL, "S00R0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL },
Expand Down Expand Up @@ -112,6 +142,7 @@ static testing_t hunnox_testing[] = {
{ "TL\r", "", -1 },
{ "T\r", "", -1 },
{ "CT\r", "", -1 },
{ "BL\r", "BL100\r", -1 },
{ NULL }
};
#endif /* TESTING */
Expand Down
Loading