|
26 | 26 |
|
27 | 27 | #include "nutdrv_qx_hunnox.h" |
28 | 28 |
|
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 | +} |
30 | 52 |
|
31 | 53 | /* qx2nut lookup table */ |
32 | 54 | static item_t hunnox_qx2nut[] = { |
@@ -77,6 +99,14 @@ static item_t hunnox_qx2nut[] = { |
77 | 99 | { "device.model", 0, NULL, "FW?\r", "", 39, '#', "", 17, 26, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, |
78 | 100 | { "ups.firmware", 0, NULL, "FW?\r", "", 39, '#', "", 28, 37, "%s", QX_FLAG_STATIC | QX_FLAG_TRIM, NULL, NULL, NULL }, |
79 | 101 |
|
| 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 | + |
80 | 110 | /* Instant commands */ |
81 | 111 | { "beeper.toggle", 0, NULL, "Q\r", "", 0, 0, "", 0, 0, NULL, QX_FLAG_CMD, NULL, NULL, NULL }, |
82 | 112 | { "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[] = { |
112 | 142 | { "TL\r", "", -1 }, |
113 | 143 | { "T\r", "", -1 }, |
114 | 144 | { "CT\r", "", -1 }, |
| 145 | + { "BL\r", "BL100\r", -1 }, |
115 | 146 | { NULL } |
116 | 147 | }; |
117 | 148 | #endif /* TESTING */ |
|
0 commit comments