Skip to content

Commit

Permalink
Misc. enhancements (driven by RSPDuo support needs) (#786)
Browse files Browse the repository at this point in the history
* Add Device name in main window title bar

* Cleaner stopping of device in case of device loss
  • Loading branch information
vsonnier authored Feb 26, 2020
1 parent 9c32b97 commit d2f9333
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 15 deletions.
26 changes: 23 additions & 3 deletions src/AppFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,13 @@ bool AppFrame::actionOnMenuReset(wxCommandEvent& event) {
wxGetApp().getSpectrumProcessor()->setFFTAverageRate(0.65f);
spectrumAvgMeter->setLevel(0.65f);

SetTitle(CUBICSDR_TITLE);
wxString titleBar = CUBICSDR_TITLE;
//append the name of the current Device, if any.
if (wxGetApp().getDevice()) {
titleBar += " - " + wxGetApp().getDevice()->getName();
}

SetTitle(titleBar);
currentSessionFile = "";
currentBookmarkFile = "";
bookmarkSplitter->Unsplit(bookmarkView);
Expand Down Expand Up @@ -2642,7 +2648,14 @@ void AppFrame::saveSession(std::string fileName) {
currentSessionFile = fileName;
std::string filePart = fileName.substr(fileName.find_last_of(filePathSeparator) + 1);
GetStatusBar()->SetStatusText(wxString::Format(wxT("Saved session: %s"), currentSessionFile.c_str()));
SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str()));

wxString titleBar = CUBICSDR_TITLE;
//append the name of the current Device, if any.
if (wxGetApp().getDevice()) {
titleBar += " - " + wxGetApp().getDevice()->getName();
}
titleBar += ": " + filePart;
SetTitle(titleBar);
}

