mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-01-24 08:44:44 +01:00
Added samplerate and center frequency tracking to http spectran source
This commit is contained in:
parent
9c0b57a036
commit
582aeed640
@ -8,8 +8,9 @@ typedef int HandlerID;
|
|||||||
|
|
||||||
template <typename... Args>
|
template <typename... Args>
|
||||||
class NewEvent {
|
class NewEvent {
|
||||||
using Handler = std::function<void(Args...)>;
|
|
||||||
public:
|
public:
|
||||||
|
using Handler = std::function<void(Args...)>;
|
||||||
|
|
||||||
HandlerID bind(const Handler& handler) {
|
HandlerID bind(const Handler& handler) {
|
||||||
std::lock_guard<std::mutex> lck(mtx);
|
std::lock_guard<std::mutex> lck(mtx);
|
||||||
HandlerID id = genID();
|
HandlerID id = genID();
|
||||||
|
@ -145,6 +145,7 @@ private:
|
|||||||
}
|
}
|
||||||
else if (connected && SmGui::Button("Disconnect##spectran_http_source")) {
|
else if (connected && SmGui::Button("Disconnect##spectran_http_source")) {
|
||||||
_this->client->onCenterFrequencyChanged.unbind(_this->onFreqChangedId);
|
_this->client->onCenterFrequencyChanged.unbind(_this->onFreqChangedId);
|
||||||
|
_this->client->onCenterFrequencyChanged.unbind(_this->onSamplerateChangedId);
|
||||||
_this->client->close();
|
_this->client->close();
|
||||||
}
|
}
|
||||||
if (_this->running) { style::endDisabled(); }
|
if (_this->running) { style::endDisabled(); }
|
||||||
@ -164,6 +165,7 @@ private:
|
|||||||
gotReport = false;
|
gotReport = false;
|
||||||
client = std::make_shared<SpectranHTTPClient>(hostname, port, &stream);
|
client = std::make_shared<SpectranHTTPClient>(hostname, port, &stream);
|
||||||
onFreqChangedId = client->onCenterFrequencyChanged.bind(&SpectranHTTPSourceModule::onFreqChanged, this);
|
onFreqChangedId = client->onCenterFrequencyChanged.bind(&SpectranHTTPSourceModule::onFreqChanged, this);
|
||||||
|
onSamplerateChangedId = client->onSamplerateChanged.bind(&SpectranHTTPSourceModule::onSamplerateChanged, this);
|
||||||
client->startWorker();
|
client->startWorker();
|
||||||
}
|
}
|
||||||
catch (std::runtime_error e) {
|
catch (std::runtime_error e) {
|
||||||
@ -178,6 +180,10 @@ private:
|
|||||||
gotReport = true;
|
gotReport = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void onSamplerateChanged(double newSr) {
|
||||||
|
core::setInputSampleRate(newSr);
|
||||||
|
}
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
bool enabled = true;
|
bool enabled = true;
|
||||||
double sampleRate;
|
double sampleRate;
|
||||||
@ -186,6 +192,7 @@ private:
|
|||||||
|
|
||||||
std::shared_ptr<SpectranHTTPClient> client;
|
std::shared_ptr<SpectranHTTPClient> client;
|
||||||
HandlerID onFreqChangedId;
|
HandlerID onFreqChangedId;
|
||||||
|
HandlerID onSamplerateChangedId;
|
||||||
|
|
||||||
double freq;
|
double freq;
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ void SpectranHTTPClient::setCenterFrequency(uint64_t freq) {
|
|||||||
// Make request
|
// Make request
|
||||||
net::http::RequestHeader rqhdr(net::http::METHOD_PUT, "/control", host);
|
net::http::RequestHeader rqhdr(net::http::METHOD_PUT, "/control", host);
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
sprintf(buf, "{\"frequencyCenter\":%d,\"frequencySpan\":%d,\"type\":\"capture\"}", freq, _span);
|
sprintf(buf, "{\"frequencyCenter\":%d,\"frequencySpan\":%d,\"type\":\"capture\"}", freq, _samplerate);
|
||||||
std::string data = buf;
|
std::string data = buf;
|
||||||
char lenBuf[16];
|
char lenBuf[16];
|
||||||
sprintf(lenBuf, "%d", data.size());
|
sprintf(lenBuf, "%d", data.size());
|
||||||
@ -93,14 +93,28 @@ void SpectranHTTPClient::worker() {
|
|||||||
std::string endFreqStr = jsonData.substr(endFreqBegin + 15, endFreqEnd - endFreqBegin - 15);
|
std::string endFreqStr = jsonData.substr(endFreqBegin + 15, endFreqEnd - endFreqBegin - 15);
|
||||||
int64_t endFreq = std::stoll(endFreqStr);
|
int64_t endFreq = std::stoll(endFreqStr);
|
||||||
|
|
||||||
|
auto sampleFreqBegin = jsonData.find("\"sampleFrequency\":");
|
||||||
|
bool sampleFreqReceived = (sampleFreqBegin != -1);
|
||||||
|
int64_t sampleFreq;
|
||||||
|
if (sampleFreqReceived) {
|
||||||
|
auto sampleFreqEnd = jsonData.find(',', sampleFreqBegin);
|
||||||
|
std::string sampleFreqStr = jsonData.substr(sampleFreqBegin + 18, sampleFreqEnd - sampleFreqBegin - 18);
|
||||||
|
sampleFreq = std::stoll(sampleFreqStr);
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate and update center freq
|
// Calculate and update center freq
|
||||||
_span = endFreq - startFreq;
|
int64_t samplerate = sampleFreqReceived ? sampleFreq : (endFreq - startFreq);
|
||||||
int64_t centerFreq = round(((double)endFreq + (double)startFreq) / 2.0);
|
int64_t centerFreq = round(((double)endFreq + (double)startFreq) / 2.0);
|
||||||
if (centerFreq != _centerFreq) {
|
if (centerFreq != _centerFreq) {
|
||||||
flog::debug("{}, {}, {}", _span, centerFreq);
|
flog::debug("New center freq: {}", centerFreq);
|
||||||
_centerFreq = centerFreq;
|
_centerFreq = centerFreq;
|
||||||
onCenterFrequencyChanged(centerFreq);
|
onCenterFrequencyChanged(centerFreq);
|
||||||
}
|
}
|
||||||
|
if (samplerate != _samplerate) {
|
||||||
|
flog::debug("New samplerate: {}", samplerate);
|
||||||
|
_samplerate = samplerate;
|
||||||
|
onSamplerateChanged(samplerate);
|
||||||
|
}
|
||||||
|
|
||||||
// Read (and check for) record separator
|
// Read (and check for) record separator
|
||||||
uint8_t rs;
|
uint8_t rs;
|
||||||
|
@ -19,6 +19,7 @@ public:
|
|||||||
void setCenterFrequency(uint64_t freq);
|
void setCenterFrequency(uint64_t freq);
|
||||||
|
|
||||||
NewEvent<uint64_t> onCenterFrequencyChanged;
|
NewEvent<uint64_t> onCenterFrequencyChanged;
|
||||||
|
NewEvent<uint64_t> onSamplerateChanged;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void worker();
|
void worker();
|
||||||
@ -33,5 +34,5 @@ private:
|
|||||||
|
|
||||||
bool streamingEnabled = false;
|
bool streamingEnabled = false;
|
||||||
int64_t _centerFreq = 0;
|
int64_t _centerFreq = 0;
|
||||||
uint64_t _span = 5000000;
|
uint64_t _samplerate = 0;
|
||||||
};
|
};
|
Loading…
x
Reference in New Issue
Block a user