18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 06:35:21 +01:00

Merge pull request #533 from MaSzyna-EU07/fix/wiperlist-bytesum-parse

Read the WiperList wiper mask as a number, not a character
This commit is contained in:
maj00r
2026-11-30 00:41:27 +01:00
committed by GitHub
2 changed files with 54 additions and 1 deletions
+4 -1
View File
@@ -447,7 +447,10 @@ bool physics::Vehicle::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 an int and clamped, as the parser would take only its first character for a uint8_t
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;
}
+50
View File
@@ -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);
}