Skip to content
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

nutdrv_qx: support replies not terminated by the required CR #441

Open
zykh opened this issue Jun 9, 2017 · 8 comments
Open

nutdrv_qx: support replies not terminated by the required CR #441

zykh opened this issue Jun 9, 2017 · 8 comments
Assignees
Labels
bug impacts-release-2.7.4 Issues reported against NUT release 2.7.4 (maybe vanilla or with minor packaging tweaks) impacts-release-2.8.0 Issues reported against NUT release 2.8.0 (maybe vanilla or with minor packaging tweaks) Qx protocol driver Driver based on Megatec Q<number> such as new nutdrv_qx, or obsoleted blazer and some others
Milestone

Comments

@zykh
Copy link
Contributor

zykh commented Jun 9, 2017

Apparently some devices don't close their replies to our commands/queries with the expected (and mandated by the specs) CR and, at the moment, this is not supported by nutdrv_qx:
http://lists.alioth.debian.org/pipermail/nut-upsuser/2017-June/010714.html
('krauler' USB subdriver)

As far as I can remember, this eventuality can only happen with certain USB subdrivers that only read a predetermined amount of data, read data from a given index or wait till no more data is available (if I recall correctly, serial communication and other USB subdrivers need the terminating CR in order to work properly), so, probably, the easiest fix should be to handle this situation in those USB subdrivers.

Also, this should not be considered an improvement, but a regression that needs to be solved, since blazer_* drivers, being less strict on the terminating CR of Q1 replies (3747fd5), should (sort of) support (some of) this kind of devices.

MAINTAINER NOTE: The null byte vs. \r at end of reads sounds reminiscent of work recently done by @blaa for the nutdrv_qx subdriver for armac in #2005; maybe this part should/can be generalized somehow to help with all devices that do not use CR/LF in protocol? It seems that the 1595a06 commit which allegedly solved this issue previously added the fix for certain *_command() methods, and so is lacking in some others that appeared afterwards.

@zykh zykh added the bug label Jun 9, 2017
@zykh zykh added this to the 2.7.5 milestone Jun 9, 2017
@zykh zykh self-assigned this Jun 9, 2017
@clepple
Copy link
Member

clepple commented Oct 8, 2017

@zykh is it okay if I move this to the 2.7.6 milestone?

@zykh
Copy link
Contributor Author

zykh commented Oct 8, 2017

ahem, yes, @clepple... it turns out I completely forgot this one...

@clepple clepple modified the milestones: 2.7.5, 2.7.6 Oct 8, 2017
@clepple
Copy link
Member

clepple commented Oct 8, 2017

no problem. (Hopefully the next release won't be a year from now :-) )

@zykh
Copy link
Contributor Author

zykh commented Sep 10, 2018

moving back to 2.7.5, since a) there is a workaround (zykh@1595a06) that apparently works as expected, and b) this is needed for #616

@zykh zykh modified the milestones: 2.7.6, 2.7.5 Sep 10, 2018
zykh added a commit to zykh/nut that referenced this issue Sep 18, 2018
Since some devices, when communicating via USB, don't close their replies to our commands/queries with the expected (and mandated by the specs) CR, rendering the driver almost useless as protocols get one less character than they expect, update the various USB subdrivers (leaving out the ones that rely on a CR to stop reading from the device) to add the missing terminating CR in such cases (as long as we get anything usable).
This is a bit of a cheat, but, at least for now, it will do -- not to mention the fact that it is way less invasive than touching all the places of the driver that expect a closing CR and all the qx2nut tables of the various protocols.

Close networkupstools#441
@trentbuck
Copy link

For the record,

I encountered this bug in nut 2.7.4 on Debian 11 with my UPS, model "UPSONIC IRT-3K 2U". My UPS is about 10 years old. The equivalent current model appears to be https://www.upsonic.com.au/upsonic-esart-rack-or-tower-series-ups/

https://bugs.debian.org/1019624

The fix in nut 2.8.0 (zykh@0e2372b) looks much nicer than mine. I am confident it will fix my problem, but as my UPS is back in production, I won't be able to verify this experimentally for a long time. :-(

