FERS 0.1.0
The Flexible Extensible Radar Simulator
Loading...
Searching...
No Matches
sim_events.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-only
2//
3// Copyright (c) 2025-present FERS Contributors (see AUTHORS.md).
4//
5// See the GNU GPLv2 LICENSE file in the FERS project root for more information.
6
7/**
8 * @file sim_events.h
9 * @brief Defines the core structures for the event-driven simulation engine.
10 */
11
12#pragma once
13
14#include <cstdint>
15
16#include "config.h"
17
18namespace radar
19{
20 class Radar;
21}
22
23namespace core
24{
25 /**
26 * @enum EventType
27 * @brief Enumerates the types of events that can occur in the simulation.
28 */
29 enum class EventType : std::uint8_t
30 {
31 TX_PULSED_START, ///< A pulsed transmitter begins emitting a pulse.
32 RX_PULSED_WINDOW_START, ///< A pulsed receiver opens its listening window.
33 RX_PULSED_WINDOW_END, ///< A pulsed receiver closes its listening window.
34 TX_STREAMING_START, ///< A streaming transmitter starts transmitting.
35 TX_STREAMING_END, ///< A streaming transmitter stops transmitting.
36 RX_STREAMING_START, ///< A streaming receiver starts listening.
37 RX_STREAMING_END, ///< A streaming receiver stops listening.
38 };
39
40 /**
41 * @struct Event
42 * @brief Represents a single event in the simulation's time-ordered queue.
43 */
44 struct Event
45 {
46 RealType timestamp; ///< The simulation time at which the event occurs.
47 EventType type; ///< The type of the event.
48 radar::Radar* source_object; ///< Pointer to the object that generated the event.
49 };
50
51 /**
52 * @struct EventComparator
53 * @brief A custom comparator for the event priority queue.
54 *
55 * This comparator creates a min-heap, ensuring that the event with the
56 * smallest timestamp is always at the top of the queue.
57 */
59 {
60 /**
61 * @brief Compares two events based on their timestamps.
62 * @param a The first event.
63 * @param b The second event.
64 * @return True if event 'a' should occur after event 'b'.
65 */
66 bool operator()(const Event& a, const Event& b) const noexcept { return a.timestamp > b.timestamp; }
67 };
68
69 /**
70 * @brief Converts an EventType enum to its string representation.
71 * @param type The event type.
72 * @return A string representing the event type.
73 */
74 inline std::string toString(const EventType type)
75 {
76 switch (type)
77 {
79 return "TxPulsedStart";
81 return "RxPulsedWindowStart";
83 return "RxPulsedWindowEnd";
85 return "TxStreamingStart";
87 return "TxStreamingEnd";
89 return "RxStreamingStart";
91 return "RxStreamingEnd";
92 default:
93 return "UnknownEvent";
94 }
95 }
96}
Represents a radar system on a platform.
Definition radar_obj.h:50
Global configuration file for the project.
double RealType
Type for real numbers.
Definition config.h:27
std::string toString(const EventType type)
Converts an EventType enum to its string representation.
Definition sim_events.h:74
EventType
Enumerates the types of events that can occur in the simulation.
Definition sim_events.h:30
@ RX_PULSED_WINDOW_START
A pulsed receiver opens its listening window.
@ RX_PULSED_WINDOW_END
A pulsed receiver closes its listening window.
@ TX_STREAMING_END
A streaming transmitter stops transmitting.
@ RX_STREAMING_END
A streaming receiver stops listening.
@ TX_STREAMING_START
A streaming transmitter starts transmitting.
@ TX_PULSED_START
A pulsed transmitter begins emitting a pulse.
@ RX_STREAMING_START
A streaming receiver starts listening.
RealType b
RealType a
A custom comparator for the event priority queue.
Definition sim_events.h:59
bool operator()(const Event &a, const Event &b) const noexcept
Compares two events based on their timestamps.
Definition sim_events.h:66
Represents a single event in the simulation's time-ordered queue.
Definition sim_events.h:45
RealType timestamp
The simulation time at which the event occurs.
Definition sim_events.h:46
EventType type
The type of the event.
Definition sim_events.h:47
radar::Radar * source_object
Pointer to the object that generated the event.
Definition sim_events.h:48