-
Notifications
You must be signed in to change notification settings - Fork 0
/
SoapyHifiBerry.h
196 lines (153 loc) · 5.54 KB
/
SoapyHifiBerry.h
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#pragma once
#include <cstdio>
#include <cstdarg>
#include <cstdlib>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdint.h>
#include <stdexcept>
#include <sys/ioctl.h>
#include <memory>
#include <unistd.h>
#include <string.h>
#include <mutex>
#include <cstring>
#include <chrono>
#include <thread>
#include <SoapySDR/Device.hpp>
#include <SoapySDR/Logger.hpp>
#include <SoapySDR/Formats.hpp>
#include "AudioInput.h"
#include "AudioOutput.h"
#include "si5351.h"
#include "TCA9548.h"
#include "configfile.h"
/*-------------------------------------------------------
Si5351
--------------------------------------------------------*/
#define SI5351_BUS_BASE_ADDR 0x60
const int hifiBerry_BufferSize = 2048;
typedef enum hifiberrysdrStreamFormat
{
HIFIBERRY_SDR_CF32,
HIFIBERRY_SDR_CS16
} hifiberrysdrStreamFormat;
typedef enum vfoMode_
{
Single,
IQSingle,
IQMulti,
IQSingleMultiPort
} vfoMode;
class sdr_stream
{
public:
sdr_stream(int dir)
{
direction = dir;
}
int get_direction() { return direction; }
void set_stream_format(hifiberrysdrStreamFormat sf) { streamFormat = sf; };
hifiberrysdrStreamFormat get_stream_format() { return streamFormat; };
private:
int direction;
hifiberrysdrStreamFormat streamFormat;
};
class SoapyHifiBerry : public SoapySDR::Device
{
public:
SoapyHifiBerry(const SoapySDR::Kwargs &args);
~SoapyHifiBerry();
/*******************************************************************
* Identification API
******************************************************************/
std::string getDriverKey(void) const;
std::string getHardwareKey(void) const;
SoapySDR::Kwargs getHardwareInfo(void) const;
/*******************************************************************
* Channels API
******************************************************************/
size_t getNumChannels(const int direction) const;
bool getFullDuplex(const int direction, const size_t channel) const;
/*******************************************************************
* Stream API
******************************************************************/
SoapySDR::RangeList getSampleRateRange(const int direction, const size_t channel) const;
std::vector<std::string> getStreamFormats(const int direction, const size_t channel) const;
std::string getNativeStreamFormat(const int direction, const size_t channel, double &fullScale) const;
SoapySDR::ArgInfoList getStreamArgsInfo(const int direction, const size_t channel) const;
size_t getStreamMTU(SoapySDR::Stream *stream) const;
void closeStream(SoapySDR::Stream *stream);
int deactivateStream(SoapySDR::Stream *stream, const int flags = 0, const long long timeNs = 0);
SoapySDR::Stream *setupStream(
const int direction,
const std::string &format,
const std::vector<size_t> &channels = std::vector<size_t>(),
const SoapySDR::Kwargs &args = SoapySDR::Kwargs());
int readStream(
SoapySDR::Stream *stream,
void *const *buffs,
const size_t numElems,
int &flags,
long long &timeNs,
const long timeoutUs = 100000);
int writeStream(
SoapySDR::Stream *stream,
const void *const *buffs,
const size_t numElems,
int &flags,
const long long timeNs = 0,
const long timeoutUs = 100000);
/*******************************************************************
* Sample Rate API
******************************************************************/
void setSampleRate(const int direction, const size_t channel, const double rate);
double getBandwidth(const int direction, const size_t channel) const;
std::vector<double> listBandwidths(const int direction, const size_t channel) const;
std::vector<double> listSampleRates(const int direction, const size_t channel) const;
/*******************************************************************
* Frequency API
******************************************************************/
void setFrequency(
const int direction,
const size_t channel,
const double frequency,
const SoapySDR::Kwargs &args = SoapySDR::Kwargs());
SoapySDR::RangeList getFrequencyRange(const int direction, const size_t channel) const;
/*******************************************************************
* Antenna API
******************************************************************/
std::vector<std::string> listAntennas(const int direction, const size_t channel) const;
/*******************************************************************
* Gain API
******************************************************************/
std::vector<std::string> listGains(const int direction, const size_t channel) const;
void setGain(const int direction, const size_t channel, const double value);
SoapySDR::Range getGainRange(const int direction, const size_t channel) const;
private:
int rx_frequency;
int no_channels;
std::mutex send_command;
bool i2c_available;
std::vector<sdr_stream *> streams;
std::unique_ptr<HifiBerryAudioOutputput> uptr_HifiBerryAudioOutputput;
std::unique_ptr<HifiBerryAudioInput> uptr_HifiBerryAudioInput;
std::unique_ptr<cfg::File> uptr_cfg;
SoapyHifiBerryDataBuffer<IQSample> source_buffer_rx;
SoapyHifiBerryDataBuffer<IQSample> source_buffer_tx;
std::unique_ptr<Si5351> pSI5351;
std::unique_ptr<Si5351> pSI5351tx;
std::unique_ptr<TCA9548> pTCA9548;
int get_int(string section, string key);
std::string get_string(string section, string key);
si5351_drive txDrive, rxDrive;
SoapySDR::Range rxGain{-12, 40};
vfoMode vfoIQMode;
int multiplier;
bool disableOutput;
int currDirection;
void setOutput(const int direction);
enum si5351_clock iclk, iclkTx;
enum si5351_clock qclk, qclkTx;
};