Skip to content

Commit

Permalink
Fixed # 41 - Added Modes for Network Rig
Browse files Browse the repository at this point in the history
  • Loading branch information
foldynl committed Apr 12, 2022
1 parent a3441f0 commit 407f60c
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 20 deletions.
57 changes: 45 additions & 12 deletions core/Rig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ Rig* Rig::instance() {
return &instance;
}

bool Rig::isNetworkRig(const struct rig_caps *caps)
{
FCT_IDENTIFICATION;

bool ret = false;

if ( caps )
{
ret = caps->port_type == RIG_PORT_NETWORK
|| caps->port_type == RIG_PORT_UDP_NETWORK;
}

qCDebug(runtime) << ret;

return ret;
}

void Rig::start() {
FCT_IDENTIFICATION;

Expand Down Expand Up @@ -367,8 +384,7 @@ void Rig::__openRig()

rig_set_debug(RIG_DEBUG_BUG);

if (rig->caps->port_type == RIG_PORT_NETWORK
|| rig->caps->port_type == RIG_PORT_UDP_NETWORK )
if ( isNetworkRig(rig->caps) )
{
//handling Network Radio
strncpy(rig->state.rigport.pathname, newRigProfile.hostname.toLocal8Bit().constData(), HAMLIB_FILPATHLEN - 1);
Expand Down Expand Up @@ -534,33 +550,49 @@ QStringList Rig::getAvailableModes()
{
FCT_IDENTIFICATION;

QStringList modes;
QStringList modeList;

RigProfile newRigProfile = RigProfilesManager::instance()->getCurProfile1();

RIG *localRig = rig_init(newRigProfile.model);

if ( localRig )
{
rmode_t localRigModes = RIG_MODE_NONE;

if ( localRig->state.mode_list != RIG_MODE_NONE )
{
for (unsigned char i = 0; i < (sizeof(rmode_t)*8)-1; i++ ) /* hamlib 3.x and 4.x are very different - workaround */
localRigModes = localRig->state.mode_list;
}
else
{
if ( isNetworkRig(localRig->caps) )
{
const char *ms = rig_strrmode(static_cast<rmode_t>(localRig->state.mode_list & rig_idx2setting(i))); /* hamlib 3.x and 4.x are very different - workaround */
/* Network rig has no mode */
/* Add some modes */
localRigModes = (RIG_MODE_CW|RIG_MODE_SSB|RIG_MODE_FM|RIG_MODE_AM);
}
}

if (!ms || !ms[0])
{
continue; /* unknown, FIXME! */
}
qCDebug(runtime) << "Supported Mode :" << ms;
/* hamlib 3.x and 4.x are very different - workaround */
for (unsigned char i = 0; i < (sizeof(rmode_t)*8)-1; i++ )
{
/* hamlib 3.x and 4.x are very different - workaround */
const char *ms = rig_strrmode(static_cast<rmode_t>(localRigModes & rig_idx2setting(i)));

modes.append(QString(ms));
if (!ms || !ms[0])
{
continue;
}
qCDebug(runtime) << "Supported Mode :" << ms;

modeList.append(QString(ms));
}

rig_cleanup(localRig);
}

return modes;
return modeList;
}

Rig::Rig(QObject *parent) :
Expand All @@ -572,6 +604,7 @@ Rig::Rig(QObject *parent) :

rig = nullptr;
rig_set_debug(RIG_DEBUG_BUG);
rig_load_all_backends();
}

Rig::~Rig()
Expand Down
2 changes: 2 additions & 0 deletions core/Rig.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ class Rig : public SerialPort
public:
static Rig* instance();

static bool isNetworkRig(const struct rig_caps *caps);

public slots:
void start();
void update();
Expand Down
21 changes: 19 additions & 2 deletions core/Rotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ bool Rotator::isRotConnected()
return (rot) ? true : false;
}

bool Rotator::isNetworkRot(const rot_caps *caps)
{
FCT_IDENTIFICATION;

bool ret = false;

if ( caps )
{
ret = caps->port_type == RIG_PORT_NETWORK
|| caps->port_type == RIG_PORT_UDP_NETWORK;
}

qCDebug(runtime) << ret;

return ret;

}

void Rotator::start() {
FCT_IDENTIFICATION;

Expand Down Expand Up @@ -167,8 +185,7 @@ void Rotator::__openRot()
return;
}

if ( rot->caps->port_type == RIG_PORT_NETWORK
|| rot->caps->port_type == RIG_PORT_UDP_NETWORK )
if ( isNetworkRot(rot->caps) )
{
// handling network rotator
strncpy(rot->state.rotport.pathname, newRotProfile.hostname.toLocal8Bit().constData(), HAMLIB_FILPATHLEN - 1);
Expand Down
2 changes: 2 additions & 0 deletions core/Rotator.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class Rotator : public SerialPort
int getElevation();
bool isRotConnected();

static bool isNetworkRot(const struct rot_caps *caps);

signals:
void positionChanged(int azimuth, int elevation);
void rotErrorPresent(QString);
Expand Down
9 changes: 3 additions & 6 deletions ui/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,7 @@ void SettingsDialog::rigChanged(int index)

if ( caps )
{
if ( caps->port_type == RIG_PORT_NETWORK
|| caps->port_type == RIG_PORT_UDP_NETWORK)
if ( Rig::isNetworkRig(caps) )
{
ui->rigStackedWidget->setCurrentIndex(1);
}
Expand Down Expand Up @@ -820,8 +819,7 @@ void SettingsDialog::rotChanged(int index)

if ( caps )
{
if ( caps->port_type == RIG_PORT_NETWORK
|| caps->port_type == RIG_PORT_UDP_NETWORK)
if ( Rotator::isNetworkRot(caps) )
{
ui->rotStackedWidget->setCurrentIndex(1);
}
Expand Down Expand Up @@ -1211,8 +1209,7 @@ void SettingsDialog::fixRigCap(const struct rig_caps *caps)
* under Win / Lin / Mac , then I'll be happy to change it
*/

if ( (caps->port_type == RIG_PORT_NETWORK
|| caps->port_type == RIG_PORT_UDP_NETWORK)
if ( Rig::isNetworkRig(caps)
&& ( QString(hamlib_version).contains("4.2.")
|| QString(hamlib_version).contains("4.3.") ) )
{
Expand Down

0 comments on commit 407f60c

Please sign in to comment.