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