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

Update vc96.c #234

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

schuma-gta02
Copy link

Fixes wrong detection and calculation.

Fixes wrong detection and calculation.
Copy link
Contributor

@harper23 harper23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In (new) line 73-77 curly brackets are added while this style is not found elsewhere for one line statements in if-clauses. The semicolon is unnecessary.

!strncmp(buf, " ", 3)

These calls in line 84 and 96 compare a string of 2 spaces and a terminating zero with the buffer. This can be done simpler with a strcmp(buf, " ")

Line 93-94 sets is_ohm if the buffer contains "OHM". It leaves is_ohm untouched if the buffer contains 2 spaces.
But line 95-96 set is_diode if the buffer contains "DIO". It also set is_diode if the buffer contains 2 spaces AND is_volt AND is_milli are set. This looks weird. At least both members is_ohm and is_volt will be evaluated later in handle_flags() where analog->meaning->mq and analog->meaning->unit will be overwritten.

Line 97-98 sets hfe only if the buffer contains "hfe" AND all members (is_ampere, is_volt, isresistance, is_diode) are not set. Is this really special for"hfe"?

Line 112-128 checks for units. Old order A, mA, µA,V,mV. New order mA,µA,A,mV,V. The order for check for K and M has also changed. Is this really necessary and is it better?

Line 148-150 contains unnecessary curly brackets and semicolon.

Line 159 looks like the real fix for calculation.

Line 271 changed the check for the return value of int parse_value(). That type of the function's return value is not of type enum sr_error_code. The main problem is, that the function always returns 0 (implicitly converted from SR_OK). The line 272 is never reached.

@harper23
Copy link
Contributor

The "cleanup curly braces" leaves an empty // comment in line 73.

The static function parse_value() that contains the actual fix is not called anywhere in the source code. It's dead code. The detection of ".0L" and similar strings is not present anymore. Is this intentional?

src/dmm/vc96.c Outdated
@@ -264,6 +263,11 @@ SR_PRIV int sr_vc96_parse(const uint8_t *buf, float *floatval,

memset(info_local, 0x00, sizeof(struct vc96_info));

if ((ret = parse_value(buf, floatval, &exponent)) != SR_OK) {
sr_dbg("Error parsing value: %d.", ret);
Copy link
Contributor

@harper23 harper23 Dec 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This program path can't be reached since the function parse_value always returns SR_OK,

@schuma-gta02
Copy link
Author

I removed those nonreachable lines 266 and 267, they were for debugging only.
What else has to be done to get it accepted?

@schuma-gta02
Copy link
Author

schuma-gta02 commented Feb 8, 2024 via email

@harper23
Copy link
Contributor

harper23 commented Feb 8, 2024 via email

@@ -63,25 +62,23 @@ static int parse_value(const uint8_t *buf, struct vc96_info *info,
is_ol += (!g_ascii_strcasecmp((const char *)&valstr, "-OL.")) ? 1 : 0;
is_ol += (!g_ascii_strcasecmp((const char *)&valstr, "-OL")) ? 1 : 0;
if (is_ol != 0) {
sr_spew("Over limit.");
Copy link
Member

@abraxa abraxa Aug 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason this was removed? Same question for all the other instances of sr_spew() that were removed.

@schuma-gta02
Copy link
Author

schuma-gta02 commented Aug 26, 2024 via email

@abraxa
Copy link
Member

abraxa commented Aug 26, 2024

okay but it's SR_SPEW log level, which is perfectly adequate for this kind of verbosity and some messages should remain for debugging when the driver isn't working as intended.

@schuma-gta02
Copy link
Author

schuma-gta02 commented Aug 26, 2024 via email

@abraxa
Copy link
Member

abraxa commented Aug 26, 2024

I would prefer if you'd add them back in yeah, because it saves work for anyone trying to debug the driver in the future and no one runs libsigrok on SR_SPEW unless they really want to.

reinvented sr_spew messages
@schuma-gta02
Copy link
Author

schuma-gta02 commented Aug 27, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants