On 01/28/2011 11:11 AM, Farkas Levente wrote:
> hi,
> it seems our latest liebertgxt2 patch still missing from the just
> released 2.6.0. i'm attached the patch to the 2.6.0. this patch:
> - add the possibility to properly shutdown the ups,
> - can be used through usb-serial adapter cable too.
> could you apply it to the source.
> regards.
>
sorry i send a wrong patch, here is the good one.
--
Levente "Si vis pacem para bellum!"
diff -up ./drivers/liebert-esp2.c.esp2 ./drivers/liebert-esp2.c
--- ./drivers/liebert-esp2.c.esp2 2010-12-24 14:24:29.000000000 +0100
+++ ./drivers/liebert-esp2.c 2011-01-28 11:31:10.000000000 +0100
@@ -24,7 +24,11 @@
#include "nut_stdint.h"
#define DRIVER_NAME "Liebert ESP-II serial UPS driver"
-#define DRIVER_VERSION "0.02"
+#define DRIVER_VERSION "0.03"
+#define UPS_SHUTDOWN_DELAY 12 //it means UPS will be shutdown 120 sec
+#define SHUTDOWN_CMD_LEN 8
+
+
static int instcmd(const char *cmdname, const char *extra);
static int setvar(const char *varname, const char *val);
@@ -33,7 +37,8 @@ static int setvar(const char *varname, c
upsdrv_info_t upsdrv_info = {
DRIVER_NAME,
DRIVER_VERSION,
- "Richard Gregory <r.gregory liv ac uk>",
+ "Richard Gregory <r.gregory liv ac uk>\n" \
+ "Robert Jobbagy <jobbagy.robert at gmail dot com",
DRV_EXPERIMENTAL,
{ NULL }
};
@@ -46,7 +51,13 @@ static const unsigned char
cmd_bitfield3[] = { 1,148,2,1,3,155 }, /* CHECK_AIR_FILTER
(10), BAD_BYPASS_PWR (8), OUTPUT_OVERVOLTAGE (7), OUTPUT_UNDERVOLTAGE (6),
LOW_BATTERY (5), CHARGER_FAIL (3), SHUTDOWN_PENDING (2), BAD_INPUT_FREQ (1),
UPS_OVERLOAD (0) */
cmd_bitfield7[] = { 1,148,2,1,7,159 }, /* AMBIENT_OVERTEMP (2)
*/
cmd_battestres[] = { 1,148,2,1,12,164 }, /* BATTERY_TEST_RESULT
*/
- cmd_selftestres[] = { 1,148,2,1,13,165 }; /* SELF_TEST_RESULT */
+ cmd_selftestres[] = { 1,148,2,1,13,165 }, /* SELF_TEST_RESULT */
+
+ /* Shutdown commands by Robert Jobbagy */
+ cmd_setOutOffMode[] = { 1,156,4,1,6,0,1,169},/* UPS OutOffMode
command */
+ cmd_setOutOffDelay[] =
{1,156,4,1,5,0,UPS_SHUTDOWN_DELAY,167+UPS_SHUTDOWN_DELAY}, /* UPS Shutdown with
delay */
+ cmd_sysLoadKey[] = {1,156,2,1,7,167}, /*UPS SysLoadKey */
+ cmd_shutdown[] = {1,156,4,1,136,76,76,194}; /* UPS shutdown */
static char cksum(const char *buf, const size_t len)
{
@@ -60,22 +71,22 @@ static char cksum(const char *buf, const
return sum;
}
-static int do_command(const unsigned char *command, char *reply)
+static int do_command(const unsigned char *command, char *reply, int cmd_len)
{
int ret;
- ret = ser_send_buf(upsfd, command, 6);
+ ret = ser_send_buf(upsfd, command, cmd_len);
if (ret < 0) {
upsdebug_with_errno(2, "send");
return -1;
- } else if (ret < 6) {
+ } else if (ret < cmd_len) {
upsdebug_hex(2, "send: truncated", command, ret);
return -1;
}
upsdebug_hex(2, "send", command, ret);
- ret = ser_get_buf(upsfd, reply, 8, 1, 0);
+ ret = ser_get_buf_len(upsfd, reply, 8, 1, 0);//it needs that this
driver works with USB to Serial cable
if (ret < 0) {
upsdebug_with_errno(2, "read");
return -1;
@@ -97,10 +108,10 @@ void upsdrv_initinfo(void)
const char *var;
const int len;
} vartab[] = {
- { "ups.model", 15 },
- { "ups.firmware", 8 },
- { "ups.serial", 10 },
- { "ups.mfr.date", 4 },
+ { "ups.model"},
+ { "ups.firmware"},
+ { "ups.serial"},
+ { "ups.mfr.date"},
{ NULL }
};
@@ -116,7 +127,7 @@ void upsdrv_initinfo(void)
snprintf(command, sizeof(command), "\x01\x88\x02\x01%c", i+4);
command[5] = cksum(command, 5);
- ret = do_command((unsigned char *)command, reply);
+ ret = do_command((unsigned char *)command, reply, 6);
if (ret == 8) {
buf[i<<1] = reply[6];
buf[(i<<1)+1] = reply[5];
@@ -180,7 +191,7 @@ void upsdrv_updateinfo(void)
for (i = 0; vartab[i].var; i++) {
int16_t val;
- ret = do_command(vartab[i].cmd, reply);
+ ret = do_command(vartab[i].cmd, reply, 6);
if (ret < 8) {
continue;
}
@@ -194,7 +205,7 @@ void upsdrv_updateinfo(void)
status_init();
- ret = do_command(cmd_bitfield1, reply);
+ ret = do_command(cmd_bitfield1, reply, 6);
if (ret < 8) {
upslogx(LOG_ERR, "Failed reading bitfield #1");
dstate_datastale();
@@ -217,7 +228,7 @@ void upsdrv_updateinfo(void)
}
}
- ret = do_command(cmd_bitfield2, reply);
+ ret = do_command(cmd_bitfield2, reply, 6);
if (ret < 8) {
upslogx(LOG_ERR, "Failed reading bitfield #2");
dstate_datastale();
@@ -240,7 +251,7 @@ void upsdrv_updateinfo(void)
status_set("TRIM");
}
- ret = do_command(cmd_bitfield3, reply);
+ ret = do_command(cmd_bitfield3, reply, 6);
if (ret < 8) {
upslogx(LOG_ERR, "Failed reading bitfield #3");
dstate_datastale();
@@ -262,8 +273,14 @@ void upsdrv_updateinfo(void)
void upsdrv_shutdown(void)
{
- /* replace with a proper shutdown function */
- fatalx(EXIT_FAILURE, "shutdown not supported");
+ char reply[8];
+
+ if(!(do_command(cmd_setOutOffMode, reply, 8) != -1) &&
+ (do_command(cmd_setOutOffDelay, reply, 8) != -1) &&
+ (do_command(cmd_sysLoadKey, reply, 6) != -1) &&
+ (do_command(cmd_shutdown, reply, 8) != -1))
+ upslogx(LOG_ERR, "Failed to shutdown UPS");
+
}
static int instcmd(const char *cmdname, const char *extra)
_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev