CubicSDR/src/CubicSDR.h

271 lines
7.6 KiB
C
Raw Normal View History

// Copyright (c) Charles J. Cliffe
// SPDX-License-Identifier: GPL-2.0+
#pragma once
//WX_GL_CORE_PROFILE 1
//WX_GL_MAJOR_VERSION 3
//WX_GL_MINOR_VERSION 2
#include <thread>
#include "GLExt.h"
#include "PrimaryGLContext.h"
#include "ThreadBlockingQueue.h"
#include "SoapySDRThread.h"
#include "SDREnumerator.h"
#include "SDRPostThread.h"
#include "AudioThread.h"
#include "DemodulatorMgr.h"
#include "AppConfig.h"
2015-05-04 19:44:03 -04:00
#include "AppFrame.h"
#include "FrequencyDialog.h"
#include "DemodLabelDialog.h"
#include "BookmarkMgr.h"
2019-01-30 23:24:33 -05:00
#include "SessionMgr.h"
2015-08-01 11:03:00 -04:00
#include "ScopeVisualProcessor.h"
#include "SpectrumVisualProcessor.h"
#include "SpectrumVisualDataThread.h"
#include "SDRDevices.h"
2015-11-17 00:21:17 -05:00
#include "Modem.h"
2015-11-18 23:06:21 -05:00
2015-11-17 00:21:17 -05:00
#include "ModemFM.h"
#include "ModemNBFM.h"
2015-11-17 00:21:17 -05:00
#include "ModemFMStereo.h"
2021-01-15 10:11:49 -05:00
#include "ModemCW.h"
2015-11-17 00:21:17 -05:00
#include "ModemAM.h"
#include "ModemUSB.h"
#include "ModemLSB.h"
#include "ModemDSB.h"
#include "ModemIQ.h"
#ifdef ENABLE_DIGITAL_LAB
2015-11-18 23:06:21 -05:00
#include "ModemAPSK.h"
#include "ModemASK.h"
#include "ModemBPSK.h"
#include "ModemDPSK.h"
#include "ModemFSK.h"
#include "ModemGMSK.h"
2015-11-18 23:06:21 -05:00
#include "ModemOOK.h"
#include "ModemPSK.h"
#include "ModemQAM.h"
#include "ModemQPSK.h"
#include "ModemSQAM.h"
#include "ModemST.h"
#endif
2015-11-18 23:06:21 -05:00
#ifdef USE_HAMLIB
class RigThread;
#endif
#include <wx/cmdline.h>
2014-12-08 02:16:06 -05:00
#define NUM_DEMODULATORS 1
std::string& filterChars(std::string& s, const std::string& allowed);
std::string frequencyToStr(long long freq);
long long strToFrequency(std::string freqStr);
class CubicSDR: public wxApp {
public:
2015-07-27 21:45:24 -04:00
CubicSDR();
PrimaryGLContext &GetContext(wxGLCanvas *canvas);
wxGLContextAttrs* GetContextAttributes();
bool OnInit() override;
int OnExit() override;
void OnInitCmdLine(wxCmdLineParser& parser) override;
bool OnCmdLineParsed(wxCmdLineParser& parser) override;
void deviceSelector();
void sdrThreadNotify(SDRThread::SDRThreadState state, const std::string& message);
void sdrEnumThreadNotify(SDREnumerator::SDREnumState state, std::string message);
void setFrequency(long long freq);
long long getFrequency();
2016-01-07 00:35:02 -05:00
void lockFrequency(long long freq);
bool isFrequencyLocked();
void unlockFrequency();
void setOffset(long long ofs);
long long getOffset();
void setAntennaName(const std::string& name);
const std::string& getAntennaName();
void setChannelizerType(SDRPostThreadChannelizerType chType);
SDRPostThreadChannelizerType getChannelizerType();
2015-01-11 17:08:16 -05:00
void setSampleRate(long long rate_in);
long long getSampleRate();
2015-01-12 00:40:43 -05:00
std::vector<SDRDeviceInfo *> *getDevices();
void setDevice(SDRDeviceInfo *dev, int waitMsForTermination);
void stopDevice(bool store, int waitMsForTermination);
SDRDeviceInfo * getDevice();
2015-01-12 00:40:43 -05:00
2015-08-01 11:03:00 -04:00
ScopeVisualProcessor *getScopeProcessor();
SpectrumVisualProcessor *getSpectrumProcessor();
SpectrumVisualProcessor *getDemodSpectrumProcessor();
2015-08-01 11:03:00 -04:00
DemodulatorThreadOutputQueuePtr getAudioVisualQueue();
DemodulatorThreadInputQueuePtr getIQVisualQueue();
DemodulatorThreadInputQueuePtr getWaterfallVisualQueue();
2018-03-20 15:00:59 -04:00
2014-12-10 21:22:13 -05:00
DemodulatorMgr &getDemodMgr();
BookmarkMgr &getBookmarkMgr();
2019-01-30 23:24:33 -05:00
SessionMgr &getSessionMgr();
SDRPostThread *getSDRPostThread();
2015-11-03 21:06:22 -05:00
SDRThread *getSDRThread();
void notifyDemodulatorsChanged();
void removeDemodulator(const DemodulatorInstancePtr& demod);
void setFrequencySnap(int snap_in);
int getFrequencySnap();
AppConfig *getConfig();
2015-04-22 22:54:48 -04:00
void saveConfig();
void setPPM(int ppm_in);
int getPPM();
void showFrequencyInput(FrequencyDialog::FrequencyDialogTarget targetMode = FrequencyDialog::FDIALOG_TARGET_DEFAULT, const wxString& initString = "");
void showLabelInput();
AppFrame *getAppFrame();
bool areDevicesReady();
bool areDevicesEnumerating();
bool areModulesMissing();
std::string getNotification();
void notifyMainUIOfDeviceChange(bool forceRefreshOfGains = false);
void addRemote(const std::string& remoteAddr);
void removeRemote(const std::string& remoteAddr);
void setDeviceSelectorClosed();
void reEnumerateDevices();
bool isDeviceSelectorOpen();
void closeDeviceSelector();
void setAGCMode(bool mode);
bool getAGCMode();
void setGain(const std::string& name, float gain_in);
float getGain(const std::string& name);
void setStreamArgs(SoapySDR::Kwargs streamArgs_in);
void setDeviceArgs(SoapySDR::Kwargs settingArgs_in);
bool getUseLocalMod();
std::string getModulePath();
void setActiveGainEntry(std::string gainName);
std::string getActiveGainEntry();
2016-02-11 01:09:15 -05:00
void setSoloMode(bool solo);
bool getSoloMode();
bool isShuttingDown();
2016-02-11 01:09:15 -05:00
#ifdef USE_HAMLIB
RigThread *getRigThread();
void initRig(int rigModel, std::string rigPort, int rigSerialRate);
void stopRig();
bool rigIsActive();
#endif
private:
int FilterEvent(wxEvent& event) override;
2016-02-07 18:01:11 -05:00
AppFrame *appframe = nullptr;
AppConfig config;
PrimaryGLContext *m_glContext = nullptr;
wxGLContextAttrs *m_glContextAttributes = nullptr;
std::vector<SDRDeviceInfo *> *devs = nullptr;
DemodulatorMgr demodMgr;
BookmarkMgr bookmarkMgr;
2019-01-30 23:24:33 -05:00
SessionMgr sessionMgr;
std::atomic_llong frequency;
std::atomic_llong offset;
std::atomic_int ppm, snap;
std::atomic_llong sampleRate;
std::string antennaName;
std::atomic_bool agcMode;
std::atomic_bool shuttingDown;
SDRThread *sdrThread = nullptr;
SDREnumerator *sdrEnum = nullptr;
SDRPostThread *sdrPostThread = nullptr;
SpectrumVisualDataThread *spectrumVisualThread = nullptr;
SpectrumVisualDataThread *demodVisualThread = nullptr;
SDRThreadIQDataQueuePtr pipeSDRIQData;
DemodulatorThreadInputQueuePtr pipeIQVisualData;
DemodulatorThreadOutputQueuePtr pipeAudioVisualData;
DemodulatorThreadInputQueuePtr pipeDemodIQVisualData;
DemodulatorThreadInputQueuePtr pipeWaterfallIQVisualData;
DemodulatorThreadInputQueuePtr pipeActiveDemodIQVisualData;
2015-08-01 11:03:00 -04:00
ScopeVisualProcessor scopeProcessor;
SDRDevicesDialog *deviceSelectorDialog = nullptr;
SoapySDR::Kwargs streamArgs;
SoapySDR::Kwargs settingArgs;
std::thread *t_SDR = nullptr;
std::thread *t_SDREnum = nullptr;
std::thread *t_PostSDR = nullptr;
std::thread *t_SpectrumVisual = nullptr;
std::thread *t_DemodVisual = nullptr;
std::atomic_bool devicesReady;
std::atomic_bool devicesFailed;
std::atomic_bool deviceSelectorOpen;
std::atomic_bool sampleRateInitialized;
std::atomic_bool useLocalMod;
std::string notifyMessage;
std::string modulePath;
std::mutex notify_busy;
2016-01-07 00:35:02 -05:00
std::atomic_bool frequency_locked;
std::atomic_llong lock_freq;
FrequencyDialog::FrequencyDialogTarget fdlgTarget;
std::string activeGain;
2016-02-11 01:09:15 -05:00
std::atomic_bool soloMode;
2016-02-28 23:16:56 -05:00
SDRDeviceInfo *stoppedDev;
#ifdef USE_HAMLIB
RigThread* rigThread = nullptr;
std::thread *t_Rig = nullptr;
#endif
2019-01-22 00:01:31 -05:00
void initAudioDevices() const;
};
static const wxCmdLineEntryDesc commandLineInfo [] =
{
{ wxCMD_LINE_SWITCH, "h", "help", "Command line parameter help", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
{ wxCMD_LINE_OPTION, "c", "config", "Specify a named configuration to use, i.e. '-c ham'", wxCMD_LINE_VAL_STRING, 0 },
{ wxCMD_LINE_OPTION, "m", "modpath", "Load modules from supplied path, i.e. '-m ~/SoapyMods/'", wxCMD_LINE_VAL_STRING, 0 },
#ifdef BUNDLE_SOAPY_MODS
{ wxCMD_LINE_SWITCH, "b", "bundled", "Use bundled SoapySDR modules first instead of local.", wxCMD_LINE_VAL_NONE, 0 },
#endif
{ wxCMD_LINE_NONE, nullptr, nullptr, nullptr, wxCMD_LINE_VAL_NONE, 0 }
};
DECLARE_APP(CubicSDR)