Skip to content

drivers: delta-hid: Add Delta HID subdriver#807

Merged
jimklimov merged 31 commits intonetworkupstools:masterfrom
lukakovacica:nut-rebase
May 8, 2021
Merged

drivers: delta-hid: Add Delta HID subdriver#807
jimklimov merged 31 commits intonetworkupstools:masterfrom
lukakovacica:nut-rebase

Conversation

@lukakovacica
Copy link
Copy Markdown
Contributor

Hello,

This commit adds initial support for the Delta RT series UPS devices (Single Phase, 1/2/3 kVA).
A new Delta HID subdriver has been added, the driver was tested and tweaked on the Delta RT 3 kVA UPS.

Some features, like shutting down the UPS, will be added gradually over use and more testing.
Basic UPS monitoring is supported for now.

Delta HID subdriver is added to support Delta RT Series,
Single Phase, 1/2/3 kVA UPS devices.

The driver was tested and tweaked on Delta RT 3 kVA UPS.

Signed-off-by: Luka Kovačič <luka.kovacic@builtin.io>
@LynxChaus
Copy link
Copy Markdown
Contributor

flag all *.nominal/ups.* entries with HU_FLAG_STATIC,
and rest battery.*/input.*/output.*/UPS.PowerConverter.PresentStatus.* with HU_FLAG_QUICK_POLL.

Update entry flags to use HU_FLAG_QUICK_POLL for status and alarm variables,
HU_FLAG_SEMI_STATIC for variables that can change on user changes and HU_FLAG_STATIC
for variables that don't need to be updated after init.

Signed-off-by: Luka Kovačič <luka.kovacic@builtin.io>
@lukakovacica
Copy link
Copy Markdown
Contributor Author

@LynxChaus thanks for pointing this out!
I updated the entries as required.

@lukakovacica
Copy link
Copy Markdown
Contributor Author

lukakovacica commented Aug 16, 2020

Hi @clepple and @aquette,

Is there anything else that should be improved here?

@flobernd
Copy link
Copy Markdown
Contributor

@lukakovacica Don't bother - this project seems dead. My PRs are still not merged after over 3 months (very few lines of code). Not sure what's going on ...

@jimklimov
Copy link
Copy Markdown
Member

@flobernd : sorry about making that impression, there was quite a bit of turbulence in private lives of people involved, and change of leadership direction, and so on...

@flobernd
Copy link
Copy Markdown
Contributor

flobernd commented Oct 7, 2020

@jimklimov No problem at all! Glad to see this project alive. A short information some months ago would have helped tho 😋

Copy link
Copy Markdown
Member

@jimklimov jimklimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't comment on actual driver content (mostly it is HID mapping... and whether correct flags, string-names and other fields are used), but structurally the change looks good :)

@jimklimov jimklimov requested review from aquette, clepple and zykh October 7, 2020 15:09
@lukakovacica
Copy link
Copy Markdown
Contributor Author

@jimklimov Thanks for reviewing the driver.
Also, great to hear that the project is moving along :).

@aquette
Copy link
Copy Markdown
Member

aquette commented Oct 8, 2020

hey there
@lukakovacica could you please send in an upsc output. I suspect a few things.
beside from this:

  • when in doubt, consider mge-hid.c as the reference implementation.
  • few comments already, but looks good. And will be fine to me when my comments are addressed

Copy link
Copy Markdown
Member

@aquette aquette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good but needs a few changes and complement, as pointed. Don't hesitate to ask for more info if needed

