mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2025-09-06 23:27:53 -04:00
Basic cleanup / mutex additions / bulk demod add
This commit is contained in:
parent
a75faaf4f2
commit
c1863d9319
@ -1627,6 +1627,7 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||||||
int numDemodulators = 0;
|
int numDemodulators = 0;
|
||||||
DemodulatorInstance *loadedDemod = NULL;
|
DemodulatorInstance *loadedDemod = NULL;
|
||||||
DemodulatorInstance *newDemod = NULL;
|
DemodulatorInstance *newDemod = NULL;
|
||||||
|
std::vector<DemodulatorInstance *> demodsLoaded;
|
||||||
|
|
||||||
while (demodulators->hasAnother("demodulator")) {
|
while (demodulators->hasAnother("demodulator")) {
|
||||||
DataNode *demod = demodulators->getNext("demodulator");
|
DataNode *demod = demodulators->getNext("demodulator");
|
||||||
@ -1727,8 +1728,9 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
newDemod->run();
|
newDemod->run();
|
||||||
newDemod->setActive(false);
|
newDemod->setActive(true);
|
||||||
wxGetApp().bindDemodulator(newDemod);
|
demodsLoaded.push_back(newDemod);
|
||||||
|
// wxGetApp().bindDemodulator(newDemod);
|
||||||
|
|
||||||
std::cout << "\tAdded demodulator at frequency " << freq << " type " << type << std::endl;
|
std::cout << "\tAdded demodulator at frequency " << freq << " type " << type << std::endl;
|
||||||
std::cout << "\t\tBandwidth: " << bandwidth << std::endl;
|
std::cout << "\t\tBandwidth: " << bandwidth << std::endl;
|
||||||
@ -1740,9 +1742,7 @@ bool AppFrame::loadSession(std::string fileName) {
|
|||||||
DemodulatorInstance *focusDemod = loadedDemod?loadedDemod:newDemod;
|
DemodulatorInstance *focusDemod = loadedDemod?loadedDemod:newDemod;
|
||||||
|
|
||||||
if (focusDemod) {
|
if (focusDemod) {
|
||||||
focusDemod->setActive(true);
|
wxGetApp().bindDemodulators(&demodsLoaded);
|
||||||
focusDemod->setFollow(true);
|
|
||||||
focusDemod->setTracking(true);
|
|
||||||
wxGetApp().getDemodMgr().setActiveDemodulator(focusDemod, false);
|
wxGetApp().getDemodMgr().setActiveDemodulator(focusDemod, false);
|
||||||
}
|
}
|
||||||
} catch (DataInvalidChildException &e) {
|
} catch (DataInvalidChildException &e) {
|
||||||
|
@ -632,6 +632,13 @@ void CubicSDR::bindDemodulator(DemodulatorInstance *demod) {
|
|||||||
sdrPostThread->bindDemodulator(demod);
|
sdrPostThread->bindDemodulator(demod);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CubicSDR::bindDemodulators(std::vector<DemodulatorInstance *> *demods) {
|
||||||
|
if (!demods) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sdrPostThread->bindDemodulators(demods);
|
||||||
|
}
|
||||||
|
|
||||||
long long CubicSDR::getSampleRate() {
|
long long CubicSDR::getSampleRate() {
|
||||||
return sampleRate;
|
return sampleRate;
|
||||||
}
|
}
|
||||||
|
@ -115,6 +115,7 @@ public:
|
|||||||
SDRThread *getSDRThread();
|
SDRThread *getSDRThread();
|
||||||
|
|
||||||
void bindDemodulator(DemodulatorInstance *demod);
|
void bindDemodulator(DemodulatorInstance *demod);
|
||||||
|
void bindDemodulators(std::vector<DemodulatorInstance *> *demods);
|
||||||
void removeDemodulator(DemodulatorInstance *demod);
|
void removeDemodulator(DemodulatorInstance *demod);
|
||||||
|
|
||||||
void setFrequencySnap(int snap);
|
void setFrequencySnap(int snap);
|
||||||
|
@ -13,9 +13,17 @@
|
|||||||
bool demodFreqCompare (DemodulatorInstance *i, DemodulatorInstance *j) { return (i->getFrequency()<j->getFrequency()); }
|
bool demodFreqCompare (DemodulatorInstance *i, DemodulatorInstance *j) { return (i->getFrequency()<j->getFrequency()); }
|
||||||
bool inactiveCompare (DemodulatorInstance *i, DemodulatorInstance *j) { return (i->isActive()<j->isActive()); }
|
bool inactiveCompare (DemodulatorInstance *i, DemodulatorInstance *j) { return (i->isActive()<j->isActive()); }
|
||||||
|
|
||||||
DemodulatorMgr::DemodulatorMgr() :
|
DemodulatorMgr::DemodulatorMgr() {
|
||||||
activeDemodulator(NULL), lastActiveDemodulator(NULL), activeVisualDemodulator(NULL), lastBandwidth(DEFAULT_DEMOD_BW), lastDemodType(
|
activeDemodulator = NULL;
|
||||||
DEFAULT_DEMOD_TYPE), lastSquelchEnabled(false), lastSquelch(-100), lastGain(1.0), lastMuted(false), lastDeltaLock(false) {
|
lastActiveDemodulator = NULL;
|
||||||
|
activeVisualDemodulator = NULL;
|
||||||
|
lastBandwidth = DEFAULT_DEMOD_BW;
|
||||||
|
lastDemodType = DEFAULT_DEMOD_TYPE;
|
||||||
|
lastSquelchEnabled = false;
|
||||||
|
lastSquelch = -100;
|
||||||
|
lastGain = 1.0;
|
||||||
|
lastMuted = false;
|
||||||
|
lastDeltaLock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorMgr::~DemodulatorMgr() {
|
DemodulatorMgr::~DemodulatorMgr() {
|
||||||
@ -23,26 +31,35 @@ DemodulatorMgr::~DemodulatorMgr() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorInstance *DemodulatorMgr::newThread() {
|
DemodulatorInstance *DemodulatorMgr::newThread() {
|
||||||
|
garbageCollect();
|
||||||
|
|
||||||
|
demods_busy.lock();
|
||||||
DemodulatorInstance *newDemod = new DemodulatorInstance;
|
DemodulatorInstance *newDemod = new DemodulatorInstance;
|
||||||
demods.push_back(newDemod);
|
|
||||||
|
|
||||||
std::stringstream label;
|
std::stringstream label;
|
||||||
label << demods.size();
|
label << demods.size();
|
||||||
newDemod->setLabel(label.str());
|
newDemod->setLabel(label.str());
|
||||||
|
|
||||||
|
demods.push_back(newDemod);
|
||||||
|
demods_busy.unlock();
|
||||||
|
|
||||||
return newDemod;
|
return newDemod;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorMgr::terminateAll() {
|
void DemodulatorMgr::terminateAll() {
|
||||||
while (demods.size()) {
|
while (demods.size()) {
|
||||||
|
demods_busy.lock();
|
||||||
DemodulatorInstance *d = demods.back();
|
DemodulatorInstance *d = demods.back();
|
||||||
demods.pop_back();
|
demods.pop_back();
|
||||||
|
demods_busy.unlock();
|
||||||
wxGetApp().removeDemodulator(d);
|
wxGetApp().removeDemodulator(d);
|
||||||
deleteThread(d);
|
deleteThread(d);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
|
std::vector<DemodulatorInstance *> &DemodulatorMgr::getDemodulators() {
|
||||||
|
demods_busy.lock();
|
||||||
|
demods_busy.unlock();
|
||||||
return demods;
|
return demods;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,6 +127,8 @@ DemodulatorInstance *DemodulatorMgr::getFirstDemodulator() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
||||||
|
demods_busy.lock();
|
||||||
|
|
||||||
std::vector<DemodulatorInstance *>::iterator i;
|
std::vector<DemodulatorInstance *>::iterator i;
|
||||||
|
|
||||||
i = std::find(demods.begin(), demods.end(), demod);
|
i = std::find(demods.begin(), demods.end(), demod);
|
||||||
@ -131,10 +150,13 @@ void DemodulatorMgr::deleteThread(DemodulatorInstance *demod) {
|
|||||||
|
|
||||||
demods_deleted.push_back(demod);
|
demods_deleted.push_back(demod);
|
||||||
|
|
||||||
|
demods_busy.unlock();
|
||||||
|
|
||||||
garbageCollect();
|
garbageCollect();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(long long freq, int bandwidth) {
|
std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(long long freq, int bandwidth) {
|
||||||
|
demods_busy.lock();
|
||||||
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
|
std::vector<DemodulatorInstance *> *foundDemods = new std::vector<DemodulatorInstance *>();
|
||||||
|
|
||||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||||
@ -150,12 +172,13 @@ std::vector<DemodulatorInstance *> *DemodulatorMgr::getDemodulatorsAt(long long
|
|||||||
foundDemods->push_back(testDemod);
|
foundDemods->push_back(testDemod);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
demods_busy.unlock();
|
||||||
|
|
||||||
return foundDemods;
|
return foundDemods;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
|
bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
|
||||||
|
demods_busy.lock();
|
||||||
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
for (int i = 0, iMax = demods.size(); i < iMax; i++) {
|
||||||
DemodulatorInstance *testDemod = demods[i];
|
DemodulatorInstance *testDemod = demods[i];
|
||||||
|
|
||||||
@ -166,10 +189,12 @@ bool DemodulatorMgr::anyDemodulatorsAt(long long freq, int bandwidth) {
|
|||||||
long long halfBuffer = bandwidth / 2;
|
long long halfBuffer = bandwidth / 2;
|
||||||
|
|
||||||
if ((freq <= (freqTest + ((testDemod->getDemodulatorType() != "LSB")?halfBandwidthTest:0) + halfBuffer)) && (freq >= (freqTest - ((testDemod->getDemodulatorType() != "USB")?halfBandwidthTest:0) - halfBuffer))) {
|
if ((freq <= (freqTest + ((testDemod->getDemodulatorType() != "LSB")?halfBandwidthTest:0) + halfBuffer)) && (freq >= (freqTest - ((testDemod->getDemodulatorType() != "USB")?halfBandwidthTest:0) - halfBuffer))) {
|
||||||
|
demods_busy.unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
demods_busy.unlock();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +231,7 @@ void DemodulatorMgr::setActiveDemodulator(DemodulatorInstance *demod, bool tempo
|
|||||||
|
|
||||||
activeDemodulator = demod;
|
activeDemodulator = demod;
|
||||||
|
|
||||||
garbageCollect();
|
// garbageCollect();
|
||||||
}
|
}
|
||||||
|
|
||||||
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
|
DemodulatorInstance *DemodulatorMgr::getActiveDemodulator() {
|
||||||
@ -222,6 +247,7 @@ DemodulatorInstance *DemodulatorMgr::getLastActiveDemodulator() {
|
|||||||
|
|
||||||
void DemodulatorMgr::garbageCollect() {
|
void DemodulatorMgr::garbageCollect() {
|
||||||
if (demods_deleted.size()) {
|
if (demods_deleted.size()) {
|
||||||
|
demods_busy.lock();
|
||||||
std::vector<DemodulatorInstance *>::iterator i;
|
std::vector<DemodulatorInstance *>::iterator i;
|
||||||
|
|
||||||
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
|
for (i = demods_deleted.begin(); i != demods_deleted.end(); i++) {
|
||||||
@ -232,9 +258,12 @@ void DemodulatorMgr::garbageCollect() {
|
|||||||
std::cout << "Garbage collected demodulator instance " << deleted->getLabel() << std::endl;
|
std::cout << "Garbage collected demodulator instance " << deleted->getLabel() << std::endl;
|
||||||
|
|
||||||
delete deleted;
|
delete deleted;
|
||||||
|
|
||||||
|
demods_busy.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
demods_busy.unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,5 +72,7 @@ private:
|
|||||||
bool lastMuted;
|
bool lastMuted;
|
||||||
bool lastDeltaLock;
|
bool lastDeltaLock;
|
||||||
|
|
||||||
|
std::mutex demods_busy;
|
||||||
|
|
||||||
std::map<std::string, ModemSettings> lastModemSettings;
|
std::map<std::string, ModemSettings> lastModemSettings;
|
||||||
};
|
};
|
||||||
|
@ -33,6 +33,18 @@ void SDRPostThread::bindDemodulator(DemodulatorInstance *demod) {
|
|||||||
busy_demod.unlock();
|
busy_demod.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDRPostThread::bindDemodulators(std::vector<DemodulatorInstance *> *demods) {
|
||||||
|
if (!demods) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
busy_demod.lock();
|
||||||
|
for (std::vector<DemodulatorInstance *>::iterator di = demods->begin(); di != demods->end(); di++) {
|
||||||
|
demodulators.push_back(*di);
|
||||||
|
doRefresh.store(true);
|
||||||
|
}
|
||||||
|
busy_demod.unlock();
|
||||||
|
}
|
||||||
|
|
||||||
void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
|
void SDRPostThread::removeDemodulator(DemodulatorInstance *demod) {
|
||||||
if (!demod) {
|
if (!demod) {
|
||||||
return;
|
return;
|
||||||
|
@ -13,6 +13,7 @@ public:
|
|||||||
~SDRPostThread();
|
~SDRPostThread();
|
||||||
|
|
||||||
void bindDemodulator(DemodulatorInstance *demod);
|
void bindDemodulator(DemodulatorInstance *demod);
|
||||||
|
void bindDemodulators(std::vector<DemodulatorInstance *> *demods);
|
||||||
void removeDemodulator(DemodulatorInstance *demod);
|
void removeDemodulator(DemodulatorInstance *demod);
|
||||||
|
|
||||||
void run();
|
void run();
|
||||||
|
@ -1554,7 +1554,7 @@ bool DataTree::SaveToFileXML(const std::string& filename) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
bool DataTree::SaveToFile(const std::string& filename, bool compress, int /* compress_level */) {
|
bool DataTree::SaveToFile(const std::string& filename, bool compress, int /* compress_level */) {
|
||||||
long dataSize, compressedSize, headerSize;
|
long dataSize, compressedSize = 0, headerSize;
|
||||||
char *serialized = nullptr, *hdr_serialized = nullptr, *compressed = nullptr;
|
char *serialized = nullptr, *hdr_serialized = nullptr, *compressed = nullptr;
|
||||||
DataTree dtHeader;
|
DataTree dtHeader;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user