mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-07-10 11:05:22 +02:00
USRP source
This commit is contained in:
@ -9,6 +9,7 @@
|
||||
#include <gui/smgui.h>
|
||||
#include <gui/widgets/stepped_slider.h>
|
||||
#include <dsp/routing/stream_link.h>
|
||||
#include <utils/optionlist.h>
|
||||
|
||||
#define CONCAT(a, b) ((std::string(a) + b).c_str())
|
||||
|
||||
@ -27,6 +28,14 @@ public:
|
||||
HermesSourceModule(std::string name) {
|
||||
this->name = name;
|
||||
|
||||
// Define samplerates
|
||||
samplerates.define(48000, "48KHz", hermes::HL_SAMP_RATE_48KHZ);
|
||||
samplerates.define(96000, "96KHz", hermes::HL_SAMP_RATE_96KHZ);
|
||||
samplerates.define(192000, "192KHz", hermes::HL_SAMP_RATE_192KHZ);
|
||||
samplerates.define(384000, "384KHz", hermes::HL_SAMP_RATE_384KHZ);
|
||||
|
||||
srId = samplerates.keyId(384000);
|
||||
|
||||
lnk.init(NULL, &stream);
|
||||
|
||||
sampleRate = 384000.0;
|
||||
@ -40,9 +49,14 @@ public:
|
||||
handler.tuneHandler = tune;
|
||||
handler.stream = &stream;
|
||||
|
||||
// TODO: Move the refresh and first select to the select event instead
|
||||
refresh();
|
||||
|
||||
// TODO: Select device
|
||||
// Select device
|
||||
config.acquire();
|
||||
selectedMac = config.conf["device"];
|
||||
config.release();
|
||||
selectMac(selectedMac);
|
||||
|
||||
sigpath::sourceManager.registerSource("Hermes", &handler);
|
||||
}
|
||||
@ -54,12 +68,6 @@ public:
|
||||
|
||||
void postInit() {}
|
||||
|
||||
enum AGCMode {
|
||||
AGC_MODE_OFF,
|
||||
AGC_MODE_LOW,
|
||||
AGC_MODE_HIGG
|
||||
};
|
||||
|
||||
void enable() {
|
||||
enabled = true;
|
||||
}
|
||||
@ -72,16 +80,56 @@ public:
|
||||
return enabled;
|
||||
}
|
||||
|
||||
void refresh() {
|
||||
devList.clear();
|
||||
devListTxt = "";
|
||||
|
||||
// TOOD: Update dev list
|
||||
}
|
||||
|
||||
// TODO: Implement select functions
|
||||
|
||||
private:
|
||||
void refresh() {
|
||||
char mac[128];
|
||||
char buf[128];
|
||||
devices.clear();
|
||||
auto devList = hermes::discover();
|
||||
for (auto& d : devList) {
|
||||
sprintf(mac, "%02X%02X%02X%02X%02X%02X", d.mac[0], d.mac[1], d.mac[2], d.mac[3], d.mac[4], d.mac[5]);
|
||||
sprintf(buf, "Hermes-Lite 2 [%s]", mac);
|
||||
devices.define(mac, buf, d);
|
||||
}
|
||||
}
|
||||
|
||||
void selectMac(std::string mac) {
|
||||
// If the device list is empty, don't select anything
|
||||
if (!devices.size()) {
|
||||
selectedMac.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// If the mac doesn't exist, select the first available one instead
|
||||
if (!devices.keyExists(mac)) {
|
||||
selectMac(devices.key(0));
|
||||
return;
|
||||
}
|
||||
|
||||
// Default config
|
||||
srId = samplerates.valueId(hermes::HL_SAMP_RATE_384KHZ);
|
||||
gain = 0;
|
||||
|
||||
// Load config
|
||||
devId = devices.keyId(mac);
|
||||
selectedMac = mac;
|
||||
config.acquire();
|
||||
if (config.conf["devices"][selectedMac].contains("samplerate")) {
|
||||
int sr = config.conf["devices"][selectedMac]["samplerate"];
|
||||
if (samplerates.keyExists(sr)) { srId = samplerates.keyId(sr); }
|
||||
}
|
||||
if (config.conf["devices"][selectedMac].contains("gain")) {
|
||||
gain = config.conf["devices"][selectedMac]["gain"];
|
||||
}
|
||||
config.release();
|
||||
|
||||
// Update host samplerate
|
||||
sampleRate = samplerates.key(srId);
|
||||
core::setInputSampleRate(sampleRate);
|
||||
}
|
||||
|
||||
static void menuSelected(void* ctx) {
|
||||
HermesSourceModule* _this = (HermesSourceModule*)ctx;
|
||||
core::setInputSampleRate(_this->sampleRate);
|
||||
@ -95,10 +143,10 @@ private:
|
||||
|
||||
static void start(void* ctx) {
|
||||
HermesSourceModule* _this = (HermesSourceModule*)ctx;
|
||||
if (_this->running) { return; }
|
||||
if (_this->running || _this->selectedMac.empty()) { return; }
|
||||
|
||||
// TODO: Implement start
|
||||
_this->dev = hermes::open("192.168.0.144", 1024);
|
||||
_this->dev = hermes::open(_this->devices[_this->devId].addr);
|
||||
|
||||
// TODO: STOP USING A LINK, FIND A BETTER WAY
|
||||
_this->lnk.setInput(&_this->dev->out);
|
||||
@ -106,9 +154,9 @@ private:
|
||||
_this->dev->start();
|
||||
|
||||
// TODO: Check if the USB commands are accepted before start
|
||||
_this->dev->setSamplerate(_this->samplerates[_this->srId]);
|
||||
_this->dev->setFrequency(_this->freq);
|
||||
_this->dev->setGain(_this->gain);
|
||||
_this->dev->writeReg(0, 3 << 24);
|
||||
|
||||
_this->running = true;
|
||||
spdlog::info("HermesSourceModule '{0}': Start!", _this->name);
|
||||
@ -131,7 +179,7 @@ private:
|
||||
HermesSourceModule* _this = (HermesSourceModule*)ctx;
|
||||
if (_this->running) {
|
||||
// TODO: Check if dev exists
|
||||
_this->dev->setFrequency(_this->freq);
|
||||
_this->dev->setFrequency(freq);
|
||||
}
|
||||
_this->freq = freq;
|
||||
spdlog::info("HermesSourceModule '{0}': Tune: {1}!", _this->name, freq);
|
||||
@ -142,22 +190,53 @@ private:
|
||||
|
||||
if (_this->running) { SmGui::BeginDisabled(); }
|
||||
|
||||
// TODO: Device selection
|
||||
if (SmGui::Button("Discover")) {
|
||||
auto disc = hermes::discover();
|
||||
spdlog::warn("Found {0} devices!", disc.size());
|
||||
SmGui::FillWidth();
|
||||
SmGui::ForceSync();
|
||||
if (SmGui::Combo(CONCAT("##_hermes_dev_sel_", _this->name), &_this->devId, _this->devices.txt)) {
|
||||
_this->selectMac(_this->devices.key(_this->devId));
|
||||
if (!_this->selectedMac.empty()) {
|
||||
config.acquire();
|
||||
config.conf["device"] = _this->devices.key(_this->devId);
|
||||
config.release(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (SmGui::Combo(CONCAT("##_hermes_sr_sel_", _this->name), &_this->srId, _this->samplerates.txt)) {
|
||||
_this->sampleRate = _this->samplerates.key(_this->srId);
|
||||
core::setInputSampleRate(_this->sampleRate);
|
||||
if (!_this->selectedMac.empty()) {
|
||||
config.acquire();
|
||||
config.conf["devices"][_this->selectedMac]["samplerate"] = _this->samplerates.key(_this->srId);
|
||||
config.release(true);
|
||||
}
|
||||
}
|
||||
|
||||
SmGui::SameLine();
|
||||
SmGui::FillWidth();
|
||||
SmGui::ForceSync();
|
||||
if (SmGui::Button(CONCAT("Refresh##_hermes_refr_", _this->name))) {
|
||||
_this->refresh();
|
||||
config.acquire();
|
||||
std::string mac = config.conf["device"];
|
||||
config.release();
|
||||
_this->selectMac(mac);
|
||||
}
|
||||
|
||||
if (_this->running) { SmGui::EndDisabled(); }
|
||||
|
||||
// TODO: Device parameters
|
||||
|
||||
if (SmGui::SliderInt("Gain##hermes_source", &_this->gain, 0, 60)) {
|
||||
_this->dev->setGain(_this->gain);
|
||||
}
|
||||
|
||||
if (SmGui::Button("Hermes Test")) {
|
||||
_this->dev->readReg(hermes::HL_REG_RX1_NCO_FREQ);
|
||||
SmGui::LeftLabel("LNA Gain");
|
||||
SmGui::FillWidth();
|
||||
if (SmGui::SliderInt("##hermes_source_lna_gain", &_this->gain, 0, 60)) {
|
||||
if (_this->running) {
|
||||
_this->dev->setGain(_this->gain);
|
||||
}
|
||||
if (!_this->selectedMac.empty()) {
|
||||
config.acquire();
|
||||
config.conf["devices"][_this->selectedMac]["gain"] = _this->gain;
|
||||
config.release(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,14 +247,18 @@ private:
|
||||
double sampleRate;
|
||||
SourceManager::SourceHandler handler;
|
||||
bool running = false;
|
||||
double freq;
|
||||
std::string selectedMac = "";
|
||||
|
||||
OptionList<std::string, hermes::Info> devices;
|
||||
OptionList<int, hermes::HermesLiteSamplerate> samplerates;
|
||||
|
||||
double freq;
|
||||
int devId = 0;
|
||||
int srId = 0;
|
||||
int gain = 0;
|
||||
|
||||
std::shared_ptr<hermes::Client> dev;
|
||||
|
||||
std::vector<uint64_t> devList;
|
||||
std::string devListTxt;
|
||||
};
|
||||
|
||||
MOD_EXPORT void _INIT_() {
|
||||
|
Reference in New Issue
Block a user