Skip to content

Commit e06b8ae

Browse files
authored
Merge pull request #3254 from rtm516/feature/hunnox-battery-charge
Add battery.charge to hunnox driver
2 parents dcd9e6e + d8b30ba commit e06b8ae

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

NEWS.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ https://github.com/networkupstools/nut/milestone/12
156156
Tested on A1000 and A2000 units. [#3181]
157157
* Hides QX_FLAG_NONUT variables from syslog unless the debug level
158158
is raised. [issue #3190, PR #3198]
159+
* Added support for battery.charge in hunnox subdriver. [#3254]
159160

160161
- `powerp-bin` and `powerp-txt` driver updates:
161162
* Their `upsdrv_initinfo()` methods did not explicitly reference the

drivers/nutdrv_qx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,7 @@ static int hunnox_command(const char *cmd, size_t cmdlen, char *buf, size_t bufl
14331433
{ "I\r", 0x0c, }, /* Vendor infos */
14341434
{ "Q\r", 0x07, }, /* Beeper toggle */
14351435
{ "C\r", 0x0a, }, /* Cancel shutdown/Load on [0x(0..F)A]*/
1436+
{ "BL\r", 0xf3, }, /* Battery charge */
14361437
{ NULL, 0 }
14371438
};
14381439
int i, ret, index = 0;

drivers/nutdrv_qx_hunnox.c

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,29 @@
2626

2727
#include "nutdrv_qx_hunnox.h"
2828

29-
#define HUNNOX_VERSION "Hunnox 0.02"
29+
#define HUNNOX_VERSION "Hunnox 0.03"
30+
31+
/* Parse BL response: BL100, BL50, BL0, etc. */
32+
static int hunnox_battery_charge(item_t *item, char *value, const size_t valuelen)
33+
{
34+
char *response = item->answer;
35+
int percent;
36+
37+
if (strncmp(response, "BL", 2) != 0) {
38+
upsdebugx(2, "%s: invalid response [%s]", __func__, response);
39+
return -1;
40+
}
41+
42+
percent = atoi(response + 2);
43+
44+
if (percent < 0 || percent > 100) {
45+
upsdebugx(2, "%s: invalid percentage [%d]", __func__, percent);
46+
return -1;
47+
}
48+
49+
snprintf(value, valuelen, "%d", percent);
50+
return 0;
51+
}
3052

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

102+
/*
103+
* > [BL\r]
104+
* < [BL100\r]
105+
* 01234
106+
* 0
107+
*/
108+
{ "battery.charge", 0, NULL, "BL\r", "", 6, 'B', "", 0, 0, "%.0f", QX_FLAG_QUICK_POLL, NULL, NULL, hunnox_battery_charge },
109+
80110
/* Instant commands */
81111
{ "beeper.toggle", 0, NULL, "Q\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL },
82112
{ "load.off", 0, NULL, "S00R0000\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL },
@@ -112,6 +142,7 @@ static testing_t hunnox_testing[] = {
112142
{ "TL\r", "", -1 },
113143
{ "T\r", "", -1 },
114144
{ "CT\r", "", -1 },
145+
{ "BL\r", "BL100\r", -1 },
115146
{ NULL }
116147
};
117148
#endif /* TESTING */

0 commit comments

Comments
 (0)