dl-fldigi/src/main.cxx

451 wiersze
11 KiB
C++
Czysty Zwykły widok Historia

2007-06-22 22:10:49 +00:00
//
// Digital Modem Program for the Fast Light Toolkit
//
// Copyright W1HKJ, Dave Freese 2006
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 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
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA.
//
// Please report all bugs and problems to "w1hkj@w1hkj.com".
//
2007-07-21 12:15:41 +00:00
2007-10-08 06:59:57 +00:00
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdlib>
#include <getopt.h>
2007-07-21 12:15:41 +00:00
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
2007-06-22 22:10:49 +00:00
#include <FL/Fl_Shared_Image.H>
2007-06-22 22:25:46 +00:00
#ifdef PORTAUDIO
#include <portaudiocpp/PortAudioCpp.hxx>
#endif
2007-06-22 22:04:50 +00:00
#include "main.h"
#include "waterfall.h"
2007-06-22 22:10:49 +00:00
#include "fft.h"
2007-06-22 22:04:50 +00:00
#include "sound.h"
#include "complex.h"
#include "fl_digi.h"
#include "rigio.h"
#include "globals.h"
#include "psk.h"
#include "cw.h"
#include "mfsk.h"
#include "Config.h"
#include "configuration.h"
#include "macros.h"
#include "status.h"
#ifndef NOHAMLIB
#include "rigclass.h"
#endif
#include "rigsupport.h"
#include "log.h"
2007-09-19 00:45:42 +00:00
#include "qrunner.h"
2007-06-22 22:04:50 +00:00
using namespace std;
string scDevice = "/dev/dsp1";
char szHomedir[120] = "";
2007-06-22 22:10:49 +00:00
char szPskMailDir[120] = "";
string PskMailDir;
string PskMailFile;
2007-07-21 12:15:41 +00:00
string ArqFilename;
2007-06-22 22:04:50 +00:00
string HomeDir;
string xmlfname;
2007-06-22 22:25:46 +00:00
bool gmfskmail = false;
2007-06-22 22:04:50 +00:00
PTT *push2talk = (PTT *)0;
#ifndef NOHAMLIB
Rig *xcvr = (Rig *)0;
#endif
cLogfile *logfile = 0;;
cLogfile *Maillogfile = (cLogfile *)0;
FILE *server;
FILE *client;
2007-07-21 12:15:41 +00:00
bool mailserver = false, mailclient = false, arqmode = false;
2007-06-22 22:04:50 +00:00
extern void start_pskmail();
2007-07-21 12:15:41 +00:00
RXMSGSTRUC rxmsgst;
int rxmsgid = -1;
2007-06-22 22:04:50 +00:00
2007-07-21 12:15:41 +00:00
TXMSGSTRUC txmsgst;
int txmsgid = -1;
2007-06-22 22:25:46 +00:00
2007-10-08 06:59:57 +00:00
string option_help;
2007-06-22 22:04:50 +00:00
2007-08-14 13:44:14 +00:00
2007-10-08 06:59:57 +00:00
void arqchecks(void);
void generate_option_help(void);
int parse_args(int argc, char **argv, int& idx);
2007-07-21 12:15:41 +00:00
2007-09-19 00:45:42 +00:00
int main(int argc, char ** argv)
{
CREATE_THREAD_ID(); // only call this once
SET_THREAD_ID(FLMAIN_TID);
2007-10-06 15:04:10 +00:00
for (int i = 0; i < NUM_QRUNNER_THREADS; i++) {
2007-09-19 00:45:42 +00:00
cbq[i] = new qrunner(1);
cbq[i]->attach();
}
2007-07-21 12:15:41 +00:00
fl_filename_expand(szHomedir, 119, "$HOME/.fldigi/");
if (fl_filename_isdir(szHomedir) == 0)
HomeDir = "./";
else
HomeDir = szHomedir;
2007-10-08 06:59:57 +00:00
generate_option_help();
int arg_idx;
Fl::args(argc, argv, arg_idx, parse_args);
2007-07-21 12:15:41 +00:00
xmlfname = HomeDir;
xmlfname.append("rig.xml");
string lfname = HomeDir;
lfname.append("fldigi.log");
logfile = new cLogfile(lfname);
logfile->log_to_file_start();
arqchecks();
2007-06-22 22:10:49 +00:00
2007-09-19 00:45:42 +00:00
FL_LOCK_E(); // start the gui thread!!
2007-08-14 01:18:58 +00:00
Fl::visual(FL_RGB); // insure 24 bit color operation
2007-08-14 01:17:50 +00:00
2007-08-14 01:18:58 +00:00
// Fl::visual(FL_DOUBLE|FL_INDEX| FL_RGB);
2007-08-14 01:17:50 +00:00
2007-06-22 22:04:50 +00:00
fl_register_images();
2007-06-22 22:19:01 +00:00
Fl::set_fonts(0);
2007-06-22 22:25:46 +00:00
2007-06-22 22:04:50 +00:00
rigcontrol = createRigDialog();
2007-10-07 13:20:44 +00:00
progdefaults.readDefaultsXML();
2007-09-28 15:18:32 +00:00
progdefaults.testCommPorts();
2007-06-22 22:04:50 +00:00
create_fl_digi_main();
2007-06-22 22:24:50 +00:00
2007-06-22 22:04:50 +00:00
createConfig();
2007-09-28 15:18:32 +00:00
inpTTYdev->tooltip(progdefaults.strCommPorts.c_str());
inpRIGdev->tooltip(progdefaults.strCommPorts.c_str());
2007-06-22 22:04:50 +00:00
macros.loadDefault();
#ifndef NOHAMLIB
xcvr = new Rig();
#endif
push2talk = new PTT();
2007-10-01 02:27:09 +00:00
progdefaults.openDefaults();
2007-06-22 22:04:50 +00:00
2007-06-22 22:25:46 +00:00
#ifndef PORTAUDIO
2007-06-22 22:26:36 +00:00
scDevice = progdefaults.SCdevice;
2007-06-22 22:25:46 +00:00
#else
2007-06-22 22:26:36 +00:00
if (progdefaults.btnAudioIOis == 0)
scDevice = progdefaults.OSSdevice;
else if (progdefaults.btnAudioIOis == 1)
scDevice = progdefaults.PAdevice;
2007-06-22 22:25:46 +00:00
#endif
2007-06-22 22:26:36 +00:00
glob_t gbuf;
glob("/dev/dsp*", 0, NULL, &gbuf);
for (size_t i = 0; i < gbuf.gl_pathc; i++)
menuOSSDev->add(gbuf.gl_pathv[i]);
globfree(&gbuf);
2007-06-22 22:25:46 +00:00
#ifdef PORTAUDIO
2007-06-22 22:26:36 +00:00
portaudio::AutoSystem autoSys;
portaudio::System &sys = portaudio::System::instance();
for (portaudio::System::DeviceIterator idev = sys.devicesBegin();
idev != sys.devicesEnd(); ++idev) {
string s;
s.append(idev->hostApi().name()).append("/").append(idev->name());
string::size_type i = s.find('/') + 1;
// backslash-escape any slashes in the device name
while ((i = s.find('/', i)) != string::npos) {
s.insert(i, 1, '\\');
i += 2;
}
menuPADev->add(s.c_str());
}
btnAudioIO[1]->activate();
2007-06-22 22:25:46 +00:00
#endif
2007-06-22 22:26:36 +00:00
glob("/dev/mixer*", 0, NULL, &gbuf);
for (size_t i = 0; i < gbuf.gl_pathc; i++)
menuMix->add(gbuf.gl_pathv[i]);
globfree(&gbuf);
2007-06-22 22:25:46 +00:00
if (progdefaults.MXdevice == "") {
int n = 0;
progdefaults.MXdevice = "/dev/mixer";
if (sscanf(progdefaults.SCdevice.c_str(), "/dev/dsp%d", &n) == 1)
progdefaults.MXdevice += n;
menuMix->value(progdefaults.MXdevice.c_str());
}
2007-06-22 22:26:36 +00:00
resetMixerControls();
2007-06-22 22:25:46 +00:00
2007-06-22 22:04:50 +00:00
trx_start(scDevice.c_str());
progdefaults.initInterface();
2007-06-22 22:19:01 +00:00
progStatus.initLastState();
2007-07-21 12:15:41 +00:00
Fl::add_timeout(1.0, pskmail_loop);
2007-06-22 22:04:50 +00:00
2007-10-08 06:59:57 +00:00
fl_digi_main->show(argc, argv);
2007-08-14 13:44:14 +00:00
2007-09-19 00:45:42 +00:00
int ret = Fl::run();
2007-10-06 15:04:10 +00:00
for (int i = 0; i < NUM_QRUNNER_THREADS; i++)
2007-09-19 00:45:42 +00:00
cbq[i]->detach();
return ret;
2007-06-22 22:10:49 +00:00
}
2007-10-08 06:59:57 +00:00
void arqchecks()
{
txmsgid = msgget( (key_t) progdefaults.tx_msgid, 0666 );
fl_filename_expand(szPskMailDir, 119, "$HOME/pskmail.files/");
PskMailDir = szPskMailDir;
PskMailFile = PskMailDir;
PskMailFile += "PSKmailserver";
ifstream testFile;
testFile.open(PskMailFile.c_str());
if (testFile.is_open()) {
mailserver = true;
testFile.close();
} else {
PskMailFile = PskMailDir;
PskMailFile += "PSKmailclient";
testFile.open(PskMailFile.c_str());
if (testFile.is_open()) {
mailclient = true;
testFile.close();
} else {
PskMailDir = "./";
PskMailFile = PskMailDir;
PskMailFile += "PSKmailserver";
testFile.open(PskMailFile.c_str());
if (testFile.is_open()) {
mailserver = true;
testFile.close();
gmfskmail = true;
} else {
PskMailFile = PskMailDir;
PskMailFile += "PSKmailclient";
testFile.open(PskMailFile.c_str());
if (testFile.is_open()) {
mailclient = true;
testFile.close();
gmfskmail = true;
}
}
}
}
if (mailserver || mailclient) {
std::cout << "Starting pskmail transport layer" << std::endl; fflush(stdout);
string PskMailLogName = PskMailDir;
if (gmfskmail == true)
PskMailLogName += "gMFSK.log";
else
PskMailLogName += "mail-io.log";
Maillogfile = new cLogfile(PskMailLogName.c_str());
Maillogfile->log_to_file_start();
}
}
void generate_option_help(void) {
// is there a better way of enumerating schemes?
string schemes = "none";
const char *possible_schemes[] = { "plastic", "gtk+", 0 };
const char *old = Fl::scheme();
const char **s = possible_schemes;
while (*s) {
Fl::scheme(*s);
if (strcasecmp(*s, Fl::scheme()) == 0)
schemes.append(" ").append(*s);
s++;
}
Fl::scheme(old ? old : "none");
ostringstream help;
int width = 37;
help << "Usage:\n " << FLDIGI_NAME << " [option...]\n";
help << '\n' << FLDIGI_NAME << " options:\n"
<< setw(width) << setiosflags(ios::left)
<< " --config-dir DIRECTORY"
<< "Look for configuration files in DIRECTORY\n"
<< setw(width) << setiosflags(ios::left)
<< "" << "The default is: " << HomeDir << '\n'
<< setw(width) << setiosflags(ios::left)
<< " --rx-ipc-key KEY" << "Set the receive message queue key\n"
<< setw(width) << setiosflags(ios::left)
<< "" << "May be given in hex if prefixed with \"0x\"\n"
<< setw(width) << setiosflags(ios::left)
<< "" << "The default is: " << progdefaults.rx_msgid
<< " or 0x" << hex << progdefaults.rx_msgid << dec << '\n'
<< setw(width) << setiosflags(ios::left)
<< " --tx-ipc-key KEY" << "Set the transmit message queue key\n"
<< setw(width) << setiosflags(ios::left)
<< "" << "May be given in hex if prefixed with \"0x\"\n"
<< setw(width) << setiosflags(ios::left)
<< "" << "The default is: " << progdefaults.tx_msgid
<< " or 0x" << hex << progdefaults.tx_msgid << dec << '\n'
<< setw(width) << setiosflags(ios::left)
<< " --version" << "Print version information\n"
<< setw(width) << setiosflags(ios::left)
<< " --help" << "Print this option help\n";
// Fl::help looks ugly so we'll write our own
help << "\nFLTK options:\n"
<< setw(width) << setiosflags(ios::left)
<< " -bg COLOR, -background COLOR"
<< "Set the background color\n"
<< setw(width) << setiosflags(ios::left)
<< " -bg2 COLOR, -background2 COLOR"
<< "Set the secondary (text) background color\n"
<< setw(width) << setiosflags(ios::left)
<< " -di, -display DISPLAY"
<< "Set the X display to use\n"
<< setw(width) << setiosflags(ios::left)
<< "" << "DISPLAY format is ``host:n.n''\n"
<< setw(width) << setiosflags(ios::left)
<< " -dn, -dnd or -nodn, -nodnd"
<< "Enable or disable drag and drop copy and\n"
<< setw(width) << setiosflags(ios::left)
<< "" << "paste in text fields\n"
<< setw(width) << setiosflags(ios::left)
<< " -fg COLOR, -foreground COLOR"
<< "Set the foreground color\n"
<< setw(width) << setiosflags(ios::left)
<< " -g GEOMETRY, -geometry GEOMETRY"
<< "Set the initial window size and position\n"
<< setw(width) << setiosflags(ios::left)
<< "" << "GEOMETRY format is ``WxH+X+Y''\n"
<< setw(width) << setiosflags(ios::left)
<< " -i, -iconic"
<< "Start " << FLDIGI_NAME << " in iconified state\n"
<< setw(width) << setiosflags(ios::left)
<< " -k, -kbd or -nok, -nokbd"
<< "Enable or disable visible keyboard focus\n"
<< setw(width) << setiosflags(ios::left)
<< "" << "in non-text widgets\n"
<< setw(width) << setiosflags(ios::left)
<< " -na CLASSNAME, -name CLASSNAME"
<< "Set the window class to CLASSNAME\n"
<< setw(width) << setiosflags(ios::left)
<< " -s SCHEME, -scheme SCHEME"
<< "Set the widget scheme\n"
<< setw(width) << setiosflags(ios::left)
<< "" << "SCHEME can be one of: " << schemes << '\n'
<< setw(width) << setiosflags(ios::left)
<< " -ti WINDOWTITLE, -title WINDOWTITLE"
<< "Set the window title\n"
<< setw(width) << setiosflags(ios::left)
<< " -to, -tooltips or -not, -notooltips"
<< "Enable or disable tooltips\n";
option_help = help.str();
}
int parse_args(int argc, char **argv, int& idx)
{
size_t arg_size = strlen(argv[idx]);
if ( !(arg_size == 2 && argv[idx][0] == '-' ||
arg_size > 2 && argv[idx][1] == '-') )
return 0;
const char shortopts[] = "+";
static struct option longopts[] = {
{ "rx-ipc-key", 1, 0, 'r' },
{ "tx-ipc-key", 1, 0, 't' },
{ "config-dir", 1, 0, 'c' },
{ "help", 0, 0, 'h' },
{ "version", 0, 0, 'v' },
{ 0 }
};
int longindex;
int c = getopt_long(argc - idx + 1, argv + idx - 1, shortopts, longopts, &longindex);
switch (c) {
case -1:
return 0;
case 0:
// handle options with non-0 flag here
return 0;
case 'r': case 't':
{
errno = 0;
int key = strtol(optarg, NULL, (strncasecmp(optarg, "0x", 2) ? 10 : 16));
if (errno || key <= 0)
cerr << "Hmm, " << key << " doesn't look like a valid IPC key\n";
if (c == 'r')
progdefaults.rx_msgid = key;
else
progdefaults.tx_msgid = key;
}
idx += 2;
return 2;
case 'c':
HomeDir = optarg;
if (*HomeDir.rbegin() != '/')
HomeDir += '/';
idx += 2;
return 2;
case 'h':
cerr << option_help;
exit(EXIT_SUCCESS);
case 'v':
cerr << FLDIGI_NAME << ' ' << FLDIGI_VERSION << '\n';
exit(EXIT_SUCCESS);
default:
break;
}
return 0;
}