1 // ---------------------------------------------------------------------------- 2 // fsq.h -- FSQCALL compatible modem 3 // 4 // Copyright (C) 2006 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 _FSQ_H 24 #define _FSQ_H 25 26 #include <string> 27 #include <iostream> 28 #include <fstream> 29 30 #include "trx.h" 31 #include "modem.h" 32 #include "complex.h" 33 #include "filters.h" 34 #include "crc8.h" 35 #include "picture.h" 36 #include <FL/Fl_Shared_Image.H> 37 38 class fsq : public modem { 39 40 #define SR 12000 41 #define FFTSIZE 4096 42 #define FSQ_SYMLEN 4096 43 44 #define NUMBINS 144 // 200 //((FFTSIZE / 4) - 2) 45 46 #define BLOCK_SIZE FFTSIZE 47 #define SHIFT_SIZE (FSQ_SYMLEN / 16) 48 49 #define MOVAVGLIMIT 15 50 51 enum STATE {TEXT, IMAGE}; 52 53 friend void timed_xmt(void *); 54 friend void sounder(void *); 55 friend void aging(void *); 56 friend void fsq_add_tx_timeout(void *); 57 friend void fsq_stop_aging(); 58 friend void try_transmit(void *); 59 friend void fsq_transmit(void *); 60 61 public: 62 63 protected: 64 // Rx 65 double rx_stream[BLOCK_SIZE + SHIFT_SIZE]; 66 cmplx fft_data[2*FFTSIZE]; 67 double a_blackman[BLOCK_SIZE]; 68 double tones[NUMBINS]; 69 Cmovavg *binfilt[NUMBINS]; 70 int movavg_size; 71 int bkptr; 72 g_fft<double> *fft; 73 Cmovavg *snfilt; 74 Cmovavg *sigfilt; 75 Cmovavg *noisefilt; 76 Cmovavg *baudfilt; 77 double val; 78 double max; 79 double noise; 80 int peak; 81 int prev_peak; 82 int last_peak; 83 int peak_counter; 84 int peak_hits; 85 int symbol; 86 int prev_symbol; 87 int curr_nibble; 88 int prev_nibble; 89 int nibbles[199]; 90 void lf_check(int); 91 void process_symbol(int); 92 double s2n; 93 char szestimate[40]; 94 std::string rx_text; 95 std::string toprint; 96 int valid_callsign(std::string s); 97 void parse_rx_text(); 98 void parse_space(bool); 99 void parse_qmark(std::string relay = ""); 100 void parse_star(); 101 void parse_repeat(); 102 void parse_delayed_repeat(); 103 void parse_pound(std::string relay = ""); 104 void parse_dollar(std::string relay = ""); 105 void parse_at(std::string relay = ""); 106 void parse_amp(std::string relay = ""); 107 void parse_carat(std::string relay = ""); 108 void parse_pcnt(); 109 void parse_vline(std::string relay = ""); 110 void parse_greater(std::string relay = ""); 111 void parse_less(std::string relay = ""); 112 void parse_plus(std::string relay = ""); 113 void parse_minus(); 114 void parse_relay(); 115 void parse_relayed(); 116 117 bool b_bot; 118 bool b_eol; 119 bool b_eot; 120 121 // Tx 122 // C_FIR_filter *xmtfilt; 123 int tone; 124 int prevtone; 125 double txphase; 126 void send_string(std::string); 127 bool send_bot; 128 void flush_buffer (); 129 void send_char (int); 130 void send_idle (); 131 void send_symbol(int sym); 132 void send_tone(int tone); 133 void reply(std::string); 134 void delayed_reply(std::string, int delay); 135 void send_ack(std::string relay = ""); 136 137 // Sounder 138 double sounder_interval; 139 void start_sounder(int); // 0, 1, 2, 3 140 void stop_sounder(); 141 142 // Aging 143 void start_aging(); 144 void stop_aging(); 145 146 // RxTx 147 int fsq_frequency; // 0 / 1 148 int spacing; 149 int basetone; 150 int tx_basetone; 151 double speed; 152 double metric; 153 bool ch_sqlch_open; 154 CRC8 crc; 155 std::string station_calling; 156 std::string mycall; 157 std::string heard_log_fname; 158 std::string audit_log_fname; 159 std::ofstream heard_log; 160 std::ofstream audit_log; 161 162 void show_mode(); 163 void adjust_for_speed(); 164 void process_tones(); 165 166 void init_nibbles(); 167 168 void set_freq(double); 169 170 bool valid_char(int); 171 172 STATE state; 173 174 public: 175 fsq (trx_mode md); 176 ~fsq (); 177 void init (); 178 void rx_init (); 179 void restart (); 180 void tx_init (); 181 int rx_process (const double *buf, int len); 182 183 int tx_process (); 184 fsq_mycall()185 std::string fsq_mycall() { return mycall; } 186 187 bool fsq_squelch_open(); 188 189 static int symlen; 190 191 // support for fsq image transfers 192 private: 193 double amplitude; 194 double pixel; 195 unsigned char tx_pixel; 196 int tx_pixelnbr; 197 int image_mode; 198 199 public: 200 int byte; 201 double picf; 202 double picpeak; 203 204 C_FIR_filter *picfilter; 205 double phidiff; 206 double phase; 207 cmplx prevz; 208 cmplx currz; 209 210 double image_freq[10]; 211 int image_counter; 212 int picW; 213 int picH; 214 int row; 215 int col; 216 int rgb; 217 int pixelnbr; 218 int RXspp; 219 int TXspp; 220 void recvpic(double smpl); 221 void send_image(); 222 void fsq_send_image(std::string s); 223 224 void toggle_logs(); 225 }; 226 227 #endif 228