Add new driver for UPS supporting microlink protocol#2663
Add new driver for UPS supporting microlink protocol#2663tom1422 wants to merge 1 commit intonetworkupstools:masterfrom tom1422:nut-microlink
Conversation
|
❌ Build nut 2.8.2.2262-master failed (commit 787c78847a by @tom1422) |
|
Wow, thanks for the effort, I'm sure many people will love to see this protocol supported. 💯 Out of personal interest, what was the UPS device that you built this around and which variables were you able to extract that worked for your device? Can you post a |
Thank you, here's some of the info as requested: The device i used was an SMT750i (that is too old to support modbus). I also tried it on a friend's UPS (some larger and or newer units that do support modbus) and they seem to all expose more or less the same variables (there's probably still more configurations that need supporting). Here is the dump from upsc for my device: (removed serial number) (I have also updated the pull request with some extra details) |
drivers/apc_ul_util.c
Outdated
| return; | ||
| } | ||
|
|
||
| for (uint8_t i = 1; i < exited.array_length; i++) |
Check failure
Code scanning / CodeQL
Comparison of narrow type with wide type in loop condition
|
Sounds great, and CI (or local Did you find a protocol definition, or was this "lock-picked" somehow? |
|
As for USB support, if you mean something greater than |
There was a problem hiding this comment.
Taking a look at this PR about why it failed CI (and to read a bit more into code, although still cursorily), got some early comments and simple fixes here.
As you noted before, I suppose the next big issue to pass NUT CI requirements across the board would be a bit of dumbing down the C language syntax (e.g. requiring the declarations to be in first lines of scope, not further in code), so it builds on old systems too.
drivers/apc_ul_util.h
Outdated
| #define FQID(id_i, type_i) {.id = (id_i), .type = (type_i), .array_index = -1, .array_length = -1} | ||
| #define FQID_INDEX(id_i, type_i, index_i, length_i) {.id = (id_i), .type = (type_i), .array_index = (index_i), .array_length = (length_i)} | ||
|
|
||
| #define FQUN(...) \ | ||
| {__VA_ARGS__} |
There was a problem hiding this comment.
Looking forward to seeing whether the different compiler generations (and their C99+ settings) in the NUT CI farm would accept this syntax or find it too revolutionary :)
drivers/apc_ul_util.h
Outdated
| int array_index; | ||
| int array_length; |
There was a problem hiding this comment.
Why not e.g. ssize_t if we want signed (and to fit into compiler-guaranteed array sizing)?
drivers/apc_ul_util.h
Outdated
| char *command_directive; | ||
|
|
||
| uint8_t *command; | ||
| int command_length; |
There was a problem hiding this comment.
Can this "length" be negative? Would a (s)size_t be better here?
drivers/apc_ul_util.h
Outdated
| typedef struct | ||
| { | ||
| uint8_t *array; | ||
| int length; |
There was a problem hiding this comment.
Can this "length" be negative? Would a (s)size_t be better here?
drivers/apc_ul_util.h
Outdated
| int fqun_to_string(const fqid_t *fqun, char *dest); | ||
|
|
||
| int compareFQUN(const fqid_t *source, const fqid_t *target, int depth); | ||
|
|
||
| int validate_row(microlink_row_t row); | ||
|
|
||
| int addChecksumToMessage(uint8_t *packet, int data_length, int array_size); | ||
|
|
||
| int parseDatastore(uint8_t *data_block, uint8_t number_of_rows, | ||
| uint8_t row_size, usage_t *usage_array); | ||
|
|
||
| void create_slave_password(uint8_t *master_password, int master_password_length, | ||
| uint8_t *microlink_header, int header_length, | ||
| uint8_t *serial_number, int serial_num_length, | ||
| uint8_t *slave_password); | ||
|
|
||
| void create_master_password_verify(uint8_t *slave_password, int slave_password_length, | ||
| uint8_t *microlink_header, int header_length, | ||
| uint8_t *serial_number, int serial_num_length, | ||
| uint8_t *master_password_verify); |
There was a problem hiding this comment.
Can "length"'s in these methods arguments be negative? Would a (s)size_t be better here?
Also. for methods that populate a caller-provided string (e/g/ fqun_to_string) I'd prefer seeing an argument to track the allowed buffer length (decremented and consulted in the logic).
|
@tom1422 : hm, I got too used to having maintainer write access to forks' branches that PRs come from. |
drivers/apc_ul_util.c
Outdated
| case fqid_collection: | ||
| if (current_fqid.array_length > 0) | ||
| { | ||
| snprintf(dest + ptr_string, 12, "[%-3i, %-3i]", current_fqid.array_index % 256, current_fqid.array_length % 256); |
There was a problem hiding this comment.
13 not 12 here, to allow for \0 always.
Also note the other comment, about adding an argument to check for not overflowing a caller-provided buffer size.
drivers/apc_ul_util.c
Outdated
| return; | ||
| } | ||
|
|
||
| for (uint8_t i = 1; i < exited.array_length; i++) |
There was a problem hiding this comment.
int i (beside moving declarations to start of scope)?
|
Per offline discussion, completion of this contribution will likely be delayed, so marking Draft for now. |
|
I just saw the driver file is empty with the latest force push, what's going on? Refactoring? |
I'm talking to jimklimov about this, but I have decided to remove it while I sort out / determine what's best (legally speaking). I hope you can understand and please feel free to close the pull request (if you think that would be better, I dont mind opening one in future or contributing on this one directly). |
Ah I see, I figured something was going on behind the scenes... 😉 |
Signed-off-by: Thomas Eldon <tom@tomeldon.com>
|
Although currently suspended, cross-linking to issue #1426 |
|
Not to poke the hornet's nest, but... any news on this? I'm guessing the issue at hand has something to do with it being proprietary? Maybe a blue-eyed type of question but is it very utopic to get APC to sign off on this? I'm sure it'd be a welcome addition for many users, so... is it likely to ever happen? 😉 |
An experimental driver for APC microlink protocol devices that I would like to contribute to the project. Currently this only supports serial, but adding USB support should be straightforward.
Will need more work to ensure it follows NUT convention more closely (e.g. Variables being defined not at start of functions).
General points
Described the changes in the PR submission or a separate issue, e.g.
known published or discovered protocols, applicable hardware (expected
compatible and actually tested/developed against), limitations, etc.
There may be multiple commits in the PR, aligned and commented with
a functional change. Notably, coding style changes better belong in a
separate PR, but certainly in a dedicated commit to simplify reviews
of "real" changes in the other commits. Similarly for typo fixes in
comments or text documents.
Please star NUT on GitHub, this helps with sponsorships! ;)
Frequent "underwater rocks" for driver addition/update PRs
Revised existing driver families and added a sub-driver if applicable
(
nutdrv_qx,usbhid-ups...) or added a brand new driver in the othercase.
Did not extend obsoleted drivers with new hardware support features
(notably
blazerand other single-device family drivers for Qx protocols,except the new
nutdrv_qxwhich should cover them all).For updated existing device drivers, bumped the
DRIVER_VERSIONmacroor its equivalent.
For USB devices (HID or not), revised that the driver uses unique
VID/PID combinations, or raised discussions when this is not the case
(several vendors do use same interface chips for unrelated protocols).
For new USB devices, built and committed the changes for the
scripts/upower/95-upower-hid.hwdbfileProposed NUT data mapping is aligned with existing
docs/nut-names.txtfile. If the device exposes useful data points not listed in the file, the
experimental.*namespace can be used as documented there, and discussionshould be raised on the NUT Developers mailing list to standardize the new
concept.
Updated
data/driver.list.inif applicable (new tested device info)Frequent "underwater rocks" for general C code PRs
structure layout and alignment in memory, endianness (layout of bytes and
bits in memory for multi-byte numeric types), or use of generic
intwherelanguage or libraries dictate the use of
size_t(orssize_tsometimes).Progress and errors are handled with
upsdebugx(),upslogx(),fatalx()and related methods, not with directprintf()orexit().Similarly, NUT helpers are used for error-checked memory allocation and
string operations (except where customized error handling is needed,
such as unlocking device ports, etc.)
Coding style (including whitespace for indentations) follows precedent
in the code of the file, and examples/guide in
docs/developers.txtfile.For newly added files, the
Makefile.amrecipes were updated and themake distchecktarget passes.General documentation updates
Updated
docs/acknowledgements.txt(for vendor-backed device support)Added or updated manual page information in
docs/man/*.txtfilesand corresponding recipe lists in
docs/man/Makefile.amfor new pagesPassed
make spellcheck, updated spell-checking dictionary in thedocs/nut.dictfile if needed (did not remove any words -- themakerule printout in case of changes suggests how to maintain it).
Additional work may be needed after posting this PR
Propose a PR for NUT DDL with detailed device data dumps from tests
against real hardware (the more models, the better).
Address NUT CI farm build failures for the PR: testing on numerous
platforms and toolkits can expose issues not seen on just one system.
the changed codebase.