Generic timed message queue for any message type with durationMs field.
More...
#include <message_queue.h>
|
| using | Clock = std::chrono::steady_clock |
| |
template<typename MsgType>
class bcnp::MessageQueue< MsgType >
Generic timed message queue for any message type with durationMs field.
This queue manages timed execution of messages, ensuring each message runs for its specified duration before the next one starts. It handles connection timeouts, lag compensation
- Template Parameters
-
| MsgType | Message struct with a uint16_t durationMs field |
drivetrain.execute(*cmd);
}
Generic timed message queue for any message type with durationMs field.
void Update(Clock::time_point now)
Update queue state - call once per control loop iteration.
std::optional< MsgType > ActiveMessage() const
Get the currently executing message.
bool Push(const MsgType &message)
Add a message to the back of the queue.
void NotifyReceived(Clock::time_point now)
Notify that messages were received from the network.
Definition at line 84 of file message_queue.h.
◆ Clock
template<typename MsgType >
◆ MessageQueue()
template<typename MsgType >
◆ ActiveMessage()
template<typename MsgType >
Get the currently executing message.
Returns the message whose duration is currently being executed. Blocks briefly if mutex is held by network thread (typically <5µs).
- Returns
- The active message, or nullopt if none active
Definition at line 200 of file message_queue.h.
◆ BeginTransaction()
template<typename MsgType >
◆ Clear()
template<typename MsgType >
Remove all messages from the queue.
Also clears the active message and resets virtual cursor. Thread-safe.
Definition at line 103 of file message_queue.h.
◆ GetConfig()
template<typename MsgType >
◆ GetMetrics()
template<typename MsgType >
Get current queue metrics.
- Returns
- Snapshot of queue statistics
Definition at line 223 of file message_queue.h.
◆ IsConnected()
template<typename MsgType >
Check if the connection is still active.
- Parameters
-
| now | Current timestamp for timeout calculation |
- Returns
- true if packets received within connectionTimeout, false otherwise
Definition at line 214 of file message_queue.h.
◆ NotifyReceived()
template<typename MsgType >
Notify that messages were received from the network.
Call this after pushing messages to update the connection timeout. The queue will clear itself if no notifications occur within the configured connectionTimeout period.
- Parameters
-
| now | Current timestamp (typically steady_clock::now()) |
Definition at line 144 of file message_queue.h.
◆ Push()
template<typename MsgType >
Add a message to the back of the queue.
- Parameters
-
| message | The message to enqueue |
- Returns
- true if successfully added, false if queue was full
- Note
- Increments queueOverflows metric on failure.
Definition at line 116 of file message_queue.h.
◆ ResetMetrics()
template<typename MsgType >
◆ SetConfig()
template<typename MsgType >
Update queue configuration.
- Note
- Clears the queue if capacity changes.
- Parameters
-
| config | New configuration to apply |
Definition at line 243 of file message_queue.h.
◆ Size()
template<typename MsgType >
Get the current number of queued messages.
- Returns
- Number of messages waiting (excludes active message)
Definition at line 130 of file message_queue.h.
◆ Update()
template<typename MsgType >
Update queue state - call once per control loop iteration.
Performs the following: Checks connection timeout - clears queue if timed out Checks if active message duration has elapsed Promotes next message from queue if ready Handles lag compensation by skipping stale messages
- Parameters
-
| now | Current timestamp for timing calculations |
Definition at line 160 of file message_queue.h.
The documentation for this class was generated from the following file: