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

Fix: Huawei AC charger sends signed values #1433

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/Huawei_can.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class HuaweiCanCommClass {
void loop();
bool gotNewRxDataFrame(bool clear);
uint8_t getErrorCode(bool clear);
uint32_t getParameterValue(uint8_t parameter);
int32_t getParameterValue(uint8_t parameter);
void setParameterValue(uint16_t in, uint8_t parameterType);

private:
Expand All @@ -109,7 +109,7 @@ class HuaweiCanCommClass {

std::mutex _mutex;

uint32_t _recValues[12];
int32_t _recValues[12];
uint16_t _txValues[5];
bool _hasNewTxValue[5];

Expand Down
9 changes: 4 additions & 5 deletions src/Huawei_can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void HuaweiCanCommClass::loop()
if((rxId & 0x80000000) == 0x80000000) { // Determine if ID is standard (11 bits) or extended (29 bits)
if ((rxId & 0x1FFFFFFF) == 0x1081407F && len == 8) {

uint32_t value = __bswap32(* reinterpret_cast<uint32_t*> (rxBuf + 4));
int32_t value = __bswap32(*reinterpret_cast<int32_t*>(rxBuf + 4));

// Input power 0x70, Input frequency 0x71, Input current 0x72
// Output power 0x73, Efficiency 0x74, Output Voltage 0x75 and Output Current 0x76
Expand Down Expand Up @@ -144,14 +144,13 @@ void HuaweiCanCommClass::loop()

}

uint32_t HuaweiCanCommClass::getParameterValue(uint8_t parameter)
int32_t HuaweiCanCommClass::getParameterValue(uint8_t parameter)
{
std::lock_guard<std::mutex> lock(_mutex);
uint32_t v = 0;
if (parameter < HUAWEI_OUTPUT_CURRENT1_IDX) {
v = _recValues[parameter];
return _recValues[parameter];
}
return v;
return 0;
}

bool HuaweiCanCommClass::gotNewRxDataFrame(bool clear)
Expand Down