-
-
Notifications
You must be signed in to change notification settings - Fork 350
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
Add Bicker serial driver #2448
Add Bicker serial driver #2448
Conversation
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.
For the first cursory look at this, looks quite solid - thanks! Feel welcome to update NEWS.adoc
and perhaps acknowledgements.txt
Also a man page would be needed.
First of all, many thanks for the review. I just added manpage and updated NEWS.adoc. Not knowing where to put it (this is my first contribution to NUT), I added the announcement at the end of the |
Rebased on c8d7e3c. |
Add a new driver for Bicker DC UPS systems based on the PSZ-1063 extension module. This includes UPSIC-1205, UPSIC-2403 and DC2412-UPS(LD) models. Signed-off-by: Nicola Fontana <[email protected]>
The protocol supports shutdown after a custom delay settable between 0 and 255 seconds. Unfortunately the real device (UPSIC-2403D) seems to always enforce a 2 seconds delay. Signed-off-by: Nicola Fontana <[email protected]>
Signed-off-by: Nicola Fontana <[email protected]>
Signed-off-by: Nicola Fontana <[email protected]>
Signed-off-by: Nicola Fontana <[email protected]>
Signed-off-by: Nicola Fontana <[email protected]>
Signed-off-by: Nicola Fontana <[email protected]>
Bicker told me to refer to the UPS Gen software's user manual for more details on their protocol, and in fact that manual contains much more info. Added a summary of available commands to the comments, as a quick reference for feature implementation. Signed-off-by: Nicola Fontana <[email protected]>
In the previous implementation the command index was always '\x03', as stated by the UPSIC manual. After new evidence has been found (UPS-Gen2 software user manual), it came out there are much more commands grouped in different indexes. Signed-off-by: Nicola Fontana <[email protected]>
I'm planning to add functions for reading strings, i.e. without knowing beforehand the size of the response packets. This required some refactoring of the receiving functions. Also, while at it, added docblocks to many Bicker functions, hopefully easing the maintenance in the future. Signed-off-by: Nicola Fontana <[email protected]>
Identification fields are now queried from the device. Also "battery.charge" is now set properly. Signed-off-by: Nicola Fontana <[email protected]>
Signed-off-by: Nicola Fontana <[email protected]>
Added the needed infrastructure for getting and setting parameters. Actually the only parameter that is surely working is "ups.delay.start". Signed-off-by: Nicola Fontana <[email protected]>
After the manufacturer provided more info, I've been able to add a lot more stuff. Now I'm quite happy with the result. |
IIRC those should be |
When a command is unsupported, the "\x01\x03\xEE\x07\x04" response packet is returned. This is different from a response packet with a wrong command index. WARNING: the "unsupported" packet has been found sperimentally and it is an undocumented feature. Signed-off-by: Nicola Fontana <[email protected]>
User provided strings could contain printf special sequences and as such they should never be used in the format argument of dstate_setinfo(). Signed-off-by: Nicola Fontana <[email protected]>
Of course you are right, sorry about that. I'm very well aware user provided strings in |
Thanks! And that reminded me to post a TODO #2450 :) |
Ugh, in
Maybe casting in the macro would suffice? Like
|
Yes, I've seen that. I was fearing that could be an issue: I think the problem is not |
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.
Looks very solid, thank you again. I've got some suggestions for further perfection or double-checking, but I think none of those are critical/blockers.
@@ -146,6 +146,10 @@ https://github.com/networkupstools/nut/milestone/11 | |||
respective warnings issued by the new generations of analysis tools. | |||
[#823, #2437, link:https://github.com/networkupstools/nut-website/issues/52[nut-website issue #52]] | |||
|
|||
- bicker_ser: added new driver for Bicker 12/24Vdc UPS via RS-232 serial |
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.
For posterity: This mixed casing of Vac
scratched my eye a bit - I'm used to seeing acronyms as upper-cased. But lower-case ac
/dc
seem to be the modern IEEE recommendation, according to internet discussions of many others whose eyes this has also got irritated :)
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.
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.
At the end I think that description is at least incomplete. We'll see if Bicker has anything to say about that.
I think you can try compiler hints to By "extracting" you mean constructing a new |
Accessing an uint16_t on odd addresses is not portable. Avoid having to deal with that issue by always constructing words mathematically from single bytes. This also solves any endianness difference. Signed-off-by: Nicola Fontana <[email protected]>
Yes, I ended up doing that. The resulting code seems even cleaner and it does not rely on endianness anymore. I will push shortly after solving some of the issue you posted (and some cosmetic issues that are striking my eyes too). |
Signed-off-by: Nicola Fontana <[email protected]>
`char` is by default signed and (as the name implies) designed to access string characters. For accessing bytes, the `uint8_t` type is more appropriate. Signed-off-by: Nicola Fontana <[email protected]>
Ensure the format string in logging messages is the correct one without subcasting. Furthermore, due to the promotion rules of the C language (where any given type, even unsigned, is promoted to int when possible), explicitly cast to unsigned where required. Signed-off-by: Nicola Fontana <[email protected]>
Change BICKER_PACKET from a constant value to a macro that depends on the data length. This should make clear that the packet size depends directly from the data size. Refactored some code here and there trying to minimize the presence of magic numbers and clarify the intentions. Signed-off-by: Nicola Fontana <[email protected]>
Using an in/out struct and making some specific field mandatory is cumbersome and error prone. Now the data needed for setting or getting parameters is explicitly required by the arguments. Signed-off-by: Nicola Fontana <[email protected]>
These devices seem to be picky on what you use to set parameters. Signed-off-by: Nicola Fontana <[email protected]>
Every Bicker parameter that has a correspondence in nut-names.txt has been mapped. If the parameter is disabled on the device, no NUT variable is created. If the NUT variable is set to an empty string, the parameter is reset and disabled on the device and that NUT variable is removed. Signed-off-by: Nicola Fontana <[email protected]>
Basically the code is now complete. I mapped the relevant Bicker parameters to nut-names but unfortunately I cannot do more testing because I borked the UPS I was using. I think I corrupted the parameter memory by passing |
My condolences about the device... its sacrifice will be remembered :( |
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.
Looks great and a lot better than much of the older code, I am out of ideas what else to complain about. Thank you very much for bearing with me and my nits :D
ret = ser_get_buf_len(upsfd, buf + 2, datalen + 3, BICKER_TIMEOUT, 0); | ||
/* Read the rest of the packet */ | ||
buflen = BICKER_PACKET(datalen); | ||
ret = ser_get_buf_len(upsfd, buf + 2, buflen - 2, BICKER_TIMEOUT, 0); |
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.
Just to be sure / for posterity: buflen - 2
here (and a bit below) is the whole packet (including BICKER_EOT
final byte) other than the first two bytes we've just read above?
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.
Yes, exactly that in both cases.
This driver supports some interesting supercap DC UPSes manufactured by Bicker. I'm planning to use them in the near future on small Linux-based industrial PC (mainly amd64 or arm64).
AFAICS, there are two main issues:
ups.delay.shutdown
stinks: most drivers defines it inupsdrv_initinfo
but then myupsdrv_shutdown
function crashes when trying to access it. I followed theusbhid-ups.c
example and put it insideupsdrv_initups
.