Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add measure of traffic light modification level #199

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/dsm/headers/Node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@
std::optional<std::pair<Delay, Delay>> m_delay;
Delay m_counter;
Delay m_phase;
/// @brief Variabile che mi dice come sono in rapporto tra di loro il tempo di verde e il tempo di rosso
/// @details Valori possibili: 0, 1, 2 (fino a che non verrà modificata)
/// - se 0: |redTime - greenTime| < 10 && redTime > 5 && greenTime > 5
/// - se 1: |redtime - greenTime| \geq 10 && |redTime - greenTime| < 40 && redTime > 5 && greenTime > 5
/// - se 2: |redTime - greenTime| \geq 40 || redTime < 5 || greenTime < 5
int m_modTime{7};

public:
TrafficLight() = delete;
Expand Down Expand Up @@ -272,6 +278,9 @@
/// @return std::optional<Delay> The node's delay
std::optional<std::pair<Delay, Delay>> delay() const { return m_delay; }
Delay counter() const { return m_counter; }
/// @brief Get the node's modTime
/// @return int. The node's modTime
int modTime() const { return m_modTime; }
/// @brief Returns true if the traffic light is green
/// @return bool True if the traffic light is green
bool isGreen() const;
Expand Down Expand Up @@ -304,6 +313,11 @@
}
}
m_delay = std::make_pair(delay, delay);
if (delay < 5) {
m_modTime = 2;
} else {
m_modTime = 0;

Check warning on line 319 in src/dsm/headers/Node.hpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/headers/Node.hpp#L319

Added line #L319 was not covered by tests
}
}
template <typename Id, typename Size, typename Delay>
requires(std::unsigned_integral<Id> && std::unsigned_integral<Size> &&
Expand All @@ -319,6 +333,18 @@
}
}
m_delay = std::move(delay);
if (delay.first < 5 || delay.second < 5) {

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
m_modTime = 2;
} else if (std::abs(delay.first - delay.second) < 10) {
m_modTime = 0;
} else if ((std::abs(delay.first - delay.second) > 10 ||

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
std::abs(delay.first - delay.second) == 10) &&
(std::abs(delay.first - delay.second) < 40 ||

Check notice

Code scanning / Cppcheck (reported by Codacy)

MISRA 12.1 rule Note

MISRA 12.1 rule
std::abs(delay.first - delay.second) == 40)) {
m_modTime = 1;

Check warning on line 344 in src/dsm/headers/Node.hpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/headers/Node.hpp#L341-L344

Added lines #L341 - L344 were not covered by tests
} else if (std::abs(delay.first - delay.second) > 40) {
m_modTime = 2;

Check warning on line 346 in src/dsm/headers/Node.hpp

View check run for this annotation

Codecov / codecov/patch

src/dsm/headers/Node.hpp#L346

Added line #L346 was not covered by tests
}
}
template <typename Id, typename Size, typename Delay>
requires(std::unsigned_integral<Id> && std::unsigned_integral<Size> &&
Expand Down
Loading