-
-
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
Updated Phoenix Contact modbus driver for newer models #2689
Updated Phoenix Contact modbus driver for newer models #2689
Conversation
…es. Choice is made basing on firmware version. Signed-off-by: RikyPlaza <[email protected]>
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.
Thanks for a solid-looking enhancement. A NEWS.adoc
entry would be good, beside addressing the specific comments I mentioned during a look at code.
drivers/phoenixcontact_modbus.c
Outdated
r = modbus_set_slave(modbus_ctx, MODBUS_SLAVE_ID); /* slave ID */ | ||
if (r < 0) { | ||
modbus_free(modbus_ctx); | ||
fatalx(EXIT_FAILURE, "Invalid modbus slave ID %d",MODBUS_SLAVE_ID); | ||
} | ||
|
||
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.
Here and several times above - needless added whitespace
drivers/phoenixcontact_modbus.c
Outdated
if (CHECK_BIT(tab_reg[0], 16)) | ||
alarm_set("Low Battery (Service)"); | ||
|
||
uint32_t alarms_word; |
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.
Here and above, variable definitions are added in the middle of scope. NUT coding style requires all definitions to be before code, so older systems can build current NUT too. Probably that is what CI failed about all over the place.
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.
Undersoot!
drivers/phoenixcontact_modbus.c
Outdated
|
||
mrir(modbus_ctx, 0x2000, 1, &actual_code_functions); | ||
|
||
tab_reg[0] = CHECK_BIT(actual_code_functions, 2); //battery mode is the 2nd bit of the register 0x2000 |
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.
Please use block comment style /* ... */
break; | ||
case OLD_UPS: | ||
|
||
mrir(modbus_ctx, 29697, 3, tab_reg); /* LB is actually called "shutdown event" on this ups */ |
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.
Any idea if these numbers make more sense in hex? Are they perhaps bit-masks of some command combos?
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.
The only reason why i kept the old addresses in dec and put the new ones in hex is the way they are reported in the UPSes datasheet. If you want to use a standard for coding i can change all addresses in the same way, but for maintenence in the furure it will be necessary to convery all numbers.
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.
No, got no particular preference here. If maintenance would be easier with decimal numbers - so be it. Maybe worth a short comment at start of the file though.
drivers/phoenixcontact_modbus.c
Outdated
|
||
#define CHECK_BIT(var,pos) ((var) & (1<<(pos))) | ||
#define MODBUS_SLAVE_ID 192 | ||
|
||
#define OLD_UPS 0 | ||
#define NEW_UPS 1 |
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.
I wonder how soon "old" vs. "new" would become obsolete? Maybe more symbolic names would be better (just a thought)?
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.
You're right, i've put the models. To be honest there would be another model (TRIO) but i don't have the hardware to test the communication. As soon as it will arrive i can test the driver and see if changes are needed.
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.
Another options can be an enum
to also constrain the values accepted at compile-time (and get warnings like that a switch
does not look at all newly defined options).
|
||
uint16_t FWVersion; | ||
|
||
mrir(modbus_ctx, 0x0004, 1, &FWVersion); |
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.
Makes sense to also populate ups.firmware
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.
I agree, not sure if the variable should be defined somewhere else or i can just call the dstate_setinfo function.
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.
Well, the global variable makes sense if this info would be used elsewhere (e.g. instead of those OLD_UPS/NEW_UPS
defines?)
Signed-off-by: RikyPlaza <[email protected]>
@jimklimov Hello, regarding the |
❌ Build nut 2.8.2.2394-master failed (commit bc3ad182ba by @RikyPlaza) |
…cted alarm trigger (wrong bit used) Signed-off-by: RikyPlaza <[email protected]>
Probably just add a paragraph (bullet point) similar to ones that are already there. |
Signed-off-by: RikyPlaza <[email protected]>
Signed-off-by: RikyPlaza <[email protected]>
Signed-off-by: RikyPlaza <[email protected]>
Signed-off-by: RikyPlaza <[email protected]>
❌ Build nut 2.8.2.2400-master failed (commit 81417050d0 by @RikyPlaza) |
Signed-off-by: RikyPlaza <[email protected]>
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.
Files reviewed.
✅ Build nut 2.8.2.2401-master completed (commit 82692db556 by @RikyPlaza) |
Signed-off-by: RikyPlaza <[email protected]>
FYI: If the lack of default label would also prove a problem with some other compilers, check other drivers for use of pragmas around that. Typically we end up with a monster like:
|
Also remembered: a man page would be needed to describe the supported devices and the driver options (per |
@jimklimov I'm not sure if the checks are running, for now i don't see any error so i would let the check finish. Do you know how much time do they ususally take? |
@jimklimov Ok, as soon as the checks are ok i'll take a look to the man page. Should i modify something already present or should i make a new man page? |
New driver - new man page :) As for checks, it's about 3-5hrs for all scenarios to run; overall time depends on how maby other PR iterations are queued... |
@jimklimov Hi, now i see that the there are errors regarding the missing default label in switch statements, but i had to remove them in commit f19c8e0 since the checks were also failing. I really don't understand what it the issue... |
@RikyPlaza : did you try the construct with pragmas per #2689 (comment) ? |
@jimklimov Hello, if i consider the driver blazer_usb.c i don't see any pragma directive. I'm a little bit confused on how those drivers, without any pragma construct, pass the checks related to the default labels in switch statements... |
@jimklimov In any case now i try to insert that statemets and commit the driver. Let's see :) |
…ault" label in switch statements. Signed-off-by: RikyPlaza <[email protected]>
Different compilers and their different warning settings require different rules to be satisfied, and are sonetimes at odds:
Also note fall-through cases (lack of |
…etworkupstools#2689, networkupstools#823] Signed-off-by: Jim Klimov <[email protected]>
Signed-off-by: RikyPlaza <[email protected]>
Signed-off-by: RikyPlaza <[email protected]>
Signed-off-by: RikyPlaza <[email protected]>
@jimklimov no idea why the checks failed :) |
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.
No idea on the fails.
…ools#2689] Signed-off-by: Jim Klimov <[email protected]>
…h cases [networkupstools#2689] Signed-off-by: Jim Klimov <[email protected]>
…rkupstools#2689] Signed-off-by: Jim Klimov <[email protected]>
…dbus_drv Signed-off-by: Jim Klimov <[email protected]>
CI setup issue, mis-added new workers :\ |
Updated Phoenix Contact modbus driver for newer models which are using different modbus addresses. Choice is made basing on the UPS firmware version and the model information have been changed in order to have a quick feedback over the new/old model detection.