Hi Guys,
I attached my shutdown patch.
I tested and works fine but please someone needs test.
You need make a shutdown script and put in it these things:
if (test -f /etc/killpower)
then
/usr/local/ups/bin/upsdrvctl shutdown <- it calls the shutdown function
of liebert-esp2 driver
/sbin/shutdown -h +0
fi
Please put in devel tree, thanks.
2010/8/3 Robert Jobbagy <[email protected]>
> Sorry, I realized my mistakes and I fixed them but I forgetted wrote to
> mail-list.
> It was some dummy mistakes from me.
>
> I tested my shutdown function and it works fine.
> I will make some test today and after I will send the patch.
>
> Sorry the some useless mails in past
>
>
>
> 2010/8/2 Arjen de Korte <[email protected] <nut%[email protected]>
> >
>
> Citeren Robert Jobbagy <[email protected]>:
>>
>> I fixed my shutdown function:
>>>
>>
>> Why you just don't look into other drivers how to use the upslog* and
>> upsdebug* functions, is beyond me... :-(
>>
>> [...]
>>
>>
>> I ran a test and doesnt exist the /tmp/liebert-esp2_debug.log file so I
>>> think shutdown function not called but I don't know why ....
>>>
>>> any idea ?
>>>
>>
>> Read 'man 8 nutupsdrv' to see if this gives you a hint when the
>> upsdrv_shutdown function is called.
>>
>> Other than that, you're not providing an awful lot of information. Again.
>> We can't help you, if you don't meticulously describe what actions you
>> performed and what the intended and actual results where. We're not
>> magicians...
>>
>>
>> Best regards, Arjen
>> --
>> Please keep list traffic on the list
>>
>>
>> _______________________________________________
>> Nut-upsdev mailing list
>> [email protected]
>> http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev
>>
>
>
>
> --
> Best Regards,
>
> Robert
>
--
Best Regards,
Robert
Index: drivers/liebert-esp2.c
===================================================================
--- drivers/liebert-esp2.c (revision 2495)
+++ drivers/liebert-esp2.c (working copy)
@@ -24,8 +24,12 @@
#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,but if you change this you need change cheksum
+#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 @@
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,11 @@
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_UPSShutdown0[] = { 1,156,4,1,6,0,1,169},/* UPS Shutdown command */
+ cmd_UPSShutdown1[] = {1,156,4,1,5,0,UPS_SHUTDOWN_DELAY,179}, /* UPS Shutdown with delay */
+ cmd_UPSShutdown2[] = {1,156,4,1,136,76,76,194}; /* UPS Shutdown command*/
static char cksum(const char *buf, const size_t len)
{
@@ -75,7 +84,7 @@
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;
@@ -95,16 +104,14 @@
{
struct {
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 }
};
-
- char buf[LARGEBUF];
+ char buf[LARGEBUF],*s;
int i, index;
dstate_setinfo("ups.mfr", "%s", "Liebert");
@@ -132,12 +139,9 @@
fatalx(EXIT_FAILURE, "ESP-II capable UPS not detected");
}
- for (index = 0, i = 0; vartab[i].var; index += vartab[i].len, i++) {
- char val[SMALLBUF];
- snprintf(val, sizeof(val), "%.*s", vartab[i].len, &buf[index]);
-
- dstate_setinfo(vartab[i].var, "%s", rtrim(val, ' '));
+ for (s = strtok(buf, " "), i = 0; s && vartab[i].var; s = strtok(NULL, " "), i++) {
+ dstate_setinfo(vartab[i].var, "%s", s);
}
upsh.instcmd = instcmd;
@@ -262,8 +266,29 @@
void upsdrv_shutdown(void)
{
- /* replace with a proper shutdown function */
- fatalx(EXIT_FAILURE, "shutdown not supported");
+ int ret;
+
+ ret = ser_send_buf(upsfd, cmd_UPSShutdown0, SHUTDOWN_CMD_LEN);
+ if(ret < 0){
+ printf("Shutdown0 command sent failed \n");
+ }else if(ret < 8){
+ printf("I can't sent Shutdown0 command\n");
+ }
+
+ ret = ser_send_buf(upsfd, cmd_UPSShutdown1, SHUTDOWN_CMD_LEN);
+ if(ret < 0){
+ printf("Shutdown1 command sent failed \n");
+ }else if(ret < 8){
+ printf("I can't sent Shutdown1 command\n");
+ }
+
+ ret = ser_send_buf(upsfd, cmd_UPSShutdown2, SHUTDOWN_CMD_LEN);
+ if(ret < 0){
+ printf("Shutdown2 command sent failed");
+ }else if(ret < 8){
+ printf("I can't sent Shutdown2 command");
+ }
+
}
static int instcmd(const char *cmdname, const char *extra)
_______________________________________________
Nut-upsdev mailing list
[email protected]
http://lists.alioth.debian.org/mailman/listinfo/nut-upsdev