refactoring - simplified usage of hexToDec (#10)

* refactoring - simplified usage of hexToDec - replaced by hexToDecFromResponse

* refactoring - simplified usage of hexToDec - replaced by hexToDecFromResponse (applied to CarHyundaiIoniq.cpp)

* refactoring - simplified usage of hexToDec - replaced by hexToDecFromResponse (applied to rest)

* refactoring - simplified usage of hexToDec - replaced by hexToDecFromResponse (fix)

* refactoring - simplified usage of float(strol(liveData->responseRowMerged.substring(...))) - as liveData->decFromResponse()
This commit is contained in:
Michal
2020-12-07 19:43:38 +01:00
committed by GitHub
parent fe6e4402c4
commit 71dc8e8555
8 changed files with 227 additions and 204 deletions

View File

@@ -138,6 +138,23 @@ float LiveData::hexToDec(String hexString, byte bytes, bool signedNum) {
return (decValue > 32767 ? (float)decValue - 65536.0 : decValue);
}
/**
Parsed from merged response row:
Hex to dec (1-2 byte values, signed/unsigned)
For 4 byte change int to long and add part for signed numbers
*/
float LiveData::hexToDecFromResponse(byte from, byte to, byte bytes, bool signedNum) {
return hexToDec(responseRowMerged.substring(from, to).c_str(), bytes, signedNum);
}
/**
Combination of responseRowMerged.substring -> strtol -> float
*/
float LiveData::decFromResponse(byte from, byte to, char **str_end, int base) {
return float(strtol(responseRowMerged.substring(from, to).c_str(), str_end, base));
}
/**
Convert km to km or miles
*/