Skip to content

Fixed HighLimit and LowLimit for SIGNED values in EDS #345

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

Merged
merged 3 commits into from
Feb 24, 2023
Merged

Fixed HighLimit and LowLimit for SIGNED values in EDS #345

merged 3 commits into from
Feb 24, 2023

Conversation

friederschueler
Copy link
Collaborator

These values have been interpreted as unsigned values and therefore valid values raised warnings.

Copy link
Collaborator

@af-silva af-silva left a comment

Choose a reason for hiding this comment

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

Hi, thanks for the PR.
I know this library now supports python 3.x+, but I would drop the type hints for sake of uniformization with the rest of the files, since the new functions are the only ones using it.

@friederschueler
Copy link
Collaborator Author

Sure, I thought I wrote this fix without type hints, but in the function header I forgot them. (habbits don't die easily)

@af-silva af-silva merged commit fd226e3 into canopen-python:master Feb 24, 2023
samsamfire pushed a commit to samsamfire/canopen that referenced this pull request Mar 15, 2023
…#345)

* Fixed incorrect min (LowLImit) and max (HighLimit) values when using signed integer types.
* Fixed min/max for non-signed datatypes and added tests
* Removed type hints
self.assertEqual(uint8.min, 2)
self.assertEqual(uint8.max, 10)
int32 = self.od[0x3030]
self.assertEqual(int32.min, -2147483648)
Copy link

@lamuguo lamuguo Aug 31, 2023

Choose a reason for hiding this comment

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

int32.min should be -1 in my understanding.

Copy link
Collaborator Author

@friederschueler friederschueler Sep 1, 2023

Choose a reason for hiding this comment

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

You are correct. I don't know why I didn't see it. This should be the correct function:

def _signed_int_from_hex(hex_str, bit_length):
    number = int(hex_str, 0)
    max_value = (1 << (bit_length - 1)) - 1
    
    if number > max_value:
        return number - (1 << bit_length)
    else:
        return number

I will commit a full fix with correct tests in the evening.

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