[Nut-upsdev] Very long delay for shutdown.restart on usbhid-ups powercom

Vincenzo Colonnella VColonnella at sigmaspa.com
Fri Feb 8 08:38:31 UTC 2013


I'm testing a Powercom UPS (branded as Control System 2 STD80S:
http://www.cs2.it/home.php?goto=prodotti&cat=0&idp=2&subid=0) with NUT.
It is a USB HID device, with ID 0d9f:0004.
I configured nut-server to use driver usbhid-ups and it works almost
correctly: upsd communicates right with the device, upsmon catches its
events...
But when I try to perform a Forced Shutdown, UPS pauses indefinitely
delaying the poweroff.

I'm using NUT ver. 2.6.4 on "Debian Squeeze", with a package installed
from "Debian Testing".

If you try to invoke a "shutdown.return", it seems delay value is badly
converted:

$> upscmd STD80S shutdown.return 30

Driver debug logs show the command as correctly processed, but with
uncorrect parameters:

  55.348163	instcmd(shutdown.return, 30)
  55.348205	powercom_shutdown_nuf: value = 30, command = 5E00
  55.348218	hu_find_valinfo: found 24064 (value: 30)
  55.348229	Unit = 00000000, UnitExp = 0
  55.348239	Exponent = 0
  55.348249	PhyMax = 0, PhyMin = 0, LogMax = 65535, LogMin = 0
  55.348920	Report[set]: (3 bytes) => 0f 00 5e
  55.348945	Set report succeeded
  55.348956	instcmd: SUCCEED

Value 30 is converted to 24064, and this seems the delay that is
configured on the device to complete its shutdown:
[...]
  56.358009	Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 24064
  58.721177	Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 23865
  60.576175	Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 23864
  62.471044	Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 23861
  64.580550	Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 23859
  66.645841	Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 23857
  68.733541	Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 23855
[...]

The translation of the value may be due to the following function, where
value seems to be splitted in seconds and minutes parts, then ORed with
0x4000 to perform the "return" feature.

$> less nut-2.6.4/drivers/powercom-hid.c
[...]
static double powercom_shutdown_nuf(const char *value)
{
        const char      *s = dstate_getinfo("ups.delay.shutdown");
        uint16_t        val, command;

        val = atoi(value ? value : s);
        command = ((val % 60) << 8) + (val / 60);
        command |= 0x4000;    /* AC RESTART NORMAL ENABLE */
        upsdebugx(3, "%s: value = %s, command = %04X", __func__, value,
command);

        return command;
}
[...]

This implementation follows Powercom specification of BNT protocol
(http://www.networkupstools.org/ups-protocols/powercom/Software_USB_comm
unication_controller_BNT_series.doc), which overrides the semantics of
the seconds field of USB HID Set Report command. As reported in
document:

Byte 13, Byte 14 (min, sec)

If Byte(sec), bit7=0 and bit6=0 Then
   If Byte 9, bit0=1 Then command 185, 188, min, sec
   If Byte 9, bit0=0 Then command 186, 188, min, sec
If Byte(sec), bit7=0 and bit6=1 Then command 185, 188, min, sec
If Byte(sec), bit7=1 and bit6=0 Then command 186, 188, min, sec
If Byte(sec), bit7=1 and bit6=1 Then no actions 

OR with 0x4000 sets the bit6 of seconds field to 1: so the commands 185,
188 are processed (shutdown and restart after elapsed time).

But such way the time value is misconfigured.
I tried to modify the driver to switch seconds and minutes field, as in
the attached patch, and now it works better: it waits for the required
time (+64 seconds) and then shuts down and restart.

  39.474936     instcmd(shutdown.return, 30)
  39.474978     powercom_shutdown_nuf: value = 30, command = 005E
  39.474990     hu_find_valinfo: found 94 (value: 30)
  39.475000     Unit = 00000000, UnitExp = 0
  39.475010     Exponent = 0
  39.475020     PhyMax = 0, PhyMin = 0, LogMax = 65535, LogMin = 0
  39.532901     Report[set]: (3 bytes) => 0f 5e 00
  39.532929     Set report succeeded
  39.532939     instcmd: SUCCEED
[...]
  40.406761     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 94 [...]
  42.483186     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 92 [...]
  44.399070     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 90 [...]
  46.264173     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 88 [...]
  48.325784     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 86 [...]
  50.167518     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 84 [...]
  53.099694     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 82 [...]
  54.200409     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 82 [...]
  56.244932     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 78 [...]
  58.328966     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 76 [...]
  60.215708     Path: UPS.PowerSummary.DelayBeforeShutdown, Type:
Feature, ReportID: 0x0f, Offset: 0, Size: 16, Value: 74
[...]

The device sums 64 seconds as the effect of "override", it doesn't reset
the overflow to max 59 seconds. But this is a better error than wait a
switched value between minutes and seconds + 64 minutes.

I don't know if the error is in provided documentation or it is a
misunderstanding of byte order.
I don't own other USB HID Powercom models, so I don't know if this issue
arises also for other models and if the solution works in general.

I hope this is useful.

Many thanks for your work and Best Regards,
Vincenzo Colonnella

-------------- next part --------------
A non-text attachment was scrubbed...
Name: nut-patch-powercom-hid-shutdownrestart.diff
Type: application/octet-stream
Size: 913 bytes
Desc: nut-patch-powercom-hid-shutdownrestart.diff
URL: <http://lists.alioth.debian.org/pipermail/nut-upsdev/attachments/20130208/b528b057/attachment.obj>


More information about the Nut-upsdev mailing list