Comment thread drivers/delta-hid.c Outdated
static hid_info_t delta_hid2nut[] = {

{ "battery.voltage.nominal", 0, 0, "UPS.BatterySystem.Battery.ConfigVoltage", NULL, "%.0f", HU_FLAG_STATIC, NULL },
{ "battery.voltage", 0, 0, "UPS.BatterySystem.Battery.Voltage", NULL, "%.1f", HU_FLAG_QUICK_POLL, NULL },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HU_FLAG_QUICK_POLL should be limited to status data and closely monitored ones, such as timers , that need refresh more often. Just put 0 for other vars

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Polling Battery.Voltage once in minute - not good, under high load battery may discharge really fast within minute.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose that would mean that the UPS is under-spec'ed for its load. The battery capacity should allow for some overhead of detection of a non-negligibly long outage, and then some for wall power to maybe come back quickly, and when the battery level gets to suspicious levels - initiate graceful shutdown of systems and survive long enough (deployment-dependent, servers can take tens of minutes for interconnected webs of services to go down correctly).

And also batteries age, so it might not hold as long in practice when the outage bites as when it did when you bought and tested it.

Rule of thumb is that you should have at least 15 minutes under your full load (e.g. server busy checksumming its disks over and over with all cores and disks busy).

So if the "once a minute" is too infrequent, something is wrong on the hardware side.

Also, voltage the battery produces is often non-linear compared to its remaining capacity or run-time; if the UPS hardware and protocol provides those data points, and does not mislead doing so (I think we had an issue open for some devices that publish unreliable values), they should be preferred for determining when you should start a shutdown.

That all ranted out, @aquette : in case of going on-battery, 1) Does an USB UPS actively push that notice into the driver or is it only seen with latency of regular polling? 2) Does the poll frequency increase when we are at risk?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. supposed to push notifications, but really depends on the mfr implem. Visible in the initial dump, if this var is both tagged notif and polled (don't remember the wording I put though)
  2. no, but could be an improvement to consider. Still, some device may not support well too much polling when on batt, since they are busy processing internals. And still, interrupts notif are supposed to be here for that!

Comment thread drivers/delta-hid.c Outdated
{ "battery.runtime", 0, 0, "UPS.PowerSummary.RunTimeToEmpty", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL },
{ "battery.charge.warning", 0, 0, "UPS.PowerSummary.WarningCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL },
{ "battery.type", 0, 0, "UPS.PowerSummary.iDeviceChemistry", NULL, "%s", HU_FLAG_STATIC, stringid_conversion },
{ "ups.mfr", 0, 0, "UPS.PowerSummary.iManufacturer", NULL, "%s", HU_FLAG_STATIC, stringid_conversion },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All usages with a leaf starting by a "i" are in fact indexes to strings in the strings table. (hence the stringid_conversion callback), but conversely to battery.type above, these 3 declarations (mfr, model and serial) can be removed, since these are addressed by the delta_format_*() functions hooks.

Comment thread drivers/delta-hid.c Outdated
{ "output.frequency.nominal", 0, 0, "UPS.Flow.ConfigFrequency", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL },
{ "output.voltage.nominal", 0, 0, "UPS.Flow.ConfigVoltage", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL },
{ "ups.realpower", 0, 0, "UPS.OutletSystem.Outlet.ActivePower", NULL, "%.1f", HU_FLAG_QUICK_POLL, NULL },
{ "ups.delay.reboot", 0, 0, "UPS.OutletSystem.Outlet.DelayBeforeReboot", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 3 delays are configs & RW, and used (duplicated) later to declare the commandss.
See
https://github.com/networkupstools/nut/blob/master/drivers/mge-hid.c#L1188
https://github.com/networkupstools/nut/blob/master/drivers/mge-hid.c#L1394
note that you just need to declare the "delay" version of the command, the instant one (delay = 0) will be automatically added

Comment thread drivers/delta-hid.c Outdated
{ "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.NeedReplacement", NULL, NULL, HU_FLAG_QUICK_POLL, replacebatt_info },
{ "BOOL", 0, 0, "UPS.PowerSummary.PresentStatus.ShutdownImminent", NULL, NULL, HU_FLAG_QUICK_POLL, shutdownimm_info },
{ "battery.charge", 0, 0, "UPS.PowerSummary.RemainingCapacity", NULL, "%.0f", HU_FLAG_QUICK_POLL, NULL },
{ "battery.charge.low", 0, 0, "UPS.PowerSummary.RemainingCapacityLimit", NULL, "%.0f", HU_FLAG_SEMI_STATIC, NULL },
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aquette
Copy link
Copy Markdown
Member

aquette commented Oct 9, 2020

Hard to say if this device do well implement usb interrupts (notification sent by the device, between millings). A driver debug output with level 1 (dump HID data tree) should show us, or otherwise higher debug when going on battery

@lukakovacica
Copy link
Copy Markdown
Contributor Author

Hi everyone,

I'll send some debug output from the driver and upsc output to you this weekend.
Also I'll refactor the HID mapping as suggested.

@jimklimov
Copy link
Copy Markdown
Member

By the way, just in case: @lukakovacica did/do you work for the maker of this UPS? One more point came up, it is worth mentioning the vendors' efforts at https://github.com/networkupstools/nut/blob/master/docs/acknowledgements.txt

@lukakovacica
Copy link
Copy Markdown
Contributor Author

@jimklimov No, I have no association with Delta in any way in preparing this driver.
I'm doing this on my own initiative.

@jimklimov
Copy link
Copy Markdown
Member

As I realized, maybe a bit too late, this effort potentially duplicates #987 which (for good or bad) had no objections so was merged recently. I suppose this PR should now be revisited to check what else it brings to the table, and/or if the merged code did have the weaknesses highlighted in this review. And ultimately, if the two contributions can be merged into the same sources and subdriver, to support both hopefully different device series (claiming "Delta UPS Amplon R Series" in #987, "Delta RT series UPS devices" in #807).

jimklimov and others added 3 commits April 20, 2021 19:20
Sync the vendor-name comment (for udev generation among others) with another Delta HID driver merged to master recently.
@jimklimov
Copy link
Copy Markdown
Member

jimklimov commented Apr 21, 2021

It seems the two PRs are quite compatible, working on a series of commits that would make this one seem to add fixes to one already merged.

Main difference seems to be in the mapping fields seen by, I suppose, generation scripts on the two authors' systems and UPSes, and different flags to many of the fields that are present in both codebases.

…ter branch: move delta_ups_format_model() to same position as in master
…ter branch: import delta_ups_format_model() content from master
…ter branch: import named delta_ups_usage_lkp[] content from master
…ter branch: change delta_ups_hid2nut[] content order by names to be same as in master
…ter branch: import Helper lookup tables and mapping functions from master
…ter branch: import delta_ups_hid2nut[] entries "as is"
…ter branch: set battery.charge* precision to %.0f same for all entries
…ter branch: set voltage/current/frequency precision to %.1f same for all entries
…ter branch: comment away ups.mfr/model/serial setting per PR comments
…ter branch: remove (read-only) mappings for ups.delay* in favor of same points polled for ups.timer*
@jimklimov
Copy link
Copy Markdown
Member

jimklimov commented Apr 21, 2021

Note: I have prepared the branch to converge the work on a new Delta UPS USB support already merged into NUT master, and the independent work done here with other devices from that vendor adding more to the support.

Currently that change is proposed at lukakovacica#1 and stored at https://github.com/networkupstools/nut/tree/PR-807 branch. It was prepared starting from an earlier commit in this PR (before it got master merged into it), renaming the delta-hid files of this PR into delta_usb-hid, and respectively adding the "_ups" into func/table names there, and resynchronizing the contents. While the changeset itself is large and seems to delete one file and modify a lot in another, the trail of numerous commits with smaller-scoped goals can help retrace and review this convergence effort.

@aquette: I would welcome very much if you could go over that resulting delta_usb-hid.c regarding your comments above, about which fields should be polled at which frequencies, and how delay vs. timer fit together, etc :)

@jungeonkim @lukakovacica: would you please have a chance to try a build of https://github.com/networkupstools/nut/tree/PR-807 to check if the combined code still works for the UPSes you developed with?

@aquette
Copy link
Copy Markdown
Member

aquette commented Apr 21, 2021

A fast 1mn review since good and showing that you applied my comments. Though reviewing on a phone... Trusting you.

@lgtm-com
Copy link
Copy Markdown

lgtm-com Bot commented Apr 23, 2021

This pull request introduces 1 alert when merging 4a24894 into 82a984b - view on LGTM.com

new alerts:

  • 1 for FIXME comment

@jimklimov
Copy link
Copy Markdown
Member

Gentle bump: @jungeonkim @lukakovacica: would you please have a chance to try a build of https://github.com/networkupstools/nut/tree/PR-807 or of this PR's branch directly as https://github.com/networkupstools/LukaKovacica/nut/tree/nut-rebase to check if the combined code still works for the UPSes you developed with? I am rather eager to merge this contribution, but would not like to break by that the use-cases that apparently did work for either of you :)

@jungeonkim
Copy link
Copy Markdown
Contributor

@jimklimov it looks like work

@lukakovacica
Copy link
Copy Markdown
Contributor Author

@jimklimov I will take a look and try this on the UPS during this weekend.
I'll get back to you.

@jimklimov
Copy link
Copy Markdown
Member

jimklimov commented May 5, 2021 via email

@lukakovacica
Copy link
Copy Markdown
Contributor Author

Hello @jimklimov,

I've tested this today on my machine.
Everything seems to work well, thank you for that!

I've attached some logs below.

On mains:
battery.capacity: 100
battery.charge: 100
battery.charge.low: 20
battery.charge.warning: 20
battery.runtime: 3861
battery.temperature: 17.9
battery.type: PbAc
battery.voltage: 83.0
battery.voltage.nominal: 72.0
device.mfr: DELTA
device.model: UPS302R2RT2B035
device.serial: << redacted >>
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.synchronous: no
driver.version: 2.7.4-2290-ge91b75e8
driver.version.data: Delta UPS HID 0.5
driver.version.internal: 0.43
input.frequency: 50.0
input.sensitivity: normal
input.source: normal
input.transfer.high: 280.0
input.transfer.high.max: 280.0
input.transfer.high.min: 270.0
input.transfer.low: 100.0
input.transfer.low.max: 110.0
input.transfer.low.min: 100.0
input.voltage: 228.0
input.voltage.nominal: 230.0
output.current: 1.6
output.frequency: 50.0
output.frequency.nominal: 50.0
output.voltage: 230.0
output.voltage.nominal: 230.0
ups.beeper.status: enabled
ups.delay.start: 0
ups.load: 12.0
ups.mfr: DELTA
ups.model: UPS302R2RT2B035
ups.power.nominal: 3000
ups.productid: 041b
ups.realpower: 342.0
ups.serial: << redacted >>
ups.start.auto: yes
ups.status: OL
ups.test.result: Done and passed
ups.timer.reboot: 0
ups.timer.shutdown: -1
ups.timer.start: 0
ups.type: online
ups.vendorid: 05dd

Discharging:
battery.capacity: 100
battery.charge: 93
battery.charge.low: 20
battery.charge.warning: 20
battery.runtime: 2393
battery.temperature: 18.9
battery.type: PbAc
battery.voltage: 74.1
battery.voltage.nominal: 72.0
device.mfr: DELTA
device.model: UPS302R2RT2B035
device.serial: << redacted >>
device.type: ups
driver.name: usbhid-ups
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.synchronous: no
driver.version: 2.7.4-2290-ge91b75e8
driver.version.data: Delta UPS HID 0.5
driver.version.internal: 0.43
input.frequency: 0.0
input.sensitivity: normal
input.source: battery
input.transfer.high: 280.0
input.transfer.high.max: 280.0
input.transfer.high.min: 270.0
input.transfer.low: 100.0
input.transfer.low.max: 110.0
input.transfer.low.min: 100.0
input.transfer.reason: input voltage out of range
input.voltage: 0.0
input.voltage.nominal: 230.0
output.current: 1.7
output.frequency: 49.9
output.frequency.nominal: 50.0
output.voltage: 232.0
output.voltage.nominal: 230.0
ups.beeper.status: enabled
ups.delay.start: 0
ups.load: 13.0
ups.mfr: DELTA
ups.model: UPS302R2RT2B035
ups.power.nominal: 3000
ups.productid: 041b
ups.realpower: 366.0
ups.serial: << redacted >>
ups.start.auto: yes
ups.status: OB DISCHRG
ups.test.result: Done and passed
ups.timer.reboot: 0
ups.timer.shutdown: -1
ups.timer.start: 0
ups.type: online
ups.vendorid: 05dd

I have also tested the following commands:
beeper.disable - Working
beeper.enable - Working
beeper.mute - Working
load.off - Working
load.off.delay - Working
shutdown.return - Working
shutdown.stayoff - Working
test.battery.start.deep - Working
test.battery.start.quick - Working
test.battery.stop - Working

0.005233 [D2] Checking device (05DD/041B) (001/010)
0.006671 [D2] - VendorID: 05dd
0.006683 [D2] - ProductID: 041b
0.006687 [D2] - Manufacturer: DELTA
0.006690 [D2] - Product: DELTA UPS
0.006694 [D2] - Serial Number: << redacted >>
0.006697 [D2] - Bus: 001
0.006701 [D2] - Device release number: 0000
0.006705 [D2] Trying to match device
0.006708 [D2] match_function_subdriver (non-SHUT mode): matching a device...
0.006715 [D3] match_function_regex: matching a device...
0.006723 [D2] Device matches

I won't be able to do any further testing now, as the machine is in production.

@jimklimov
Copy link
Copy Markdown
Member

Super, thanks!

@jimklimov jimklimov merged commit 1e4b5ce into networkupstools:master May 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants