Skip to content

Commit

Permalink
Fix bug causing CSV header misalignment for undefined sensor ranges
Browse files Browse the repository at this point in the history
Resolved an issue where sensors defined in `globals/ranges` but not set in any action were still included in the CSV log file header. Since no values were provided for these ranges, data entries were ignored, leading to misaligned CSV rows.

Changed the behavior to ignore sensor ranges set in an action if they are not set in `globals/ranges`
  • Loading branch information
raffael0 committed Dec 31, 2024
1 parent 6c87bc6 commit 55af172
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/SequenceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,14 @@ bool SequenceManager::LoadSequence(nlohmann::json jsonSeq)
{
if (sensorsIt.value().type() == nlohmann::json::value_t::array && sensorsIt.value().size() == 2)
{
sensorsNominalRangeMap[sensorsIt.key()][timestampMicros][0] = sensorsIt.value()[0];
sensorsNominalRangeMap[sensorsIt.key()][timestampMicros][1] = sensorsIt.value()[1];
sensorsNominalRangeTimeMap[timestampMicros][sensorsIt.key()][0] = sensorsIt.value()[0];
sensorsNominalRangeTimeMap[timestampMicros][sensorsIt.key()][1] = sensorsIt.value()[1];
if(jsonSeq["globals"]["ranges"].contains(sensorsIt.key())) {
sensorsNominalRangeMap[sensorsIt.key()][timestampMicros][0] = sensorsIt.value()[0];
sensorsNominalRangeMap[sensorsIt.key()][timestampMicros][1] = sensorsIt.value()[1];
sensorsNominalRangeTimeMap[timestampMicros][sensorsIt.key()][0] = sensorsIt.value()[0];
sensorsNominalRangeTimeMap[timestampMicros][sensorsIt.key()][1] = sensorsIt.value()[1];
} else{
Debug::warning("Sensor Ranges set for %s but not defined in globals", sensorsIt.key().c_str());
}
}
else
{
Expand Down Expand Up @@ -251,19 +255,11 @@ void SequenceManager::StartSequence(nlohmann::json jsonSeq, nlohmann::json jsonA
// }
// msg += "Status;";
msg += "SequenceTime;";
for (auto rangeName : jsonSeq["globals"]["ranges"])
for (const auto& rangeName: sensorsNominalRangeMap)
{
Debug::info("Sensor nominal range found: %s", ((std::string) rangeName).c_str());
if (rangeName.type() == nlohmann::json::value_t::string)
{
msg += (std::string) rangeName + "Min;";
msg += (std::string) rangeName + "Max;";
}
else
{
Debug::error("range name in sequence globals not a string");
}

Debug::info("Sensor nominal range found: %s", ((std::string) rangeName.first).c_str());
msg += rangeName.first + "Min;";
msg += rangeName.first + "Max;";
}
for (auto &item : deviceMap)
{
Expand Down Expand Up @@ -419,7 +415,8 @@ void SequenceManager::sequenceLoop(int64_t interval_us)
syncMtx.lock();

//log nominal ranges
for (const auto &sensor : sensorsNominalRangeMap)

for (const auto &sensor : sensorsNominalRangeMap)
{
msg += std::to_string(sensor.second.begin()->second[0]) + ";";
msg += std::to_string(sensor.second.begin()->second[1]) + ";";
Expand Down

0 comments on commit 55af172

Please sign in to comment.