PicoScenes API Docs
 
Loading...
Searching...
No Matches
VirtualSDRFrontEnd.hxx
Go to the documentation of this file.
1//
2// Created by Zhiping Jiang on 5/4/21.
3//
4
5#ifndef PICOSCENES_PLATFORM_VIRTUALSDRFRONTEND_HXX
6#define PICOSCENES_PLATFORM_VIRTUALSDRFRONTEND_HXX
7
8#include <thread>
10
21public:
27 static std::shared_ptr<VirtualSDRFrontEnd> getInstance(const std::string& referredInterfaceName);
28
36 int32_t transmitSignals(const std::vector<const void*>& signals, int64_t bufferLength, double postfixDuration) override {
37 // VirtualSDR does not perform actual transmission
38 return 0;
39 }
40
45 ExtraInfo buildExtraInfo() override {
46 ExtraInfo extraInfo;
47 return extraInfo;
48 }
49
53 void printStatus() override {
54 LoggingService_Frontend_info_printf("[VirtualSDR(%s)]: cf=%.4fMHz, sf=%.4fMHz, mode=%s, txcm = %u, rxcm = %u, txpower = %0.f\n", getReferredInterfaceName(),
55 getRxCarrierFrequencies()[0] / 1e6, getSamplingRate() / 1e6, channelModel2String(channelFlags2ChannelMode(getChannelFlags())), getTxChainMask(), getRxChainMask(), getTxpower());
56 }
57
62 std::tuple<double, double, double> getChannelAndBandwidth() override {
63 // Virtual SDR does not manage real channel information
64 return std::tuple<double, double, double>();
65 }
66
74 int setChannelAndBandwidth(double center, double bw, double control) override { return 0; }
75
83 int setChannelAndBandwidth(std::optional<double> control, std::optional<double> bw, std::optional<double> center) override {
84 return 0;
85 }
86
92 bool isHardwareSupportedPreset(const std::string& presetName) override {
93 // Support all presets
94 return true;
95 }
96
103 void applyPreset(const std::string& presetName, bool skipChangeRate) override {
104 // Convert preset name to uppercase for case-insensitive comparison
105 std::string upperPresetName = boost::to_upper_copy(presetName);
106
107 // First check if preset exists and is supported by hardware
108 if (!isHardwareSupportedPreset(upperPresetName)) {
109 throw std::invalid_argument(fmt::format("Preset '{}' is not supported by the current USRP device type.", presetName));
110 }
111
112 // Get the preset from the preset map
113 const auto& preset = FrontEndModePreset::getPresetMap().at(upperPresetName);
114 userSpecifiedTxParameters.applyPreset(upperPresetName);
115
116 if (preset->txCBW.has_value()) {
117 if (!skipChangeRate)
118 setTxSamplingRate(preset->txCBW.value() * 1e6);
119 setTxResampleRatio(1.0); // Virtual SDR doesn't actually resample
120 }
121
122 if (preset->rxCBW.has_value()) {
123 if (!skipChangeRate)
124 setRxSamplingRate(preset->rxCBW.value() * 1e6);
125 setRxResampleRatio(1.0); // Virtual SDR doesn't actually resample
126 setRxChannelBandwidthMode(static_cast<ChannelBandwidthEnum>(preset->rxCBW.value()));
127 }
128 }
129
134 void setTxCarrierFrequencies(std::vector<double> carrierFreqsV) override {
135 if (!carrierFreqsV.empty()) {
136 carrierFrequency = carrierFreqsV[0];
137 }
138 }
139
144 void setRxCarrierFrequencies(std::vector<double> carrierFreqsV) override {
145 if (!carrierFreqsV.empty()) {
146 carrierFrequency = carrierFreqsV[0];
147 }
148 }
149
154 std::vector<double> getTxCarrierFrequencies() override {
155 return {carrierFrequency};
156 }
157
162 std::vector<double> getRxCarrierFrequencies() override {
163 return {carrierFrequency};
164 }
165
170 double getTxSamplingRate() override {
171 return txSamplingRate;
172 }
173
178 double getRxSamplingRate() override {
179 return rxSamplingRate;
180 }
181
186 void setTxSamplingRate(double txRate) override {
187 txSamplingRate = txRate;
188 }
189
194 void setRxSamplingRate(double rxRate) override {
195 rxSamplingRate = rxRate;
196 }
197
202 double getControlChannelFrequency() override {
203 return controlFrequency;
204 }
205
210 void setControlChannelFrequency(const double controlFrequencyV) override {
211 controlFrequency = controlFrequencyV;
212 }
213
218 double getTxpower() override {
219 return txpower;
220 }
221
226 void setTxpower(const double txpowerV) override {
227 txpower = txpowerV;
228 }
229
234 double getRxGain() override {
235 return rxGain;
236 }
237
242 void setRxGain(const double rxGainV) override {
243 rxGain = rxGainV;
244 }
245
251 void setRxGain(const double rxGainV, uint8_t channel) override {
252 rxGain = rxGainV; // VirtualSDR has only one global gain setting
253 };
254
259 bool supportAGC() override {
260 return false;
261 }
262
267 void setAGC(bool enableAGC) override {
268 // VirtualSDR does not support AGC
269 }
270
275 uint16_t getChannelFlags() override {
276 return channelFlags;
277 }
278
283 std::string getClockSource() override {
284 return clockSource;
285 }
286
291 void setClockSource(const std::string& clockSourceV) override {
292 clockSource = clockSourceV;
293 }
294
299 std::string getTimeSource() override {
300 return timeSource;
301 }
302
307 void setTimeSource(const std::string& timeSourceV) override {
308 timeSource = timeSourceV;
309 }
310
315 double getMasterClockRate() override {
316 return masterClockRate;
317 }
318
323 void setMasterClockRate(const double masterClockRateV) override {
324 masterClockRate = masterClockRateV;
325 }
326
331 double getSDRFrontEndTime() override {
332 // Return a simulated timestamp, e.g., system time
333 return std::chrono::system_clock::now().time_since_epoch().count();
334 }
335
340 std::vector<std::string> getTxAntennas() override {
341 return txAntennas;
342 }
343
348 void setTxAntennas(const std::vector<std::string>& txAnts) override {
349 txAntennas = txAnts;
350 }
351
356 std::vector<std::string> getRxAntennas() override {
357 return rxAntennas;
358 }
359
364 void setRxAntennas(const std::vector<std::string>& rxAnts) override {
365 rxAntennas = rxAnts;
366 }
367
372 double getFilterBandwidth() override {
373 return filterBandwidth;
374 }
375
380 void setFilterBandwidth(const double bw) override {
381 filterBandwidth = bw;
382 }
383
384protected:
385 double carrierFrequency = 2412e6;
386 double txSamplingRate = 20e6;
387 double rxSamplingRate = 20e6;
388 double controlFrequency = 2412e6;
389 double txpower = 10;
390 double rxGain = 30;
391 uint16_t channelFlags{};
392 std::string clockSource;
393 std::string timeSource;
394 std::optional<double> rxCarrierFrequencyOffset = std::nullopt;
395 ChannelBandwidthEnum rxCBW = ChannelBandwidthEnum::CBW_20;
396 double masterClockRate = 100e6;
397 std::vector<std::string> txAntennas{"TX/RX"};
398 std::vector<std::string> rxAntennas{"RX2"};
399 double filterBandwidth = 40e6;
400
406};
407
408
409#endif //PICOSCENES_PLATFORM_VIRTUALSDRFRONTEND_HXX
#define LoggingService_Frontend_info_printf(...)
std::string referredInterfaceName
the user specified frontend name
PicoScenesFrameTxParameters userSpecifiedTxParameters
user-specified Tx parameters
const std::string & getReferredInterfaceName() const
Get the user-specified frontend name.
The shared abstract frontend for SDR devices only.
void setRxChannelBandwidthMode(ChannelBandwidthEnum rxCbw) override
Set the channel bandwidth mode for Rx.
void setTxResampleRatio(double txResampleRatioV) override
Set the Tx resampling ratio.
double getSamplingRate() override
Get the baseband sampling rate.
void setRxResampleRatio(double rxResampleRatioV) override
Set the Rx resampling ratio.
uint8_t getRxChainMask() override
Get Rx chain mask.
uint8_t getTxChainMask() override
Get the Tx chain mask.
Interface class for the Virtual SDR Frontend.
void setTxSamplingRate(double txRate) override
Sets the transmit sampling rate for the virtual SDR.
uint16_t getChannelFlags() override
Gets the channel flags for the virtual SDR.
std::tuple< double, double, double > getChannelAndBandwidth() override
Gets the channel, bandwidth, and center frequency (returns an empty tuple).
void setRxGain(const double rxGainV) override
Sets the receive gain for the virtual SDR.
double rxGain
Receive gain (dB).
static std::shared_ptr< VirtualSDRFrontEnd > getInstance(const std::string &referredInterfaceName)
Gets the instance of VirtualSDRFrontEnd.
ChannelBandwidthEnum rxCBW
Receive channel bandwidth mode.
double getTxpower() override
Gets the transmit power for the virtual SDR.
void setTimeSource(const std::string &timeSourceV) override
Sets the time source for the virtual SDR.
double getRxSamplingRate() override
Gets the receive sampling rate for the virtual SDR.
bool supportAGC() override
Checks if the virtual SDR supports Automatic Gain Control (AGC).
void setFilterBandwidth(const double bw) override
Sets the filter bandwidth for the virtual SDR.
void setMasterClockRate(const double masterClockRateV) override
Sets the master clock rate for the virtual SDR.
double rxSamplingRate
Receive sampling rate (Hz).
void setRxAntennas(const std::vector< std::string > &rxAnts) override
Sets the receive antenna names for the virtual SDR.
void setRxGain(const double rxGainV, uint8_t channel) override
Sets the receive gain for a specific channel of the virtual SDR (only sets the global gain).
std::string getClockSource() override
Gets the clock source for the virtual SDR.
double txpower
Transmit power (dBm or linear unit, context-dependent).
void setClockSource(const std::string &clockSourceV) override
Sets the clock source for the virtual SDR.
double txSamplingRate
Transmit sampling rate (Hz).
bool isHardwareSupportedPreset(const std::string &presetName) override
Checks if the hardware supports the specified preset mode.
std::optional< double > rxCarrierFrequencyOffset
Receive carrier frequency offset (Hz).
void setAGC(bool enableAGC) override
Sets the Automatic Gain Control (AGC) for the virtual SDR (no actual operation).
double masterClockRate
Master clock rate (Hz).
void setControlChannelFrequency(const double controlFrequencyV) override
Sets the control channel frequency for the virtual SDR.
ExtraInfo buildExtraInfo() override
Builds extra information for the frontend (currently empty).
std::vector< std::string > txAntennas
List of transmit antenna names.
double getFilterBandwidth() override
Gets the filter bandwidth for the virtual SDR.
std::string clockSource
Clock source ("internal", "external", etc.).
uint16_t channelFlags
Channel flags (define channel mode, etc.).
std::vector< double > getTxCarrierFrequencies() override
Gets the transmit carrier frequencies for the virtual SDR (returns a single frequency).
void setRxCarrierFrequencies(std::vector< double > carrierFreqsV) override
Sets the receive carrier frequencies for the virtual SDR (only sets the first channel).
VirtualSDRFrontEnd(const std::string &referredInterfaceName)
Constructor (protected, get instance via getInstance).
double controlFrequency
Control channel frequency (Hz).
int32_t transmitSignals(const std::vector< const void * > &signals, int64_t bufferLength, double postfixDuration) override
Simulates signal transmission (no actual operation).
double getTxSamplingRate() override
Gets the transmit sampling rate for the virtual SDR.
double getMasterClockRate() override
Gets the master clock rate for the virtual SDR.
void setTxCarrierFrequencies(std::vector< double > carrierFreqsV) override
Sets the transmit carrier frequencies for the virtual SDR (only sets the first channel).
void setTxAntennas(const std::vector< std::string > &txAnts) override
Sets the transmit antenna names for the virtual SDR.
std::vector< double > getRxCarrierFrequencies() override
Gets the receive carrier frequencies for the virtual SDR (returns a single frequency).
double getControlChannelFrequency() override
Gets the control channel frequency for the virtual SDR.
double carrierFrequency
Carrier frequency (Hz).
std::vector< std::string > getTxAntennas() override
Gets the transmit antenna names for the virtual SDR.
std::vector< std::string > getRxAntennas() override
Gets the receive antenna names for the virtual SDR.
void setTxpower(const double txpowerV) override
Sets the transmit power for the virtual SDR.
void setRxSamplingRate(double rxRate) override
Sets the receive sampling rate for the virtual SDR.
double filterBandwidth
Hardware filter bandwidth (Hz).
int setChannelAndBandwidth(double center, double bw, double control) override
Sets the channel, bandwidth, and center frequency (no actual operation).
std::string timeSource
Time source ("internal", "gpsdo", etc.).
double getSDRFrontEndTime() override
Gets the current time of the virtual SDR (uses system clock).
int setChannelAndBandwidth(std::optional< double > control, std::optional< double > bw, std::optional< double > center) override
Optionally sets the channel, bandwidth, and center frequency (no actual operation).
void applyPreset(const std::string &presetName, bool skipChangeRate) override
Applies the specified preset mode to the virtual SDR.
double getRxGain() override
Gets the receive gain for the virtual SDR.
std::vector< std::string > rxAntennas
List of receive antenna names.
std::string getTimeSource() override
Gets the time source for the virtual SDR.
void printStatus() override
Prints the status information of the virtual SDR to the log.