VR-Engage  2.3
Loading...
Searching...
No Matches
radioLogic.h
Go to the documentation of this file.
1/******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*****************************************************************************/
5
6//! \file radioLogic.h
7//! \brief Component for managing radio communications in the simulation
8//! \ingroup vreCommonComponents
9
10#pragma once
11
15
17
18#include <boost/function.hpp>
19
20namespace makVre
21{
22class DtRadioEventProcessor;
24
26{
27//! \ingroup RoleConfigParams
28//! \defgroup RadioLogicRoleParams Radio Logic Role Parameters
29//! \roleInherits{PlayerComponentRoleParams}
30//! Configuration Options for radio logic role.
31//! @{
32
33//! \vreRoleParam{defaultRadio,string,"",radioLogic,Name of the default radio to activate on startup.}
34constexpr const char* defaultRadio = "defaultRadio";
35
36//! \vreRoleParam{radios,table,"",radioLogic,Table of radio configurations with channel and crypto settings.}
37constexpr const char* radios = "radios";
38
39//! @}
40} // namespace RadioLogicConfig
41
42//! \brief Type identifier for DtRadioLogic component
43constexpr const char* DtRadioLogicType = "DtRadioLogic";
44
45//! \brief Component for managing radio communications in the simulation
46//!
47//! DtRadioLogic provides management of radio communication systems in the simulation,
48//! handling radio channel selection, push-to-talk functionality, crypto settings,
49//! and various radio modulation parameters. It supports both standard radios and
50//! vehicle intercom systems, automatically managing radio state when embarking or
51//! disembarking from vehicles. The component provides menu-driven controls for
52//! switching between radios, channels, and communication settings.
54{
55public:
56 //! \brief Enumeration for push-to-talk state
57 //!
58 //! Defines the possible states for the push-to-talk functionality
60 {
61 PTT_ON, //!< Push-to-talk button is pressed, transmitting
62 PTT_OFF //!< Push-to-talk button is released, not transmitting
63 };
64
65 //! \brief Constructor for DtRadioLogic
66 //!
67 //! Initializes the component with the name "DtRadioLogic" and sets up
68 //! handlers for various radio menu actions
70
71 //! \brief Virtual destructor for DtRadioLogic
72 virtual ~DtRadioLogic() override;
73
74 //! \brief Initializes the radio logic component
75 //! \param player Pointer to the player station this component belongs to
76 //! \param config Configuration table containing radio settings
77 //! \return True if initialization succeeded, false otherwise
78 //!
79 //! Sets up the radio manager, registers message handlers, and configures
80 //! input handling for push-to-talk functionality. Also initializes the current
81 //! radio based on saved state or configuration.
82 virtual bool initialize(DtPlayerStation* player, DtInitTable& config) override;
83 //! \brief Performs post-initialization after all components are initialized
84 //! \return True if post-initialization succeeded, false otherwise
85 //!
86 //! Currently just returns true as no special post-initialization is needed
87 virtual bool postInitialize() override;
88
89 //! \brief Called every frame to update the component state
90 //! \param dt Delta time since the last frame in seconds
91 //!
92 //! Current implementation is empty as updates occur through message handlers
93 //! and attribute change callbacks
94 virtual void tick(double dt) override {};
95 //! \brief Shuts down the radio logic component
96 //!
97 //! Saves the current radio state to attributes for persistence, removes
98 //! message handlers and callbacks, and shuts down the radio manager
99 virtual void shutdown() override;
100
101 //! \brief Returns the type identifier for this component
102 //! \return The type string for DtRadioLogic
103 virtual const char* type() const override;
104
105 //! \brief Sets the push-to-talk state for the current radio
106 //! \param state The desired PTT state (on or off)
107 //!
108 //! Activates or deactivates transmission on the current radio based on
109 //! the specified PTT state. Does nothing if no radio is selected.
110 virtual void ptt(PttState state);
111
112
113protected:
114 //! \brief Initializes state attributes for radio communication
115 //!
116 //! Current implementation is empty as attributes are initialized elsewhere
117 virtual void initializeStateAttributes() override;
118
119 //! \brief Handles menu messages related to radio operations
120 //! \param msg The menu message to process
121 //! \return Message handling result indicating the message was handled
122 //!
123 //! Routes menu action messages to the appropriate handler based on the action type
125
126 //! \brief Handles changes to the player's embarked state
127 //! \param val Entity identifier of the vehicle being embarked on, or null if disembarking
128 //!
129 //! Manages vehicle intercom system when embarking on or disembarking from vehicles
130 void handleEmbarkedOnChanged(const DtEntityIdentifier& val);
131
132 //! \brief Updates the radio manager based on current radio state
133 //!
134 //! Ensures only the current radio is powered on, manages audio capture settings,
135 //! and configures push-to-talk functionality based on radio state
137
138 //! \brief Updates state attributes with current radio settings
139 //!
140 //! Stores all current radio parameters (current radio, channel, crypto settings, etc.)
141 //! to the player attribute store for UI display and persistence
143
144 //! \brief Handles push-to-talk input events
145 //! \param val Input value (1.0 for pressed, 0.0 for released)
146 //!
147 //! Translates input values to PTT states and calls the ptt() function
148 void handlePushToTalk(float val);
149
150 //! \brief Sets the current radio to a specific index
151 //! \param msg Menu message containing the radio index as a parameter
153
154 //! \brief Cycles to the next available radio or turns off if at the last radio
155 //! \param msg Menu message triggering the action
157
158 //! \brief Cycles to the next channel on the current radio
159 //! \param msg Menu message triggering the action
161
162 //! \brief Cycles through available audio channel options (LEFT/CENTER/RIGHT)
163 //! \param msg Menu message triggering the action
165
166 //! \brief Cycles through available cryptographic systems
167 //! \param msg Menu message triggering the action
169
170 //! \brief Sets the crypto key based on input from a menu
171 //! \param msg Menu message containing the crypto key as a parameter
173
174 //! \brief Cycles through available cryptographic modes
175 //! \param msg Menu message triggering the action
177
178 //! \brief Cycles through available modulation system types
179 //! \param msg Menu message triggering the action
181
182 //! \brief Cycles through available major modulation types
183 //! \param msg Menu message triggering the action
185
186 //! \brief Cycles through available modulation detail types
187 //! \param msg Menu message triggering the action
189
190 //! \brief Toggles frequency hopping on/off
191 //! \param msg Menu message triggering the action
193
194 //! \brief Toggles time hopping on/off
195 //! \param msg Menu message triggering the action
197
198 //! \brief Toggles pseudo-noise on/off
199 //! \param msg Menu message triggering the action
201
202 //! \brief Gets the name of the current radio
203 //! \return Name of the current radio or "OFF" if no radio is selected
204 std::string currentRadioName() const;
205
206 //! \brief Gets the channel name of the current radio
207 //! \return Channel name with frequency information or placeholder if not applicable
208 std::string currentChannelName() const;
209
210 //! \brief Gets the audio channel of the current radio
211 //! \return Audio channel as a string or placeholder if no radio selected
212 std::string currentAudioChannel() const;
213
214 //! \brief Gets the cryptographic system of the current radio
215 //! \return Crypto system name or "OTHER" if no radio/channel selected
216 std::string currentCryptoSystem() const;
217
218 //! \brief Gets the cryptographic key of the current radio
219 //! \return Crypto key as a string or "0" if no radio/channel selected
220 std::string currentCryptoKey() const;
221
222 //! \brief Gets the cryptographic mode of the current radio
223 //! \return Crypto mode as a string or empty if no radio/channel selected
224 std::string currentCryptoMode() const;
225
226 //! \brief Gets the modulation system of the current radio
227 //! \return Modulation system as a string or empty if no radio/channel selected
228 std::string currentModulationSystem() const;
229
230 //! \brief Gets the major modulation type of the current radio
231 //! \return Major modulation type as a string or empty if no radio/channel selected
232 std::string currentModulationMajor() const;
233
234 //! \brief Gets the modulation detail type of the current radio
235 //! \return Modulation detail as a string or empty if no radio/channel selected
236 std::string currentModulationDetail() const;
237
238 //! \brief Gets the frequency hopping state of the current radio
239 //! \return "ON" or "OFF" as a string or empty if no radio/channel selected
240 std::string currentFrequencyHopping() const;
241
242 //! \brief Gets the time hopping state of the current radio
243 //! \return "ON" or "OFF" as a string or empty if no radio/channel selected
244 std::string currentTimeHopping() const;
245
246 //! \brief Gets the pseudo-noise state of the current radio
247 //! \return "ON" or "OFF" as a string or empty if no radio/channel selected
248 std::string currentPseudoNoise() const;
249
250 //! \brief Sets the cryptographic key for the current radio
251 //! \param cryptoKey The crypto key value to set
252 //!
253 //! Updates the crypto key of the current radio if one is selected
254 void setCryptoKey(unsigned short cryptoKey) const;
255
256 //! \brief Index of the currently selected radio (-1 if no radio selected)
258
259 //! \brief Input logic for handling push-to-talk and other input actions
261
262 //! \brief Map of menu action names to handler functions
263 //!
264 //! Used to dispatch menu action messages to the appropriate handler methods
265 std::map<std::string, boost::function<void(DtRadioLogic*, MenuActionMessage*)>> myMenuActionMessageFnMap;
266
267 //! \brief Connection made to de post tick to tick the radio manager
268 boost::signals2::connection myRadioManagerTickConnection;
269
270 // Commented out attributes - likely moved to using the attribute store directly
271 // instead of keeping local attribute pointers
272 // DtAttribute<std::string>* myCurrentRadioAttr;
273 // DtAttribute<std::string>* myCurrentChannelAttr;
274 // DtAttribute<DtEntityIdentifier>* myEmbarkedOnAttr;
275
276 DtEntityIdentifier myPreviouslyEmbarkedOn;
277
278 //! \brief Handle for the current radio name attribute.
279 //! \vreAttrKey{currentRadio}
281 //! \brief Handle for the current radio identifier attribute.
282 //! \vreAttrKey{currentRadioId}
284 //! \brief Handle for the current channel name attribute.
285 //! \vreAttrKey{currentChannel}
287 //! \brief Handle for the current audio channel attribute.
288 //! \vreAttrKey{currentAudioChannel}
290 //! \brief Handle for the current cryptographic system attribute.
291 //! \vreAttrKey{currentCryptoSystem}
293 //! \brief Handle for the current cryptographic key attribute.
294 //! \vreAttrKey{currentCryptoKey}
296 //! \brief Handle for the current cryptographic mode attribute.
297 //! \vreAttrKey{currentCryptoMode}
299 //! \brief Handle for the current modulation system attribute.
300 //! \vreAttrKey{currentModulationSystem}
302 //! \brief Handle for the current modulation major value attribute.
303 //! \vreAttrKey{currentModulationMajor}
305 //! \brief Handle for the current modulation detail value attribute.
306 //! \vreAttrKey{currentModulationDetail}
308 //! \brief Handle for the current frequency hopping state attribute.
309 //! \vreAttrKey{currentFrequencyHopping}
311 //! \brief Handle for the current time hopping state attribute.
312 //! \vreAttrKey{currentTimeHopping}
314 //! \brief Handle for the current pseudo-noise state attribute.
315 //! \vreAttrKey{currentPseudoNoise}
317 //! \brief Handle for the current radio transmit state attribute.
318 //! \vreAttrKey{currentRadioTransmitting}
320};
321
322} // namespace makVre
Type-specific handle class for attributes.
Definition attributeHandle.h:229
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Class for managing input configuration and handling in VR-Engage.
Definition inputLogic.h:39
Base class for all role components in VR-Engage.
Definition playerComponent.h:102
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
void handleCycleAudioChannel(MenuActionMessage *msg)
Cycles through available audio channel options (LEFT/CENTER/RIGHT)
DtAttributeHandleType< std::string > myCurrentModulationMajorAttr
Handle for the current modulation major value attribute.
Definition radioLogic.h:304
virtual ~DtRadioLogic() override
Virtual destructor for DtRadioLogic.
DtAttributeHandleType< std::string > myCurrentFrequencyHoppingAttr
Handle for the current frequency hopping state attribute.
Definition radioLogic.h:310
std::string currentCryptoKey() const
Gets the cryptographic key of the current radio.
void updateAttributes()
Updates state attributes with current radio settings.
void handleCryptoKeyInput(const MenuActionMessage *msg)
Sets the crypto key based on input from a menu.
void handleCycleModulationSystem(MenuActionMessage *msg)
Cycles through available modulation system types.
DtInputLogic myInputLogic
Input logic for handling push-to-talk and other input actions.
Definition radioLogic.h:260
std::string currentModulationMajor() const
Gets the major modulation type of the current radio.
virtual const char * type() const override
Returns the type identifier for this component.
std::string currentCryptoSystem() const
Gets the cryptographic system of the current radio.
void setCryptoKey(unsigned short cryptoKey) const
Sets the cryptographic key for the current radio.
void handleEmbarkedOnChanged(const DtEntityIdentifier &val)
Handles changes to the player's embarked state.
DtAttributeHandleType< bool > myCurrentRadioTransmittingAttr
Handle for the current radio transmit state attribute.
Definition radioLogic.h:319
void handleCycleFrequencyHopping(MenuActionMessage *msg)
Toggles frequency hopping on/off.
void handleCycleModulationDetail(MenuActionMessage *msg)
Cycles through available modulation detail types.
void handleCycleRadio(MenuActionMessage *msg)
Cycles to the next available radio or turns off if at the last radio.
void updateRadioManager()
Updates the radio manager based on current radio state.
void handleCycleTimeHopping(MenuActionMessage *msg)
Toggles time hopping on/off.
virtual bool postInitialize() override
Performs post-initialization after all components are initialized.
void handleCycleCryptoMode(MenuActionMessage *msg)
Cycles through available cryptographic modes.
void handleCycleCryptoSystem(MenuActionMessage *msg)
Cycles through available cryptographic systems.
std::string currentFrequencyHopping() const
Gets the frequency hopping state of the current radio.
DtVreMessageResult handleRadioMenuMessage(DtVreMessage *msg)
Handles menu messages related to radio operations.
DtAttributeHandleType< std::string > myCurrentCryptoSystemAttr
Handle for the current cryptographic system attribute.
Definition radioLogic.h:292
DtAttributeHandleType< std::string > myCurrentChannelNameAttr
Handle for the current channel name attribute.
Definition radioLogic.h:286
std::string currentPseudoNoise() const
Gets the pseudo-noise state of the current radio.
std::map< std::string, boost::function< void(DtRadioLogic *, MenuActionMessage *)> > myMenuActionMessageFnMap
Map of menu action names to handler functions.
Definition radioLogic.h:265
DtAttributeHandleType< std::string > myCurrentCryptoModeAttr
Handle for the current cryptographic mode attribute.
Definition radioLogic.h:298
std::string currentModulationDetail() const
Gets the modulation detail type of the current radio.
DtAttributeHandleType< std::string > myCurrentCryptoKeyAttr
Handle for the current cryptographic key attribute.
Definition radioLogic.h:295
virtual void shutdown() override
Shuts down the radio logic component.
int myCurrentRadio
Index of the currently selected radio (-1 if no radio selected)
Definition radioLogic.h:257
std::string currentAudioChannel() const
Gets the audio channel of the current radio.
void handleCyclePseudoNoise(MenuActionMessage *msg)
Toggles pseudo-noise on/off.
DtAttributeHandleType< std::string > myCurrentTimeHoppingAttr
Handle for the current time hopping state attribute.
Definition radioLogic.h:313
std::string currentChannelName() const
Gets the channel name of the current radio.
void handleSetRadio(const MenuActionMessage *msg)
Sets the current radio to a specific index.
std::string currentCryptoMode() const
Gets the cryptographic mode of the current radio.
boost::signals2::connection myRadioManagerTickConnection
Connection made to de post tick to tick the radio manager.
Definition radioLogic.h:268
DtRadioLogic()
Constructor for DtRadioLogic.
DtEntityIdentifier myPreviouslyEmbarkedOn
Definition radioLogic.h:276
void handlePushToTalk(float val)
Handles push-to-talk input events.
virtual void tick(double dt) override
Called every frame to update the component state.
Definition radioLogic.h:94
std::string currentRadioName() const
Gets the name of the current radio.
DtAttributeHandleType< std::string > myCurrentModulationDetailAttr
Handle for the current modulation detail value attribute.
Definition radioLogic.h:307
DtAttributeHandleType< std::string > myCurrentModulationSystemAttr
Handle for the current modulation system attribute.
Definition radioLogic.h:301
PttState
Enumeration for push-to-talk state.
Definition radioLogic.h:60
@ PTT_ON
Push-to-talk button is pressed, transmitting.
Definition radioLogic.h:61
@ PTT_OFF
Push-to-talk button is released, not transmitting.
Definition radioLogic.h:62
DtAttributeHandleType< std::string > myCurrentAudioChannelAttr
Handle for the current audio channel attribute.
Definition radioLogic.h:289
DtAttributeHandleType< std::string > myCurrentRadioNameAttr
Handle for the current radio name attribute.
Definition radioLogic.h:280
void handleCycleModulationMajor(MenuActionMessage *msg)
Cycles through available major modulation types.
virtual void ptt(PttState state)
Sets the push-to-talk state for the current radio.
DtAttributeHandleType< int > myCurrentRadioIdAttr
Handle for the current radio identifier attribute.
Definition radioLogic.h:283
virtual void initializeStateAttributes() override
Initializes state attributes for radio communication.
std::string currentModulationSystem() const
Gets the modulation system of the current radio.
DtAttributeHandleType< std::string > myCurrentPseudoNoiseAttr
Handle for the current pseudo-noise state attribute.
Definition radioLogic.h:316
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the radio logic component.
void handleCycleChannel(MenuActionMessage *msg)
Cycles to the next channel on the current radio.
std::string currentTimeHopping() const
Gets the time hopping state of the current radio.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Sent when the user activates an action menu element.
Definition menuAction.h:34
constexpr const char * defaultRadio
Definition radioLogic.h:34
constexpr const char * radios
Definition radioLogic.h:37
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Defines the DtInputLogic class for handling input in VR-Engage.
Definition radioLogic.h:26
!
Definition glsVreMessageUtil.h:50
DtVreMessageResult
Enumeration of possible message handling results.
Definition vreMessage.h:33
constexpr const char * DtRadioLogicType
Type identifier for DtRadioLogic component.
Definition radioLogic.h:43
Defines the DtPlayerComponent base class for VR-Engage role components.