bool AppFrame::loadSession(std::string fileName) {
Expand Down Expand Up @@ -2677,7 +2690,14 @@ bool AppFrame::loadSession(std::string fileName) {
std::string filePart = fileName.substr(fileName.find_last_of(filePathSeparator) + 1);

GetStatusBar()->SetStatusText(wxString::Format(wxT("Loaded session file: %s"), currentSessionFile.c_str()));
SetTitle(wxString::Format(wxT("%s: %s"), CUBICSDR_TITLE, filePart.c_str()));

wxString titleBar = CUBICSDR_TITLE;
//append the name of the current Device, if any.
if (wxGetApp().getDevice()) {
titleBar += " - " + wxGetApp().getDevice()->getName();
}
titleBar += ": " + filePart;
SetTitle(titleBar);

wxGetApp().getBookmarkMgr().updateActiveList();

Expand Down
7 changes: 6 additions & 1 deletion src/forms/SDRDevices/SDRDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ SDRDevicesDialog::SDRDevicesDialog( wxWindow* parent, const wxPoint &pos): devFr
#elif _WIN32
SetIcon(wxICON(frame_icon));
#endif

}

void SDRDevicesDialog::OnClose( wxCloseEvent& /* event */) {
Expand Down Expand Up @@ -395,6 +394,12 @@ void SDRDevicesDialog::OnUseSelected( wxMouseEvent& event) {
wxGetApp().setDeviceArgs(settingArgs);
wxGetApp().setStreamArgs(streamArgs);
wxGetApp().setDevice(dev,0);

//update main application title with Device name:
wxString titleBar = CUBICSDR_TITLE;
titleBar += " - " + wxGetApp().getDevice()->getName();
wxGetApp().getAppFrame()->SetTitle(titleBar);

Close();
}
event.Skip();
Expand Down
52 changes: 42 additions & 10 deletions src/sdr/SoapySDRThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#include <SoapySDR/Logger.h>
#include <chrono>

#define TARGET_DISPLAY_FPS 60
#define TARGET_DISPLAY_FPS (60)
#define SDR_DEVICE_LOST (-666)

SDRThread::SDRThread() : IOThread(), buffers("SDRThreadBuffers") {
device = nullptr;
Expand Down Expand Up @@ -240,6 +241,7 @@ int SDRThread::readStream(SDRThreadIQDataQueuePtr iqDataOutQueue) {
}
} //end if numOverflow > 0

//default means blocking.
int readStreamCode = 0;

//2. attempt readStream() at most nElems, by mtElems-sized chunks, append in dataOut->data directly.
Expand All @@ -257,8 +259,29 @@ int SDRThread::readStream(SDRThreadIQDataQueuePtr iqDataOutQueue) {
break;
}
else if (n_stream_read < 0) {
std::cout << "SDRThread::readStream(): 2. SoapySDR read failed with code: " << n_stream_read << std::endl;
break;

//trace here interesting error codes from the Soapy side.
switch (n_stream_read) {

case SOAPY_SDR_TIMEOUT:
std::cout << "SDRThread::readStream(): 2. SoapySDR read failed with code SOAPY_SDR_TIMEOUT";
break;
case SOAPY_SDR_STREAM_ERROR:
std::cout << "SDRThread::readStream(): 2. SoapySDR read failed with code SOAPY_SDR_STREAM_ERROR";
break;

case SOAPY_SDR_CORRUPTION:
std::cout << "SDRThread::readStream(): 2. SoapySDR read failed with code SOAPY_SDR_CORRUPTION";
break;

case SOAPY_SDR_NOT_SUPPORTED:
//return a special code to mean that the device has to be stopped entirely:
std::cout << "SDRThread::readStream(): 2. SoapySDR read failed with code SOAPY_SDR_NOT_SUPPORTED => stopping device.";
readStreamCode = SDR_DEVICE_LOST;
break;
default:
std::cout << "SDRThread::readStream(): 2. SoapySDR read failed with unknown code: " << n_stream_read << std::endl;
}
}

//sucess read beyond nElems, so with overflow:
Expand Down Expand Up @@ -360,15 +383,15 @@ int SDRThread::readStream(SDRThreadIQDataQueuePtr iqDataOutQueue) {
if (!iqDataOutQueue->try_push(dataOut)) {
//The rest of the system saturates,
//finally the push didn't suceeded.
readStreamCode = -32;
readStreamCode = 0;
std::cout << "SDRThread::readStream(): 3.2 iqDataOutQueue output queue is full, discard processing of the batch..." << std::endl;

//saturation, let a chance to the other threads to consume the existing samples
std::this_thread::yield();
}
}
else {
readStreamCode = -31;
readStreamCode = 0;
std::cout << "SDRThread::readStream(): 3.1 iqDataOutQueue output queue is full, discard processing of the batch..." << std::endl;
//saturation, let a chance to the other threads to consume the existing samples
std::this_thread::yield();
Expand All @@ -388,13 +411,22 @@ void SDRThread::readLoop() {

updateGains();

while (!stopping.load()) {

updateSettings();
try {
while (!stopping.load()) {

readStream(iqDataOutQueue);
updateSettings();

} //End while
if (SDR_DEVICE_LOST == readStream(iqDataOutQueue)) {
//stop reading loop:
stopping = true;
}
} //End while
}
catch (...) {
//notify App of device loss:
std::cout << "SDRThread::readLoop() exception, stopping device..." << std::endl << std::flush;
stopping = true;
}

iqDataOutQueue->flush();
}
Expand Down
2 changes: 1 addition & 1 deletion src/sdr/SoapySDRThread.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SDRThread : public IOThread {
void deinit();

//returns the SoapyDevice readStream return value,
//i.e if >= 0 the numbre of samples read, else if < 0 an error code.
//i.e if >= 0 the number of samples read, else if < 0 an error code.
int readStream(SDRThreadIQDataQueuePtr iqDataOutQueue);

void readLoop();
Expand Down

0 comments on commit d2f9333

Please sign in to comment.