mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 22:25:23 +01:00
fix: read the WiperList wiper mask as a number, not a character
byteSum is a uint8_t, and cParser reads an unsigned char as one character of the token: "5" became 53, and "12" became '1' (49), wiper 0 alone instead of wipers 2 and 3. The single digits in the current data kept the right low bits by chance. Read it as an int, clamped to the byte's range.
This commit is contained in:
+4
-1
@@ -11925,7 +11925,10 @@ bool TMoverParameters::readWiperList(std::string const &line)
|
||||
WriteLog("Read WiperList: number of entries exceeded capacity of the data table");
|
||||
return false;
|
||||
}
|
||||
parser >> WiperList[idx].byteSum >> WiperList[idx].WiperSpeed >> WiperList[idx].interval >> WiperList[idx].outBackDelay;
|
||||
// the mask of the wipers is a number: read into the uint8_t directly, the parser would take only its first character
|
||||
int bytesum{0};
|
||||
parser >> bytesum >> WiperList[idx].WiperSpeed >> WiperList[idx].interval >> WiperList[idx].outBackDelay;
|
||||
WiperList[idx].byteSum = static_cast<uint8_t>(std::clamp(bytesum, 0, 255));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
#include "vehicle.h"
|
||||
|
||||
using test::definition;
|
||||
using test::vehicle;
|
||||
|
||||
// the first number of a WiperList row is the mask of the wipers working in that position of the wiper switch,
|
||||
// bit n for the wiper n. it's a number: read as a character "5" was 53 and "12" was '1', the wiper 0 alone
|
||||
|
||||
namespace {
|
||||
|
||||
definition wiper_list(nlohmann::ordered_json const &Rows) {
|
||||
return definition::load("cab_vehicle")
|
||||
.set("WiperList", "rows", Rows)
|
||||
.set("WiperList", "Size", static_cast<int>(Rows.size()))
|
||||
.set("WiperList", "Angle", 58);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("wipers: the mask of the wipers of a WiperList row is read as a number") {
|
||||
vehicle cab{wiper_list(nlohmann::ordered_json::array({
|
||||
{"0", "0.7", "0.0", "0.5"},
|
||||
{"5", "0.7", "7.0", "0.5"},
|
||||
{"12", "0.6", "0.7", "0.0"},
|
||||
{"15", "0.5", "0.5", "0.25"},
|
||||
}))};
|
||||
REQUIRE(cab->WiperListSize == 4);
|
||||
|
||||
CHECK(cab->WiperList[0].byteSum == 0);
|
||||
CHECK(cab->WiperList[1].byteSum == 5);
|
||||
CHECK(cab->WiperList[2].byteSum == 12);
|
||||
CHECK(cab->WiperList[3].byteSum == 15);
|
||||
|
||||
// and the numbers after it still land in their own fields
|
||||
CHECK(cab->WiperList[1].interval == doctest::Approx(7.0));
|
||||
CHECK(cab->WiperList[2].WiperSpeed == doctest::Approx(0.6));
|
||||
CHECK(cab->WiperList[3].outBackDelay == doctest::Approx(0.25));
|
||||
}
|
||||
|
||||
TEST_CASE("wipers: a mask out of the range of a byte is clamped to it") {
|
||||
vehicle cab{wiper_list(nlohmann::ordered_json::array({
|
||||
{"-1", "0.7", "0.0", "0.5"},
|
||||
{"300", "0.7", "0.0", "0.5"},
|
||||
}))};
|
||||
|
||||
CHECK(cab->WiperList[0].byteSum == 0);
|
||||
CHECK(cab->WiperList[1].byteSum == 255);
|
||||
}
|
||||
Reference in New Issue
Block a user