1 // ----------------------------------------------------------------------------
2 // viewpsk.h  --  psk modem
3 //
4 // Copyright (C) 2008
5 //		Dave Freese, W1HKJ
6 //
7 // This file is part of fldigi.
8 //
9 // Fldigi is free software: you can redistribute it and/or modify
10 // it under the terms of the GNU General Public License as published by
11 // the Free Software Foundation, either version 3 of the License, or
12 // (at your option) any later version.
13 //
14 // Fldigi is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 // GNU General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with fldigi.  If not, see <http://www.gnu.org/licenses/>.
21 // ----------------------------------------------------------------------------
22 
23 #ifndef _VIEWPSK_H
24 #define _VIEWPSK_H
25 
26 #include "complex.h"
27 #include "modem.h"
28 #include "globals.h"
29 #include "filters.h"
30 #include "pskeval.h"
31 #include "viterbi.h"
32 #include "mfskvaricode.h"
33 #include "interleave.h"
34 
35 //=====================================================================
36 #define	VPSKSAMPLERATE	(8000)
37 #define VAFCDECAY 8
38 #define MAXCHANNELS 30
39 #define VSEARCHWIDTH 70
40 #define VSIGSEARCH 5
41 #define VWAITCOUNT 4
42 #define NULLFREQ 1e6
43 //=====================================================================
44 
45 struct CHANNEL {
46 	double			phaseacc;
47 	cmplx			prevsymbol;
48 	cmplx			quality;
49 	unsigned int	shreg;
50 	unsigned int	shreg2;
51 	double			metric;
52 
53 	double			frequency;
54 	double			freqerr;
55 	double			phase;
56 	double			syncbuf[16];
57 	double			averageamp;
58 
59 	C_FIR_filter	*fir1;
60 	C_FIR_filter	*fir2;
61 	viterbi 		*dec;
62 	viterbi			*dec2;
63 
64 	unsigned int 	bitshreg;
65 	int 			rxbitstate;
66 
67 	unsigned char	symbolpair[2];
68 	int				fecmet;
69 	int				fecmet2;
70 
71 	interleave		*Rxinlv;
72 	interleave		*Rxinlv2;
73 
74 	int				bits;
75 	double 			bitclk;
76 	unsigned int	dcdshreg;
77 	unsigned int	dcdshreg2;
78 	int 			dcd;
79 	int				waitcount;
80 	int				timeout;
81 	bool			reset;
82 	int				acquire;
83 
84 };
85 
86 class viewpsk {
87 
88 private:
89 	trx_mode	viewmode;
90 
91 	int			symbollen;
92 	int			symbits;
93 	double		bandwidth;
94 	int			dcdbits;
95 
96 	int			fa;
97 	int			fb;
98 	int			ftest;
99 	double		test_peak_amp;
100 	time_t		now;
101 	bool		reset_all;
102 	bool		tracked;
103 	bool		browser_changed;
104 
105 	CHANNEL		channel[MAXCHANNELS];
106 	int			nchannels;
107 	int			lowfreq;
108 
109 	bool		_pskr;
110 	bool		_qpsk;
111 
112 	pskeval*	evalpsk;
113 
114 	void		rx_symbol(int ch, cmplx symbol);
115 	void 		rx_bit(int ch, int bit);
116 	void		findsignal(int);
117 	void		afc(int);
118 
119 	void 		rx_bit2(int ch, int bit);
120 	void		rx_pskr(int ch, unsigned char symbol);
121 	void		rx_qpsk(int ch, int bits);
122 
123 	bool		is_valid_char(int &c);
124 
125 	inline void		timeout_check();
126 	inline void		insert();
127 
128 public:
129 	viewpsk(pskeval* eval, trx_mode mode);
130 	~viewpsk();
131 	void init();
132 	void restart(trx_mode mode);
rx_init()133 	void rx_init() {};
tx_init()134 	void tx_init() {};
restart()135 	void restart() {};
136 	int rx_process(const double *buf, int len);
137 	int get_freq(int n);
set_freq(int n,double f)138 	void set_freq(int n, double f) { channel[n].frequency = f; }
139 	void findsignals();
140 	void clearch(int n);
141 	void clear();
142 
143 };
144 
145 extern viewpsk *pskviewer;
146 
147 #endif
148