Scanning works now, like actually
This commit is contained in:
parent
9b7fa0f3e7
commit
9dbf2fb763
|
|
@ -102,12 +102,15 @@ void ScannerSM::ST_Scan(EventData* data){
|
|||
_currentContext.state = ScannerContext::SCAN;
|
||||
_manualMode = false;
|
||||
|
||||
// incremental scan pattern
|
||||
_entryCounter = (_entryCounter + 1) % _currentSystem->size();
|
||||
|
||||
if(currentState != lastState)
|
||||
_broadcastContextUpdate();
|
||||
|
||||
// incremental scan pattern
|
||||
if(!_squelchHits || (currentState != lastState)){
|
||||
_entryCounter = (_entryCounter + 1) % _currentSystem->size();
|
||||
|
||||
|
||||
|
||||
if(_entryCounter == 0){
|
||||
_sysCounter = (_sysCounter + 1) % _systems.size();
|
||||
|
||||
|
|
@ -121,12 +124,20 @@ void ScannerSM::ST_Scan(EventData* data){
|
|||
_currentEntry = _currentSystem->operator[](_entryCounter);
|
||||
CHECK_F(_currentEntry != NULL);
|
||||
|
||||
}
|
||||
|
||||
if(_currentEntry->hasSignal()){
|
||||
LOG_F(2, "Signal found: %s", _currentEntry->tag().c_str());
|
||||
InternalEvent(ST_RECEIVE);
|
||||
_squelchHits++;
|
||||
if(_squelchHits >= SQUELCH_TRIGGER_HITS){
|
||||
LOG_F(2, "Signal found: %s", _currentEntry->tag().c_str());
|
||||
InternalEvent(ST_RECEIVE);
|
||||
}
|
||||
else{
|
||||
InternalEvent(ST_SCAN);
|
||||
}
|
||||
}
|
||||
else{
|
||||
_squelchHits = 0;
|
||||
InternalEvent(ST_SCAN);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@
|
|||
#include "messages.h"
|
||||
#include "clientmessage.h"
|
||||
|
||||
#define SQUELCH_TRIGGER_HITS 10
|
||||
|
||||
namespace piscan {
|
||||
|
||||
class ScannerSM: public MessageReceiver, public StateMachine {
|
||||
|
|
@ -74,6 +76,8 @@ private:
|
|||
bool _manualMode = false;
|
||||
std::time_t timeoutStart = 0;
|
||||
|
||||
int _squelchHits = 0;
|
||||
|
||||
void _broadcastContextUpdate();
|
||||
void _enableAudioOut(bool en);
|
||||
void _handleRequest(ClientRequest& request);
|
||||
|
|
|
|||
|
|
@ -129,16 +129,13 @@ static int audioCallback(void *outputBuffer, void * /* inputBuffer */, unsigned
|
|||
//lock every single boundThread srcmix in succession the time we process
|
||||
//its audio samples.
|
||||
//std::lock_guard<std::recursive_mutex> lock(srcmix->getMutex());
|
||||
std::unique_lock<std::recursive_mutex> lock2(srcmix->getMutex(), std::defer_lock);
|
||||
|
||||
//this is hacky AF but whatever
|
||||
while(!lock2.try_lock())
|
||||
std::this_thread::yield();
|
||||
|
||||
if (srcmix->isTerminated() || !srcmix->inputQueue || srcmix->inputQueue->empty() || !srcmix->isActive()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
std::lock_guard<std::recursive_mutex> lock2(srcmix->getMutex());
|
||||
|
||||
if (!srcmix->currentInput) {
|
||||
srcmix->audioQueuePtr = 0;
|
||||
|
||||
|
|
|
|||
|
|
@ -88,12 +88,12 @@ void DemodulatorPreThread::run() {
|
|||
currentFrequency.store(newFrequency);
|
||||
frequencyChanged.store(false);
|
||||
|
||||
/*std::unique_lock<std::mutex> lock(_msgMutex, std::defer_lock);
|
||||
std::unique_lock<std::mutex> lock(_msgMutex, std::defer_lock);
|
||||
if(lock.try_lock()){
|
||||
_msgAvailable = true;
|
||||
lock.unlock();
|
||||
}
|
||||
_cv.notify_one();*/
|
||||
_cv.notify_one();
|
||||
}
|
||||
|
||||
if (inp->sampleRate != currentSampleRate) {
|
||||
|
|
@ -312,10 +312,10 @@ void DemodulatorPreThread::setFrequency(long long freq) {
|
|||
frequencyChanged.store(true);
|
||||
newFrequency = freq;
|
||||
|
||||
/*if(!stopping.load()){
|
||||
if(!stopping.load()){
|
||||
std::unique_lock<std::mutex> lock(_msgMutex);
|
||||
_cv.wait(lock, [this]{return this->_msgAvailable;});
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
long long DemodulatorPreThread::getFrequency() {
|
||||
|
|
|
|||
|
|
@ -383,8 +383,9 @@ int SDRThread::readStream(SDRThreadIQDataQueuePtr iqDataOutQueue) {
|
|||
readStreamCode = -31;
|
||||
//std::cout << "SDRThread::readStream(): 3.1 iqDataOutQueue output queue is full, discard processing of the batch..." << std::endl;
|
||||
if(!stopping.load()){
|
||||
if(++blocked_attempts >= 50)
|
||||
throw new std::runtime_error("SDRPostThread is blocked - deadlock");
|
||||
if(++blocked_attempts >= 50){
|
||||
ABORT_F("SDRPostThread is blocked - deadlock");
|
||||
}
|
||||
LOG_F(WARNING, "SDRThread::readStream(): 3.1 iqDataOutQueue output queue is full, discard processing of the batch...");
|
||||
}
|
||||
//saturation, let a chance to the other threads to consume the existing samples
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ void SentinelFile::_newAnalogEntry(std::vector<std::string>& tokens){
|
|||
|
||||
if(!mode.compare(SENTINEL_NFM) || !mode.compare(SENTINEL_FM) || !mode.compare(SENTINEL_AUTO)) {
|
||||
Entry* entry = new FMChannel(std::stoul(freq), tag,
|
||||
(!lockout.compare(SENTINEL_TRUE)), (!delay.compare(SENTINEL_TRUE)));
|
||||
(!lockout.compare(SENTINEL_TRUE)), (delay.compare("0")));
|
||||
_system->addEntry(entry);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,8 +104,8 @@ void Demodulator::start(){
|
|||
newDemod->setSquelchLevel(-100);
|
||||
newDemod->setMuted(true);
|
||||
newDemod->setOutputDevice(audiodev);
|
||||
newDemod->setFrequency(INIT_FREQUENCY);
|
||||
newDemod->run();
|
||||
newDemod->setFrequency(INIT_FREQUENCY);
|
||||
_demods[NFM] = newDemod;
|
||||
LOG_F(INFO, "Added modem NFM");
|
||||
|
||||
|
|
@ -153,20 +153,27 @@ void Demodulator::stop(){
|
|||
}
|
||||
|
||||
bool Demodulator::setFrequency(uint32_t freq) {
|
||||
if(freq == _demodMgr.getActiveContextModem()->getFrequency()){
|
||||
/*if(freq == _demodMgr.getCurrentModem()->getFrequency()){
|
||||
DLOG_F(9, "Frequency already set");
|
||||
return true;
|
||||
}*/
|
||||
|
||||
_demodMgr.getCurrentModem()->setFrequency(freq);
|
||||
|
||||
//TODO account for bandwidth
|
||||
if(std::abs(_cubic->getFrequency() - freq) >= (_cubic->getSampleRate() / 2)){
|
||||
_cubic->setFrequency(freq);
|
||||
//also arbitrary
|
||||
usleep(200000);
|
||||
}
|
||||
|
||||
_demodMgr.getActiveContextModem()->setFrequency(freq);
|
||||
//TODO account for bandwidth
|
||||
if(std::abs(_cubic->getFrequency() - _demodMgr.getActiveContextModem()->getFrequency()) >= (_cubic->getSampleRate() / 2))
|
||||
_cubic->setFrequency(freq);
|
||||
_demodMgr.getCurrentModem()->setFrequency(freq);
|
||||
//this is totally arbitrary
|
||||
usleep(1000);
|
||||
|
||||
_currentFreq = freq;
|
||||
|
||||
//this is totally arbitrary
|
||||
usleep(1000);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
@ -236,11 +243,17 @@ void Demodulator::_handleRequest(ClientRequest& request){
|
|||
break;
|
||||
case DEMOD_SET_GAIN:
|
||||
DCHECK_F(data != nullptr);
|
||||
//_tuner.setGain(*data);
|
||||
if (*data == AUTO_GAIN)
|
||||
|
||||
if (*data == AUTO_GAIN){
|
||||
_cubic->setAGCMode(true);
|
||||
|
||||
LOG_F(1, "Gain set to auto");
|
||||
else
|
||||
}
|
||||
else{
|
||||
_cubic->setAGCMode(false);
|
||||
_cubic->setGain("TUNER", *data);
|
||||
LOG_F(1, "Gain set to %i", *data);
|
||||
}
|
||||
_gain = *data;
|
||||
delete data;
|
||||
break;
|
||||
|
|
@ -251,7 +264,6 @@ void Demodulator::_handleRequest(ClientRequest& request){
|
|||
_contextUpdate();
|
||||
}
|
||||
else if(request.rqInfo.type == GET_CONTEXT){
|
||||
_gain = _cubic->getGain("TUNER");
|
||||
DemodContext* context = new DemodContext(_gain, _squelchLevel);
|
||||
request.connection->demodContextRequestCallback(request.rqHandle, context);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue