-
-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
First commit of NHS drivers/nhs-nut.c #2692
Conversation
Signed-off-by: Lucas Willian Bocchi [email protected]
MAINTAINER NOTE: The initial driver code has some Linux-specific bits and can get a number of portability complaints from the NUT CI farm agents running on other platforms. This will be addressed later as the PR evolves to get merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, thanks for a solid-looking driver that yields a lot of info. As a stand-alone program, it looks mostly good (some spots with C memory handling are commented, e.g. with upsdata
returns).
Most of the requested fixes (maybe I'll handle at least some of those notes myself) would be required to ensure portability of this driver to other platforms than yours, and to improve maintainability by using more of common NUT methods and approaches - probably including the serial-port communications.
Some general concerns are about which logical code landed into which standard methods for NUT driver structure, as documented at docs/new-drivers.txt
- fixes there would be needed, but probably simple ones, moving blocks of code into suitably named methods from wrong current locations.
Also a NEWS.adoc
entry to announce the driver, and data/driver.list.in
HCL entry (or several) to suggest use of this driver for some NHS device name(s), would be useful. You have a lot of names and VA values mapped in a method - perhaps these names can become the first pass of HCL data enhancement.
Also needs a manual page to describe the supported devices and the driver options (per addvar()
in code) and maybe other nuances - known caveats, etc. Ideally this comes from a driver author, as they best know if there is anything special to know about the devices.
Finally, as "naming is one of the hardest problems in IT" (citation needed), nhs-nut
would need to be changed, I think. There was a guideline (alas, mostly overlooked) to name new drivers as nutdrv_something
to help identify them in process listing, and there are several precedents for that. There is also one nut-*ipmi*
set of files. But none with nut
in the middle/end...
I think following the precedent of bcmxcp
, blazer
, riello
or sms
drivers suffuxed with _ser
and/or _usb
for different media, e.g. drivers/sms_ser.c
- this one deserves to be nhs_ser
.
drivers/nhs-nut.c
Outdated
#include "nut_stdint.h" | ||
#include "serial.h" | ||
#include <stdio.h> | ||
#include <linux/serial.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably some NUT CI agents (and end-user non-Linux platforms) will complain about this one.
Generally this can be revised as needed, by comparing to other serial-media drivers (using methods in drivers/serial.c
etc.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UPDATE: As found later, initial code relies on struct serial_struct
and TIOCSSERIAL
which are only defined there. So platform expansion would need finding equivalents for whatever those bits solved.
drivers/nhs-nut.c
Outdated
} | ||
|
||
void upsdrv_initups(void) { | ||
upsdebugx(1,"Start initups()"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upsdrv_initups()
should take care of hardware communications init (maybe fail with fatalx()
if port
is not accessible).
The upsdrv_initinfo()
method is called later to detect the device details (maybe fail with fatalx()
if no compatible device was found) and set write-once values like device model etc. and populate the list of supported commands and/or settable variables, if any.
Please do check docs/new-drivers.txt
for general driver code structure overview.
drivers/nhs-nut.c
Outdated
strcpy(porta,DEFAULTPORT); | ||
else | ||
strcpy(porta,device_path); | ||
serial_fd = openfd(porta,baudrate); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
upsdrv_initups()
should take care of hardware communications init (maybe fail with fatalx()
if port
is not accessible).
The upsdrv_initinfo()
method is called later to detect the device details (maybe fail with fatalx()
if no compatible device was found) and set write-once values like device model etc. and populate the list of supported commands and/or settable variables, if any.
Please do check docs/new-drivers.txt
for general driver code structure overview.
Signed-off-by: Lucas Willian Bocchi [email protected]
1) Miscalculations of battery voltage and amps 2) Miscalculations in battery capacity 3) Miscalculations in time remaining Signed-off-by: Lucas Willian Bocchi [email protected]
…s#2692] Signed-off-by: Jim Klimov <[email protected]>
nhs-nut.c: In function ‘print_pkt_data’: nhs-nut.c:464:17: error: zero-length gnu_printf format string [-Werror=format-zero-length] 464 | upsdebugx(1,""); | ^~ Signed-off-by: Jim Klimov <[email protected]>
nhs-nut.c:604:59: error: unused parameter ‘size’ [-Werror=unused-parameter] 604 | pkt_data mount_datapacket(unsigned char * datapacket, int size, double tempodecorrido,pkt_hwinfo pkt_upsinfo) { | ~~~~^~~~ nhs-nut.c:604:72: error: unused parameter ‘tempodecorrido’ [-Werror=unused-parameter] 604 | pkt_data mount_datapacket(unsigned char * datapacket, int size, double tempodecorrido,pkt_hwinfo pkt_upsinfo) { | ~~~~~~~^~~~~~~~~~~~~~ Signed-off-by: Jim Klimov <[email protected]>
nhs-nut.c:713:43: error: suggest braces around empty body in an ‘if’ statement [-Werror=empty-body] 713 | if (pktdata.perc_output > 100); | ^ nhs-nut.c:713:13: error: this ‘if’ clause does not guard... [-Werror=misleading-indentation] 713 | if (pktdata.perc_output > 100); | ^~ nhs-nut.c:714:17: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the ‘if’ 714 | pktdata.perc_output = 100; | ^~~~~~~ Signed-off-by: Jim Klimov <[email protected]>
nhs-nut.c:797:29: error: iteration 6 invokes undefined behavior [-Werror=aggressive-loop-optimizations] 797 | pkthwinfo.status[i] = get_bit_in_position(&datapacket[14],sizeof(datapacket[14]),i,0); | ~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jim Klimov <[email protected]>
nhs-nut.c: In function ‘upsdrv_updateinfo’: nhs-nut.c:1733:53: error: format not a string literal and no format arguments [-Werror=format-security] 1733 | upsdebugx(1,alarm); | ^~~~~ Signed-off-by: Jim Klimov <[email protected]>
nhs-nut.c: In function ‘upsdrv_makevartable’: nhs-nut.c:2090:88: error: format ‘%f’ expects argument of type ‘double’, but argument 3 has type ‘int’ [-Werror=format=] 2090 | sprintf(help,"Voltage In Percentage to calculate warning low level. Default is %0.2f",DEFAULLTPERC); | ~~~~^ | | | double | %0.2d etc. for other default macros Signed-off-by: Jim Klimov <[email protected]>
nhs-nut.c: In function ‘get_bit_in_position’: nhs-nut.c:357:22: error: comparison of integer expressions of different signedness: ‘int’ and ‘size_t’ {aka ‘long unsigned int’} [-Werror=sign-compare] 357 | if (bit_position >= size * 8) { | ^~ Signed-off-by: Jim Klimov <[email protected]>
Copy-paste typo? nhs-nut.c: In function ‘mount_datapacket’: nhs-nut.c:693:29: error: operation on ‘pktdata.icarregrms_real’ may be undefined [-Werror=sequence-point] 693 | pktdata.icarregrms_real = pktdata.icarregrms_real = pktdata.icarregrms * 30; | ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Jim Klimov <[email protected]>
nhs-nut.c: In function ‘mount_hwinfo’: nhs-nut.c:786:5: error: missing initializer for field ‘end_marker’ of ‘pkt_hwinfo’ [-Werror=missing-field-initializers] 786 | }; | ^ nhs-nut.c:177:18: note: ‘end_marker’ declared here 177 | unsigned int end_marker; | ^~~~~~~~~~ Signed-off-by: Jim Klimov <[email protected]>
Signed-off-by: Jim Klimov <[email protected]>
Signed-off-by: Jim Klimov <[email protected]>
❌ Build nut 2.8.2.2413-master failed (commit 41316bc334 by @jimklimov) |
Signed-off-by: Jim Klimov <[email protected]>
…ls#2692] Signed-off-by: Jim Klimov <[email protected]>
…etworkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
…ix some more markup [networkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
…etworkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
] Signed-off-by: Jim Klimov <[email protected]>
… __func__ [networkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
…t_data() [networkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
…rbosity 1, add __func__ [networkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
…t verbosity 3-4_ [networkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
@Challado : note, large changes of raw C text have landed as NUT code style was applied and some comments reformatted. Overall, most (not all) of the initial review comments above got addressed and resolved. It would be great if you can confirm that this code base state still builds and works for your device, before I get into some more significant refactoring to share some of your code with common |
…_ser.txt, NEWS.adoc: temporarily constrain nhs_ser to Linux-only NUT builds [networkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
✅ Build nut 2.8.2.2435-master completed (commit 3fbaf07f11 by @jimklimov) |
@Challado : upon the closer inspection, I found that you parse hwinfo details ( |
NOTE: I've also constrained builds of this driver and its man page to happen by default just on Linux for now, and added respective wording to the I've checked that this arrangement does not preclude |
Yep. Compiled and still working here in arm / amd4 platforms. |
NOTE: CI hiccups about openbsd are due to build agent reconfiguration. |
Probably some clean-up remains e.g. to reshuffle code between methods, improve portability, etc. - but as a first code drop that passes CI this is "good enough" to not keep the PR indefinitely open. |
…d upsdrv_initups() [networkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
…indent main code a bit [networkupstools#2692] Fixed the retries from being an infinite loop along the way... Signed-off-by: Jim Klimov <[email protected]>
…a-stale related messages and status changes [networkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
…f_needed() [networkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
Signed-off-by: Jim Klimov <[email protected]>
Signed-off-by: Jim Klimov <[email protected]>
…packet data interpretation; un-indent more code [networkupstools#2692] Add range-check to not overflow the datapacket[] buffer. Signed-off-by: Jim Klimov <[email protected]>
…winfo() and interpret_pkt_data() logic, separated by domain [networkupstools#2692] Also rename some data points that do not conform to NUT standards, or drop if redundant. Signed-off-by: Jim Klimov <[email protected]>
…at and min_input_power in static vars [networkupstools#2692] Signed-off-by: Jim Klimov <[email protected]>
…ls#2692] Signed-off-by: Jim Klimov <[email protected]>
First commit of driver NHS-NUT for NHS senoidal lines.
Signed-off-by: Lucas Willian Bocchi [email protected]
MAINTAINER UPDATE: Started from mailing list submission at https://alioth-lists.debian.net/pipermail/nut-upsdev/2024-November/008046.html