This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeable.hpp
96 lines (74 loc) · 2.64 KB
/
Timeable.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/**
* Created by Raini Wu, February 22nd, 2021
* Contact me at: [email protected]
*/
#ifndef Timeable_hpp
#define Timeable_hpp
#include <uhd/usrp/multi_usrp.hpp>
namespace locker {
enum class TimeableType { RX = 0, TX = 1, settings = 2, none = 99 };
enum class SettingType { rxgain = 0, rxfreq, rxrate, txgain, txfreq, txrate };
/** Timeable commands interface
* A Timeable command has an overloaded functor which sends some commands
* to a given USRP which execute at a given time.
*/
struct ITimeable {
ITimeable(TimeableType type = TimeableType::none);
virtual void operator()(uhd::usrp::multi_usrp::sptr &aUSRP,
const uhd::time_spec_t &sendTime) = 0;
TimeableType type;
bool active = false;
};
/** Timeable change USRP settings */
class Setter : public ITimeable {
public:
Setter(SettingType setting, double value);
~Setter();
virtual void operator()(uhd::usrp::multi_usrp::sptr &aUSRP,
const uhd::time_spec_t &sendTime);
protected:
SettingType mySetting;
double value;
};
/** Timeable recieve to buffer */
class Receiver : public ITimeable {
public:
Receiver(size_t samples = 0, std::vector<size_t> channels = {0});
~Receiver(); /** prevents default double free */
virtual void operator()(uhd::usrp::multi_usrp::sptr &aUSRP,
const uhd::time_spec_t &sendTime);
/** holds rx'd data */
std::vector<std::vector<std::complex<float>>> buffer;
const size_t samples;
const std::vector<size_t> channels;
uhd::rx_metadata_t metadata; /** collects received metadata */
protected:
void readToBuf(); /** read received data, helps threading */
void genBuffer(); /** create buffers used in rx */
/** ptrs passed to uhd recv */
std::vector<std::complex<float> *> bufferPtrs;
/** required for threading */
inline static uhd::rx_streamer::sptr rxStreamer = nullptr;
inline static bool reading = false; /** recv active flag */
uhd::time_spec_t myTime; /** saves queued time */
};
/** Timeable transmit from buffer */
class Transmitter : public ITimeable {
public:
Transmitter(std::shared_ptr<std::vector<std::complex<float>>> buffer,
size_t samples = 0, size_t channel = 0);
~Transmitter();
virtual void operator()(uhd::usrp::multi_usrp::sptr &aUSRP,
const uhd::time_spec_t &sendTime);
std::shared_ptr<std::vector<std::complex<float>>> buffer;
uhd::tx_metadata_t metadata;
protected:
void sendFromBuf();
size_t samples;
size_t channel;
inline static uhd::tx_streamer::sptr txStreamer = nullptr;
inline static bool streaming = false;
uhd::time_spec_t myTime;
};
} // namespace locker
#endif