File: sdrinterface.h

package info (click to toggle)
cutesdr 1.20-4
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 2,848 kB
  • sloc: cpp: 18,902; makefile: 21; sh: 5
file content (239 lines) | stat: -rw-r--r-- 8,338 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
//////////////////////////////////////////////////////////////////////
// sdrinterface.h: interface for the CSdrInterface class.
//
// History:
//	2010-09-15  Initial creation MSW
//	2011-03-27  Initial release
//	2011-04-16  Added Frequency range logic for optional down converter modules
//	2011-08-07  Added WFM Support
/////////////////////////////////////////////////////////////////////
//==========================================================================================
// + + +   This Software is released under the "Simplified BSD License"  + + +
//Copyright 2010 Moe Wheatley. All rights reserved.
//
//Redistribution and use in source and binary forms, with or without modification, are
//permitted provided that the following conditions are met:
//
//   1. Redistributions of source code must retain the above copyright notice, this list of
//	  conditions and the following disclaimer.
//
//   2. Redistributions in binary form must reproduce the above copyright notice, this list
//	  of conditions and the following disclaimer in the documentation and/or other materials
//	  provided with the distribution.
//
//THIS SOFTWARE IS PROVIDED BY Moe Wheatley ``AS IS'' AND ANY EXPRESS OR IMPLIED
//WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
//FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Moe Wheatley OR
//CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
//CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
//SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
//ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
//NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
//ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//The views and conclusions contained in the software and documentation are those of the
//authors and should not be interpreted as representing official policies, either expressed
//or implied, of Moe Wheatley.
//=============================================================================
#ifndef SDRINTERFACE_H
#define SDRINTERFACE_H

#include "interface/netiobase.h"
#include "dsp/fft.h"
#include "interface/ad6620.h"
#include "dsp/demodulator.h"
#include "dsp/noiseproc.h"
#include "interface/soundout.h"
#include "interface/protocoldefs.h"
#include "interface/wavefilewriter.h"
#include "dataprocess.h"


#define RECORDMODE_AUDIO 0
#define RECORDMODE_IQ 1

#define PKT_LENGTH_TXMSG 16		//if msg is less than this then if TX control  msg

#define MSGFIFO_SIZE 8


/////////////////////////////////////////////////////////////////////
// Derived class from NetIOBase for all the custom SDR msg processing
/////////////////////////////////////////////////////////////////////
class CSdrInterface : public CNetio
{
	Q_OBJECT
public:
	CSdrInterface();
	~CSdrInterface();


	enum eRadioType {
		SDR14,
		SDRIQ,
		SDRIP,
		NETSDR,
		CLOUDSDR
	};
	//NCO spur management commands for ManageNCOSpurOffsets(...)
	enum eNCOSPURCMD {
		NCOSPUR_CMD_SET,
		NCOSPUR_CMD_STARTCAL,
		NCOSPUR_CMD_READ
	};

	void StopIO();	//stops IO threads

	// virtual functioncalled by TCP thread with new msg from radio to parse
	void ParseAscpMsg(CAscpRxMsg *pMsg);
	//virtual function called by UDP thread with new raw data to process
	void ProcessUdpData(char* pBuf, qint64 Length);
	//called by DataProcess thread with new I/Q data samples to process
	void ProcessIQData( TYPECPX* pIQData, int NumSamples);

	void StartSdr();
	void StopSdr();
	bool GetScreenIntegerFFTData(qint32 MaxHeight, qint32 MaxWidth,
									TYPEREAL MaxdB, TYPEREAL MindB,
									qint32 StartFreq, qint32 StopFreq,
									qint32* OutBuf );
	void ScreenUpdateDone(){m_ScreenUpateFinished = true;}
	void KeepAlive();
	void ManageNCOSpurOffsets( eNCOSPURCMD cmd, TYPEREAL* pNCONullValueI,  TYPEREAL* pNCONullValueQ);
	void SetRx2Parameters(TYPEREAL Rx2Gain, TYPEREAL Rx2Phase);

	//calls to these functions promt a signal in response
	void GetSdrInfo();
	void ReqStatus();
	quint64 SetRxFreq(quint64 freq);

	//bunch of public members containing sdr related information and data
	QString m_DeviceName;
	QString m_SerialNum;
	float m_BootRev;
	float m_AppRev;
	int m_MissedPackets;
	CAscpRxMsg m_TxAscpMsg[MSGFIFO_SIZE];
	int m_TxMsgFifoPtr;


	//GUI Public settings and access functions
	void SetRadioType(qint32 radiotype ){m_RadioType = (eRadioType)radiotype;}
	qint32 GetRadioType(){return (qint32)m_RadioType;}

	void SetSoundCardSelection(qint32 SoundInIndex, qint32 SoundOutIndex,bool StereoOut)
				{ m_pSoundCardOut->Stop(); m_SoundInIndex = SoundInIndex;
					m_SoundOutIndex = SoundOutIndex;  m_StereoOut = StereoOut;}

