VR-Engage  2.2
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(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 duplex modes (FULL/HALF)
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();
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();
209
210 //! \brief Gets the duplex mode of the current radio
211 //! \return Duplex mode as a string or placeholder if no radio selected
212 std::string currentDuplex();
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();
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();
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();
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
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
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
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
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();
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();
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);
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
279} // namespace makVre
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:35
Base class for all role components in VR-Engage.
Definition playerComponent.h:78
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
std::string currentModulationSystem()
Gets the modulation system of the current radio.
void setCryptoKey(unsigned short cryptoKey)
Sets the cryptographic key for the current radio.
virtual ~DtRadioLogic() override
Virtual destructor for DtRadioLogic.
void updateAttributes()
Updates state attributes with current radio settings.
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
virtual const char * type() const override
Returns the type identifier for this component.
std::string currentModulationMajor()
Gets the major modulation type of the current radio.
std::string currentCryptoMode()
Gets the cryptographic mode of the current radio.
void handleCycleFrequencyHopping(MenuActionMessage *msg)
Toggles frequency hopping on/off.
void handleCycleModulationDetail(MenuActionMessage *msg)
Cycles through available modulation detail types.
std::string currentModulationDetail()
Gets the modulation detail type of the current radio.
void handleCycleRadio(MenuActionMessage *msg)
Cycles to the next available radio or turns off if at the last radio.
void handleCryptoKeyInput(MenuActionMessage *msg)
Sets the crypto key based on input from a menu.
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.
DtVreMessageResult handleRadioMenuMessage(DtVreMessage *msg)
Handles menu messages related to radio operations.
std::string currentCryptoSystem()
Gets the cryptographic system of the current radio.
std::string currentCryptoKey()
Gets the cryptographic key 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
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
void handleCycleDuplex(MenuActionMessage *msg)
Cycles through available duplex modes (FULL/HALF)
void handleCyclePseudoNoise(MenuActionMessage *msg)
Toggles pseudo-noise on/off.
void handleEmbarkedOnChanged(DtEntityIdentifier val)
Handles changes to the player's embarked state.
std::string currentRadioName()
Gets the name 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
std::string currentPseudoNoise()
Gets the pseudo-noise state of the current radio.
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
void handleSetRadio(MenuActionMessage *msg)
Sets the current radio to a specific index.
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
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.
virtual void initializeStateAttributes() override
Initializes state attributes for radio communication.
std::string currentTimeHopping()
Gets the time hopping state of the current radio.
std::string currentFrequencyHopping()
Gets the frequency hopping state of the current radio.
std::string currentDuplex()
Gets the duplex mode of the current radio.
virtual bool initialize(DtPlayerStation *player, DtInitTable &config) override
Initializes the radio logic component.
std::string currentChannelName()
Gets the channel name of the current radio.
void handleCycleChannel(MenuActionMessage *msg)
Cycles to the next channel on the current radio.
Abstract base class for all VREngage messages.
Definition vreMessage.h:50
Definition menuAction.h:30
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
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
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.