Here's my upsc output (inc. make/model):

cyber@light:~$ upsc upset
Init SSL without certificate database
battery.charge: 100
battery.voltage: 2.29
battery.voltage.high: 78.00
battery.voltage.low: 62.40
battery.voltage.nominal: 72.0
device.mfr: UPSONIC
device.model: IRT-3K 2U
device.type: ups
driver.name: nutdrv_qx_cyber
driver.parameter.pollfreq: 30
driver.parameter.pollinterval: 2
driver.parameter.port: auto
driver.parameter.synchronous: no
driver.version: 2.7.4
driver.version.data: Upsonic 0.06
driver.version.internal: 0.28
input.current.nominal: 14.0
input.frequency: 49.9
input.frequency.nominal: 50
input.voltage: 229.0
input.voltage.fault: 120.0
input.voltage.nominal: 240
output.voltage: 240.0
ups.beeper.status: enabled
ups.delay.shutdown: 30
ups.delay.start: 180
ups.firmware: MP001155
ups.load: 49
ups.productid: 0000
ups.status: OL
ups.temperature: 20.0
ups.type: online
ups.vendorid: ffff

cyber@light:~$ dpkg-query -W 'nut*'
nut-cgi
nut-client      2.7.4-13
nut-ipmi
nut-monitor
nut-server      2.7.4-13
nut-snmp
nut-xml

@jimklimov jimklimov modified the milestones: 2.8.0, 2.8.2 Aug 31, 2023
@jimklimov jimklimov reopened this Aug 31, 2023
@jimklimov
Copy link
Member

As noted in the "Maintainer note" above, the solution for NUT v2.8.0 release was pin-point to certain protocol dialects. Apparently the problem is more wide-spread, so finding some way to apply the solution commonly (including to future driver contributions) would be welcome. At the very least, the several copies of same fix proposed in the PR which solved it previously seems like an invitation for refactoring into a helper method to invoke from everywhere, perhaps?..

@jimklimov jimklimov moved this to Done in NUT HCL/DDL Aug 31, 2023
@jimklimov jimklimov added Qx protocol driver Driver based on Megatec Q<number> such as new nutdrv_qx, or obsoleted blazer and some others impacts-release-2.8.0 Issues reported against NUT release 2.8.0 (maybe vanilla or with minor packaging tweaks) impacts-release-2.7.4 Issues reported against NUT release 2.7.4 (maybe vanilla or with minor packaging tweaks) labels Aug 31, 2023
jimklimov added a commit to jimklimov/nut-ddl that referenced this issue Aug 31, 2023
jimklimov added a commit to jimklimov/nut that referenced this issue Aug 31, 2023
@blaa
Copy link

blaa commented Aug 31, 2023

BTW, in Armac, the final solution was different. I was forging the \r for a second when finding \0 in the datastream prematurely for Vultech. But in the end, after coercing \0 to '0' the UPS eventually sends \r at the right position and everything seems to work "fine". Just single bit is sent as \0.

This \0 is weird obviously. When finishing on it though, there was not enough status bits to correctly parse response, although those lacking weren't particularly important and could be synthesized as zeroes.

@jimklimov
Copy link
Member

Note for future, regarding Armac subdriver approach, see:

I am not convinced that devices covered by armac_command() are the only ones in need of such approach. There were a number of reports (couldn't find them quickly at the moment, but I think they regarded "short read" errors?) which I think could have the same root cause with NUL bytes instead of ASCII zeroes in a bitmap.

If so - then possibly this solution should be generalized to all QX reads?..

@jimklimov jimklimov modified the milestones: 2.8.2, 2.8.3 Apr 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug impacts-release-2.7.4 Issues reported against NUT release 2.7.4 (maybe vanilla or with minor packaging tweaks) impacts-release-2.8.0 Issues reported against NUT release 2.8.0 (maybe vanilla or with minor packaging tweaks) Qx protocol driver Driver based on Megatec Q<number> such as new nutdrv_qx, or obsoleted blazer and some others
Projects
Status: Done
Development

No branches or pull requests

5 participants