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

BYD CAN: Fix average temperature calculation #158

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

dalathegreat
Copy link
Owner

What

User brennar10 noticed a bug in the temperature calculation when using BYD CAN. When values go negative, there is a risk that the signed bit is lost during the calculation, causing temperature to appear incorrect

Why

bild

How

The bug is fixed by converting the uint16 values to local int16 values before performing any calculations.

@dalathegreat
Copy link
Owner Author

Confirmed working by brennar10 🥳
bild

@dalathegreat dalathegreat merged commit 7324ac8 into main Feb 7, 2024
34 checks passed
@dalathegreat dalathegreat deleted the bugfix/BYD-CAN-temperatures-negative branch February 7, 2024 09:48
Copy link
Collaborator

@matvey83 matvey83 left a comment

Choose a reason for hiding this comment

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

(Forgot to "submit" review earlier, but better late than never.)

Comment on lines +138 to +139
temp_min = temperature_min; //Convert from unsigned to signed
temp_max = temperature_max;
Copy link
Collaborator

Choose a reason for hiding this comment

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

oh wow, this can be very confusing. I don't think we should be storing signed values in unsigned ints ever (except perhaps very briefly, if really needed). Can we update the code throughout to make temperature_min and temperature_max signed? And do the cast right as they are assigned, in file for each battery?

Comment on lines +113 to +114
static int16_t temp_min = 0;
static int16_t temp_max = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Instead of adding these 2 variables, I'd prefer we make temperature_min and temperature_max signed. (I know it will be more work but having 2 sets of variables for same data is a bit confusing and redundant).

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.

2 participants