WSJT-X/rigclass.cpp

333 lines
8.1 KiB
C++
Raw Normal View History

Added audio channel support. Audio input can be mono, left of stereo pair or, right of stereo pair. Audio output can be mono, left of stereo pair, right of stereo pair or, both of stereo pair (the same output goes to both channels in both mode). Settings are remembered between sessions. Stream channel suport is implemented mainly in the new AudioDevice class which is now the base class of Modulator and Detector. Audio channels are selected on the configuration screen. Only supported channel configurations per device can be selected. Audio output volume (actually attenuation) is now possible from the GUI. I have added a slider control to the main window; I don't necessarily propose this as a final release location for the widget as I understand that changes to the main screen are sensitive. This location is just a starting suggestion for a trial. The volume (attenuation) setting is remembered between sessions and is not device dependent. This addresses all issues of volume setting on *nix versions since there is no need to use pavucontrol to set audio levels. The volume (attenuation) action is logarithmic. Shaped CW keying has been implemented in Modulator although it is currently disabled as I am not 100% happy wth the implementation. If you want to try it define the C++ preprocessor macro WSJT_SOFT_KEYING in your build. The Modulator instance has been moved to the same thread as the SoundOutput instance as it should have been since the output callback already operates in that thread. Cross thread slots are now correctly called in a thread safe way as a result. A number of files where in the SVN repository with DOS line endings which I have removed. SVN users on Windows need set the config for native line endings so that DOS line endings are automatically stripped on checkin. The DevSetup class now holds it's UI o the heap to reduce imapact on build dependencies. The application settings are now passed to objects from the main.cpp file. Management of settings are moved to the responsible classes (top level windows). This has involved a few settings moving groups so users will see some settings reverting to default values on the first run of an update. Persistance of top level windows geometry and position is now handled in the recommened manner (constructor for load, closeEvent for store in modal windows and, hideEvent for store in modeless dialogs). The MainWindow class now holds its children as members rather than global variables. The LogQSO class now hides its implementation and takes responsibility for its own settings and widows rendering parameters. A new settings file group is implemented to persist the LogQSO class settings. The WideGraph class now hides its implementation and manages its own settings and window rendering parameters. --This line, and those below, will be ignored-- M Modulator.cpp M rigclass.cpp M widegraph.cpp M signalmeter.cpp M soundin.cpp M soundout.cpp M mainwindow.h M main.cpp M meterwidget.h M devsetup.cpp M mainwindow.ui M Detector.cpp M logqso.h M rigclass.h M mainwindow.cpp M meterwidget.cpp M soundin.h M devsetup.ui M wsjtx.pro M devsetup.h M logqso.cpp M Modulator.hpp M psk_reporter.cpp M killbyname.cpp M Detector.hpp M signalmeter.h M widegraph.h M psk_reporter.h M soundout.h M PSKReporter.h M lib/afc65b.f90 M lib/gran.c M lib/usleep.c M lib/afc9.f90 M lib/wrapkarn.c A AudioDevice.hpp git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3542 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
2013-08-10 11:29:55 -04:00
/**
* \file src/rigclass.cc
* \brief Ham Radio Control Libraries C++ interface
* \author Stephane Fillod
* \date 2001-2003
*
* Hamlib C++ interface is a frontend implementing wrapper functions.
*/
/**
*
* Hamlib C++ bindings - main file
* Copyright (c) 2001-2003 by Stephane Fillod
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <hamlib/rig.h>
#include "rigclass.h"
#include <QDebug>
#include <QHostAddress>
#define NUMTRIES 5
static int hamlibpp_freq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg);
static int hamlibpp_freq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg)
{
if (!rig || !rig->state.obj)
return -RIG_EINVAL;
/* assert rig == ((Rig*)rig->state.obj).theRig */
return ((Rig*)rig->state.obj)->FreqEvent(vfo, freq, arg);
}
Rig::Rig()
{
rig_set_debug_level( RIG_DEBUG_WARN);
}
Rig::~Rig() {
theRig->state.obj = NULL;
rig_cleanup(theRig);
caps = NULL;
}
int Rig::init(rig_model_t rig_model)
{
int initOk;
theRig = rig_init(rig_model);
if (!theRig)
initOk = false;
else
initOk = true;
caps = theRig->caps;
theRig->callbacks.freq_event = &hamlibpp_freq_event;
theRig->state.obj = (rig_ptr_t)this;
return initOk;
}
int Rig::open(int n) {
m_hrd=false;
m_cmndr=false;
if(n<9900) {
if(n==-99999) return -1; //Silence compiler warning
return rig_open(theRig);
}
#ifdef WIN32 // Ham radio Deluxe or Commander (Windows only)
if(n==9999) {
m_hrd=true;
bool bConnect=false;
bConnect = HRDInterfaceConnect(L"localhost",7809);
if(bConnect) {
const wchar_t* context=HRDInterfaceSendMessage(L"Get Context");
m_context="[" + QString::fromWCharArray (context,-1) + "] ";
HRDInterfaceFreeString(context);
return 0;
} else {
m_hrd=false;
return -1;
}
}
if(n==9998) {
if(commanderSocket->state()==QAbstractSocket::ConnectedState) {
commanderSocket->abort();
}
if(commanderSocket->state()==QAbstractSocket::UnconnectedState) {
commanderSocket->connectToHost(QHostAddress::LocalHost, 52002);
if(!commanderSocket->waitForConnected(1000)) {
return -1;
}
}
QString t;
t="<command:10>CmdGetFreq<parameters:0>";
QByteArray ba = t.toLocal8Bit();
const char* buf=ba.data();
commanderSocket->write(buf);
commanderSocket->waitForReadyRead(1000);
QByteArray reply=commanderSocket->read(128);
if(reply.indexOf("<CmdFreq:")==0) {
m_cmndr=true;
return 0;
}
}
#endif
return -1;
}
int Rig::close(void) {
#ifdef WIN32 // Ham Radio Deluxe only on Windows
if(m_hrd) {
HRDInterfaceDisconnect();
return 0;
} else if(m_cmndr) {
commanderSocket->close();
return 0;
} else
#endif
{
return rig_close(theRig);
}
}
int Rig::setConf(const char *name, const char *val)
{
return rig_set_conf(theRig, tokenLookup(name), val);
}
int Rig::setFreq(freq_t freq, vfo_t vfo) {
#ifdef WIN32 // Ham Radio Deluxe (only on Windows)
if(m_hrd) {
QString t;
int nhz=(int)freq;
t=m_context + "Set Frequency-Hz " + QString::number(nhz);
const wchar_t* cmnd = (const wchar_t*) t.utf16();
const wchar_t* result=HRDInterfaceSendMessage(cmnd);
QString t2=QString::fromWCharArray (result,-1);
HRDInterfaceFreeString(result);
if(t2=="OK") {
return 0;
} else {
return -1;
}
} else if(m_cmndr) {
QString t;
double f=0.001*freq;
t.sprintf("<command:10>CmdSetFreq<parameters:23><xcvrfreq:10>%10.3f",f);
QLocale locale;
t.replace(".",locale.decimalPoint());
QByteArray ba = t.toLocal8Bit();
const char* buf=ba.data();
commanderSocket->write(buf);
commanderSocket->waitForBytesWritten(1000);
return 0;
} else
#endif
{
return rig_set_freq(theRig, vfo, freq);
}
}
int Rig::setXit(shortfreq_t xit, vfo_t vfo)
{
return rig_set_xit(theRig, vfo, xit);
}
int Rig::setVFO(vfo_t vfo)
{
return rig_set_vfo(theRig, vfo);
}
vfo_t Rig::getVFO()
{
vfo_t vfo;
rig_get_vfo(theRig, &vfo);
return vfo;
}
int Rig::setSplitFreq(freq_t tx_freq, vfo_t vfo) {
#ifdef WIN32 // Ham Radio Deluxe only on Windows
if(m_hrd) {
QString t;
int nhz=(int)tx_freq;
t=m_context + "Set Frequency-Hz " + QString::number(nhz);
const wchar_t* cmnd = (const wchar_t*) t.utf16();
const wchar_t* result=HRDInterfaceSendMessage(cmnd);
QString t2=QString::fromWCharArray (result,-1);
HRDInterfaceFreeString(result);
if(t2=="OK") {
return 0;
} else {
return -1;
}
} else if(m_cmndr) {
QString t;
double f=0.001*tx_freq;
t.sprintf("<command:12>CmdSetTxFreq<parameters:23><xcvrfreq:10>%10.3f",f);
QLocale locale;
t.replace(".",locale.decimalPoint());
QByteArray ba = t.toLocal8Bit();
const char* buf=ba.data();
commanderSocket->write(buf);
commanderSocket->waitForBytesWritten(1000);
return 0;
} else
#endif
{
return rig_set_split_freq(theRig, vfo, tx_freq);
}
}
freq_t Rig::getFreq(vfo_t vfo)
{
freq_t freq;
#ifdef WIN32 // Ham Radio Deluxe (only on Windows)
if(m_hrd) {
const wchar_t* cmnd = (const wchar_t*) (m_context+"Get Frequency").utf16();
const wchar_t* freqString=HRDInterfaceSendMessage(cmnd);
QString t2=QString::fromWCharArray (freqString,-1);
HRDInterfaceFreeString(freqString);
freq=t2.toDouble();
return freq;
} else if(m_cmndr) {
QString t;
t="<command:10>CmdGetFreq<parameters:0>";
QByteArray ba = t.toLocal8Bit();
const char* buf=ba.data();
commanderSocket->write(buf);
commanderSocket->waitForReadyRead(1000);
QByteArray reply=commanderSocket->read(128);
QString t2(reply);
if(t2.indexOf("<CmdFreq:")==0) {
int i1=t2.indexOf(">");
t2=t2.mid(i1+1).replace(",","");
freq=1000.0*t2.toDouble();
return freq;
} else {
return -1.0;
}
} else
#endif
{
freq=-1.0;
for(int i=0; i<NUMTRIES; i++) {
int iret=rig_get_freq(theRig, vfo, &freq);
if(iret==RIG_OK) break;
}
return freq;
}
}
int Rig::setMode(rmode_t mode, pbwidth_t width, vfo_t vfo) {
return rig_set_mode(theRig, vfo, mode, width);
}
rmode_t Rig::getMode(pbwidth_t& width, vfo_t vfo) {
rmode_t mode;
rig_get_mode(theRig, vfo, &mode, &width);
return mode;
}
int Rig::setPTT(ptt_t ptt, vfo_t vfo)
{
#ifdef WIN32 // Ham Radio Deluxe only on Windows
if(m_hrd) {
wchar_t* cmnd;
if(ptt==0) {
cmnd = (wchar_t*) (m_context +
"Set Button-Select TX 0").utf16();
} else {
cmnd = (wchar_t*) (m_context +
"Set Button-Select TX 1").utf16();
}
const wchar_t* result=HRDInterfaceSendMessage(cmnd);
QString t2=QString::fromWCharArray (result,-1);
HRDInterfaceFreeString(result);
if(t2=="OK") {
return 0;
} else {
return -1;
}
} else if(m_cmndr) {
QString t;
if(ptt==0) t="<command:5>CmdRX<parameters:0>";
if(ptt>0) t="<command:5>CmdTX<parameters:0>";
QByteArray ba = t.toLocal8Bit();
const char* buf=ba.data();
commanderSocket->write(buf);
commanderSocket->waitForBytesWritten(1000);
return 0;
} else
#endif
{
return rig_set_ptt(theRig, vfo, ptt);
}
}
ptt_t Rig::getPTT(vfo_t vfo)
{
ptt_t ptt;
rig_get_ptt(theRig, vfo, &ptt);
return ptt;
}
token_t Rig::tokenLookup(const char *name)
{
return rig_token_lookup(theRig, name);
}