Repository navigation
Updated Phoenix Contact modbus driver for newer models - #2689
Conversation
…es. Choice is made basing on firmware version. Signed-off-by: RikyPlaza <rikyrod2001@gmail.com>
jimklimov
left a comment
There was a problem hiding this comment.
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.
| fatalx(EXIT_FAILURE, "Invalid modbus slave ID %d",MODBUS_SLAVE_ID); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Here and several times above - needless added whitespace
| if (CHECK_BIT(tab_reg[0], 16)) | ||
| alarm_set("Low Battery (Service)"); | ||
|
|
||
| uint32_t alarms_word; |
There was a problem hiding this comment.
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.
|
|
||
| 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.
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.
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.
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.
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.
| #define MODBUS_SLAVE_ID 192 | ||
|
|
||
| #define OLD_UPS 0 | ||
| #define NEW_UPS 1 |
There was a problem hiding this comment.
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.
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.
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.
Makes sense to also populate ups.firmware
There was a problem hiding this comment.
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.
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 <158032745+RikyPlaza@users.noreply.github.com>
|
@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 <158032745+RikyPlaza@users.noreply.github.com>
Probably just add a paragraph (bullet point) similar to ones that are already there. |
Signed-off-by: RikyPlaza <158032745+RikyPlaza@users.noreply.github.com>
Signed-off-by: RikyPlaza <158032745+RikyPlaza@users.noreply.github.com>
Signed-off-by: RikyPlaza <158032745+RikyPlaza@users.noreply.github.com>
Signed-off-by: RikyPlaza <158032745+RikyPlaza@users.noreply.github.com>
|
❌ Build nut 2.8.2.2400-master failed (commit 81417050d0 by @RikyPlaza) |
Signed-off-by: RikyPlaza <158032745+RikyPlaza@users.noreply.github.com>
RikyPlaza
left a comment
There was a problem hiding this comment.
Files reviewed.
|
✅ Build nut 2.8.2.2401-master completed (commit 82692db556 by @RikyPlaza) |
Signed-off-by: RikyPlaza <158032745+RikyPlaza@users.noreply.github.com>
|
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 <158032745+RikyPlaza@users.noreply.github.com>
|
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 <jimklimov+nut@gmail.com>
Signed-off-by: RikyPlaza <158032745+RikyPlaza@users.noreply.github.com>
Signed-off-by: RikyPlaza <158032745+RikyPlaza@users.noreply.github.com>
Signed-off-by: RikyPlaza <158032745+RikyPlaza@users.noreply.github.com>
|
@jimklimov no idea why the checks failed :) |
RikyPlaza
left a comment
There was a problem hiding this comment.
No idea on the fails.
…ools#2689] Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…h cases [networkupstools#2689] Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…rkupstools#2689] Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
…dbus_drv Signed-off-by: Jim Klimov <jimklimov+nut@gmail.com>
|
CI setup issue, mis-added new workers :\ |
…_modbus_drv Updated Phoenix Contact modbus driver for newer models SVN-Git-Bridge: nut-3e341d2d9c-3fc79f1e8124 3984321 Bridge-Author: Jim Klimov <jimklimov+nut@gmail.com> Bridge-Author-Date: 2024-12-01T18:22:00+01:00 Bridge-Committer: GitHub <noreply@github.com> Bridge-Committer-Date: 2024-12-01T18:22:00+01:00 From: Jim Klimov <jimklimov+nut@gmail.com> git-svn-id: file:///mnt/export/subversion/nut/trunk@4172 5f2f2009-99cd-4845-9af7-39d0aa6e3748
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.