mirror of
https://github.com/cjcliffe/CubicSDR.git
synced 2024-09-27 15:56:48 -04:00
Error dialog feedback when rig thread exits unexpectedly.
This commit is contained in:
parent
4cc0958f7b
commit
7742646794
@ -2237,6 +2237,7 @@ void AppFrame::handleRigMenu() {
|
|||||||
if (rigEnableMenuItem->IsChecked()) {
|
if (rigEnableMenuItem->IsChecked()) {
|
||||||
if (!wxGetApp().rigIsActive()) {
|
if (!wxGetApp().rigIsActive()) {
|
||||||
rigEnableMenuItem->Check(false);
|
rigEnableMenuItem->Check(false);
|
||||||
|
wxGetApp().stopRig();
|
||||||
wxGetApp().getConfig()->setRigEnabled(false);
|
wxGetApp().getConfig()->setRigEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,6 +198,18 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class ActionDialogRigError : public ActionDialog {
|
||||||
|
public:
|
||||||
|
ActionDialogRigError(std::string message) : ActionDialog(wxGetApp().getAppFrame(), wxID_ANY, wxT("Rig Control Error")) {
|
||||||
|
m_questionText->SetLabelText(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
void doClickOK() {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
CubicSDR::CubicSDR() : frequency(0), offset(0), ppm(0), snap(1), sampleRate(DEFAULT_SAMPLE_RATE), agcMode(false)
|
CubicSDR::CubicSDR() : frequency(0), offset(0), ppm(0), snap(1), sampleRate(DEFAULT_SAMPLE_RATE), agcMode(false)
|
||||||
{
|
{
|
||||||
config.load();
|
config.load();
|
||||||
@ -1157,9 +1169,12 @@ void CubicSDR::stopRig() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rigThread) {
|
if (rigThread) {
|
||||||
|
|
||||||
rigThread->terminate();
|
rigThread->terminate();
|
||||||
rigThread->isTerminated(1000);
|
rigThread->isTerminated(1000);
|
||||||
|
|
||||||
|
if (rigThread->getErrorState()) {
|
||||||
|
ActionDialog::showDialog(new ActionDialogRigError(rigThread->getErrorMessage()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t_Rig && t_Rig->joinable()) {
|
if (t_Rig && t_Rig->joinable()) {
|
||||||
|
@ -14,6 +14,8 @@ RigThread::RigThread() {
|
|||||||
followMode.store(true);
|
followMode.store(true);
|
||||||
centerLock.store(false);
|
centerLock.store(false);
|
||||||
followModem.store(false);
|
followModem.store(false);
|
||||||
|
errorState.store(false);
|
||||||
|
errorMessage = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
RigThread::~RigThread() {
|
RigThread::~RigThread() {
|
||||||
@ -44,10 +46,70 @@ void RigThread::initRig(rig_model_t rig_model, std::string rig_file, int serial_
|
|||||||
serialRate = serial_rate;
|
serialRate = serial_rate;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void RigThread::setErrorStateFromHamlibCode(int errcode) {
|
||||||
|
errorState.store(true);
|
||||||
|
switch (abs(errcode)) {
|
||||||
|
case RIG_EINVAL:
|
||||||
|
errorMessage = "Invalid parameter specified.";
|
||||||
|
break; /*!< invalid parameter */
|
||||||
|
case RIG_ECONF:
|
||||||
|
errorMessage = "Invalid configuration i.e. serial, etc.";
|
||||||
|
break; /*!< invalid configuration (serial,..) */
|
||||||
|
case RIG_ENOMEM:
|
||||||
|
errorMessage = "Out of memory.";
|
||||||
|
break; /*!< memory shortage */
|
||||||
|
case RIG_ENIMPL:
|
||||||
|
errorMessage = "Function Not Yet Implemented.";
|
||||||
|
break; /*!< function not implemented, but will be */
|
||||||
|
case RIG_ETIMEOUT:
|
||||||
|
errorMessage = "Communication timed out.";
|
||||||
|
break; /*!< communication timed out */
|
||||||
|
case RIG_EIO:
|
||||||
|
errorMessage = "I/O error (Open failed?)";
|
||||||
|
break; /*!< IO error, including open failed */
|
||||||
|
case RIG_EINTERNAL:
|
||||||
|
errorMessage = "Internal hamlib error :(";
|
||||||
|
break; /*!< Internal Hamlib error, huh! */
|
||||||
|
case RIG_EPROTO:
|
||||||
|
errorMessage = "Protocol Error.";
|
||||||
|
break; /*!< Protocol error */
|
||||||
|
case RIG_ERJCTED:
|
||||||
|
errorMessage = "Command rejected by rig.";
|
||||||
|
break; /*!< Command rejected by the rig */
|
||||||
|
case RIG_ETRUNC:
|
||||||
|
errorMessage = "Argument truncated.";
|
||||||
|
break; /*!< Command performed, but arg truncated */
|
||||||
|
case RIG_ENAVAIL:
|
||||||
|
errorMessage = "Function not available.";
|
||||||
|
break; /*!< function not available */
|
||||||
|
case RIG_ENTARGET:
|
||||||
|
errorMessage = "VFO not targetable.";
|
||||||
|
break; /*!< VFO not targetable */
|
||||||
|
case RIG_BUSERROR:
|
||||||
|
errorMessage = "Error talking on the bus.";
|
||||||
|
break; /*!< Error talking on the bus */
|
||||||
|
case RIG_BUSBUSY:
|
||||||
|
errorMessage = "Collision on the bus.";
|
||||||
|
break; /*!< Collision on the bus */
|
||||||
|
case RIG_EARG:
|
||||||
|
errorMessage = "Invalid rig handle.";
|
||||||
|
break; /*!< NULL RIG handle or any invalid pointer parameter in get arg */
|
||||||
|
case RIG_EVFO:
|
||||||
|
errorMessage = "Invalid VFO.";
|
||||||
|
break; /*!< Invalid VFO */
|
||||||
|
case RIG_EDOM:
|
||||||
|
errorMessage = "Argument out of domain of function.";
|
||||||
|
break; /*!< Argument out of domain of func */
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "Rig error: " << errorMessage << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
void RigThread::run() {
|
void RigThread::run() {
|
||||||
int retcode, status;
|
int retcode, status;
|
||||||
|
|
||||||
termStatus = 0;
|
termStatus = 0;
|
||||||
|
errorState.store(0);
|
||||||
|
|
||||||
std::cout << "Rig thread starting." << std::endl;
|
std::cout << "Rig thread starting." << std::endl;
|
||||||
|
|
||||||
@ -57,7 +119,7 @@ void RigThread::run() {
|
|||||||
retcode = rig_open(rig);
|
retcode = rig_open(rig);
|
||||||
|
|
||||||
if (retcode != 0) {
|
if (retcode != 0) {
|
||||||
std::cout << "Rig failed to init. " << std::endl;
|
setErrorStateFromHamlibCode(retcode);
|
||||||
IOThread::terminate();
|
IOThread::terminate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -89,8 +151,12 @@ void RigThread::run() {
|
|||||||
freqChanged.store(false);
|
freqChanged.store(false);
|
||||||
setOneShot.store(false);
|
setOneShot.store(false);
|
||||||
} else {
|
} else {
|
||||||
termStatus = 0;
|
if (status == -RIG_ENIMPL) {
|
||||||
break;
|
std::cout << "Rig does not support rig_get_freq?" << std::endl;
|
||||||
|
} else {
|
||||||
|
termStatus = status;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
freq_t checkFreq;
|
freq_t checkFreq;
|
||||||
@ -111,7 +177,13 @@ void RigThread::run() {
|
|||||||
}
|
}
|
||||||
} else if (wxGetApp().getFrequency() != freq && controlMode.load() && !centerLock.load() && !followModem.load()) {
|
} else if (wxGetApp().getFrequency() != freq && controlMode.load() && !centerLock.load() && !followModem.load()) {
|
||||||
freq = wxGetApp().getFrequency();
|
freq = wxGetApp().getFrequency();
|
||||||
rig_set_freq(rig, RIG_VFO_CURR, freq);
|
status = rig_set_freq(rig, RIG_VFO_CURR, freq);
|
||||||
|
if (status == -RIG_ENIMPL) {
|
||||||
|
std::cout << "Rig does not support rig_set_freq?" << std::endl;
|
||||||
|
} else if (status != 0) {
|
||||||
|
termStatus = status;
|
||||||
|
break;
|
||||||
|
}
|
||||||
} else if (followModem.load()) {
|
} else if (followModem.load()) {
|
||||||
if (lastDemod) {
|
if (lastDemod) {
|
||||||
if (lastDemod->getFrequency() != freq) {
|
if (lastDemod->getFrequency() != freq) {
|
||||||
@ -122,8 +194,12 @@ void RigThread::run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
termStatus = 0;
|
if (status == -RIG_ENIMPL) {
|
||||||
break;
|
std::cout << "Rig does not support rig_get_freq?" << std::endl;
|
||||||
|
} else {
|
||||||
|
termStatus = status;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +212,11 @@ void RigThread::run() {
|
|||||||
|
|
||||||
rig_close(rig);
|
rig_close(rig);
|
||||||
rig_cleanup(rig);
|
rig_cleanup(rig);
|
||||||
|
|
||||||
|
if (termStatus != 0) {
|
||||||
|
setErrorStateFromHamlibCode(termStatus);
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << "Rig thread exiting status " << termStatus << "." << std::endl;
|
std::cout << "Rig thread exiting status " << termStatus << "." << std::endl;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -185,3 +265,12 @@ void RigThread::setFollowModem(bool mFollow) {
|
|||||||
bool RigThread::getFollowModem() {
|
bool RigThread::getFollowModem() {
|
||||||
return followModem.load();
|
return followModem.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool RigThread::getErrorState() {
|
||||||
|
return errorState.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string RigThread::getErrorMessage() {
|
||||||
|
return errorMessage;
|
||||||
|
}
|
@ -44,9 +44,15 @@ public:
|
|||||||
void setFollowModem(bool mFollow);
|
void setFollowModem(bool mFollow);
|
||||||
bool getFollowModem();
|
bool getFollowModem();
|
||||||
|
|
||||||
|
bool getErrorState();
|
||||||
|
std::string getErrorMessage();
|
||||||
|
|
||||||
static RigList &enumerate();
|
static RigList &enumerate();
|
||||||
static int add_hamlib_rig(const struct rig_caps *rc, void* f);
|
static int add_hamlib_rig(const struct rig_caps *rc, void* f);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setErrorStateFromHamlibCode(int errcode);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RIG *rig;
|
RIG *rig;
|
||||||
rig_model_t rigModel;
|
rig_model_t rigModel;
|
||||||
@ -57,5 +63,7 @@ private:
|
|||||||
freq_t newFreq;
|
freq_t newFreq;
|
||||||
std::atomic_bool freqChanged, setOneShot;
|
std::atomic_bool freqChanged, setOneShot;
|
||||||
std::atomic_bool controlMode, followMode, centerLock, followModem;
|
std::atomic_bool controlMode, followMode, centerLock, followModem;
|
||||||
|
std::atomic_bool errorState;
|
||||||
|
std::string errorMessage;
|
||||||
static RigList rigCaps;
|
static RigList rigCaps;
|
||||||
};
|
};
|
Loading…
Reference in New Issue
Block a user