1 /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3   Grig:  Gtk+ user interface for the Hamradio Control Libraries.
4 
5   Copyright (C)  2001-2007  Alexandru Csete.
6 
7   Authors: Alexandru Csete <oz9aec@gmail.com>
8 
9   Comments, questions and bugreports should be submitted via
10   http://sourceforge.net/projects/groundstation/
11   More details can be found at the project home page:
12 
13   http://groundstation.sourceforge.net/
14 
15   This program is free software; you can redistribute it and/or modify
16   it under the terms of the GNU General Public License as published by
17   the Free Software Foundation; either version 2 of the License, or
18   (at your option) any later version.
19 
20   This program is distributed in the hope that it will be useful,
21   but WITHOUT ANY WARRANTY; without even the implied warranty of
22   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23   GNU General Public License for more details.
24 
25   You should have received a copy of the GNU General Public License
26   along with this program; if not, visit http://www.fsf.org/
27 */
28 
29 /**** FIXME: Add support for double-reading of some values. For example,
30       ALC and RF power should support both meter reading as well
31       as setting
32 */
33 
34 
35 /**  \file    rig-data.h
36  *   \ingroup shdata
37  *   \brief   Data type definitions for shared rig data.
38  *
39  * This file containes the data type definitions for the shared rig data
40  * object.
41  *
42  * \bug packege is incomplete!
43  *
44  * \bug tx meter levels are not ok... need response from hamlib
45  */
46 
47 #ifndef RIG_DATA_H
48 #define RIG_DATA_H 1
49 
50 
51 #include <hamlib/rig.h>
52 
53 /** \brief Grig representation of passband widths.
54  *
55  * Grig has to keep it's own passband values due to the fact
56  * that the passband width is varying with the mode and the
57  * GUI is not supposed to poll hamlib in order to have the
58  * correct numerical value of the passband width. Therefore we
59  * use this representation and the daemon will convert it while
60  * talking to hamlib.
61  */
62 typedef enum rig_data_pbw_e {
63 	RIG_DATA_PB_WIDE = 0,   /**!< Passband corresponding to wide */
64 	RIG_DATA_PB_NORMAL,     /**!< Passband corresponding to normal */
65 	RIG_DATA_PB_NARROW      /**!< Passband corresponding to narrow */
66 } rig_data_pbw_t;
67 
68 
69 /** \brief Structure representing rig settings
70  *
71  * This structure is used to hold rig settings (frequency, mode, vfo, etc).
72  * One structure holds the values commanded by the user while the other
73  * holds the actual settings obtained from the rig.
74  */
75 typedef struct {
76 	powerstat_t      pstat;    /*!< Power status (ON/OFF). */
77 	ptt_t            ptt;      /*!< PTT status (ON/OFF). */
78 	int              lock;     /*!< Dial lock rig_set_func */
79 	vfo_t            vfo;      /*!< VFO. */
80 	rmode_t          mode;     /*!< Mode. */
81 	rig_data_pbw_t   pbw;      /*!< Passband width. */
82 	freq_t           freq1;    /*!< Primary (working) frequency. */
83 	freq_t           freq2;    /*!< Secondary frequency. */
84 	shortfreq_t      rit;      /*!< RIT. */
85 	shortfreq_t      xit;      /*!< XIT. */
86 	int              agc;      /*!< AGC level. */
87 	int              att;      /*!< Attenuator. */
88 	int              preamp;   /*!< Pre-amplifier. */
89 	split_t          split;    /*!< Spit ON/OFF. */
90 	ant_t            antenna;  /*!< Antenna. */
91 
92 	/* R/W levels */
93 	float           afg;       /*!< AF gain */
94 	float           rfg;       /*!< RF gain */
95 	float           sql;       /*!< Squelch */
96 	int             ifs;       /*!< IF shitf in Hz */
97 	float           apf;       /*!< APF */
98 	float           nr;        /*!< Noise reduction */
99 	int             notch;     /*!< Notch freq */
100 	float           pbtin;     /*!< PBT in */
101 	float           pbtout;    /*!< PBT out */
102 	int             cwpitch;   /*!< CW pitch */
103 	int             keyspd;    /*!< keyer speed */
104 	int             bkindel;   /*!< break in delay in tens of dots :-L */
105 	float           balance;   /*!< balance */
106 	int             voxdel;    /*!< Vox delay tenth of sec */
107 	float           voxg;      /*!< Vox gain */
108 	float           antivox;   /*!< Antivox */
109 	float           micg;      /*!< Mic gain */
110 	float           comp;      /*!< Compression */
111 	float           power;     /*!< TX power. */
112 
113 	/* read only fields */
114 	int             strength;  /*!< Signal strength. */
115 	float           swr;       /*!< SWR. */
116 	float           alc;       /*!< ALC. */
117 
118 	/* func's */
119 	int             funcs[RIG_SETTING_MAX]; /*!< Func's */
120 
121 	/* write only fields */
122 	int             vfo_op_toggle;  /*!< Toggle VFO */
123 	int             vfo_op_copy;    /*!< Copy VFO */
124 	int             vfo_op_xchg;    /*!< Exchange VFO */
125 
126 	/* more or less constant values */
127 	freq_t          fmin;      /*!< Lower frequency limit for current mode. */
128 	freq_t          fmax;      /*!< Upper frequency limit for current mode. */
129 	shortfreq_t     fstep;     /*!< Smallest freqency step for current mode. */
130 	shortfreq_t     ritmax;    /*!< Absolute max RIT. */
131 	shortfreq_t     ritstep;   /*!< Smallest RIT step. */
132 	shortfreq_t     xitmax;    /*!< Absolute max XIT. */
133 	shortfreq_t     xitstep;   /*!< Smallest XIT step. */
134 	shortfreq_t     ifsmax;    /*!< Absolute max IF shift. */
135 	shortfreq_t     ifsstep;   /*!< Smallest IF shift step. */
136 	int             allmodes;  /*!< Bit field of all supported modes. */
137 	int             allantennas;/*!< Bit field of all supported antennas. */
138 } grig_settings_t;
139 
140 
141 typedef struct {
142 	int         pstat;
143 	int         ptt;
144 	int         lock;
145 	int         vfo;
146 	int         mode;
147 	int         pbw;
148 	int         freq1;
149 	int         freq2;
150 	int         rit;
151 	int         xit;
152 	int         agc;
153 	int         att;
154 	int         preamp;
155 	int         split;
156 	int         vfo_op_toggle;
157 	int         vfo_op_copy;
158 	int         vfo_op_xchg;
159 	int         antenna;
160 
161 	/* R/W levels */
162 	int         afg;       /*!< AF gain */
163 	int         rfg;       /*!< RF gain */
164 	int         sql;       /*!< Squelch */
165 	int         ifs;       /*!< IF shitf in Hz */
166 	int         apf;       /*!< APF */
167 	int         nr;        /*!< Noise reduction */
168 	int         notch;     /*!< Notch freq */
169 	int         pbtin;     /*!< PBT in */
170 	int         pbtout;    /*!< PBT out */
171 	int         cwpitch;   /*!< CW pitch */
172 	int         keyspd;    /*!< keyer speed */
173 	int         bkindel;   /*!< break in delay in tens of dots :-L */
174 	int         balance;   /*!< balance */
175 	int         voxdel;    /*!< Vox delay tenth of sec */
176 	int         voxg;      /*!< Vox gain */
177 	int         antivox;   /*!< Antivox */
178 	int         micg;      /*!< Mic gain */
179 	int         comp;      /*!< Compression */
180 	int         power;     /*!< TX power. */
181 
182 	/* read only fields */
183 	int         strength;
184 	int         swr;
185 	int         alc;
186 
187 	int         funcs[RIG_SETTING_MAX];
188 } grig_cmd_avail_t;
189 
190 
191 #define GRIG_LEVEL_RD (RIG_LEVEL_RFPOWER | RIG_LEVEL_AGC | RIG_LEVEL_SWR | RIG_LEVEL_ALC | \
192                        RIG_LEVEL_STRENGTH | RIG_LEVEL_ATT | RIG_LEVEL_PREAMP | \
193                        RIG_LEVEL_VOXDELAY | RIG_LEVEL_AF | RIG_LEVEL_RF | RIG_LEVEL_SQL | \
194                        RIG_LEVEL_IF | RIG_LEVEL_APF | RIG_LEVEL_NR | RIG_LEVEL_PBT_IN | \
195                        RIG_LEVEL_PBT_OUT | RIG_LEVEL_CWPITCH |          \
196                        RIG_LEVEL_MICGAIN | RIG_LEVEL_KEYSPD | RIG_LEVEL_NOTCHF | \
197                        RIG_LEVEL_COMP | RIG_LEVEL_BKINDL | RIG_LEVEL_BALANCE | \
198                        RIG_LEVEL_VOXGAIN | RIG_LEVEL_ANTIVOX)
199 
200 #define GRIG_LEVEL_WR (RIG_LEVEL_RFPOWER | RIG_LEVEL_AGC | RIG_LEVEL_ATT | RIG_LEVEL_PREAMP | \
201                        RIG_LEVEL_VOXDELAY | RIG_LEVEL_AF | RIG_LEVEL_RF | RIG_LEVEL_SQL | \
202                        RIG_LEVEL_IF | RIG_LEVEL_APF | RIG_LEVEL_NR | RIG_LEVEL_PBT_IN | \
203                        RIG_LEVEL_PBT_OUT | RIG_LEVEL_CWPITCH |          \
204                        RIG_LEVEL_MICGAIN | RIG_LEVEL_KEYSPD | RIG_LEVEL_NOTCHF | \
205                        RIG_LEVEL_COMP | RIG_LEVEL_BKINDL | RIG_LEVEL_BALANCE | \
206                        RIG_LEVEL_VOXGAIN | RIG_LEVEL_ANTIVOX)
207 
208 
209 #define GRIG_FUNC_RD (RIG_FUNC_LOCK)
210 #define GRIG_FUNC_WR (RIG_FUNC_LOCK)
211 
212 #define GRIG_VFO_OP  (RIG_OP_TOGGLE | RIG_OP_CPY | RIG_OP_XCHG)
213 
214 
215 /* init functions */
216 void rig_data_init        (void);
217 void rig_data_free        (void);
218 int  rig_data_initialized (void);
219 
220 /* init and get preamp, att and vfo data */
221 void rig_data_set_att_data     (int index, int data);
222 int  rig_data_get_att_data     (int index);
223 int  rig_data_get_att_index    (int data);
224 void rig_data_set_preamp_data  (int index, int data);
225 int  rig_data_get_preamp_data  (int index);
226 int  rig_data_get_preamp_index (int data);
227 int  rig_data_get_vfos         (void);
228 void rig_data_set_vfos         (int);
229 int  rig_data_get_all_modes    (void);
230 int  rig_data_get_all_antennas (void);
231 
232 
233 /* FIXME: group functions accoring to functionality */
234 
235 /* set functions */
236 void rig_data_set_pstat   (powerstat_t);
237 void rig_data_set_ptt     (ptt_t);
238 void rig_data_set_mode    (rmode_t);
239 void rig_data_set_pbwidth (rig_data_pbw_t);
240 void rig_data_set_freq    (int, freq_t);
241 void rig_data_set_rit     (shortfreq_t);
242 void rig_data_set_xit     (shortfreq_t);
243 void rig_data_set_agc     (int);
244 void rig_data_set_att     (int);
245 void rig_data_set_preamp  (int);
246 void rig_data_set_split   (int);
247 void rig_data_set_max_rfpwr (float);
248 void rig_data_set_antenna   (ant_t);
249 
250 
251 #define rig_data_set_freq1(x) (rig_data_set_freq(1,x))
252 #define rig_data_set_freq2(x) (rig_data_set_freq(2,x))
253 
254 /* get functions */
255 powerstat_t      rig_data_get_pstat    (void);
256 ptt_t            rig_data_get_ptt      (void);
257 rmode_t          rig_data_get_mode     (void);
258 rig_data_pbw_t   rig_data_get_pbwidth  (void);
259 freq_t           rig_data_get_freq     (int);
260 shortfreq_t      rig_data_get_rit      (void);
261 shortfreq_t      rig_data_get_xit      (void);
262 int              rig_data_get_agc      (void);
263 int              rig_data_get_att      (void);
264 int              rig_data_get_preamp   (void);
265 int              rig_data_get_strength (void);
266 float            rig_data_get_swr      (void);
267 freq_t           rig_data_get_fmin     (void);
268 freq_t           rig_data_get_fmax     (void);
269 shortfreq_t      rig_data_get_fstep    (void);
270 shortfreq_t      rig_data_get_ritmin   (void);
271 shortfreq_t      rig_data_get_ritmax   (void);
272 shortfreq_t      rig_data_get_ritstep  (void);
273 shortfreq_t      rig_data_get_xitmin   (void);
274 shortfreq_t      rig_data_get_xitmax   (void);
275 shortfreq_t      rig_data_get_xitstep  (void);
276 int              rig_data_get_split    (void);
277 float            rig_data_get_max_rfpwr (void);
278 ant_t            rig_data_get_antenna   (void);
279 
280 
281 /* has_get functions */
282 int   rig_data_has_get_pstat    (void);
283 int   rig_data_has_get_ptt      (void);
284 /* int   rig_data_has_get_mode     (void); */
285 /* int   rig_data_has_get_pbwidth  (void); */
286 int   rig_data_has_get_freq1     (void);
287 int   rig_data_has_get_freq2     (void);
288 int   rig_data_has_get_rit      (void);
289 int   rig_data_has_get_xit      (void);
290 int   rig_data_has_get_agc      (void);
291 int   rig_data_has_get_att      (void);
292 int   rig_data_has_get_preamp   (void);
293 int   rig_data_has_get_strength (void);
294 int   rig_data_has_get_swr      (void);
295 int   rig_data_has_get_split    (void);
296 
297 
298 /* has_set functions */
299 int   rig_data_has_set_pstat    (void);
300 int   rig_data_has_set_ptt      (void);
301 int   rig_data_has_set_freq1    (void);
302 int   rig_data_has_set_freq2    (void);
303 int   rig_data_has_set_rit      (void);
304 int   rig_data_has_set_xit      (void);
305 int   rig_data_has_set_att      (void);
306 int   rig_data_has_set_preamp   (void);
307 int   rig_data_has_set_split    (void);
308 
309 
310 
311 /* ALC */
312 float rig_data_get_alc      (void);
313 void  rig_data_set_alc      (float);
314 int   rig_data_has_get_alc  (void);
315 int   rig_data_has_set_alc  (void);
316 
317 
318 /* RF power */
319 int   rig_data_has_get_power    (void);
320 int   rig_data_has_set_power    (void);
321 float rig_data_get_power    (void);
322 void  rig_data_set_power   (float);
323 
324 
325 /* AF gain */
326 int   rig_data_has_get_afg (void);
327 int   rig_data_has_set_afg (void);
328 float rig_data_get_afg     (void);
329 void  rig_data_set_afg     (float afg);
330 
331 /* RF gain */
332 int   rig_data_has_get_rfg (void);
333 int   rig_data_has_set_rfg (void);
334 float rig_data_get_rfg     (void);
335 void  rig_data_set_rfg     (float rfg);
336 
337 /* SQL */
338 int   rig_data_has_get_sql (void);
339 int   rig_data_has_set_sql (void);
340 float rig_data_get_sql     (void);
341 void  rig_data_set_sql     (float sql);
342 
343 /* IF shift */
344 int   rig_data_has_get_ifs (void);
345 int   rig_data_has_set_ifs (void);
346 int   rig_data_get_ifs     (void);
347 void  rig_data_set_ifs     (int ifs);
348 shortfreq_t rig_data_get_ifsmax   (void);
349 shortfreq_t rig_data_get_ifsstep  (void);
350 
351 /* APF */
352 int   rig_data_has_get_apf (void);
353 int   rig_data_has_set_apf (void);
354 float rig_data_get_apf     (void);
355 void  rig_data_set_apf     (float apf);
356 
357 /* NR */
358 int   rig_data_has_get_nr (void);
359 int   rig_data_has_set_nr (void);
360 float rig_data_get_nr     (void);
361 void  rig_data_set_nr     (float nr);
362 
363 /* Notch */
364 int   rig_data_has_get_notch (void);
365 int   rig_data_has_set_notch (void);
366 int   rig_data_get_notch     (void);
367 void  rig_data_set_notch     (int notch);
368 
369 /* PBT in */
370 int   rig_data_has_get_pbtin (void);
371 int   rig_data_has_set_pbtin (void);
372 float rig_data_get_pbtin     (void);
373 void  rig_data_set_pbtin     (float pbt);
374 
375 /* PBT out */
376 int   rig_data_has_get_pbtout (void);
377 int   rig_data_has_set_pbtout (void);
378 float rig_data_get_pbtout     (void);
379 void  rig_data_set_pbtout     (float pbt);
380 
381 /* CW pitch */
382 int   rig_data_has_get_cwpitch (void);
383 int   rig_data_has_set_cwpitch (void);
384 int   rig_data_get_cwpitch     (void);
385 void  rig_data_set_cwpitch     (int cwp);
386 
387 /* keyer speed */
388 int   rig_data_has_get_keyspd (void);
389 int   rig_data_has_set_keyspd (void);
390 int   rig_data_get_keyspd     (void);
391 void  rig_data_set_keyspd     (int keyspd);
392 
393 /* break-in delay */
394 int   rig_data_has_get_bkindel (void);
395 int   rig_data_has_set_bkindel (void);
396 int   rig_data_get_bkindel     (void);
397 void  rig_data_set_bkindel     (int bkindel);
398 
399 /* balance */
400 int   rig_data_has_get_balance (void);
401 int   rig_data_has_set_balance (void);
402 float rig_data_get_balance     (void);
403 void  rig_data_set_balance     (float bal);
404 
405 /* VOX delay */
406 int   rig_data_has_get_voxdel (void);
407 int   rig_data_has_set_voxdel (void);
408 int   rig_data_get_voxdel     (void);
409 void  rig_data_set_voxdel     (int voxdel);
410 
411 /* VOX gain */
412 int   rig_data_has_get_voxg (void);
413 int   rig_data_has_set_voxg (void);
414 float rig_data_get_voxg     (void);
415 void  rig_data_set_voxg     (float voxg);
416 
417 /* anti VOX */
418 int   rig_data_has_get_antivox (void);
419 int   rig_data_has_set_antivox (void);
420 float rig_data_get_antivox     (void);
421 void  rig_data_set_antivox     (float antivox);
422 
423 /* MIC gain */
424 int   rig_data_has_get_micg (void);
425 int   rig_data_has_set_micg (void);
426 float rig_data_get_micg     (void);
427 void  rig_data_set_micg     (float micg);
428 
429 /* compression */
430 int   rig_data_has_get_comp (void);
431 int   rig_data_has_set_comp (void);
432 float rig_data_get_comp     (void);
433 void  rig_data_set_comp     (float comp);
434 
435 
436 /* func */
437 int   rig_data_has_get_func (setting_t func);
438 int   rig_data_has_set_func (setting_t func);
439 int   rig_data_get_func     (setting_t func);
440 void  rig_data_set_func     (setting_t func, int status);
441 
442 /* LOCK */
443 int  rig_data_has_set_lock (void);
444 int  rig_data_has_get_lock (void);
445 void rig_data_set_lock     (int lock);
446 int  rig_data_get_lock     (void);
447 
448 /* VFO TOGGLE */
449 int  rig_data_has_vfo_op_toggle (void);
450 void rig_data_vfo_op_toggle     (void);
451 
452 /* VFO COPY */
453 int  rig_data_has_vfo_op_copy (void);
454 void rig_data_vfo_op_copy     (void);
455 
456 /* VFO COPY */
457 int  rig_data_has_vfo_op_xchg (void);
458 void rig_data_vfo_op_xchg     (void);
459 
460 /* SET and GET VFO */
461 int   rig_data_has_get_vfo  (void);
462 int   rig_data_has_set_vfo  (void);
463 vfo_t rig_data_get_vfo      (void);
464 void  rig_data_set_vfo      (vfo_t);
465 
466 /* address acquisition functions */
467 grig_settings_t  *rig_data_get_get_addr     (void);
468 grig_settings_t  *rig_data_get_set_addr     (void);
469 grig_cmd_avail_t *rig_data_get_new_addr     (void);
470 grig_cmd_avail_t *rig_data_get_has_set_addr (void);
471 grig_cmd_avail_t *rig_data_get_has_get_addr (void);
472 
473 #endif
474