[Nut-upsuser] NUT 2.0.5 and 2.2.2 hacking -- there is something to improve!
Kārlis Repsons
karlis.repsons at gmail.com
Fri Dec 5 10:20:43 UTC 2008
Hello,
I wanted to set my own time intervals for shutdown.
{poweroff,return,paused.return}, so I had to change sources, where it has
been set in a hard way.
poweroff: Sxx\r
return: Zxx\r
paused.return: SxxRyyyy\r
Solution A: Why not adding an info about these commands in a generic way and
issuing shutdown.{poweroff.xx,return.xx,paused.return.xxyyyy}
Solution B: Why not creating a special command, which takes UPS command as an
argument?
Really, for A (with 2.0.5 at least):
unsigned int i;
const char spo[] = "shutdown.poweroff";
const char sre[] = " shutdown.return";
const char spre[] = "shutdown.paused.return";
/*
CMDDESC shutdown.poweroff.xx "Turn off the load after xx minute(s) and
remain off"
CMDDESC shutdown.return.xx "Turn off the load after xx minute(s) and
return when power is back"
CMDDESC shutdown.paused.return.xxyyyy "Turn off the load after xx
minute(s) and return when power is back no sooner than after yyyy minutes"
*/
if (!strcasecmp(cmdname, "test.battery.start"))
ret = powpan_command("T\r");
if (!strcasecmp(cmdname, "test.battery.stop"))
ret = powpan_command("CT\r");
if (!strcasecmp(cmdname, "beeper.on"))
ret = powpan_command("C7:1\r");
if (!strcasecmp(cmdname, "beeper.off"))
ret = powpan_command("C7:0\r");
if (!strcasecmp(cmdname, "shutdown.stop"))
ret = powpan_command("C\r");
// check for shutdown.poweroff:
if ( (strlen(spo) + 3) == strlen(cmdname) )
{
for ( i=0; i<strlen(spo); i++ )
if ( cmdname[ i ] != spo[ i ] ) break;
if ( i == strlen(spo) )
{
char comm[] = "Sxx\r";
comm[1] = cmdname[ strlen( spo ) + 1 ];
comm[2] = cmdname[ strlen( spo ) + 2 ];
ret = powpan_command(comm);
}
}
// check for shutdown.return:
if ( (strlen(sre) + 3) == strlen(cmdname) )
{
for ( i=0; i<strlen(sre); i++ )
if ( cmdname[ i ] != sre[ i ] ) break;
if ( i == strlen(sre) )
{
char comm[] = "Zxx\r";
comm[1] = cmdname[ strlen( sre ) + 1 ];
comm[2] = cmdname[ strlen( sre ) + 2 ];
ret = powpan_command(comm);
}
}
// check for shutdown.paused.return:
if ( (strlen(spre) + 7) == strlen(cmdname) )
{
for ( i=0; i<strlen(spre); i++ )
if ( cmdname[ i ] != spre[ i ] ) break;
if ( i == strlen(spre) )
{
char comm[] = "SxxRyyyy\r";
comm[1] = cmdname[ strlen( sre ) + 1 ];
comm[2] = cmdname[ strlen( sre ) + 2 ];
comm[4] = cmdname[ strlen( sre ) + 3 ];
comm[5] = cmdname[ strlen( sre ) + 4 ];
comm[6] = cmdname[ strlen( sre ) + 5 ];
comm[7] = cmdname[ strlen( sre ) + 6 ];
ret = powpan_command(comm);
}
}
For B: you should know better, as I found NUT src tree complex enough not to
do it.
I would've stopped at expanding commandtab in 2.2.2, but I didn't like, I have
to make such a great redundancy and also I had an error while doing
hibernation or being in battery mode: my main terminal vt1 received many
error messages: "Error: Data stale". Ugly.
I would like to have these problems addressed, at least, removing error
message and adding a function, which should be there is really not much asked
for the author! So, solution B looks better, as there will always be a
possibility, that new UPS command is possible.
Ah, also, when experimenting with UPS commands (upscmd) in 2.2.2, they all
return 0, even if there is no such command!
Well, what people think?
Regards,
Kārlis
More information about the Nut-upsuser
mailing list