PicoScenes API Docs
 
Loading...
Searching...
No Matches
AbstractFrontEnd.hxx
Go to the documentation of this file.
1//
2// Created by Zhiping Jiang on 12/24/19.
3//
4
5#ifndef PICOSCENES_PLATFORM_ABSTRACTFRONTEND_HXX
6#define PICOSCENES_PLATFORM_ABSTRACTFRONTEND_HXX
7
8#include <functional>
9#include <array>
10#include <condition_variable>
11#include "BoostHeaders.hxx"
12#include "ModularPicoScenesFrame.hxx"
14
20public:
26 explicit AbstractFrontEnd(const std::string &referredInterfaceName);
27
31 virtual int startTx();
32
36 virtual int stopTx();
37
41 [[nodiscard]] virtual bool isTxServiceStarted() const;
42
46 virtual int pauseTx();
47
51 virtual int resumeTx();
52
53 virtual int transmit(const ModularPicoScenesTxFrame &frame) = 0;
54
58 virtual int transmitFramesInBatch(const std::vector<const ModularPicoScenesTxFrame *> &frames, uint32_t repeat) = 0;
59
60 [[deprecated("Use the pointer-version or variadic-template versions of transmitFramesInBatch instead. This method will be removed in future release.")]]
61 virtual int transmitFramesInBatch(const std::vector<ModularPicoScenesTxFrame> &frames, const uint32_t repeat) {
62 std::vector<const ModularPicoScenesTxFrame *> framePoints;
63 framePoints.reserve(frames.size());
64 for (const auto &frame: frames)
65 framePoints.emplace_back(&frame);
66 return transmitFramesInBatch(framePoints, repeat);
67 }
68
69 template<int repeat = 1, typename ... Frames, typename = std::enable_if_t<(std::is_same_v<std::remove_cvref_t<Frames>, ModularPicoScenesTxFrame *> &&...) ||
70 (std::is_same_v<std::remove_cvref_t<Frames>, ModularPicoScenesTxFrame> &&...) ||
71 ((std::is_same_v<std::remove_cvref_t<Frames>, std::shared_ptr<ModularPicoScenesTxFrame>> ||
72 std::is_same_v<std::remove_cvref_t<Frames>, std::unique_ptr<ModularPicoScenesTxFrame>>) &&...)>>
73 int transmitFramesInBatch(Frames &&... frames) {
74 std::vector<const ModularPicoScenesTxFrame *> framePoints;
75
76 if constexpr ((std::is_same_v<std::remove_cvref_t<Frames>, ModularPicoScenesTxFrame *> && ...)) {
77 (framePoints.emplace_back(frames), ...);
78 } else if constexpr ((std::is_same_v<std::remove_cvref_t<Frames>, ModularPicoScenesTxFrame> && ...)) {
79 (framePoints.emplace_back(&frames), ...);
80 } else if constexpr (((std::is_same_v<std::remove_cvref_t<Frames>, std::shared_ptr<ModularPicoScenesTxFrame>> ||
81 std::is_same_v<std::remove_cvref_t<Frames>, std::unique_ptr<ModularPicoScenesTxFrame>>) && ...)) {
82 (framePoints.emplace_back(frames.get()), ...);
83 }
84 return transmitFramesInBatch(framePoints, repeat);
85 }
86
87// int transmitTest(const ModularPicoScenesTxFrame &frame1, const ModularPicoScenesTxFrame &frame2) {
88// ModularPicoScenesTxFrame t1, t2, t3;
89// auto t4 = std::make_shared<ModularPicoScenesTxFrame>();
90// auto t5 = std::make_shared<ModularPicoScenesTxFrame>();
91// auto t6 = std::make_unique<ModularPicoScenesTxFrame>();
92// auto t7 = std::make_unique<ModularPicoScenesTxFrame>();
93// transmitFramesInBatch(t4, t6);
94// transmitFramesInBatch(t6, t7);
95// transmitFramesInBatch(t1, t2, t3);
96// return transmitFramesInBatch(frame1, frame2);
97// }
98
109 virtual int startRx() = 0;
110
115 virtual int stopRx() = 0;
116
121 virtual int pauseRx();
122
127 virtual int resumeRx();
128
132 virtual void printStatus() = 0;
133
139 void registerRxHandle(const std::function<void(const ModularPicoScenesRxFrame &)> &rxHandle);
140
144 [[nodiscard]] const std::string &getReferredInterfaceName() const;
145
150 void setReferredInterfaceName(const std::string &name);
151
155 [[nodiscard]] const std::string &getPhyId() const;
156
161 [[nodiscard]] PicoScenesDeviceType getFrontEndType() const;
162
167 [[nodiscard]] PicoScenesDeviceSubtype getFrontEndSubtype() const;
168
172 [[nodiscard]] const std::array<uint8_t, 6> &getMacAddressPhy() const;
173
178 PicoScenesFrameTxParameters &getUserSpecifiedTxParameters();
179
180 ModularPicoScenesTxFrame initializeTxFrame() override;
181
182 virtual ~AbstractFrontEnd() = default;
183
184protected:
186 std::string phyId;
187 std::array<uint8_t, 6> macAddress_PHY{0, 0, 0, 0, 0, 0};
188 PicoScenesDeviceType frontEndType = PicoScenesDeviceType::Unknown;
189 PicoScenesDeviceSubtype frontEndSubtype = PicoScenesDeviceSubtype::Unknown;
190
191 bool txServiceStarted = false;
192 PicoScenesFrameTxParameters userSpecifiedTxParameters;
193 std::mutex txPauseMutex;
194 std::condition_variable txPauseCV;
195 bool txPaused = false;
196
197 std::function<void(const ModularPicoScenesRxFrame &)> rxHandle = nullptr;
198 bool rxPaused = false;
199 bool rxServiceStarted = false;
200};
201
202
203#endif //PICOSCENES_PLATFORM_ABSTRACTFRONTEND_HXX
The shared abstract frontend interface for both SDR and NIC.
PicoScenesDeviceSubtype getFrontEndSubtype() const
Return the PicoScenesDeviceType subtype of this frontend.
std::string referredInterfaceName
the user specified frontend name
virtual int startTx()
Activate internal Tx service loop.
std::condition_variable txPauseCV
void registerRxHandle(const std::function< void(const ModularPicoScenesRxFrame &)> &rxHandle)
Register a handler for the received ModularPicoScenesRxFrame frames.
PicoScenesDeviceType frontEndType
frontend type
AbstractFrontEnd(const std::string &referredInterfaceName)
Create AbstractFrontEnd object according to the user-specified frontend name referredInterfaceName.
std::string phyId
phyId
PicoScenesDeviceSubtype frontEndSubtype
frontend subtype
virtual int transmit(const ModularPicoScenesTxFrame &frame)=0
virtual int resumeRx()
Resuase the paused Rx service loop, set rxPaused to false.
virtual int transmitFramesInBatch(const std::vector< const ModularPicoScenesTxFrame * > &frames, uint32_t repeat)=0
Transmit frames in batch with precise inter-frame timing.
void setReferredInterfaceName(const std::string &name)
Set the user-specified frontend name.
virtual int startRx()=0
Activiate the Rx service loop.
virtual int stopRx()=0
De-activate the Rx service loop, set rxServiceStarted to false.
PicoScenesFrameTxParameters & getUserSpecifiedTxParameters()
ModularPicoScenesTxFrame initializeTxFrame() override
bool txServiceStarted
indicate whether Tx service is running
bool rxServiceStarted
indicate whether Rx service loop is running
bool txPaused
indicate whether Tx serivce is paused
const std::array< uint8_t, 6 > & getMacAddressPhy() const
Return the MAC address of this frontend. For SDR frontend, this method should generate a pseudo-MAC a...
int transmitFramesInBatch(Frames &&... frames)
virtual void printStatus()=0
Print a status string to command line.
virtual int pauseTx()
Pause Tx service loop.
PicoScenesFrameTxParameters userSpecifiedTxParameters
user-specified Tx parameters
std::array< uint8_t, 6 > macAddress_PHY
macAddress of the frontend
virtual int stopTx()
De-activate Tx service loop.
const std::string & getPhyId() const
Return the PhyId for NIC frontend. This is a undefined behavior for SDR frontend.
virtual int transmitFramesInBatch(const std::vector< ModularPicoScenesTxFrame > &frames, const uint32_t repeat)
virtual ~AbstractFrontEnd()=default
virtual int pauseRx()
Pause the Rx service loop, set rxPaused to true.
virtual bool isTxServiceStarted() const
Returns whether Tx service is started.
bool rxPaused
indicate whether Rx service loop is paused
PicoScenesDeviceType getFrontEndType() const
Return the PicoScenesDeviceType of this frontend.
virtual int resumeTx()
Resume Tx service loop.
const std::string & getReferredInterfaceName() const
Get the user-specified frontend name.
std::function< void(const ModularPicoScenesRxFrame &)> rxHandle
The Rx frame handler.
This class holds the common hardware configuration setters/getters for ALL types of frontend (SDR or ...