PicoScenes API Docs
 
Loading...
Searching...
No Matches
AbstractNIC.hxx
Go to the documentation of this file.
1//
2// Created by Zhiping Jiang on 12/26/19.
3//
4
5#ifndef PICOSCENES_PLATFORM_ABSTRACTNIC_HXX
6#define PICOSCENES_PLATFORM_ABSTRACTNIC_HXX
7
8#include "AsyncPipeline.hxx"
10#include "LoggingService.hxx"
12#include "FrontEndFactory.hxx"
14
15using namespace std::chrono_literals;
16
18
20
28class AbstractNIC : public std::enable_shared_from_this<AbstractNIC> {
29public:
30
34 virtual void startTxService() = 0;
35
39 virtual void stopTxService() = 0;
40
44 virtual void pauseTx() = 0;
45
49 virtual void resumeTx() = 0;
50
55 virtual bool isTxServiceStarted() const = 0;
56
62 virtual int transmitPicoScenesFrame(const ModularPicoScenesTxFrame &frame) = 0;
63
69 virtual int transmitPicoScenesFrameSync(const ModularPicoScenesTxFrame &frame) = 0;
70
77 virtual int transmitFramesInBatch(const std::vector<ModularPicoScenesTxFrame> &frames, uint16_t numRepeats) = 0;
78
86 template<int repeat = 1, typename ... Frames, typename = std::enable_if_t<(std::is_same_v<std::remove_cvref_t<Frames>, ModularPicoScenesTxFrame *> &&...) ||
87 (std::is_same_v<std::remove_cvref_t<Frames>, ModularPicoScenesTxFrame> &&...) ||
88 ((std::is_same_v<std::remove_cvref_t<Frames>, std::shared_ptr<ModularPicoScenesTxFrame>> ||
89 std::is_same_v<std::remove_cvref_t<Frames>, std::unique_ptr<ModularPicoScenesTxFrame>>) &&...)>>
90 int transmitFramesInBatch(Frames &&... frames) {
91 std::vector<ModularPicoScenesTxFrame> batchFrames;
92
93 if constexpr (((std::is_same_v<std::remove_cvref_t<Frames>, ModularPicoScenesTxFrame *> ||
94 std::is_same_v<std::remove_cvref_t<Frames>, std::shared_ptr<ModularPicoScenesTxFrame>> ||
95 std::is_same_v<std::remove_cvref_t<Frames>, std::unique_ptr<ModularPicoScenesTxFrame>>) && ...)) {
96 (batchFrames.emplace_back(*frames), ...);
97 } else if constexpr ((std::is_same_v<std::remove_cvref_t<Frames>, ModularPicoScenesTxFrame> && ...)) {
98 (batchFrames.emplace_back(frames), ...);
99 }
100 return transmitFramesInBatch(batchFrames, repeat);
101 }
102
108 virtual ModularPicoScenesTxFrame initializeTxFrame() {
109 return frontEnd->initializeTxFrame();
110 }
111
112// int transmitTest(const ModularPicoScenesTxFrame &frame1, const ModularPicoScenesTxFrame &frame2) {
113// ModularPicoScenesTxFrame t1, t2, t3;
114// auto t4 = std::make_shared<ModularPicoScenesTxFrame>();
115// auto t5 = std::make_shared<ModularPicoScenesTxFrame>();
116// auto t6 = std::make_unique<ModularPicoScenesTxFrame>();
117// auto t7 = std::make_unique<ModularPicoScenesTxFrame>();
118// transmitFramesInBatch(t4, t6);
119// transmitFramesInBatch(t6, t7);
120// transmitFramesInBatch(t1, t2, t3);
121// return transmitFramesInBatch(frame1, frame2);
122// }
123
127 virtual void startRxService() = 0;
128
132 virtual void stopRxService() = 0;
133
137 virtual void pauseRx() = 0;
138
142 virtual void resumeRx() = 0;
143
148 virtual bool isRxServiceStarted() const = 0;
149
157 virtual std::optional<ModularPicoScenesRxFrame> syncRxConditionally(const std::function<bool(const ModularPicoScenesRxFrame &)> &condition, const std::chrono::milliseconds &maxWait_ms, std::optional<std::string> conditionaName = std::nullopt) = 0;
158
165 virtual std::optional<ModularPicoScenesRxFrame> syncRxWaitTaskId(uint16_t taskid, uint32_t maxWait_ms) = 0;
166
172 virtual void registerTaskIdHandler(uint16_t taskId, const std::function<bool(const ModularPicoScenesRxFrame &)> &handle) = 0;
173
179 virtual std::function<bool(const ModularPicoScenesRxFrame &)> getHandlerForFrameType(uint8_t frameType) = 0;
180
185 virtual void unregisterTaskIdHandler(uint16_t taskId) = 0;
186
192 virtual bool checkTaskIdHandlerExist(uint16_t taskId) = 0;
193
199 virtual void registerFrameTypeHandler(uint8_t frameType, const std::function<bool(const ModularPicoScenesRxFrame &)> &handle) = 0;
200
206 virtual std::function<bool(const ModularPicoScenesRxFrame &)> getHandlerForTaskId(uint16_t taskId) = 0;
207
212 virtual void unregisterFrameTypeHandler(uint8_t frameType) = 0;
213
219 virtual bool checkFrameTypeHandlerExist(uint8_t frameType) = 0;
220
226 virtual void registerGeneralHandler(const std::string &handlerKeyName, const std::function<bool(const ModularPicoScenesRxFrame &)> &handle) = 0;
227
233 virtual std::function<bool(const ModularPicoScenesRxFrame &)> getGeneralHandler(const std::string &handlerKeyName) = 0;
234
239 virtual void unregisterGeneralHandler(const std::string &handlerKeyName) = 0;
240
246 virtual bool checkGeneralHandlerExist(const std::string &handlerKeyName) = 0;
247
252 const std::string &getReferredInterfaceName() const;
253
258 const std::string &getPhyId() const;
259
264 const std::shared_ptr<AbstractFrontEnd> &getFrontEnd() const;
265
274 virtual const PicoScenesFrameTxParameters &getUserSpecifiedTxParameters() const = 0;
275
284 virtual PicoScenesFrameTxParameters &getUserSpecifiedTxParameters() = 0;
285
290 PicoScenesDeviceType getDeviceType() const;
291
296 std::shared_ptr<AbstractHALConfiguration> getConfiguration() const;
297
303 template<typename FrontEndT, class = std::enable_if_t<std::is_base_of_v<AbstractFrontEnd, FrontEndT>>>
307
312 const std::shared_ptr<PicoScenesPluginManager> &getPluginManager() const;
313
317 virtual void installPlugins() const = 0;
318
323 std::vector<std::shared_ptr<po::options_description>> getAllNICOptions();
324
325protected:
330
334 std::string phyId;
335
339 PicoScenesDeviceType deviceType = PicoScenesDeviceType::Unknown;
340
344 std::shared_ptr<AbstractHALConfiguration> configuration;
345
349 std::shared_ptr<AbstractFrontEnd> frontEnd;
350
354 std::shared_ptr<PicoScenesPluginManager> pluginManager;
355
360 explicit AbstractNIC(const std::string &referredInterfaceName);
361};
362
363
364#endif //PICOSCENES_PLATFORM_ABSTRACTNIC_HXX
Abstract base class for Hardware Abstraction Layer (HAL) configuration.
Abstract base class for Network Interface Card (NIC) operations.
virtual bool checkGeneralHandlerExist(const std::string &handlerKeyName)=0
Check if general handler exists.
virtual void pauseRx()=0
Temporarily pause reception.
virtual void stopTxService()=0
Stop the transmission service.
virtual bool isTxServiceStarted() const =0
Check if transmission service is running.
virtual std::function< bool(const ModularPicoScenesRxFrame &)> getGeneralHandler(const std::string &handlerKeyName)=0
Get general handler by name.
virtual ModularPicoScenesTxFrame initializeTxFrame()
Initialize a new transmission frame.
std::string referredInterfaceName
Interface name reference.
virtual void registerGeneralHandler(const std::string &handlerKeyName, const std::function< bool(const ModularPicoScenesRxFrame &)> &handle)=0
Register a general handler.
const std::string & getReferredInterfaceName() const
Get the interface name.
virtual std::optional< ModularPicoScenesRxFrame > syncRxWaitTaskId(uint16_t taskid, uint32_t maxWait_ms)=0
Wait for a frame with specific task ID.
std::string phyId
Physical interface identifier.
virtual void startRxService()=0
Start the reception service.
virtual void stopRxService()=0
Stop the reception service.
std::shared_ptr< AbstractHALConfiguration > configuration
Hardware abstraction layer configuration.
virtual bool checkFrameTypeHandlerExist(uint8_t frameType)=0
Check if handler exists for specific frame type.
std::shared_ptr< PicoScenesPluginManager > pluginManager
Plugin manager for extending functionality.
std::shared_ptr< AbstractHALConfiguration > getConfiguration() const
Get the HAL configuration.
PicoScenesDeviceType getDeviceType() const
Get the device type.
virtual void resumeRx()=0
Resume paused reception.
const std::shared_ptr< AbstractFrontEnd > & getFrontEnd() const
Get the front end interface.
virtual void pauseTx()=0
Temporarily pause transmission.
virtual void resumeTx()=0
Resume paused transmission.
virtual int transmitPicoScenesFrame(const ModularPicoScenesTxFrame &frame)=0
Transmit a single PicoScenes frame.
virtual void startTxService()=0
Start the transmission service.
virtual bool checkTaskIdHandlerExist(uint16_t taskId)=0
Check if handler exists for specific task ID.
std::shared_ptr< FrontEndT > getTypedFrontEnd() const
Get typed front end instance.
PicoScenesDeviceType deviceType
Type of the device (NIC/SDR)
virtual std::optional< ModularPicoScenesRxFrame > syncRxConditionally(const std::function< bool(const ModularPicoScenesRxFrame &)> &condition, const std::chrono::milliseconds &maxWait_ms, std::optional< std::string > conditionaName=std::nullopt)=0
Wait for a frame that matches specific conditions.
virtual void unregisterFrameTypeHandler(uint8_t frameType)=0
Unregister handler for specific frame type.
virtual void installPlugins() const =0
Install plugins for this NIC.
virtual int transmitFramesInBatch(const std::vector< ModularPicoScenesTxFrame > &frames, uint16_t numRepeats)=0
Transmit multiple frames in batch mode.
virtual PicoScenesFrameTxParameters & getUserSpecifiedTxParameters()=0
This methods returns the PicoScenesFrameTxParameters object created by the user specified Tx paramete...
AbstractNIC(const std::string &referredInterfaceName)
Protected constructor.
std::vector< std::shared_ptr< po::options_description > > getAllNICOptions()
Get all NIC options.
virtual int transmitPicoScenesFrameSync(const ModularPicoScenesTxFrame &frame)=0
Transmit a frame synchronously.
virtual std::function< bool(const ModularPicoScenesRxFrame &)> getHandlerForTaskId(uint16_t taskId)=0
Get handler for specific task ID.
virtual void unregisterTaskIdHandler(uint16_t taskId)=0
Unregister handler for specific task ID.
virtual std::function< bool(const ModularPicoScenesRxFrame &)> getHandlerForFrameType(uint8_t frameType)=0
Get handler for specific frame type.
virtual bool isRxServiceStarted() const =0
Check if reception service is running.
std::shared_ptr< AbstractFrontEnd > frontEnd
Frontend interface for hardware interaction.
virtual void unregisterGeneralHandler(const std::string &handlerKeyName)=0
Unregister general handler.
virtual const PicoScenesFrameTxParameters & getUserSpecifiedTxParameters() const =0
This methods returns the PicoScenesFrameTxParameters object created by the user specified Tx paramete...
const std::shared_ptr< PicoScenesPluginManager > & getPluginManager() const
Get the plugin manager.
virtual void registerFrameTypeHandler(uint8_t frameType, const std::function< bool(const ModularPicoScenesRxFrame &)> &handle)=0
Register handler for specific frame type.
virtual void registerTaskIdHandler(uint16_t taskId, const std::function< bool(const ModularPicoScenesRxFrame &)> &handle)=0
Register a handler for specific task ID.
int transmitFramesInBatch(Frames &&... frames)
Template method for batch transmission of frames.
const std::string & getPhyId() const
Get the physical interface ID.
static std::shared_ptr< FrontEndT > getTypedFrontEndInstance(const std::string &referredInterfaceName)
Get a typed front-end instance for the specified interface.
Manager class for PicoScenes plugins.