	int GetRateError(){return m_pSoundCardOut->GetRateError();}
	void SetVolume(qint32 vol){ m_pSoundCardOut->SetVolume(vol); }

	bool StartFileRecord(QString Filename, int RecordMode, qint64 CenterFreq);
	void StopFileRecord();

	void SetChannelMode(qint32 channelmode);

	void SetSdrRfGain(qint32 gain);
	qint32 GetSdrRfGain(){return m_RfGain;}

	void SetSdrBandwidthIndex(qint32 bwindex);
	TYPEREAL GetSdrSampleRate(){return m_SampleRate;}
	TYPEREAL GetSdrMaxBandwidth(){return m_SampleRate;}

	void SetFftSize(qint32 size);
	quint32 GetSdrFftSize(){return m_FftSize;}

	void SetFftAve(qint32 ave);
	quint32 GetSdrFftAve(){return m_FftAve;}

	qint32 GetMaxBWFromIndex(qint32 index);
	TYPEREAL GetSampleRateFromIndex(qint32 index);

	void SetMaxDisplayRate(int updatespersec){m_MaxDisplayRate = updatespersec;
							m_DisplaySkipValue = m_SampleRate/(m_FftSize*m_MaxDisplayRate);
							m_DisplaySkipCounter = 0; }

	void SetDemod(int Mode, tDemodInfo CurrentDemodInfo);
	void SetDemodFreq(qint64 Freq){m_Demodulator.SetDemodFreq((TYPEREAL)Freq);}

	void SetupNoiseProc(tNoiseProcdInfo* pNoiseProcSettings);

	TYPEREAL GetSMeterPeak(){return m_Demodulator.GetSMeterPeak();}
	TYPEREAL GetSMeterAve(){return m_Demodulator.GetSMeterAve();}

	void SetSpectrumInversion(bool Invert){m_InvertSpectrum = Invert;}
	void SetUSFmVersion(bool USFm){m_USFm = USFm;}
	bool GetUSFmVersion(){return m_USFm;}
	void SetPskMode(int Index);

	//access to WFM mode status/data
	int GetStereoLock(int* pPilotLock){ return m_Demodulator.GetStereoLock(pPilotLock);}
	int GetNextRdsGroupData(tRDS_GROUPS* pGroupData){return m_Demodulator.GetNextRdsGroupData(pGroupData);}


signals:
	void NewInfoData();			//emitted when sdr information is received after GetSdrInfo()
	void NewFftData();			//emitted when new FFT data is available
	void NewTxFiFoStatus(int BytesFree);		//emitted to tell Tx fifo buffer status
	void FreqChange(int freq);	//emitted if requested frequency has been clamped by radio
	void NewTxMsg(int FifoPtr);	//emitted when sdr tx msg is received from UDP

private:
	void SendAck(quint8 chan);
	void Start6620Download();
	void NcoSpurCalibrate(TYPECPX* pData, qint32 NumSamples);

	bool m_Running;
	bool m_ScreenUpateFinished;
	bool m_StereoOut;
	bool m_InvertSpectrum;
	bool m_USFm;
	bool m_FileRecordActive;
	bool m_24BitData;
	qint32 m_BandwidthIndex;
	qint32 m_DisplaySkipCounter;
	qint32 m_DisplaySkipValue;
	qint32 m_FftSize;
	qint32 m_FftAve;
	qint32 m_FftBufPos;
	qint32 m_KeepAliveCounter;
	qint32 m_MaxBandwidth;
	qint32 m_MaxDisplayRate;
	qint32 m_RfGain;
	qint32 m_SoundInIndex;
	qint32 m_SoundOutIndex;
	qint32 m_ChannelMode;
	qint32 m_RecordMode;

	quint8 m_Channel;
	quint64 m_CurrentFrequency;
	quint64 m_BaseFrequencyRangeMin;
	quint64 m_BaseFrequencyRangeMax;
	quint64 m_OptionFrequencyRangeMin;
	quint64 m_OptionFrequencyRangeMax;
	TYPEREAL m_SampleRate;
	TYPEREAL m_GainCalibrationOffset;
	TYPECPX m_DataBuf[MAX_FFT_SIZE];

	Cad6620 m_AD6620;
	eRadioType m_RadioType;

	bool m_NcoSpurCalActive;	//NCO spur reduction variables
	qint32 m_NcoSpurCalCount;
	TYPEREAL m_NCOSpurOffsetI;
	TYPEREAL m_NCOSpurOffsetQ;

	CFft m_Fft;
	CDemodulator m_Demodulator;
	CNoiseProc m_NoiseProc;
	CSoundOut* m_pSoundCardOut;
	CDataProcess* m_pdataProcess;
	CWaveFileWriter* m_pWaveFileWriter;

CIir m_Iir;

};



#endif // SDRINTERFACE_H