Add Node time fallback for headerless messages (take 2) #30
Add Node time fallback for headerless messages (take 2) #30
Conversation
Greptile SummaryThis PR adds timestamp monitoring mode selection to handle headerless ROS 2 messages. It introduces three modes: Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
Start[Topic monitoring request] --> ParseMode[Parse timestamp_monitor_mode parameter]
ParseMode --> CheckHeader{Topic has header?}
CheckHeader -->|Yes - Header available| HeaderedPath[Headered topic path]
CheckHeader -->|No - Headerless| HeaderlessPath[Headerless topic path]
HeaderedPath --> ModeCheck1{Monitor mode?}
ModeCheck1 -->|header_with_nodetime_fallback| HF_H[Enable: msg checks only]
ModeCheck1 -->|header_only| HO_H[Enable: msg checks only]
ModeCheck1 -->|nodetime_only| NO_H[Enable: node checks only]
HeaderlessPath --> ModeCheck2{Monitor mode?}
ModeCheck2 -->|header_with_nodetime_fallback| HF_HL[Enable: node checks only - FALLBACK]
ModeCheck2 -->|header_only| HO_HL[Disable: both checks]
ModeCheck2 -->|nodetime_only| NO_HL[Enable: node checks only]
HF_H --> Monitor[Monitor topic with config]
HO_H --> Monitor
NO_H --> Monitor
HF_HL --> Monitor
HO_HL --> Monitor
NO_HL --> Monitor
Monitor --> Diagnostics[Publish diagnostics]
Last reviewed commit: 2c0d1d8 |
| std::pair<bool, bool> resolve_timestamp_checks( | ||
| greenwave_diagnostics::TimestampMonitorMode mode, bool topic_has_header) | ||
| { | ||
| switch (mode) { | ||
| case greenwave_diagnostics::TimestampMonitorMode::kHeaderWithNodetimeFallback: | ||
| return topic_has_header ? std::make_pair(false, true) : std::make_pair(true, false); | ||
| case greenwave_diagnostics::TimestampMonitorMode::kHeaderOnly: | ||
| return topic_has_header ? std::make_pair(false, true) : std::make_pair(false, false); | ||
| case greenwave_diagnostics::TimestampMonitorMode::kNodetimeOnly: | ||
| return std::make_pair(true, false); | ||
| } | ||
| return std::make_pair(false, false); | ||
| } |
There was a problem hiding this comment.
Missing default case in switch statement
The switch covers all enum values but lacks a default case. Add default: return std::make_pair(false, false); for defensive programming and to silence potential compiler warnings.
| std::pair<bool, bool> resolve_timestamp_checks( | |
| greenwave_diagnostics::TimestampMonitorMode mode, bool topic_has_header) | |
| { | |
| switch (mode) { | |
| case greenwave_diagnostics::TimestampMonitorMode::kHeaderWithNodetimeFallback: | |
| return topic_has_header ? std::make_pair(false, true) : std::make_pair(true, false); | |
| case greenwave_diagnostics::TimestampMonitorMode::kHeaderOnly: | |
| return topic_has_header ? std::make_pair(false, true) : std::make_pair(false, false); | |
| case greenwave_diagnostics::TimestampMonitorMode::kNodetimeOnly: | |
| return std::make_pair(true, false); | |
| } | |
| return std::make_pair(false, false); | |
| } | |
| switch (mode) { | |
| case greenwave_diagnostics::TimestampMonitorMode::kHeaderWithNodetimeFallback: | |
| return topic_has_header ? std::make_pair(false, true) : std::make_pair(true, false); | |
| case greenwave_diagnostics::TimestampMonitorMode::kHeaderOnly: | |
| return topic_has_header ? std::make_pair(false, true) : std::make_pair(false, false); | |
| case greenwave_diagnostics::TimestampMonitorMode::kNodetimeOnly: | |
| return std::make_pair(true, false); | |
| default: | |
| return std::make_pair(false, false); | |
| } |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
No description provided.