Skip to content

Commit

Permalink
Fix: Huawei AC charger sends signed values
Browse files Browse the repository at this point in the history
as shown in #1432, the Huawei AC charger sends signed values to
communicate the temperature. given that the value range for all
other data points is expected to be less than ~2 million, we now
interpret all data as signed values.
  • Loading branch information
schlimmchen committed Dec 2, 2024
1 parent 9b4f3d2 commit 9534978
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
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

0 comments on commit 9534978

Please sign in to comment.