Skip to content

[Issue #616] legrand usb support - #1075

Merged
jimklimov merged 28 commits into
networkupstools:masterfrom
blecher-at:issue-441+legrand_updated-3
Jan 19, 2022
Merged

jimklimov merged 28 commits into
networkupstools:masterfrom
blecher-at:issue-441+legrand_updated-3

Conversation

@blecher-at

@blecher-at blecher-at commented Aug 19, 2021 •

Copy link
Copy Markdown
Contributor

Revive the effort to solve (most of) issue #616

zykh and others added 15 commits July 28, 2018 22:13
Since some devices, when communicating via USB, don't close their replies to our commands/queries with the expected (and mandated by the specs) CR, rendering the driver almost useless as protocols get one less character than they expect, update the various USB subdrivers (leaving out the ones that rely on a CR to stop reading from the device) to add the missing terminating CR in such cases (as long as we get anything usable).
This is a bit of a cheat, but, at least for now, it will do -- not to mention the fact that it is way less invasive than touching all the places of the driver that expect a closing CR and all the qx2nut tables of the various protocols.

Close networkupstools#441
As per protocol documentation, data is sent by the device with unsigned integers of 8, 16 or 32 bits, with errors/special values being:
- for uint16: 0xFFFF and 0xFFFE,
- for uint32: 0xFFFFFFFF.
Alas, those values are (and, probably, have always been) actually reported in the documentation (mostly) as if their types were not unsigned (so, in decimal: -1, and -2) and the metasys driver used them like that, converting the values to non-fixed width signed types (int and long) and then expecting a value of -1 or -2 to signal a particular event, but this only happens on platforms where int is exactly 16 bits, and long 32 bits.
So, leave values as unsigned types (adjusting all the printf formats accordingly), and use the right hex values, instead.
Add to the metasys driver a few new models (Meta System DHEA, and others now branded Legrand) speaking the Meta System UPS protocol.
The added command is only supported by devices with an 'id code' >= 14, while for other, older, models the command is not enabled by default, and the user has to perform a specific procedure via serial to enable it (where supported).
As per the provided protocol: see nut-website's 570c1e5e9f1fb4f82abef9359897b5159e88fc50
Also, fix name of "HF Line /2".
Also, specify that Legrand Multiplug is USB-only.
As per the provided protocol: see nut-website's 66d30c90401ff7929b25e5a87f9299b728f861ea
@blecher-at blecher-at changed the title Issue 441+legrand updated 3 [Issue #616] legrand usb support Aug 19, 2021
@blecher-at blecher-at mentioned this pull request Aug 19, 2021
7 of 8 tasks
@jimklimov

jimklimov commented Sep 15, 2021 •

Copy link
Copy Markdown
Member

Now that CI is about usable again, it has valid complaints:

  • This needs a NUT_UNUSED_VARIABLE(device) (and an #include "common.h" if not there yet somehow):
[2021-09-15T04:13:59.193Z] legrand-hid.c: In function 'disable_interrupt_pipe':
[2021-09-15T04:13:59.193Z] legrand-hid.c:37:50: error: unused parameter 'device' [-Werror=unused-parameter]
[2021-09-15T04:13:59.193Z]    37 | static void *disable_interrupt_pipe(USBDevice_t *device)
[2021-09-15T04:13:59.193Z]       |                                     ~~~~~~~~~~~~~^~~~~~
  • These need a few explicit NULLs in the end of initializer:
[2021-09-15T04:13:59.193Z] legrand-hid.c: At top level:
[2021-09-15T04:13:59.193Z] legrand-hid.c:78:2: error: missing initializer for field 'nuf' of 'info_lkp_t' [-Werror=missing-field-initializers]
[2021-09-15T04:13:59.193Z]    78 |  { 0, NULL, legrand_times10 }
[2021-09-15T04:13:59.193Z]       |  ^

[2021-09-15T04:13:59.193Z] In file included from legrand-hid.c:25:
[2021-09-15T04:13:59.193Z] usbhid-ups.h:69:11: note: 'nuf' declared here
[2021-09-15T04:13:59.193Z]    69 |  double (*nuf)(const char *nut_value);  /* optional NUT to HID mapping */
[2021-09-15T04:13:59.193Z]       |           ^~~

[2021-09-15T04:13:59.193Z] legrand-hid.c:89:2: error: missing initializer for field 'nuf' of 'info_lkp_t' [-Werror=missing-field-initializers]
[2021-09-15T04:13:59.193Z]    89 |  { 0, NULL, legrand_times100k }
[2021-09-15T04:13:59.193Z]       |  ^

[2021-09-15T04:13:59.193Z] In file included from legrand-hid.c:25:
[2021-09-15T04:13:59.193Z] usbhid-ups.h:69:11: note: 'nuf' declared here
[2021-09-15T04:13:59.193Z]    69 |  double (*nuf)(const char *nut_value);  /* optional NUT to HID mapping */
[2021-09-15T04:13:59.193Z]       |           ^~~

[2021-09-15T04:13:59.193Z] legrand-hid.c:100:2: error: missing initializer for field 'nuf' of 'info_lkp_t' [-Werror=missing-field-initializers]
[2021-09-15T04:13:59.193Z]   100 |  { 0, NULL, legrand_times1M }
[2021-09-15T04:13:59.193Z]       |  ^

[2021-09-15T04:13:59.193Z] In file included from legrand-hid.c:25:
[2021-09-15T04:13:59.193Z] usbhid-ups.h:69:11: note: 'nuf' declared here
[2021-09-15T04:13:59.193Z]    69 |  double (*nuf)(const char *nut_value);  /* optional NUT to HID mapping */
[2021-09-15T04:13:59.193Z]       |           ^~~

[2021-09-15T04:13:59.193Z] legrand-hid.c:111:2: error: missing initializer for field 'nuf' of 'info_lkp_t' [-Werror=missing-field-initializers]
[2021-09-15T04:13:59.193Z]   111 |  { 0, NULL, legrand_times10M }
[2021-09-15T04:13:59.193Z]       |  ^
[2021-09-15T04:13:59.193Z] In file included from legrand-hid.c:25:

[2021-09-15T04:13:59.193Z] usbhid-ups.h:69:11: note: 'nuf' declared here
[2021-09-15T04:13:59.193Z]    69 |  double (*nuf)(const char *nut_value);  /* optional NUT to HID mapping */
[2021-09-15T04:13:59.193Z]       |           ^~~
[2021-09-15T04:13:59.193Z] cc1: all warnings being treated as errors
[2021-09-15T04:13:59.193Z] *** Error code 1

@jimklimov jimklimov added Qx protocol driver Driver based on Megatec Q<number> such as new nutdrv_qx, or obsoleted blazer and some others ready / gonna merge The PR is in final cycles leading to merge unless someone logs an objection before we hit the button USB labels Dec 21, 2021
@jimklimov

jimklimov commented Dec 21, 2021 •

Copy link
Copy Markdown
Member

Thanks, finally got back to look at this and formally seems okay - but I don't have the devices to test against.

Looking at (C) lines, seems this contribution comes (partially?) from Legrand itself; this may be worth highlighting in docs/acknowledgements.txt then.

As a reminder to myself, this PR is likely to have mild merge conflicts with #1135 and (as mentioned in original issue) possibly with libusb-1.0 branches that are converging to getting merged soonish too.

@jimklimov
jimklimov merged commit 5a414a3 into networkupstools:master Jan 19, 2022
@blecher-at
blecher-at deleted the issue-441+legrand_updated-3 branch February 7, 2022 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Qx protocol driver Driver based on Megatec Q<number> such as new nutdrv_qx, or obsoleted blazer and some others ready / gonna merge The PR is in final cycles leading to merge unless someone logs an objection before we hit the button USB

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants