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
30
31 */
32
33 /** \file rig-daemon.c
34 * \ingroup rigd
35 * \brief Radio control interface to hamlib.
36 *
37 * This object is responsible for interfacing the Hamradio Control Libraries
38 * (hamlib).
39 *
40 * After initialization of the radio it starts a cyclic thread which will
41 * execute some pre-defined commands. Because some manufacturers discourage
42 * agressive polling while in TX mode, the daemon will only acquire very
43 * few things while in this mode.
44 *
45 * More about cycles and periods...
46 *
47 */
48 #include <gtk/gtk.h>
49 #include <glib/gi18n.h>
50 #include <hamlib/rig.h>
51 #include <string.h>
52 #include <stdlib.h>
53 #include "grig-config.h"
54 #include "grig-debug.h"
55 #include "rig-anomaly.h"
56 #include "rig-data.h"
57 #include "rig-gui-smeter.h"
58 #include "rig-daemon-check.h"
59 #include "rig-daemon.h"
60
61
62
63 RIG *myrig; /*!< The rig structure. We keep this public so GUI can access the info fields. */
64
65 //#define GRIG_DEBUG 1
66
67 #ifdef GRIG_DEBUG
68
69
70 static const rig_cmd_t DEF_RX_CYCLE[C_MAX_CMD_PER_CYCLE] = {
71 RIG_CMD_VFO_TOGGLE,
72 RIG_CMD_VFO_COPY,
73 RIG_CMD_VFO_XCHG,
74 RIG_CMD_SET_SPLIT,
75 RIG_CMD_GET_SPLIT,
76 RIG_CMD_NONE,
77 RIG_CMD_NONE,
78 RIG_CMD_NONE,
79 RIG_CMD_NONE,
80 RIG_CMD_NONE,
81 RIG_CMD_NONE,
82 RIG_CMD_NONE,
83 RIG_CMD_NONE,
84 RIG_CMD_NONE,
85 RIG_CMD_NONE,
86 RIG_CMD_NONE,
87 RIG_CMD_NONE,
88 RIG_CMD_NONE,
89 RIG_CMD_NONE,
90 RIG_CMD_NONE,
91 RIG_CMD_NONE,
92 RIG_CMD_NONE,
93 RIG_CMD_NONE,
94 RIG_CMD_NONE,
95 RIG_CMD_NONE,
96 RIG_CMD_NONE,
97 RIG_CMD_NONE,
98 RIG_CMD_NONE,
99 RIG_CMD_NONE,
100 RIG_CMD_NONE,
101 RIG_CMD_NONE,
102 RIG_CMD_NONE,
103 RIG_CMD_NONE,
104 RIG_CMD_NONE,
105 RIG_CMD_NONE,
106 RIG_CMD_NONE,
107 RIG_CMD_NONE,
108 RIG_CMD_NONE,
109 RIG_CMD_NONE,
110 RIG_CMD_NONE,
111 RIG_CMD_NONE,
112 RIG_CMD_NONE,
113 RIG_CMD_NONE,
114 RIG_CMD_NONE,
115 RIG_CMD_NONE,
116 RIG_CMD_NONE,
117 RIG_CMD_NONE,
118 RIG_CMD_NONE,
119 RIG_CMD_NONE,
120 RIG_CMD_NONE,
121 RIG_CMD_NONE,
122 RIG_CMD_NONE,
123 RIG_CMD_NONE,
124 RIG_CMD_NONE,
125 RIG_CMD_NONE,
126 RIG_CMD_NONE,
127 RIG_CMD_NONE,
128 RIG_CMD_NONE,
129 RIG_CMD_NONE,
130 RIG_CMD_NONE,
131 RIG_CMD_NONE,
132 RIG_CMD_NONE,
133 RIG_CMD_NONE,
134 RIG_CMD_NONE,
135 RIG_CMD_NONE,
136 RIG_CMD_NONE,
137 RIG_CMD_NONE,
138 RIG_CMD_NONE,
139 RIG_CMD_NONE,
140 RIG_CMD_NONE,
141 RIG_CMD_NONE,
142 RIG_CMD_NONE,
143 RIG_CMD_NONE,
144 RIG_CMD_NONE,
145 RIG_CMD_NONE,
146 RIG_CMD_NONE,
147 RIG_CMD_NONE,
148 RIG_CMD_NONE,
149 RIG_CMD_NONE,
150 RIG_CMD_NONE,
151 RIG_CMD_NONE,
152 RIG_CMD_NONE,
153 RIG_CMD_NONE,
154 RIG_CMD_NONE,
155 RIG_CMD_NONE,
156 RIG_CMD_NONE,
157 RIG_CMD_NONE,
158 RIG_CMD_NONE,
159 RIG_CMD_NONE,
160 RIG_CMD_NONE,
161 RIG_CMD_NONE,
162 RIG_CMD_NONE,
163 RIG_CMD_NONE,
164 RIG_CMD_NONE,
165 RIG_CMD_NONE,
166 RIG_CMD_NONE,
167 RIG_CMD_NONE,
168 RIG_CMD_NONE,
169 RIG_CMD_NONE,
170 RIG_CMD_NONE
171 };
172
173 #else
174
175 /** \brief Matrix defining the default RX cycle.
176 *
177 * More description of the idea.
178 *
179 */
180 static const rig_cmd_t DEF_RX_CYCLE[C_MAX_CMD_PER_CYCLE] = {
181 RIG_CMD_GET_STRENGTH,
182 RIG_CMD_SET_FREQ_1,
183 RIG_CMD_GET_FREQ_1,
184 RIG_CMD_SET_PSTAT,
185 RIG_CMD_GET_PSTAT,
186 RIG_CMD_SET_KEYSPD,
187 RIG_CMD_GET_KEYSPD,
188 RIG_CMD_SET_LOCK,
189 RIG_CMD_SET_AF,
190 RIG_CMD_GET_AF,
191 RIG_CMD_GET_STRENGTH,
192 RIG_CMD_SET_FREQ_1,
193 RIG_CMD_GET_FREQ_1,
194 RIG_CMD_SET_BKINDEL,
195 RIG_CMD_GET_BKINDEL,
196 RIG_CMD_SET_ATT,
197 RIG_CMD_GET_ATT,
198 RIG_CMD_SET_RIT,
199 RIG_CMD_GET_RIT,
200 RIG_CMD_SET_RF,
201 RIG_CMD_GET_RF,
202 RIG_CMD_GET_STRENGTH,
203 RIG_CMD_SET_FREQ_1,
204 RIG_CMD_GET_FREQ_1,
205 RIG_CMD_GET_LOCK,
206 RIG_CMD_SET_VFO,
207 RIG_CMD_GET_VFO,
208 RIG_CMD_SET_VOXDEL,
209 RIG_CMD_GET_VOXDEL,
210 RIG_CMD_SET_PTT,
211 RIG_CMD_GET_PTT,
212 RIG_CMD_SET_IFS,
213 RIG_CMD_GET_IFS,
214 RIG_CMD_SET_AF,
215 RIG_CMD_GET_AF,
216 RIG_CMD_GET_STRENGTH,
217 RIG_CMD_SET_FREQ_1,
218 RIG_CMD_GET_FREQ_1,
219 RIG_CMD_SET_VOXGAIN,
220 RIG_CMD_GET_VOXGAIN,
221 RIG_CMD_SET_AGC,
222 RIG_CMD_GET_AGC,
223 RIG_CMD_SET_SQL,
224 RIG_CMD_GET_SQL,
225 RIG_CMD_VFO_TOGGLE,
226 RIG_CMD_VFO_COPY,
227 RIG_CMD_VFO_XCHG,
228 RIG_CMD_GET_STRENGTH,
229 RIG_CMD_SET_FREQ_1,
230 RIG_CMD_GET_FREQ_1,
231 RIG_CMD_SET_ANTIVOX,
232 RIG_CMD_GET_ANTIVOX,
233 RIG_CMD_SET_PBT_IN,
234 RIG_CMD_GET_PBT_IN,
235 RIG_CMD_SET_PBT_OUT,
236 RIG_CMD_GET_PBT_OUT,
237 RIG_CMD_SET_AF,
238 RIG_CMD_GET_AF,
239 RIG_CMD_GET_STRENGTH,
240 RIG_CMD_SET_FREQ_1,
241 RIG_CMD_GET_FREQ_1,
242 RIG_CMD_SET_CW_PITCH,
243 RIG_CMD_GET_CW_PITCH,
244 RIG_CMD_SET_PREAMP,
245 RIG_CMD_GET_PREAMP,
246 RIG_CMD_SET_SPLIT,
247 RIG_CMD_GET_SPLIT,
248 RIG_CMD_SET_MICGAIN,
249 RIG_CMD_GET_MICGAIN,
250 RIG_CMD_GET_STRENGTH,
251 RIG_CMD_SET_FREQ_1,
252 RIG_CMD_GET_FREQ_1,
253 RIG_CMD_SET_MODE,
254 RIG_CMD_GET_MODE,
255 RIG_CMD_SET_BALANCE,
256 RIG_CMD_GET_BALANCE,
257 RIG_CMD_GET_STRENGTH,
258 RIG_CMD_SET_FREQ_1,
259 RIG_CMD_GET_FREQ_1,
260 RIG_CMD_SET_VFO,
261 RIG_CMD_GET_VFO,
262 RIG_CMD_SET_PTT,
263 RIG_CMD_GET_PTT,
264 RIG_CMD_SET_COMP,
265 RIG_CMD_GET_COMP,
266 RIG_CMD_VFO_TOGGLE,
267 RIG_CMD_VFO_COPY,
268 RIG_CMD_VFO_XCHG,
269 RIG_CMD_SET_AF,
270 RIG_CMD_GET_AF,
271 RIG_CMD_GET_STRENGTH,
272 RIG_CMD_SET_FREQ_1,
273 RIG_CMD_GET_FREQ_1,
274 RIG_CMD_SET_APF,
275 RIG_CMD_GET_APF,
276 RIG_CMD_SET_NR,
277 RIG_CMD_GET_NR,
278 RIG_CMD_SET_NOTCH,
279 RIG_CMD_GET_NOTCH,
280 RIG_CMD_SET_FUNC,
281 RIG_CMD_GET_FUNC
282 };
283
284 #endif
285
286
287 /** \brief Matrix defining the default TX cycle.
288 *
289 * More description.
290 *
291 * \note Some radios do not like being polled while in TX mode so
292 * we make TX cycle easy...
293 *
294 */
295 static const rig_cmd_t DEF_TX_CYCLE[C_MAX_CMD_PER_CYCLE] = {
296 RIG_CMD_SET_PTT,
297 RIG_CMD_SET_FREQ_1,
298 RIG_CMD_SET_POWER,
299 RIG_CMD_GET_POWER,
300 RIG_CMD_NONE,
301 RIG_CMD_NONE,
302 RIG_CMD_GET_SWR,
303 RIG_CMD_GET_ALC,
304 RIG_CMD_NONE,
305 RIG_CMD_SET_LOCK,
306 RIG_CMD_NONE,
307 RIG_CMD_NONE,
308 RIG_CMD_GET_PTT,
309 RIG_CMD_NONE,
310 RIG_CMD_NONE,
311 RIG_CMD_SET_POWER,
312 RIG_CMD_GET_POWER,
313 RIG_CMD_GET_SWR,
314 RIG_CMD_GET_PTT,
315 RIG_CMD_NONE,
316 RIG_CMD_SET_ALC,
317 RIG_CMD_GET_ALC,
318 RIG_CMD_GET_FREQ_1,
319 RIG_CMD_NONE,
320 RIG_CMD_NONE,
321 RIG_CMD_SET_POWER,
322 RIG_CMD_GET_PTT,
323 RIG_CMD_NONE,
324 RIG_CMD_GET_POWER,
325 RIG_CMD_GET_SWR,
326 RIG_CMD_GET_ALC,
327 RIG_CMD_NONE,
328 RIG_CMD_SET_PTT,
329 RIG_CMD_NONE,
330 RIG_CMD_GET_ALC,
331 RIG_CMD_GET_POWER,
332 RIG_CMD_GET_SWR,
333 RIG_CMD_NONE,
334 RIG_CMD_NONE,
335 RIG_CMD_GET_ALC,
336 RIG_CMD_NONE,
337 RIG_CMD_NONE,
338 RIG_CMD_SET_PTT,
339 RIG_CMD_SET_FREQ_1,
340 RIG_CMD_NONE,
341 RIG_CMD_NONE,
342 RIG_CMD_GET_ALC,
343 RIG_CMD_GET_POWER,
344 RIG_CMD_GET_SWR,
345 RIG_CMD_NONE,
346 RIG_CMD_NONE,
347 RIG_CMD_SET_MICGAIN,
348 RIG_CMD_GET_MICGAIN,
349 RIG_CMD_GET_PTT,
350 RIG_CMD_GET_POWER,
351 RIG_CMD_GET_SWR,
352 RIG_CMD_NONE,
353 RIG_CMD_NONE,
354 RIG_CMD_SET_FREQ_1,
355 RIG_CMD_GET_PTT,
356 RIG_CMD_NONE,
357 RIG_CMD_NONE,
358 RIG_CMD_GET_POWER,
359 RIG_CMD_NONE,
360 RIG_CMD_NONE,
361 RIG_CMD_GET_PTT,
362 RIG_CMD_GET_SWR,
363 RIG_CMD_NONE,
364 RIG_CMD_NONE,
365 RIG_CMD_GET_ALC,
366 RIG_CMD_NONE,
367 RIG_CMD_NONE,
368 RIG_CMD_SET_PTT,
369 RIG_CMD_SET_POWER,
370 RIG_CMD_NONE,
371 RIG_CMD_GET_FREQ_1,
372 RIG_CMD_NONE,
373 RIG_CMD_NONE,
374 RIG_CMD_GET_PTT,
375 RIG_CMD_GET_POWER,
376 RIG_CMD_GET_SWR,
377 RIG_CMD_NONE,
378 RIG_CMD_NONE,
379 RIG_CMD_GET_ALC,
380 RIG_CMD_GET_PTT,
381 RIG_CMD_NONE,
382 RIG_CMD_NONE,
383 RIG_CMD_SET_MICGAIN,
384 RIG_CMD_GET_MICGAIN,
385 RIG_CMD_GET_PTT,
386 RIG_CMD_GET_POWER,
387 RIG_CMD_GET_SWR,
388 RIG_CMD_NONE,
389 RIG_CMD_NONE,
390 RIG_CMD_SET_COMP,
391 RIG_CMD_GET_COMP
392 };
393
394
395 /** \brief Conversion table to convert rig error to string */
396 static const gchar *ERR_TO_STR[] = {
397 N_("No error"),
398 N_("Invalid parameter"),
399 N_("Invalid configuration"),
400 N_("Memory shortage"),
401 N_("Function not implemented"),
402 N_("Communication timed out"),
403 N_("I/O error"),
404 N_("Internal Hamlib error :-("),
405 N_("Protocol error"),
406 N_("Command rejected"),
407 N_("Command performed, but arg truncated"),
408 N_("Function not available"),
409 N_("VFO not targetable"),
410 N_("BUS error"),
411 N_("Collision on the bus"),
412 N_("NULL RIG handle or invalid pointer param"),
413 N_("Invalid VFO"),
414 N_("Argument out of domain")
415 };
416
417
418 static gboolean stopdaemon = FALSE; /*!< Used to signal the daemon thread that it should stop */
419 static gboolean daemonclear = FALSE; /*!< Used to signal back when daemon is finished */
420 static gint cmd_delay = 0; /*!< Delay between two RX commands TX = 3*RX */
421 static gint timeoutid = -1; /*!< The ID of the timeout callback when we don't use threads. */
422 static gboolean timeout_busy = FALSE; /*!< Flag used to avoid to callbacks at the same time. */
423 static gboolean suspended = FALSE; /*!< Flag indicating whether the daemon is susended or not. */
424
425 /* private function prototypes */
426 static void rig_daemon_post_init (gboolean, gboolean);
427 static gpointer rig_daemon_cycle (gpointer);
428 static gint rig_daemon_cycle_cb (gpointer);
429 static gint rig_daemon_exec_cmd (rig_cmd_t,
430 grig_settings_t *,
431 grig_settings_t *,
432 grig_cmd_avail_t *,
433 grig_cmd_avail_t *,
434 grig_cmd_avail_t *);
435
436
437
438 /** \brief Start radio control daemon.
439 * \param rignum The Hamlib ID of the radio (0 to use default).
440 * \param port The port device (NULL to use default).
441 * \param speed The serial speed (0 to use default).
442 * \param civaddr CIV address for ICOM rigs (NULL means no need to set conf).
443 * \param rigconf Additional config options necessary for some rigs.
444 * \param cmddel Delay between two RX commands.
445 * \param nothread Whether to use threads (FALSE) or just a timeout callback.
446 * \return 0 if the daemon has been initialized correctly.
447 *
448 * This function initializes the radio and starts the control daemon. The rignum
449 * parameter is the rig ID in hamlib.
450 *
451 * The \a rigconf parameter contains one or more configuration options that are
452 * necessary for some rigs. The syntax is param=value and if more than one config
453 * options are specified, they are separated by comma.
454 *
455 * \note The default port is /dev/ttyS0 for regular backends and localhost for RPC rig.
456 *
457 */
458 int
rig_daemon_start(int rigid,const gchar * port,int speed,const gchar * civaddr,const gchar * rigconf,gint cmddel,gboolean nothread,gboolean ptt,gboolean pstat)459 rig_daemon_start (int rigid,
460 const gchar *port,
461 int speed,
462 const gchar *civaddr,
463 const gchar *rigconf,
464 gint cmddel,
465 gboolean nothread,
466 gboolean ptt,
467 gboolean pstat)
468 {
469
470 gchar *rigport;
471 gint retcode;
472 gchar **confvec;
473 gchar **confent;
474 GError *err = NULL; /* used when starting daemon thread */
475 #if GLIB_CHECK_VERSION(2,32,0)
476 GThread* thread = NULL;
477 #endif
478
479
480 grig_debug_local (RIG_DEBUG_TRACE,
481 _("%s entered"),
482 __FUNCTION__);
483
484 /* in order to be sure that we have a sensible command delay
485 we set it already here
486 */
487 if (cmddel > 0) {
488 cmd_delay = cmddel;
489 }
490 else {
491 cmd_delay = C_DEF_RX_CMD_DELAY;
492 }
493
494
495 /* check if rig is already initialized */
496 if (myrig != NULL) {
497 return 1;
498 }
499
500 /* use dummy backend if no ID pecified */
501 if (!rigid) {
502 rigid = 1;
503 }
504
505 /* use default port, if none specified; localhost for RPC rig
506 first serial port otherwise.
507 */
508 if (port == NULL) {
509
510 if (rigid == 1901) {
511 rigport = g_strdup ("localhost");
512 }
513 else {
514 rigport = g_strdup ("/dev/ttyS0");
515 }
516 }
517 else {
518 rigport = g_strdup (port);
519 }
520
521
522 grig_debug_local (RIG_DEBUG_TRACE,
523 _("%s: Initializing rig (id=%d)"),
524 __FUNCTION__, rigid);
525
526 /* initilize rig */
527 myrig = rig_init (rigid);
528
529 if (myrig == NULL) {
530
531 grig_debug_local (RIG_DEBUG_ERR,
532 _("%s: Init failed; Hamlib returned NULL!"),
533 __FUNCTION__);
534
535 g_free (rigport);
536 return 1;
537 }
538
539 /* configure and open rig device */
540 strncpy (myrig->state.rigport.pathname, rigport, HAMLIB_FILPATHLEN);
541 g_free (rigport);
542
543 /* set speed if any special whishes */
544 if (speed) {
545 myrig->state.rigport.parm.serial.rate = speed;
546 }
547
548 if (civaddr) {
549 retcode = rig_set_conf (myrig, rig_token_lookup (myrig, "civaddr"), civaddr);
550 }
551
552 /* split conf parameter string; */
553 if (rigconf) {
554 guint i = 0;
555
556 confvec = g_strsplit (rigconf, ",", 0);
557
558 /* split each conf entity into param and val
559 and set conf
560 */
561 while (confvec[i]) {
562
563 confent = g_strsplit (confvec[i], "=", 2);
564
565 grig_debug_local (RIG_DEBUG_VERBOSE,
566 _("%s: Setting conf param (%s,%s)..."),
567 __FUNCTION__, confent[0], confent[1]);
568
569 retcode = rig_set_conf (myrig,
570 rig_token_lookup (myrig, confent[0]),
571 confent[1]);
572
573 if (retcode == RIG_OK) {
574 grig_debug_local (RIG_DEBUG_VERBOSE,
575 _("%s: Set conf OK"),
576 __FUNCTION__);
577 }
578 else {
579 grig_debug_local (RIG_DEBUG_VERBOSE,
580 _("%s: Set conf failed (%d)"),
581 __FUNCTION__, retcode);
582 }
583
584 i++;
585
586 g_strfreev (confent);
587 }
588
589 g_strfreev (confvec);
590 }
591
592
593 #ifndef DISABLE_HW
594 /* open rig */
595 retcode = rig_open (myrig);
596 if (retcode != RIG_OK) {
597
598 /* send error report */
599 grig_debug_local (RIG_DEBUG_ERR,
600 _("%s: Failed to open rig port %s: %s (permissions?)"),
601 __FUNCTION__,
602 myrig->state.rigport.pathname,
603 rigerror(retcode));
604
605 rig_cleanup (myrig);
606 return 1;
607 }
608 #endif
609
610 grig_debug_local (RIG_DEBUG_TRACE,
611 _("%s: Init successfull, executing post-init"),
612 __FUNCTION__);
613
614 /* get capabilities and settings */
615 rig_daemon_post_init (ptt, pstat);
616
617 grig_debug_local (RIG_DEBUG_TRACE,
618 _("%s: Starting rig daemon"),
619 __FUNCTION__);
620
621 #ifndef DISABLE_HW
622
623 /* if nothread flag is TRUE start a usual timeout, otherwise
624 fork a separate thread.
625 */
626 if (nothread == TRUE) {
627
628 /* we start a regular g_timeout;
629 we use C_MAX_CYCLES * C_MAX_CMD_PER_CYCLE * cmd_delay
630 for delay.
631 */
632 timeoutid = g_timeout_add (2 * C_MAX_CYCLES * C_MAX_CMD_PER_CYCLE * cmd_delay,
633 rig_daemon_cycle_cb,
634 NULL);
635
636 grig_debug_local (RIG_DEBUG_VERBOSE,
637 _("%s: Daemon timeout started, ID: %d"),
638 __FUNCTION__, timeoutid);
639
640 }
641 else {
642 #if !GLIB_CHECK_VERSION(2,32,0)
643 g_thread_create (rig_daemon_cycle, NULL, FALSE, &err);
644 #else
645 thread = g_thread_try_new ("daemon thread", rig_daemon_cycle, NULL, &err);
646 if (thread != NULL) {
647 g_thread_unref(thread);
648 }
649 #endif
650
651 /* check whether any error occurred when starting the daemon
652 thread; if yes, close rig and return with error code
653 (assuming that err->code will be non-zero)
654 */
655 if (err != NULL) {
656
657 grig_debug_local (RIG_DEBUG_ERR,
658 _("%s: Failed to start daemon thread"),
659 __FUNCTION__);
660 grig_debug_local (RIG_DEBUG_ERR,
661 _("%s: Error %d: %s"),
662 __FUNCTION__, err->code, err->message);
663
664 rig_close (myrig);
665 rig_cleanup (myrig);
666
667 return err->code;
668 }
669 else {
670 grig_debug_local (RIG_DEBUG_VERBOSE,
671 _("%s: Daemon thread started"),
672 __FUNCTION__);
673
674 }
675 }
676
677 #endif
678
679 return 0;
680 }
681
682
683
684 /** \brief Stop the radio control daemon.
685 *
686 * This function stops the radio control daemon and frees the resources used
687 * by the control process and backends.
688 */
689 void
rig_daemon_stop()690 rig_daemon_stop ()
691 {
692 guint i = 0;
693
694
695 /* send a debug message */
696 grig_debug_local (RIG_DEBUG_TRACE,
697 _("%s: Sending stop signal to rig daemon"),
698 __FUNCTION__);
699
700
701 /* if we are running in time-out mode
702 we can remove the callback directly here;
703 otherwise, send stop signal to daemon and
704 wait until 'daemonclear' flag is TRUE or
705 we time out (in case of time out we also send
706 and error message
707 */
708 if (timeoutid != -1) {
709 g_source_remove (timeoutid);
710 }
711 else {
712 stopdaemon = TRUE;
713
714 /* wait until flag is clear or we time out */
715 while ((daemonclear == FALSE) &&
716 (i*C_RIG_DAEMON_STOP_SLEEP_TIME < C_RIG_DAEMON_STOP_TIMEOUT)) {
717
718 i++;
719 g_usleep (C_RIG_DAEMON_STOP_SLEEP_TIME * 1000);
720 }
721
722 /* print an error message if the flag has not been cleared */
723 if (daemonclear == FALSE) {
724 g_print ("\n\nCRITICAL: Daemon process has not been shut down properly. "\
725 "You may have a zombie hanging around :-(\n\n");
726 }
727 }
728
729 /* send a debug message */
730 grig_debug_local (RIG_DEBUG_TRACE,
731 _("%s: Cleaning up rig"),
732 __FUNCTION__);
733
734 #ifndef DISABLE_HW
735 /* close radio device */
736 rig_close (myrig);
737 #endif
738
739 /* clean up hamlib */
740 rig_cleanup (myrig);
741
742 myrig = NULL;
743 }
744
745
746 /** \brief Execute post initialization tasks.
747 * \param ptt Flag indicating whether to enable PTT.
748 * \param pstat Flag indicting whether to enable POWER.
749 *
750 * This function executes some tasks after initialization of the radio
751 * hardware. These include testing the radio capabilities and obtaining
752 * the current settings. The test results are communicated to the user
753 * via the rig_debug() Hamlib function.
754 *
755 */
756 static void
rig_daemon_post_init(gboolean ptt,gboolean pstat)757 rig_daemon_post_init (gboolean ptt, gboolean pstat)
758 {
759 grig_settings_t *get; /* pointer to shared data 'get' */
760 grig_settings_t *set; /* pointer to shared data 'set' */
761 grig_cmd_avail_t *has_get; /* pointer to shared data 'has_get' */
762 grig_cmd_avail_t *has_set; /* pointer to shared data 'has_set' */
763
764
765 /* get pointers to shared data */
766 get = rig_data_get_get_addr ();
767 set = rig_data_get_set_addr ();
768 has_get = rig_data_get_has_get_addr ();
769 has_set = rig_data_get_has_set_addr ();
770
771
772 /* check command availabilities */
773 if (pstat == TRUE) {
774 rig_daemon_check_pwrstat (myrig, get, has_get, has_set);
775 }
776 else {
777 has_get->pstat = FALSE;
778 has_set->pstat = FALSE;
779 get->pstat = RIG_POWER_ON;
780 set->pstat = RIG_POWER_ON;
781 }
782
783 if (ptt == TRUE) {
784 rig_daemon_check_ptt (myrig, get, has_get, has_set);
785 }
786 else {
787 has_get->ptt = FALSE;
788 has_set->ptt = FALSE;
789 get->ptt = RIG_PTT_OFF;
790 set->ptt = RIG_PTT_OFF;
791 }
792
793 rig_daemon_check_vfo (myrig, get, has_get, has_set);
794 rig_daemon_check_freq (myrig, get, has_get, has_set);
795 rig_daemon_check_rit (myrig, get, has_get, has_set);
796 rig_daemon_check_xit (myrig, get, has_get, has_set);
797 rig_daemon_check_mode (myrig, get, has_get, has_set);
798 rig_daemon_check_level (myrig, get, has_get, has_set);
799 rig_daemon_check_func (myrig, get, has_get, has_set);
800
801 /* debug info about detected has-get caps */
802 grig_debug_local (RIG_DEBUG_TRACE,
803 _("%s: GET bits: %d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d"),
804 __FUNCTION__,
805 has_get->pstat,
806 has_get->ptt,
807 has_get->att,
808 has_get->preamp,
809 has_get->vfo,
810 has_get->mode,
811 has_get->pbw,
812 has_get->freq1,
813 has_get->freq2,
814 has_get->rit,
815 has_get->xit,
816 has_get->agc,
817 has_get->power,
818 has_get->strength,
819 has_get->swr,
820 has_get->alc);
821
822 /*** FIXME: FUNC **/
823
824 /* debug info about detected has-set caps */
825 grig_debug_local (RIG_DEBUG_TRACE,
826 _("%s: SET bits: %d%d%d%d%d%d%d%d%d%d%d%d%dXXX"),
827 __FUNCTION__,
828 has_set->pstat,
829 has_set->ptt,
830 has_set->att,
831 has_set->preamp,
832 has_set->vfo,
833 has_set->mode,
834 has_set->pbw,
835 has_set->freq1,
836 has_set->freq2,
837 has_set->rit,
838 has_set->xit,
839 has_set->agc,
840 has_set->power
841 /* not settable
842 has_get->strength,
843 has_get->swr,
844 has_get->alc
845 */
846 );
847
848 }
849
850
851
852 /** \brief Radio control daemon main cycle (threaded version).
853 * \param data Unused.
854 * \return Always NULL.
855 *
856 * This function implements the main cycle of the radio control daemon. The executed
857 * commands are defined in the DEF_RX_CYCLE and DEF_TX_CYCLE constant arrays.
858 */
859 static gpointer
rig_daemon_cycle(gpointer data)860 rig_daemon_cycle (gpointer data)
861 {
862 grig_settings_t *get; /* pointer to shared data 'get' */
863 grig_settings_t *set; /* pointer to shared data 'set' */
864 grig_cmd_avail_t *new; /* pointer to shared data 'new' */
865 grig_cmd_avail_t *has_get; /* pointer to shared data 'has_get' */
866 grig_cmd_avail_t *has_set; /* pointer to shared data 'has_set' */
867
868 guint step; /* step counter */
869
870
871 /* get pointers to shared data */
872 get = rig_data_get_get_addr ();
873 set = rig_data_get_set_addr ();
874 new = rig_data_get_new_addr ();
875 has_get = rig_data_get_has_get_addr ();
876 has_set = rig_data_get_has_set_addr ();
877
878
879 /* send a debug message */
880 grig_debug_local (RIG_DEBUG_TRACE, _("%s started."), __FUNCTION__);
881
882 /* loop forever until reception of STOP signal */
883 while (stopdaemon == FALSE) {
884
885 /* first we check whether rig is powered ON since some rigs
886 will not talk to us in power-off tate.
887 NOTE: code should be safe even if rig does not support
888 get_powerstat since get->pstat is set to ON if rig
889 does not have functionality.
890 */
891 if (get->pstat == RIG_POWER_ON) {
892
893 /* execute one cylce; note that the switch between the
894 RX and TX tables can happen within a cycle :-)
895 */
896 for (step = 0; step < C_MAX_CMD_PER_CYCLE; step++) {
897
898 /* only execute commands if the daemon is not
899 suspended.
900 */
901 if (!suspended) {
902
903 /* check whether we are in RX or TX mode; */
904 if (get->ptt == RIG_PTT_OFF) {
905
906 /* Execute a receiver command */
907 rig_daemon_exec_cmd (DEF_RX_CYCLE[step],
908 get,
909 set,
910 new,
911 has_get,
912 has_set);
913 /* slow motion in debug mode */
914 #ifdef GRIG_DEBUG
915 g_usleep (5000 * cmd_delay);
916 #else
917 g_usleep (1000 * cmd_delay);
918 #endif
919 }
920 else {
921
922 /* Execute transmitter command */
923 rig_daemon_exec_cmd (DEF_TX_CYCLE[step],
924 get,
925 set,
926 new,
927 has_get,
928 has_set);
929 /* slow motion in debug mode */
930 #ifdef GRIG_DEBUG
931 g_usleep (15000 * cmd_delay);
932 #else
933 g_usleep (3000 * cmd_delay);
934 #endif
935 }
936 }
937
938 }
939
940 }
941
942 /* otherwise check the power status, but only if daemon
943 is not suspended */
944 else {
945 if (!suspended) {
946 rig_daemon_exec_cmd (RIG_CMD_SET_PSTAT,
947 get, set, new,
948 has_get, has_set);
949 /* slow motion in debug mode */
950
951 /* If the rig has been powered OFF, we only execute set_pstat in order
952 to be compatible with as many rigs as possible. Even like this, there
953 is no guarantee that the rig will react to a wake-up command.
954 */
955
956 /* #ifdef GRIG_DEBUG */
957 /* g_usleep (15000 * cmd_delay); */
958 /* #else */
959 /* g_usleep (3000 * cmd_delay); */
960 /* #endif */
961 /* rig_daemon_exec_cmd (RIG_CMD_GET_PSTAT, */
962 /* get, set, new, */
963 /* has_get, has_set); */
964 }
965
966 /* slow motion in debug mode */
967 #ifdef GRIG_DEBUG
968 g_usleep (15000 * cmd_delay);
969 #else
970 g_usleep (3000 * cmd_delay);
971 #endif
972
973 }
974
975 }
976
977 /* send a debug message */
978 grig_debug_local (RIG_DEBUG_TRACE, _("%s stopped"), __FUNCTION__);
979
980 /* set clear flag to indicate that daemon terminated */
981 daemonclear = TRUE;
982
983 return NULL;
984 }
985
986
987 /** \brief Radio control daemon main cycle (callback version).
988 * \param data Unused.
989 * \return Always TRUE.
990 *
991 * This function implements the main cycle of the radio control daemon. The executed
992 * commands are defined in the DEF_RX_CYCLE and DEF_TX_CYCLE constant arrays.
993 */
994 static gint
rig_daemon_cycle_cb(gpointer data)995 rig_daemon_cycle_cb (gpointer data)
996 {
997
998 grig_settings_t *get; /* pointer to shared data 'get' */
999 grig_settings_t *set; /* pointer to shared data 'set' */
1000 grig_cmd_avail_t *new; /* pointer to shared data 'new' */
1001 grig_cmd_avail_t *has_get; /* pointer to shared data 'has_get' */
1002 grig_cmd_avail_t *has_set; /* pointer to shared data 'has_set' */
1003
1004 guint step; /* step counter */
1005
1006 /* check whether the previous callback has terminated.
1007 if not, skip this cycle.
1008 */
1009 if (timeout_busy == TRUE) {
1010 return TRUE;
1011 }
1012
1013 timeout_busy = TRUE;
1014
1015 /* get pointers to shared data */
1016 get = rig_data_get_get_addr ();
1017 set = rig_data_get_set_addr ();
1018 new = rig_data_get_new_addr ();
1019 has_get = rig_data_get_has_get_addr ();
1020 has_set = rig_data_get_has_set_addr ();
1021
1022
1023 /* send a debug message */
1024 grig_debug_local (RIG_DEBUG_TRACE, _("%s called."), __FUNCTION__);
1025
1026
1027 /* first we check whether rig is powered ON since some rigs
1028 will not talk to us in power-off state.
1029 NOTE: code should be safe even if rig does not support
1030 get_powerstat since get->pstat is set to ON if rig
1031 does not have functionality.
1032 */
1033 if (get->pstat == RIG_POWER_ON) {
1034
1035 for (step = 0; step < C_MAX_CMD_PER_CYCLE; step++) {
1036
1037 /* check whether we are in RX or TX mode; */
1038 if (get->ptt == RIG_PTT_OFF) {
1039
1040 /* Execute receiver command;
1041 sleep for cmd_delay ms if command has been executed
1042 */
1043 if (rig_daemon_exec_cmd (DEF_RX_CYCLE[step],
1044 get,
1045 set,
1046 new,
1047 has_get,
1048 has_set)) {
1049 /* slow motion in debug mode */
1050 #ifdef GRIG_DEBUG
1051 g_usleep (5000 * cmd_delay);
1052 #else
1053 g_usleep (1000 * cmd_delay);
1054 #endif
1055 }
1056
1057 }
1058 else {
1059
1060 /* Execute transmitter command;
1061 sleep for cmd_delay ms if command has been executed
1062 */
1063 if (rig_daemon_exec_cmd (DEF_TX_CYCLE[step],
1064 get,
1065 set,
1066 new,
1067 has_get,
1068 has_set)) {
1069 /* slow motion in debug mode */
1070 #ifdef GRIG_DEBUG
1071 g_usleep (10000 * cmd_delay);
1072 #else
1073 g_usleep (2000 * cmd_delay);
1074 #endif
1075 }
1076 }
1077 }
1078
1079 }
1080
1081 /* otherwise check the power status only */
1082 else {
1083 if (rig_daemon_exec_cmd (RIG_CMD_SET_PSTAT, get, set, new, has_get, has_set)) {
1084
1085 /* slow motion in debug mode */
1086 #ifdef GRIG_DEBUG
1087 g_usleep (15000 * cmd_delay);
1088 #else
1089 g_usleep (3000 * cmd_delay);
1090 #endif
1091 }
1092
1093 rig_daemon_exec_cmd (RIG_CMD_GET_PSTAT, get, set, new, has_get, has_set);
1094 }
1095
1096
1097 timeout_busy = FALSE;
1098
1099
1100 return TRUE;
1101 }
1102
1103
1104
1105
1106 /** \brief Execute a specific command.
1107 * \param cmd The command to be executed.
1108 * \param get Pointer to the 'get' command buffer.
1109 * \param set Pointer to the 'set' command buffer.
1110 * \param new Pointer to the 'new' command buffer.
1111 * \param has_get Pointer to get capabilities record.
1112 * \param has_set Pointer to set capabilities record.
1113 * \return 1 if the command has been executed, 0 otherwise.
1114 *
1115 * This function is responsible for the execution of the specified rig command.
1116 * First, it checks whether the command is supported by the current radio, if yes,
1117 * it executes the corresponding hamlib API call. If the command execution is not
1118 * successfull, an anomaly report is sent to the rig error manager which will take
1119 * care of any further actions like disabling repeatedly failing commands.
1120 *
1121 * \note The 'get' commands use local buffers for the acquired value and do not
1122 * write directly to the shared memory. This way the contents of the shared memory
1123 * do not get corrupted if the command execution was erroneous.
1124 */
1125 static gint
rig_daemon_exec_cmd(rig_cmd_t cmd,grig_settings_t * get,grig_settings_t * set,grig_cmd_avail_t * new,grig_cmd_avail_t * has_get,grig_cmd_avail_t * has_set)1126 rig_daemon_exec_cmd (rig_cmd_t cmd,
1127 grig_settings_t *get,
1128 grig_settings_t *set,
1129 grig_cmd_avail_t *new,
1130 grig_cmd_avail_t *has_get,
1131 grig_cmd_avail_t *has_set)
1132
1133 {
1134 int retcode;
1135 gint status = 0;
1136 setting_t func;
1137 int i;
1138
1139
1140 switch (cmd) {
1141
1142 /* No command. Do nothing */
1143 case RIG_CMD_NONE:
1144 break;
1145
1146 /* get primary frequency */
1147 case RIG_CMD_GET_FREQ_1:
1148
1149 /* check whether command is available */
1150 if (has_get->freq1) {
1151 freq_t freq;
1152
1153 /* try to execute command */
1154 retcode = rig_get_freq (myrig, RIG_VFO_CURR, &freq);
1155
1156 /* raise anomaly if execution did not succeed */
1157 if (retcode != RIG_OK) {
1158 grig_debug_local (RIG_DEBUG_ERR,
1159 _("%s: Failed to execute RIG_CMD_GET_FREQ_1:\n%s"),
1160 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1161
1162 rig_anomaly_raise (RIG_CMD_GET_FREQ_1);
1163 }
1164 else {
1165 get->freq1 = freq;
1166 }
1167
1168 status = 1;
1169 }
1170
1171 break;
1172
1173
1174 /* set primary frequency */
1175 case RIG_CMD_SET_FREQ_1:
1176
1177 /* check whether command is available */
1178 if (has_set->freq1 && new->freq1) {
1179
1180 /* try to execute command */
1181 retcode = rig_set_freq (myrig, RIG_VFO_CURR, set->freq1);
1182
1183 /* raise anomaly if execution did not succeed */
1184 if (retcode != RIG_OK) {
1185 grig_debug_local (RIG_DEBUG_ERR,
1186 _("%s: Failed to execute RIG_CMD_SET_FREQ_1:\n%s"),
1187 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1188
1189 rig_anomaly_raise (RIG_CMD_SET_FREQ_1);
1190 }
1191
1192 /* reset flag */
1193 new->freq1 = FALSE;
1194 get->freq1 = set->freq1;
1195
1196 status = 1;
1197 }
1198
1199 break;
1200
1201
1202 /* get secondary frequency */
1203 case RIG_CMD_GET_FREQ_2:
1204
1205 /* check whether command is available */
1206 if (has_get->freq2) {
1207 freq_t freq;
1208 vfo_t vfo;
1209
1210 /* find out which is the secondary VFO */
1211 switch (get->vfo) {
1212
1213 /* VFO A */
1214 case RIG_VFO_A:
1215 vfo = RIG_VFO_B;
1216 break;
1217
1218 /* VFO B or C; grig is too stupid to know about 3 VFOs ...
1219 or at least I am to lazy to bother about 3 VFOs ;)
1220 */
1221 case RIG_VFO_B:
1222 case RIG_VFO_C:
1223 vfo = RIG_VFO_A;
1224 break;
1225
1226 /* Main VFO */
1227 case RIG_VFO_MAIN:
1228 vfo = RIG_VFO_SUB;
1229 break;
1230
1231 /* Sub VFO */
1232 case RIG_VFO_SUB:
1233 vfo = RIG_VFO_MAIN;
1234 break;
1235
1236 /* trouble... */
1237 case RIG_VFO_CURR:
1238 case RIG_VFO_NONE:
1239 default:
1240
1241 /* send an error report */
1242 grig_debug_local (RIG_DEBUG_ERR,
1243 _("%s: I can't figure out available VFOs (got %d)"),
1244 __FUNCTION__, get->vfo);
1245
1246 vfo = RIG_VFO_NONE;
1247 break;
1248 }
1249
1250 /* try to execute command */
1251 retcode = rig_get_freq (myrig, vfo, &freq);
1252
1253 /* raise anomaly if execution did not succeed */
1254 if (retcode != RIG_OK) {
1255 grig_debug_local (RIG_DEBUG_ERR,
1256 _("%s: Failed to execute RIG_CMD_GET_FREQ_2:\n%s"),
1257 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1258
1259 rig_anomaly_raise (RIG_CMD_GET_FREQ_2);
1260 }
1261 else {
1262 get->freq2 = freq;
1263 }
1264
1265 status = 1;
1266 }
1267
1268 break;
1269
1270
1271 /* set secondary frequency */
1272 case RIG_CMD_SET_FREQ_2:
1273
1274 /* check whether command is available */
1275 if (has_set->freq2 && new->freq2) {
1276 vfo_t vfo;
1277
1278 /* find out which is the secondary VFO */
1279 switch (get->vfo) {
1280
1281 /* VFO A */
1282 case RIG_VFO_A:
1283 vfo = RIG_VFO_B;
1284 break;
1285
1286 /* VFO B or C; grig is too stupid to know about 3 VFOs ...
1287 or at least I am to lazy to bother about 3 VFOs ;)
1288 */
1289 case RIG_VFO_B:
1290 case RIG_VFO_C:
1291 vfo = RIG_VFO_A;
1292 break;
1293
1294 /* Main VFO */
1295 case RIG_VFO_MAIN:
1296 vfo = RIG_VFO_SUB;
1297 break;
1298
1299 /* Sub VFO */
1300 case RIG_VFO_SUB:
1301 vfo = RIG_VFO_MAIN;
1302 break;
1303
1304 /* trouble... */
1305 case RIG_VFO_CURR:
1306 case RIG_VFO_NONE:
1307 default:
1308
1309 /* send an error report */
1310 grig_debug_local (RIG_DEBUG_ERR,
1311 _("%s: I can't figure out available VFOs (got %d)"),
1312 __FUNCTION__, get->vfo);
1313
1314 vfo = RIG_VFO_NONE;
1315 break;
1316 }
1317
1318 /* try to execute command */
1319 retcode = rig_set_freq (myrig, vfo, set->freq2);
1320
1321 /* raise anomaly if execution did not succeed */
1322 if (retcode != RIG_OK) {
1323 grig_debug_local (RIG_DEBUG_ERR,
1324 _("%s: Failed to execute RIG_CMD_SET_FREQ_2:\n%s"),
1325 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1326
1327 rig_anomaly_raise (RIG_CMD_SET_FREQ_2);
1328 }
1329
1330 /* reset flag */
1331 new->freq2 = FALSE;
1332 get->freq2 = set->freq2;
1333
1334 status = 1;
1335 }
1336
1337 break;
1338
1339
1340 /* get RIT offset */
1341 case RIG_CMD_GET_RIT:
1342
1343 /* check whether command is available */
1344 if (has_get->rit) {
1345 shortfreq_t rit;
1346
1347 /* try to execute command */
1348 retcode = rig_get_rit (myrig, RIG_VFO_CURR, &rit);
1349
1350 /* raise anomaly if execution did not succeed */
1351 if (retcode != RIG_OK) {
1352 grig_debug_local (RIG_DEBUG_ERR,
1353 _("%s: Failed to execute RIG_CMD_GET_RIT:\n%s"),
1354 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1355
1356 rig_anomaly_raise (RIG_CMD_GET_RIT);
1357 }
1358 else {
1359 get->rit = rit;
1360 }
1361
1362 status = 1;
1363 }
1364
1365 break;
1366
1367
1368 /* set RIT offset */
1369 case RIG_CMD_SET_RIT:
1370
1371 /* check whether command is available */
1372 if (has_set->rit && new->rit) {
1373
1374 /* try to execute command */
1375 retcode = rig_set_rit (myrig, RIG_VFO_CURR, set->rit);
1376
1377 /* raise anomaly if execution did not succeed */
1378 if (retcode != RIG_OK) {
1379 grig_debug_local (RIG_DEBUG_ERR,
1380 _("%s: Failed to execute RIG_CMD_SET_RIT:\n%s"),
1381 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1382
1383 rig_anomaly_raise (RIG_CMD_SET_RIT);
1384 }
1385
1386 /* reset flag */
1387 new->rit = FALSE;
1388 get->rit = set->rit;
1389
1390 status = 1;
1391 }
1392
1393 break;
1394
1395
1396 /* get XIT offset */
1397 case RIG_CMD_GET_XIT:
1398
1399 /* check whether command is available */
1400 if (has_get->xit) {
1401 shortfreq_t xit;
1402
1403 /* try to execute command */
1404 retcode = rig_get_xit (myrig, RIG_VFO_CURR, &xit);
1405
1406 /* raise anomaly if execution did not succeed */
1407 if (retcode != RIG_OK) {
1408 grig_debug_local (RIG_DEBUG_ERR,
1409 _("%s: Failed to execute RIG_CMD_GET_XIT:\n%s"),
1410 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1411
1412 rig_anomaly_raise (RIG_CMD_GET_XIT);
1413 }
1414 else {
1415 get->xit = xit;
1416 }
1417
1418 status = 1;
1419 }
1420
1421 break;
1422
1423
1424 /* set XIT offset */
1425 case RIG_CMD_SET_XIT:
1426
1427 /* check whether command is available */
1428 if (has_set->xit && new->xit) {
1429
1430 /* try to execute command */
1431 retcode = rig_set_xit (myrig, RIG_VFO_CURR, set->xit);
1432
1433 /* raise anomaly if execution did not succeed */
1434 if (retcode != RIG_OK) {
1435 grig_debug_local (RIG_DEBUG_ERR,
1436 _("%s: Failed to execute RIG_CMD_SET_XIT:\n%s"),
1437 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1438
1439 rig_anomaly_raise (RIG_CMD_SET_XIT);
1440 }
1441
1442 /* reset flag */
1443 new->xit = FALSE;
1444 get->xit = set->xit;
1445
1446 status = 1;
1447 }
1448
1449 break;
1450
1451
1452 /* get current VFO */
1453 case RIG_CMD_GET_VFO:
1454
1455 /* check whether command is available */
1456 if (has_get->vfo) {
1457 vfo_t vfo;
1458
1459 /* try to execute command */
1460 retcode = rig_get_vfo (myrig, &vfo);
1461
1462 /* raise anomaly if execution did not succeed */
1463 if (retcode != RIG_OK) {
1464 grig_debug_local (RIG_DEBUG_ERR,
1465 _("%s: Failed to execute RIG_CMD_GET_VFO:\n%s"),
1466 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1467
1468 rig_anomaly_raise (RIG_CMD_GET_VFO);
1469 }
1470 else {
1471 get->vfo = vfo;
1472 }
1473
1474 status = 1;
1475 }
1476
1477 break;
1478
1479
1480 /* set current VFO */
1481 case RIG_CMD_SET_VFO:
1482
1483 /* check whether command is available */
1484 if (has_set->vfo && new->vfo) {
1485
1486 /* try to execute command */
1487 retcode = rig_set_vfo (myrig, set->vfo);
1488
1489 /* raise anomaly if execution did not succeed */
1490 if (retcode != RIG_OK) {
1491 grig_debug_local (RIG_DEBUG_ERR,
1492 _("%s: Failed to execute RIG_CMD_SET_VFO:\n%s"),
1493 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1494
1495 rig_anomaly_raise (RIG_CMD_SET_VFO);
1496 }
1497
1498 /* reset flag */
1499 new->vfo = FALSE;
1500 get->vfo = set->vfo;
1501
1502 status = 1;
1503 }
1504
1505 break;
1506
1507
1508 /* get power status */
1509 case RIG_CMD_GET_PSTAT:
1510
1511 /* check whether command is available */
1512 if (has_get->pstat) {
1513 powerstat_t pstat;
1514
1515 /* try to execute command */
1516 retcode = rig_get_powerstat (myrig, &pstat);
1517
1518 /* raise anomaly if execution did not succeed */
1519 if (retcode != RIG_OK) {
1520 grig_debug_local (RIG_DEBUG_ERR,
1521 _("%s: Failed to execute RIG_CMD_GET_PSTAT:\n%s"),
1522 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1523
1524 rig_anomaly_raise (RIG_CMD_GET_PSTAT);
1525 }
1526 else {
1527 get->pstat = pstat;
1528 }
1529
1530 status = 1;
1531 }
1532
1533 break;
1534
1535
1536 /* set power status */
1537 case RIG_CMD_SET_PSTAT:
1538
1539 /* check whether command is available */
1540 if (has_set->pstat && new->pstat) {
1541
1542 /* try to execute command */
1543 retcode = rig_set_powerstat (myrig, set->pstat);
1544
1545 /* raise anomaly if execution did not succeed */
1546 if (retcode != RIG_OK) {
1547 grig_debug_local (RIG_DEBUG_ERR,
1548 _("%s: Failed to execute RIG_CMD_SET_PSTAT:\n%s"),
1549 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1550
1551 rig_anomaly_raise (RIG_CMD_SET_PSTAT);
1552 }
1553
1554 /* reset flag */
1555 new->pstat = FALSE;
1556 get->pstat = set->pstat;
1557
1558 status = 1;
1559 }
1560
1561 break;
1562
1563
1564 /* get PTT status */
1565 case RIG_CMD_GET_PTT:
1566
1567 /* check whether command is available */
1568 if (has_get->ptt) {
1569 ptt_t ptt;
1570
1571 /* try to execute command */
1572 retcode = rig_get_ptt (myrig, RIG_VFO_CURR, &ptt);
1573
1574 /* raise anomaly if execution did not succeed */
1575 if (retcode != RIG_OK) {
1576 grig_debug_local (RIG_DEBUG_ERR,
1577 _("%s: Failed to execute RIG_CMD_GET_PTT:\n%s"),
1578 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1579
1580 rig_anomaly_raise (RIG_CMD_GET_PTT);
1581 }
1582 else {
1583 get->ptt = ptt;
1584 }
1585
1586 status = 1;
1587 }
1588
1589 break;
1590
1591
1592 /* set PTT status */
1593 case RIG_CMD_SET_PTT:
1594
1595 /* check whether command is available */
1596 if (has_set->ptt && new->ptt) {
1597
1598 /* try to execute command */
1599 retcode = rig_set_ptt (myrig, RIG_VFO_CURR, set->ptt);
1600
1601 /* raise anomaly if execution did not succeed */
1602 if (retcode != RIG_OK) {
1603 grig_debug_local (RIG_DEBUG_ERR,
1604 _("%s: Failed to execute RIG_CMD_SET_PTT:\n%s"),
1605 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1606
1607 rig_anomaly_raise (RIG_CMD_SET_PTT);
1608 }
1609
1610 /* reset flag */
1611 new->ptt = FALSE;
1612 get->ptt = set->ptt;
1613
1614 status = 1;
1615 }
1616
1617 break;
1618
1619
1620 /* get current mode and passband width */
1621 case RIG_CMD_GET_MODE:
1622
1623 /* check whether command is available */
1624 if (has_get->mode || has_get->pbw) {
1625 rmode_t mode;
1626 pbwidth_t pbw;
1627
1628 /* try to execute command */
1629 retcode = rig_get_mode (myrig, RIG_VFO_CURR, &mode, &pbw);
1630
1631 /* raise anomaly if execution did not succeed */
1632 if (retcode != RIG_OK) {
1633 grig_debug_local (RIG_DEBUG_ERR,
1634 _("%s: Failed to execute RIG_CMD_GET_MODE:\n%s"),
1635 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1636
1637 rig_anomaly_raise (RIG_CMD_GET_MODE);
1638 }
1639 else {
1640 int i = 0; /* iterator */
1641 int found_mode = 0; /* flag to indicate found mode */
1642
1643 /* convert and store the new passband width;
1644 note: RIG_PASSBAND_NORMAL = 0, which is also
1645 the value returned by rig_passband_wide and
1646 rig_passband_narrow if these passbands are not
1647 defined in the backend.
1648 */
1649 if ((pbw == rig_passband_wide (myrig, mode)) &&
1650 (pbw > 0)) {
1651 get->pbw = RIG_DATA_PB_WIDE;
1652 }
1653 else if ((pbw == rig_passband_narrow (myrig, mode)) &&
1654 (pbw > 0)) {
1655 get->pbw = RIG_DATA_PB_NARROW;
1656 }
1657 else {
1658 get->pbw = RIG_DATA_PB_NORMAL;
1659 }
1660
1661 /* if mode has changed we need to update frequency limits */
1662 if (get->mode != mode) {
1663
1664 get->mode = mode;
1665
1666 /* FIXME: VY SIMILAR CODE IS PRESENT IN RIG_DAEMON_CHECK_MODE */
1667
1668 /* get frequency limits for this mode; we use the rx_range_list
1669 stored in the rig_state structure
1670 */
1671 while (!RIG_IS_FRNG_END(myrig->state.rx_range_list[i]) && !found_mode) {
1672
1673 /* is this list good for current mode?
1674 is the current frequency within this range?
1675 */
1676 if (((mode & myrig->state.rx_range_list[i].modes) == mode) &&
1677 (get->freq1 >= myrig->state.rx_range_list[i].startf) &&
1678 (get->freq1 <= myrig->state.rx_range_list[i].endf)) {
1679
1680 found_mode = 1;
1681 get->fmin = myrig->state.rx_range_list[i].startf;
1682 get->fmax = myrig->state.rx_range_list[i].endf;
1683
1684 grig_debug_local (RIG_DEBUG_VERBOSE,
1685 _("%s: Found frequency range for mode %d"),
1686 __FUNCTION__, mode);
1687 grig_debug_local (RIG_DEBUG_VERBOSE,
1688 _("%s: %.0f...(%.0f)...%.0f kHz"),
1689 __FUNCTION__,
1690 get->fmin / 1.0e3,
1691 get->freq1 / 1.0e3,
1692 get->fmax / 1.0e3);
1693
1694 }
1695 else {
1696 i++;
1697 }
1698
1699
1700 }
1701
1702 /* if we did not find any suitable range there could be a bug
1703 in the backend!
1704 */
1705 if (!found_mode) {
1706 grig_debug_local (RIG_DEBUG_BUG,
1707 _("%s: Can not find frequency range for this mode (%d)!"\
1708 "Bug in backend?"),
1709 __FUNCTION__, mode);
1710 }
1711
1712 /* get the smallest tuning step */
1713 get->fstep = rig_get_resolution (myrig, mode);
1714 }
1715 }
1716
1717 status = 1;
1718 }
1719
1720 break;
1721
1722
1723 /* set current mode and passband width */
1724 case RIG_CMD_SET_MODE:
1725
1726 /* check whether command is available */
1727 if ((has_set->mode && new->mode) || (has_set->pbw && new->pbw)) {
1728 pbwidth_t pbw;
1729 rmode_t mode;
1730
1731 if (new->mode) {
1732 mode = set->mode;
1733 }
1734 else {
1735 mode = get->mode;
1736 }
1737
1738 /* don't modify pbw unless asked by user */
1739 if (new->pbw) {
1740 switch (set->pbw) {
1741 case RIG_DATA_PB_WIDE:
1742 pbw = rig_passband_wide (myrig, mode);
1743 break;
1744 case RIG_DATA_PB_NORMAL:
1745 pbw = rig_passband_normal (myrig, mode);
1746 break;
1747 case RIG_DATA_PB_NARROW:
1748 pbw = rig_passband_narrow (myrig, mode);
1749 break;
1750 default:
1751 /* we have no idea what to set! */
1752 pbw = rig_passband_normal (myrig, mode);
1753 break;
1754 }
1755 }
1756 else {
1757 switch (get->pbw) {
1758 case RIG_DATA_PB_WIDE:
1759 pbw = rig_passband_wide (myrig, mode);
1760 break;
1761 case RIG_DATA_PB_NORMAL:
1762 pbw = rig_passband_normal (myrig, mode);
1763 break;
1764 case RIG_DATA_PB_NARROW:
1765 pbw = rig_passband_narrow (myrig, mode);
1766 break;
1767 default:
1768 /* we have no idea what to set! */
1769 pbw = rig_passband_normal (myrig, mode);
1770 break;
1771 }
1772 }
1773
1774 /* try to execute command */
1775 retcode = rig_set_mode (myrig, RIG_VFO_CURR, set->mode, pbw);
1776
1777 /* raise anomaly if execution did not succeed */
1778 if (retcode != RIG_OK) {
1779 grig_debug_local (RIG_DEBUG_ERR,
1780 _("%s: Failed to execute RIG_CMD_SET_MODE:\n%s"),
1781 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1782
1783 rig_anomaly_raise (RIG_CMD_SET_MODE);
1784 }
1785
1786 if (new->mode) {
1787 get->mode = set->mode;
1788 new->mode = FALSE;
1789 }
1790 if (new->pbw) {
1791 get->pbw = set->pbw;
1792 new->pbw = FALSE;
1793 }
1794 status = 1;
1795 }
1796
1797
1798 break;
1799
1800
1801 /* get AGC level */
1802 case RIG_CMD_GET_AGC:
1803
1804 /* check whether command is available */
1805 if (has_get->agc) {
1806 value_t val;
1807
1808 /* try to execute command */
1809 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_AGC, &val);
1810
1811 /* raise anomaly if execution did not succeed */
1812 if (retcode != RIG_OK) {
1813 grig_debug_local (RIG_DEBUG_ERR,
1814 _("%s: Failed to execute RIG_CMD_GET_AGC:\n%s"),
1815 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1816
1817 rig_anomaly_raise (RIG_CMD_GET_AGC);
1818 }
1819 else {
1820 get->agc = val.i;
1821 }
1822
1823 status = 1;
1824 }
1825
1826 break;
1827
1828
1829 /* set AGC level */
1830 case RIG_CMD_SET_AGC:
1831
1832 /* check whether command is available */
1833 if (has_set->agc && new->agc) {
1834 value_t val;
1835
1836 val.i = set->agc;
1837
1838 /* try to execute command */
1839 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_AGC, val);
1840
1841 /* raise anomaly if execution did not succeed */
1842 if (retcode != RIG_OK) {
1843 grig_debug_local (RIG_DEBUG_ERR,
1844 _("%s: Failed to execute RIG_CMD_SET_AGC:\n%s"),
1845 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1846
1847 rig_anomaly_raise (RIG_CMD_SET_AGC);
1848 }
1849 /* reset flag */
1850 new->agc = FALSE;
1851 get->agc = set->agc;
1852
1853 status = 1;
1854 }
1855
1856 break;
1857
1858
1859 /* get attenuator level */
1860 case RIG_CMD_GET_ATT:
1861
1862 /* check whether command is available */
1863 if (has_get->att) {
1864 value_t val;
1865
1866 /* try to execute command */
1867 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_ATT, &val);
1868
1869 /* raise anomaly if execution did not succeed */
1870 if (retcode != RIG_OK) {
1871 grig_debug_local (RIG_DEBUG_ERR,
1872 _("%s: Failed to execute RIG_CMD_GET_ATT:\n%s"),
1873 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1874
1875 rig_anomaly_raise (RIG_CMD_GET_ATT);
1876 }
1877 else {
1878 get->att = val.i;
1879 }
1880 }
1881
1882 break;
1883
1884
1885 /* set attenuator level */
1886 case RIG_CMD_SET_ATT:
1887
1888 /* check whether command is available */
1889 if (has_set->att && new->att) {
1890 value_t val;
1891
1892 val.i = set->att;
1893
1894 /* try to execute command */
1895 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_ATT, val);
1896
1897 /* raise anomaly if execution did not succeed */
1898 if (retcode != RIG_OK) {
1899 grig_debug_local (RIG_DEBUG_ERR,
1900 _("%s: Failed to execute RIG_CMD_SET_ATT:\n%s"),
1901 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1902
1903 rig_anomaly_raise (RIG_CMD_SET_ATT);
1904 }
1905 /* reset flag */
1906 new->att = FALSE;
1907 get->att = set->att;
1908
1909 status = 1;
1910 }
1911
1912 break;
1913
1914
1915 /* get pre-amp level */
1916 case RIG_CMD_GET_PREAMP:
1917
1918 /* check whether command is available */
1919 if (has_get->preamp) {
1920 value_t val;
1921
1922 /* try to execute command */
1923 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_PREAMP, &val);
1924
1925 /* raise anomaly if execution did not succeed */
1926 if (retcode != RIG_OK) {
1927 grig_debug_local (RIG_DEBUG_ERR,
1928 _("%s: Failed to execute RIG_CMD_GET_PREAMP:\n%s"),
1929 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1930
1931 rig_anomaly_raise (RIG_CMD_GET_PREAMP);
1932 }
1933 else {
1934 get->preamp = val.i;
1935 }
1936
1937 status = 1;
1938 }
1939
1940 break;
1941
1942
1943 /* set pre-amp level */
1944 case RIG_CMD_SET_PREAMP:
1945
1946 /* check whether command is available */
1947 if (has_set->preamp && new->preamp) {
1948 value_t val;
1949
1950 val.i = set->preamp;
1951
1952 /* try to execute command */
1953 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_PREAMP, val);
1954
1955 /* raise anomaly if execution did not succeed */
1956 if (retcode != RIG_OK) {
1957 grig_debug_local (RIG_DEBUG_ERR,
1958 _("%s: Failed to execute RIG_CMD_SET_PREAMP:\n%s"),
1959 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1960
1961 rig_anomaly_raise (RIG_CMD_SET_PREAMP);
1962 }
1963 /* reset flag */
1964 new->preamp = FALSE;
1965 get->preamp = set->preamp;
1966
1967 status = 1;
1968 }
1969
1970 break;
1971
1972
1973 /* get signal strength, S-meter */
1974 case RIG_CMD_GET_STRENGTH:
1975
1976 /* check whether command is available */
1977 if (has_get->strength) {
1978 value_t val;
1979
1980 /* try to execute command */
1981 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_STRENGTH, &val);
1982
1983 /* raise anomaly if execution did not succeed */
1984 if (retcode != RIG_OK) {
1985 grig_debug_local (RIG_DEBUG_ERR,
1986 _("%s: Failed to execute RIG_CMD_GET_STRENGTH:\n%s"),
1987 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
1988
1989 rig_anomaly_raise (RIG_CMD_GET_STRENGTH);
1990 }
1991 else {
1992 get->strength = val.i;
1993 }
1994
1995 status = 1;
1996 }
1997
1998 break;
1999
2000 /* set transmitter power */
2001 case RIG_CMD_SET_POWER:
2002
2003 /* check whether command is available */
2004 if (has_set->power && new->power) {
2005 value_t val;
2006
2007 val.f = set->power;
2008
2009 /* try to execute command */
2010 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, val);
2011
2012 /* raise anomaly if execution did not succeed */
2013 if (retcode != RIG_OK) {
2014 grig_debug_local (RIG_DEBUG_ERR,
2015 _("%s: Failed to execute RIG_CMD_SET_POWER:\n%s"),
2016 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2017
2018 rig_anomaly_raise (RIG_CMD_SET_POWER);
2019 }
2020
2021 /* reset flag */
2022 new->power = FALSE;
2023 get->power = set->power;
2024
2025 status = 1;
2026 }
2027
2028 break;
2029
2030 /* get transmitter power */
2031 case RIG_CMD_GET_POWER:
2032
2033 /* check whether command is available */
2034 if (has_get->power && (rig_gui_smeter_get_tx_mode() == SMETER_TX_MODE_POWER)) {
2035 value_t val;
2036
2037 /* try to execute command */
2038 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_RFPOWER, &val);
2039
2040 /* raise anomaly if execution did not succeed */
2041 if (retcode != RIG_OK) {
2042 grig_debug_local (RIG_DEBUG_ERR,
2043 _("%s: Failed to execute RIG_CMD_GET_POWER:\n%s"),
2044 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2045
2046 rig_anomaly_raise (RIG_CMD_GET_POWER);
2047 }
2048 else {
2049 get->power = val.f;
2050 }
2051
2052 status = 1;
2053 }
2054
2055 break;
2056
2057 /* get SWR */
2058 case RIG_CMD_GET_SWR:
2059
2060 /* check whether command is available */
2061 if (has_get->swr && (rig_gui_smeter_get_tx_mode() == SMETER_TX_MODE_SWR)) {
2062 value_t val;
2063
2064 /* try to execute command */
2065 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_SWR, &val);
2066
2067 /* raise anomaly if execution did not succeed */
2068 if (retcode != RIG_OK) {
2069 grig_debug_local (RIG_DEBUG_ERR,
2070 _("%s: Failed to execute RIG_CMD_GET_SWR:\n%s"),
2071 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2072
2073 rig_anomaly_raise (RIG_CMD_GET_SWR);
2074 }
2075 else {
2076 get->swr = val.f;
2077 }
2078
2079 status = 1;
2080 }
2081
2082 break;
2083
2084 /* get ALC */
2085 case RIG_CMD_GET_ALC:
2086
2087 /* check whether command is available */
2088 if (has_get->alc && (rig_gui_smeter_get_tx_mode() == SMETER_TX_MODE_ALC)) {
2089 value_t val;
2090
2091 /* try to execute command */
2092 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_ALC, &val);
2093
2094 /* raise anomaly if execution did not succeed */
2095 if (retcode != RIG_OK) {
2096 grig_debug_local (RIG_DEBUG_ERR,
2097 _("%s: Failed to execute RIG_CMD_GET_ALC:\n%s"),
2098 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2099
2100 rig_anomaly_raise (RIG_CMD_GET_ALC);
2101 }
2102 else {
2103 get->alc = val.f;
2104 }
2105
2106 status = 1;
2107 }
2108
2109 break;
2110
2111 /* set ALC */
2112 case RIG_CMD_SET_ALC:
2113
2114 /* check whether command is available */
2115 if (has_set->alc && new->alc) {
2116 value_t val;
2117
2118 val.f = set->alc;
2119
2120 /* try to execute command */
2121 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_ALC, val);
2122
2123 /* raise anomaly if execution did not succeed */
2124 if (retcode != RIG_OK) {
2125 grig_debug_local (RIG_DEBUG_ERR,
2126 _("%s: Failed to execute RIG_CMD_SET_ALC:\n%s"),
2127 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2128
2129 rig_anomaly_raise (RIG_CMD_SET_ALC);
2130 }
2131
2132 /* reset flag */
2133 new->alc = FALSE;
2134
2135 status = 1;
2136 }
2137
2138 break;
2139
2140 /* set LOCK status */
2141 case RIG_CMD_SET_LOCK:
2142
2143 if (has_set->lock && new->lock) {
2144 retcode = rig_set_func (myrig,
2145 RIG_VFO_CURR,
2146 RIG_FUNC_LOCK,
2147 set->lock);
2148
2149 if (retcode != RIG_OK) {
2150 grig_debug_local (RIG_DEBUG_ERR,
2151 _("%s: Failed to execute RIG_CMD_SET_LOCK:\n%s"),
2152 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2153
2154 rig_anomaly_raise (RIG_CMD_SET_LOCK);
2155 }
2156
2157 get->lock = set->lock;
2158 new->lock = 0;
2159
2160 status = 1;
2161 }
2162
2163 break;
2164
2165 /* get LOCK status */
2166 case RIG_CMD_GET_LOCK:
2167
2168 /* check whether command is available */
2169 if (has_get->lock) {
2170 int lock;
2171
2172 /* try to execute command */
2173 retcode = rig_get_func (myrig, RIG_VFO_CURR, RIG_FUNC_LOCK, &lock);
2174
2175 /* raise anomaly if execution did not succeed */
2176 if (retcode != RIG_OK) {
2177 grig_debug_local (RIG_DEBUG_ERR,
2178 _("%s: Failed to execute RIG_CMD_GET_LOCK:\n%s"),
2179 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2180
2181 rig_anomaly_raise (RIG_CMD_GET_LOCK);
2182 }
2183 else {
2184 get->lock = lock;
2185 }
2186
2187 status = 1;
2188 }
2189
2190 break;
2191
2192 /* execute RIG_OP_TOGGLE */
2193 case RIG_CMD_VFO_TOGGLE:
2194
2195 if (has_set->vfo_op_toggle && new->vfo_op_toggle) {
2196
2197 retcode = rig_vfo_op (myrig, RIG_VFO_CURR, RIG_OP_TOGGLE);
2198
2199 /* raise anomaly if execution did not succeed */
2200 if (retcode != RIG_OK) {
2201 grig_debug_local (RIG_DEBUG_ERR,
2202 _("%s: Failed to execute RIG_CMD_VFO_TOGGLE:\n%s"),
2203 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2204
2205 rig_anomaly_raise (RIG_CMD_VFO_TOGGLE);
2206 }
2207
2208 new->vfo_op_toggle = 0;
2209
2210 status = 1;
2211 }
2212
2213 break;
2214
2215 /* execute RIG_OP_COPY */
2216 case RIG_CMD_VFO_COPY:
2217
2218 if (has_set->vfo_op_copy && new->vfo_op_copy) {
2219
2220 retcode = rig_vfo_op (myrig, RIG_VFO_CURR, RIG_OP_CPY);
2221
2222 /* raise anomaly if execution did not succeed */
2223 if (retcode != RIG_OK) {
2224 grig_debug_local (RIG_DEBUG_ERR,
2225 _("%s: Failed to execute RIG_CMD_VFO_COPY:\n%s"),
2226 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2227
2228 rig_anomaly_raise (RIG_CMD_VFO_COPY);
2229 }
2230
2231 new->vfo_op_copy = 0;
2232
2233 status = 1;
2234 }
2235
2236 break;
2237
2238 /* execute RIG_OP_XCHG */
2239 case RIG_CMD_VFO_XCHG:
2240
2241 if (has_set->vfo_op_xchg && new->vfo_op_xchg) {
2242
2243 retcode = rig_vfo_op (myrig, RIG_VFO_CURR, RIG_OP_XCHG);
2244
2245 /* raise anomaly if execution did not succeed */
2246 if (retcode != RIG_OK) {
2247 grig_debug_local (RIG_DEBUG_ERR,
2248 _("%s: Failed to execute RIG_CMD_VFO_XCHG:\n%s"),
2249 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2250
2251 rig_anomaly_raise (RIG_CMD_VFO_XCHG);
2252 }
2253
2254 new->vfo_op_xchg = 0;
2255
2256 status = 1;
2257 }
2258
2259 break;
2260
2261 /* set split on or off */
2262 case RIG_CMD_SET_SPLIT:
2263 if (has_set->split && new->split) {
2264
2265 retcode = rig_set_split_vfo (myrig, RIG_VFO_RX, set->split, RIG_VFO_TX);
2266
2267 /* raise anomaly if execution did not succeed */
2268 if (retcode != RIG_OK) {
2269 grig_debug_local (RIG_DEBUG_ERR,
2270 _("%s: Failed to execute RIG_CMD_SET_SPLIT:\n%s"),
2271 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2272
2273 rig_anomaly_raise (RIG_CMD_SET_SPLIT);
2274 }
2275
2276 new->split = 0;
2277
2278 status = 1;
2279 }
2280
2281 break;
2282
2283 case RIG_CMD_GET_SPLIT:
2284 if (has_get->split) {
2285
2286 retcode = rig_get_split (myrig, RIG_VFO_RX, &get->split);
2287
2288 /* raise anomaly if execution did not succeed */
2289 if (retcode != RIG_OK) {
2290 grig_debug_local (RIG_DEBUG_ERR,
2291 _("%s: Failed to execute RIG_CMD_GET_SPLIT:\n%s"),
2292 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2293
2294 rig_anomaly_raise (RIG_CMD_GET_SPLIT);
2295 }
2296
2297 status = 1;
2298 }
2299
2300 break;
2301
2302
2303 case RIG_CMD_SET_AF:
2304 /* check whether command is available */
2305 if (has_set->afg && new->afg) {
2306 value_t val;
2307
2308 val.f = set->afg;
2309
2310 /* try to execute command */
2311 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_AF, val);
2312
2313 /* raise anomaly if execution did not succeed */
2314 if (retcode != RIG_OK) {
2315 grig_debug_local (RIG_DEBUG_ERR,
2316 _("%s: Failed to execute RIG_CMD_SET_AF:\n%s"),
2317 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2318
2319 rig_anomaly_raise (RIG_CMD_SET_AF);
2320 }
2321
2322 /* reset flag */
2323 new->afg = FALSE;
2324 get->afg = set->afg;
2325
2326 status = 1;
2327 }
2328 break;
2329
2330 case RIG_CMD_GET_AF:
2331 /* check whether command is available */
2332 if (has_get->afg) {
2333 value_t val;
2334
2335 /* try to execute command */
2336 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_AF, &val);
2337
2338 /* raise anomaly if execution did not succeed */
2339 if (retcode != RIG_OK) {
2340 grig_debug_local (RIG_DEBUG_ERR,
2341 _("%s: Failed to execute RIG_CMD_GET_AF:\n%s"),
2342 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2343
2344 rig_anomaly_raise (RIG_CMD_GET_AF);
2345 }
2346 else {
2347 get->afg = val.f;
2348 }
2349
2350 status = 1;
2351 }
2352 break;
2353
2354 case RIG_CMD_SET_RF:
2355 /* check whether command is available */
2356 if (has_set->rfg && new->rfg) {
2357 value_t val;
2358
2359 val.f = set->rfg;
2360
2361 /* try to execute command */
2362 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_RF, val);
2363
2364 /* raise anomaly if execution did not succeed */
2365 if (retcode != RIG_OK) {
2366 grig_debug_local (RIG_DEBUG_ERR,
2367 _("%s: Failed to execute RIG_CMD_SET_RF:\n%s"),
2368 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2369
2370 rig_anomaly_raise (RIG_CMD_SET_RF);
2371 }
2372
2373 /* reset flag */
2374 new->rfg = FALSE;
2375 get->rfg = set->rfg;
2376
2377 status = 1;
2378 }
2379 break;
2380
2381 case RIG_CMD_GET_RF:
2382 /* check whether command is available */
2383 if (has_get->rfg) {
2384 value_t val;
2385
2386 /* try to execute command */
2387 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_RF, &val);
2388
2389 /* raise anomaly if execution did not succeed */
2390 if (retcode != RIG_OK) {
2391 grig_debug_local (RIG_DEBUG_ERR,
2392 _("%s: Failed to execute RIG_CMD_GET_RF:\n%s"),
2393 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2394
2395 rig_anomaly_raise (RIG_CMD_GET_RF);
2396 }
2397 else {
2398 get->rfg = val.f;
2399 }
2400
2401 status = 1;
2402 }
2403 break;
2404
2405 case RIG_CMD_SET_SQL:
2406 /* check whether command is available */
2407 if (has_set->sql && new->sql) {
2408 value_t val;
2409
2410 val.f = set->sql;
2411
2412 /* try to execute command */
2413 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_SQL, val);
2414
2415 /* raise anomaly if execution did not succeed */
2416 if (retcode != RIG_OK) {
2417 grig_debug_local (RIG_DEBUG_ERR,
2418 _("%s: Failed to execute RIG_CMD_SET_SQL:\n%s"),
2419 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2420
2421 rig_anomaly_raise (RIG_CMD_SET_SQL);
2422 }
2423
2424 /* reset flag */
2425 new->sql = FALSE;
2426 get->sql = set->sql;
2427
2428 status = 1;
2429 }
2430 break;
2431
2432 case RIG_CMD_GET_SQL:
2433 /* check whether command is available */
2434 if (has_get->sql) {
2435 value_t val;
2436
2437 /* try to execute command */
2438 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_SQL, &val);
2439
2440 /* raise anomaly if execution did not succeed */
2441 if (retcode != RIG_OK) {
2442 grig_debug_local (RIG_DEBUG_ERR,
2443 _("%s: Failed to execute RIG_CMD_GET_SQL:\n%s"),
2444 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2445
2446 rig_anomaly_raise (RIG_CMD_GET_SQL);
2447 }
2448 else {
2449 get->sql = val.f;
2450 }
2451
2452 status = 1;
2453 }
2454 break;
2455
2456 case RIG_CMD_SET_IFS:
2457 /* check whether command is available */
2458 if (has_set->ifs && new->ifs) {
2459 value_t val;
2460
2461 val.i = set->ifs;
2462
2463 /* try to execute command */
2464 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_IF, val);
2465
2466 /* raise anomaly if execution did not succeed */
2467 if (retcode != RIG_OK) {
2468 grig_debug_local (RIG_DEBUG_ERR,
2469 _("%s: Failed to execute RIG_CMD_SET_IFS:\n%s"),
2470 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2471
2472 rig_anomaly_raise (RIG_CMD_SET_IFS);
2473 }
2474
2475 /* reset flag */
2476 new->ifs = FALSE;
2477 get->ifs = set->ifs;
2478
2479 status = 1;
2480 }
2481 break;
2482
2483 case RIG_CMD_GET_IFS:
2484 /* check whether command is available */
2485 if (has_get->ifs) {
2486 value_t val;
2487
2488 /* try to execute command */
2489 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_IF, &val);
2490
2491 /* raise anomaly if execution did not succeed */
2492 if (retcode != RIG_OK) {
2493 grig_debug_local (RIG_DEBUG_ERR,
2494 _("%s: Failed to execute RIG_CMD_GET_IFS:\n%s"),
2495 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2496
2497 rig_anomaly_raise (RIG_CMD_GET_IFS);
2498 }
2499 else {
2500 get->ifs = val.i;
2501 }
2502
2503 status = 1;
2504 }
2505 break;
2506
2507 case RIG_CMD_SET_APF:
2508 /* check whether command is available */
2509 if (has_set->apf && new->apf) {
2510 value_t val;
2511
2512 val.f = set->apf;
2513
2514 /* try to execute command */
2515 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_APF, val);
2516
2517 /* raise anomaly if execution did not succeed */
2518 if (retcode != RIG_OK) {
2519 grig_debug_local (RIG_DEBUG_ERR,
2520 _("%s: Failed to execute RIG_CMD_SET_APF:\n%s"),
2521 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2522
2523 rig_anomaly_raise (RIG_CMD_SET_APF);
2524 }
2525
2526 /* reset flag */
2527 new->apf = FALSE;
2528 get->apf = set->apf;
2529
2530 status = 1;
2531 }
2532 break;
2533
2534 case RIG_CMD_GET_APF:
2535 /* check whether command is available */
2536 if (has_get->apf) {
2537 value_t val;
2538
2539 /* try to execute command */
2540 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_APF, &val);
2541
2542 /* raise anomaly if execution did not succeed */
2543 if (retcode != RIG_OK) {
2544 grig_debug_local (RIG_DEBUG_ERR,
2545 _("%s: Failed to execute RIG_CMD_GET_APF:\n%s"),
2546 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2547
2548 rig_anomaly_raise (RIG_CMD_GET_APF);
2549 }
2550 else {
2551 get->apf = val.f;
2552 }
2553
2554 status = 1;
2555 }
2556 break;
2557
2558 case RIG_CMD_SET_NR:
2559 /* check whether command is available */
2560 if (has_set->nr && new->nr) {
2561 value_t val;
2562
2563 val.f = set->nr;
2564
2565 /* try to execute command */
2566 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_NR, val);
2567
2568 /* raise anomaly if execution did not succeed */
2569 if (retcode != RIG_OK) {
2570 grig_debug_local (RIG_DEBUG_ERR,
2571 _("%s: Failed to execute RIG_CMD_SET_NR:\n%s"),
2572 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2573
2574 rig_anomaly_raise (RIG_CMD_SET_NR);
2575 }
2576
2577 /* reset flag */
2578 new->nr = FALSE;
2579 get->nr = set->nr;
2580
2581 status = 1;
2582 }
2583 break;
2584
2585 case RIG_CMD_GET_NR:
2586 /* check whether command is available */
2587 if (has_get->nr) {
2588 value_t val;
2589
2590 /* try to execute command */
2591 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_NR, &val);
2592
2593 /* raise anomaly if execution did not succeed */
2594 if (retcode != RIG_OK) {
2595 grig_debug_local (RIG_DEBUG_ERR,
2596 _("%s: Failed to execute RIG_CMD_GET_NR:\n%s"),
2597 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2598
2599 rig_anomaly_raise (RIG_CMD_GET_NR);
2600 }
2601 else {
2602 get->nr = val.f;
2603 }
2604
2605 status = 1;
2606 }
2607 break;
2608
2609 case RIG_CMD_SET_NOTCH:
2610 /* check whether command is available */
2611 if (has_set->notch && new->notch) {
2612 value_t val;
2613
2614 val.i = set->notch;
2615
2616 /* try to execute command */
2617 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_NOTCHF, val);
2618
2619 /* raise anomaly if execution did not succeed */
2620 if (retcode != RIG_OK) {
2621 grig_debug_local (RIG_DEBUG_ERR,
2622 _("%s: Failed to execute RIG_CMD_SET_NOTCH:\n%s"),
2623 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2624
2625 rig_anomaly_raise (RIG_CMD_SET_NOTCH);
2626 }
2627
2628 /* reset flag */
2629 new->notch = FALSE;
2630 get->notch = set->notch;
2631
2632 status = 1;
2633 }
2634 break;
2635
2636 case RIG_CMD_GET_NOTCH:
2637 /* check whether command is available */
2638 if (has_get->notch) {
2639 value_t val;
2640
2641 /* try to execute command */
2642 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_NOTCHF, &val);
2643
2644 /* raise anomaly if execution did not succeed */
2645 if (retcode != RIG_OK) {
2646 grig_debug_local (RIG_DEBUG_ERR,
2647 _("%s: Failed to execute RIG_CMD_GET_NOTCH:\n%s"),
2648 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2649
2650 rig_anomaly_raise (RIG_CMD_GET_NOTCH);
2651 }
2652 else {
2653 get->notch = val.i;
2654 }
2655
2656 status = 1;
2657 }
2658 break;
2659
2660 case RIG_CMD_SET_PBT_IN:
2661 /* check whether command is available */
2662 if (has_set->pbtin && new->pbtin) {
2663 value_t val;
2664
2665 val.f = set->pbtin;
2666
2667 /* try to execute command */
2668 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_PBT_IN, val);
2669
2670 /* raise anomaly if execution did not succeed */
2671 if (retcode != RIG_OK) {
2672 grig_debug_local (RIG_DEBUG_ERR,
2673 _("%s: Failed to execute RIG_CMD_SET_PBT_IN:\n%s"),
2674 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2675
2676 rig_anomaly_raise (RIG_CMD_SET_PBT_IN);
2677 }
2678
2679 /* reset flag */
2680 new->pbtin = FALSE;
2681 get->pbtin = set->pbtin;
2682
2683 status = 1;
2684 }
2685 break;
2686
2687 case RIG_CMD_GET_PBT_IN:
2688 /* check whether command is available */
2689 if (has_get->pbtin) {
2690 value_t val;
2691
2692 /* try to execute command */
2693 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_PBT_IN, &val);
2694
2695 /* raise anomaly if execution did not succeed */
2696 if (retcode != RIG_OK) {
2697 grig_debug_local (RIG_DEBUG_ERR,
2698 _("%s: Failed to execute RIG_CMD_GET_PBT_IN:\n%s"),
2699 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2700
2701 rig_anomaly_raise (RIG_CMD_GET_PBT_IN);
2702 }
2703 else {
2704 get->pbtin = val.f;
2705 }
2706
2707 status = 1;
2708 }
2709 break;
2710
2711 case RIG_CMD_SET_PBT_OUT:
2712 /* check whether command is available */
2713 if (has_set->pbtout && new->pbtout) {
2714 value_t val;
2715
2716 val.f = set->pbtout;
2717
2718 /* try to execute command */
2719 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_PBT_OUT, val);
2720
2721 /* raise anomaly if execution did not succeed */
2722 if (retcode != RIG_OK) {
2723 grig_debug_local (RIG_DEBUG_ERR,
2724 _("%s: Failed to execute RIG_CMD_SET_PBT_OUT:\n%s"),
2725 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2726
2727 rig_anomaly_raise (RIG_CMD_SET_PBT_OUT);
2728 }
2729
2730 /* reset flag */
2731 new->pbtout = FALSE;
2732 get->pbtout = set->pbtout;
2733
2734 status = 1;
2735 }
2736 break;
2737
2738 case RIG_CMD_GET_PBT_OUT:
2739 /* check whether command is available */
2740 if (has_get->pbtout) {
2741 value_t val;
2742
2743 /* try to execute command */
2744 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_PBT_OUT, &val);
2745
2746 /* raise anomaly if execution did not succeed */
2747 if (retcode != RIG_OK) {
2748 grig_debug_local (RIG_DEBUG_ERR,
2749 _("%s: Failed to execute RIG_CMD_GET_PBT_OUT:\n%s"),
2750 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2751
2752 rig_anomaly_raise (RIG_CMD_GET_PBT_OUT);
2753 }
2754 else {
2755 get->pbtout = val.f;
2756 }
2757
2758 status = 1;
2759 }
2760 break;
2761
2762 case RIG_CMD_SET_CW_PITCH:
2763 /* check whether command is available */
2764 if (has_set->cwpitch && new->cwpitch) {
2765 value_t val;
2766
2767 val.i = set->cwpitch;
2768
2769 /* try to execute command */
2770 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_CWPITCH, val);
2771
2772 /* raise anomaly if execution did not succeed */
2773 if (retcode != RIG_OK) {
2774 grig_debug_local (RIG_DEBUG_ERR,
2775 _("%s: Failed to execute RIG_CMD_SET_CW_PITCH:\n%s"),
2776 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2777
2778 rig_anomaly_raise (RIG_CMD_SET_CW_PITCH);
2779 }
2780
2781 /* reset flag */
2782 new->cwpitch = FALSE;
2783 get->cwpitch = set->cwpitch;
2784
2785 status = 1;
2786 }
2787 break;
2788
2789 case RIG_CMD_GET_CW_PITCH:
2790 /* check whether command is available */
2791 if (has_get->cwpitch) {
2792 value_t val;
2793
2794 /* try to execute command */
2795 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_CWPITCH, &val);
2796
2797 /* raise anomaly if execution did not succeed */
2798 if (retcode != RIG_OK) {
2799 grig_debug_local (RIG_DEBUG_ERR,
2800 _("%s: Failed to execute RIG_CMD_GET_CW_PITCH:\n%s"),
2801 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2802
2803 rig_anomaly_raise (RIG_CMD_GET_CW_PITCH);
2804 }
2805 else {
2806 get->cwpitch = val.i;
2807 }
2808
2809 status = 1;
2810 }
2811 break;
2812
2813 case RIG_CMD_SET_KEYSPD:
2814 /* check whether command is available */
2815 if (has_set->keyspd && new->keyspd) {
2816 value_t val;
2817
2818 val.i = set->keyspd;
2819
2820 /* try to execute command */
2821 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_KEYSPD, val);
2822
2823 /* raise anomaly if execution did not succeed */
2824 if (retcode != RIG_OK) {
2825 grig_debug_local (RIG_DEBUG_ERR,
2826 _("%s: Failed to execute RIG_CMD_SET_KEYSPD:\n%s"),
2827 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2828
2829 rig_anomaly_raise (RIG_CMD_SET_KEYSPD);
2830 }
2831
2832 /* reset flag */
2833 new->keyspd = FALSE;
2834 get->keyspd = set->keyspd;
2835
2836 status = 1;
2837 }
2838 break;
2839
2840 case RIG_CMD_GET_KEYSPD:
2841 /* check whether command is available */
2842 if (has_get->keyspd) {
2843 value_t val;
2844
2845 /* try to execute command */
2846 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_KEYSPD, &val);
2847
2848 /* raise anomaly if execution did not succeed */
2849 if (retcode != RIG_OK) {
2850 grig_debug_local (RIG_DEBUG_ERR,
2851 _("%s: Failed to execute RIG_CMD_GET_KEYSPD:\n%s"),
2852 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2853
2854 rig_anomaly_raise (RIG_CMD_GET_KEYSPD);
2855 }
2856 else {
2857 get->keyspd = val.i;
2858 }
2859
2860 status = 1;
2861 }
2862 break;
2863
2864 case RIG_CMD_SET_BKINDEL:
2865 /* check whether command is available */
2866 if (has_set->bkindel && new->bkindel) {
2867 value_t val;
2868
2869 val.i = set->bkindel;
2870
2871 /* try to execute command */
2872 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_BKINDL, val);
2873
2874 /* raise anomaly if execution did not succeed */
2875 if (retcode != RIG_OK) {
2876 grig_debug_local (RIG_DEBUG_ERR,
2877 _("%s: Failed to execute RIG_CMD_SET_BKINDEL:\n%s"),
2878 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2879
2880 rig_anomaly_raise (RIG_CMD_SET_BKINDEL);
2881 }
2882
2883 /* reset flag */
2884 new->bkindel = FALSE;
2885 get->bkindel = set->bkindel;
2886
2887 status = 1;
2888 }
2889 break;
2890
2891 case RIG_CMD_GET_BKINDEL:
2892 /* check whether command is available */
2893 if (has_get->bkindel) {
2894 value_t val;
2895
2896 /* try to execute command */
2897 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_BKINDL, &val);
2898
2899 /* raise anomaly if execution did not succeed */
2900 if (retcode != RIG_OK) {
2901 grig_debug_local (RIG_DEBUG_ERR,
2902 _("%s: Failed to execute RIG_CMD_GET_BKINDEL:\n%s"),
2903 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2904
2905 rig_anomaly_raise (RIG_CMD_GET_BKINDEL);
2906 }
2907 else {
2908 get->bkindel = val.i;
2909 }
2910
2911 status = 1;
2912 }
2913 break;
2914
2915 case RIG_CMD_SET_BALANCE:
2916 /* check whether command is available */
2917 if (has_set->balance && new->balance) {
2918 value_t val;
2919
2920 val.f = set->balance;
2921
2922 /* try to execute command */
2923 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_BALANCE, val);
2924
2925 /* raise anomaly if execution did not succeed */
2926 if (retcode != RIG_OK) {
2927 grig_debug_local (RIG_DEBUG_ERR,
2928 _("%s: Failed to execute RIG_CMD_SET_BALANCE:\n%s"),
2929 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2930
2931 rig_anomaly_raise (RIG_CMD_SET_BALANCE);
2932 }
2933
2934 /* reset flag */
2935 new->balance = FALSE;
2936 get->balance = set->balance;
2937
2938 status = 1;
2939 }
2940 break;
2941
2942 case RIG_CMD_GET_BALANCE:
2943 /* check whether command is available */
2944 if (has_get->balance) {
2945 value_t val;
2946
2947 /* try to execute command */
2948 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_BALANCE, &val);
2949
2950 /* raise anomaly if execution did not succeed */
2951 if (retcode != RIG_OK) {
2952 grig_debug_local (RIG_DEBUG_ERR,
2953 _("%s: Failed to execute RIG_CMD_GET_BALANCE:\n%s"),
2954 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2955
2956 rig_anomaly_raise (RIG_CMD_GET_BALANCE);
2957 }
2958 else {
2959 get->balance = val.f;
2960 }
2961
2962 status = 1;
2963 }
2964 break;
2965
2966 case RIG_CMD_SET_VOXDEL:
2967 /* check whether command is available */
2968 if (has_set->voxdel && new->voxdel) {
2969 value_t val;
2970
2971 val.i = set->voxdel;
2972
2973 /* try to execute command */
2974 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_VOXDELAY, val);
2975
2976 /* raise anomaly if execution did not succeed */
2977 if (retcode != RIG_OK) {
2978 grig_debug_local (RIG_DEBUG_ERR,
2979 _("%s: Failed to execute RIG_CMD_SET_VOXDEL:\n%s"),
2980 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
2981
2982 rig_anomaly_raise (RIG_CMD_SET_VOXDEL);
2983 }
2984
2985 /* reset flag */
2986 new->voxdel = FALSE;
2987 get->voxdel = set->voxdel;
2988
2989 status = 1;
2990 }
2991 break;
2992
2993 case RIG_CMD_GET_VOXDEL:
2994 /* check whether command is available */
2995 if (has_get->voxdel) {
2996 value_t val;
2997
2998 /* try to execute command */
2999 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_VOXDELAY, &val);
3000
3001 /* raise anomaly if execution did not succeed */
3002 if (retcode != RIG_OK) {
3003 grig_debug_local (RIG_DEBUG_ERR,
3004 _("%s: Failed to execute RIG_CMD_GET_VOXDEL:\n%s"),
3005 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
3006
3007 rig_anomaly_raise (RIG_CMD_GET_VOXDEL);
3008 }
3009 else {
3010 get->voxdel = val.i;
3011 }
3012
3013 status = 1;
3014 }
3015 break;
3016
3017 case RIG_CMD_SET_VOXGAIN:
3018 /* check whether command is available */
3019 if (has_set->voxg && new->voxg) {
3020 value_t val;
3021
3022 val.f = set->voxg;
3023
3024 /* try to execute command */
3025 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_VOXGAIN, val);
3026
3027 /* raise anomaly if execution did not succeed */
3028 if (retcode != RIG_OK) {
3029 grig_debug_local (RIG_DEBUG_ERR,
3030 _("%s: Failed to execute RIG_CMD_SET_VOXGAIN:\n%s"),
3031 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
3032
3033 rig_anomaly_raise (RIG_CMD_SET_VOXGAIN);
3034 }
3035
3036 /* reset flag */
3037 new->voxg = FALSE;
3038 get->voxg = set->voxg;
3039
3040 status = 1;
3041 }
3042 break;
3043
3044 case RIG_CMD_GET_VOXGAIN:
3045 /* check whether command is available */
3046 if (has_get->voxg) {
3047 value_t val;
3048
3049 /* try to execute command */
3050 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_VOXGAIN, &val);
3051
3052 /* raise anomaly if execution did not succeed */
3053 if (retcode != RIG_OK) {
3054 grig_debug_local (RIG_DEBUG_ERR,
3055 _("%s: Failed to execute RIG_CMD_GET_VOXGAIN:\n%s"),
3056 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
3057
3058 rig_anomaly_raise (RIG_CMD_GET_VOXGAIN);
3059 }
3060 else {
3061 get->voxg = val.f;
3062 }
3063
3064 status = 1;
3065 }
3066 break;
3067
3068 case RIG_CMD_SET_ANTIVOX:
3069 /* check whether command is available */
3070 if (has_set->antivox && new->antivox) {
3071 value_t val;
3072
3073 val.f = set->antivox;
3074
3075 /* try to execute command */
3076 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_ANTIVOX, val);
3077
3078 /* raise anomaly if execution did not succeed */
3079 if (retcode != RIG_OK) {
3080 grig_debug_local (RIG_DEBUG_ERR,
3081 _("%s: Failed to execute RIG_CMD_SET_ANTIVOX:\n%s"),
3082 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
3083
3084 rig_anomaly_raise (RIG_CMD_SET_ANTIVOX);
3085 }
3086
3087 /* reset flag */
3088 new->antivox = FALSE;
3089 get->antivox = set->antivox;
3090
3091 status = 1;
3092 }
3093 break;
3094
3095 case RIG_CMD_GET_ANTIVOX:
3096 /* check whether command is available */
3097 if (has_get->antivox) {
3098 value_t val;
3099
3100 /* try to execute command */
3101 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_ANTIVOX, &val);
3102
3103 /* raise anomaly if execution did not succeed */
3104 if (retcode != RIG_OK) {
3105 grig_debug_local (RIG_DEBUG_ERR,
3106 _("%s: Failed to execute RIG_CMD_GET_ANTIVOX:\n%s"),
3107 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
3108
3109 rig_anomaly_raise (RIG_CMD_GET_ANTIVOX);
3110 }
3111 else {
3112 get->antivox = val.f;
3113 }
3114
3115 status = 1;
3116 }
3117 break;
3118
3119 case RIG_CMD_SET_MICGAIN:
3120 /* check whether command is available */
3121 if (has_set->micg && new->micg) {
3122 value_t val;
3123
3124 val.f = set->micg;
3125
3126 /* try to execute command */
3127 retcode = rig_set_level (myrig, RIG_VFO_CURR, RIG_LEVEL_MICGAIN, val);
3128
3129 /* raise anomaly if execution did not succeed */
3130 if (retcode != RIG_OK) {
3131 grig_debug_local (RIG_DEBUG_ERR,
3132 _("%s: Failed to execute RIG_CMD_SET_MICGAIN:\n%s"),
3133 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
3134
3135 rig_anomaly_raise (RIG_CMD_SET_MICGAIN);
3136 }
3137
3138 /* reset flag */
3139 new->micg = FALSE;
3140 get->micg = set->micg;
3141
3142 status = 1;
3143 }
3144 break;
3145
3146 case RIG_CMD_GET_MICGAIN:
3147 /* check whether command is available */
3148 if (has_get->micg) {
3149 value_t val;
3150
3151 /* try to execute command */
3152 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_MICGAIN, &val);
3153
3154 /* raise anomaly if execution did not succeed */
3155 if (retcode != RIG_OK) {
3156 grig_debug_local (RIG_DEBUG_ERR,
3157 _("%s: Failed to execute RIG_CMD_GET_MICGAIN:\n%s"),
3158 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
3159
3160 rig_anomaly_raise (RIG_CMD_GET_MICGAIN);
3161 }
3162 else {
3163 get->micg = val.f;
3164 }
3165
3166 status = 1;
3167 }
3168 break;
3169
3170 case RIG_CMD_SET_COMP:
3171 break;
3172
3173 case RIG_CMD_GET_COMP:
3174 /* check whether command is available */
3175 if (has_get->comp) {
3176 value_t val;
3177
3178 /* try to execute command */
3179 retcode = rig_get_level (myrig, RIG_VFO_CURR, RIG_LEVEL_COMP, &val);
3180
3181 /* raise anomaly if execution did not succeed */
3182 if (retcode != RIG_OK) {
3183 grig_debug_local (RIG_DEBUG_ERR,
3184 _("%s: Failed to execute RIG_CMD_GET_COMP:\n%s"),
3185 __FUNCTION__, ERR_TO_STR[abs(retcode)]);
3186
3187 rig_anomaly_raise (RIG_CMD_GET_COMP);
3188 }
3189 else {
3190 get->comp = val.f;
3191 }
3192
3193 status = 1;
3194 }
3195 break;
3196
3197 /* set FUNC's status */
3198 case RIG_CMD_SET_FUNC:
3199
3200 for (i = 0; i < RIG_SETTING_MAX; i++) {
3201 func = rig_idx2setting(i);
3202 if (has_set->funcs[i] && new->funcs[i]) {
3203 retcode = rig_set_func (myrig,
3204 RIG_VFO_CURR,
3205 func,
3206 set->funcs[i]);
3207
3208 if (retcode != RIG_OK) {
3209 grig_debug_local (RIG_DEBUG_ERR,
3210 _("%s: Failed to execute RIG_CMD_SET_FUNC(%s):\n%s"),
3211 __FUNCTION__, rig_strfunc(func), ERR_TO_STR[abs(retcode)]);
3212
3213 rig_anomaly_raise (RIG_CMD_SET_FUNC);
3214 }
3215
3216 get->funcs[i] = set->funcs[i];
3217 new->funcs[i] = 0;
3218
3219 status = 1;
3220 }
3221 }
3222
3223 break;
3224
3225 /* get FUNC's status */
3226 case RIG_CMD_GET_FUNC:
3227
3228 for (i = 0; i < RIG_SETTING_MAX; i++) {
3229 func = rig_idx2setting(i);
3230 /* check whether command is available */
3231 if (has_get->funcs[i]) {
3232 int func_status;
3233
3234 /* try to execute command */
3235 retcode = rig_get_func (myrig, RIG_VFO_CURR, func, &func_status);
3236
3237 /* raise anomaly if execution did not succeed */
3238 if (retcode != RIG_OK) {
3239 grig_debug_local (RIG_DEBUG_ERR,
3240 _("%s: Failed to execute RIG_CMD_GET_FUNC(%s):\n%s"),
3241 __FUNCTION__, rig_strfunc(func), ERR_TO_STR[abs(retcode)]);
3242
3243 rig_anomaly_raise (RIG_CMD_GET_FUNC);
3244 }
3245 else {
3246 get->funcs[i] = func_status;
3247 }
3248
3249 status = 1;
3250 }
3251 }
3252
3253 break;
3254
3255
3256 /* bug in grig! */
3257 default:
3258 grig_debug_local (RIG_DEBUG_BUG,
3259 _("%s: Unknown command %d (grig bug)"),
3260 __FUNCTION__, cmd);
3261 break;
3262
3263 }
3264
3265 return status;
3266
3267 }
3268
3269
3270 /** \brief Get hamlib id of radio.
3271 * \return The id of the rig
3272 */
3273 gint
rig_daemon_get_rig_id()3274 rig_daemon_get_rig_id ()
3275 {
3276 if (myrig == NULL) {
3277 return -1;
3278 }
3279
3280 return myrig->caps->rig_model;
3281 }
3282
3283 /** \brief Get radio brand.
3284 * \return A character string containing the radio brand.
3285 *
3286 * This function returns the brand of the currently active radio.
3287 * If no radio has yet been initialised the function returns NULL.
3288 * The returned string should be freed when no longer needed.
3289 */
3290 gchar *
rig_daemon_get_brand()3291 rig_daemon_get_brand ()
3292 {
3293 gchar *text;
3294
3295 if (myrig == NULL) {
3296 return NULL;
3297 }
3298 text = g_strdup (myrig->caps->mfg_name);
3299
3300 return text;
3301 }
3302
3303
3304 /** \brief Get radio model.
3305 * \return A character string containing the radio model.
3306 *
3307 * This function returns the model of the currently active radio.
3308 * If no radio has yet been initialised the function returns NULL.
3309 * The returned string should be freed when no longer needed.
3310 */
3311 gchar *
rig_daemon_get_model()3312 rig_daemon_get_model ()
3313 {
3314 gchar *text;
3315
3316 if (myrig == NULL) {
3317 return NULL;
3318 }
3319 text = g_strdup (myrig->caps->model_name);
3320
3321 return text;
3322 }
3323
3324
3325 /** \brief Get command delay.
3326 * \return The current command delay in msec.
3327 *
3328 * This function returns the current command delay
3329 * in milliseconds. This allows the GUI to have a rough idea
3330 * about what delay to use in the readback timeout functions.
3331 */
3332 gint
rig_daemon_get_delay()3333 rig_daemon_get_delay ()
3334 {
3335 return cmd_delay;
3336 }
3337
3338
3339 /** \brief Suspend daemon.
3340 * \param spnd Flag indicating whether to suspend or re-enable the daemon.
3341 *
3342 * This function can be used to suspend the daemon without shutting it down.
3343 * TRUE means suspend the daemon while FALSE means re-enable execution.
3344 * When in suspended mode, the daemon will keep on executing it's cycles,
3345 * but no commands will be sent to hamlib, as long as the daemon is suspended.
3346 */
3347 void
rig_daemon_set_suspend(gboolean spnd)3348 rig_daemon_set_suspend (gboolean spnd)
3349 {
3350 suspended = spnd;
3351
3352 grig_debug_local (RIG_DEBUG_VERBOSE, _("%s: %d"), __FUNCTION__, spnd);
3353 }
3354
3355
3356 /** \brief Check suspended status of daemon.
3357 * \return TRUE if the daemon is suspended, FALSE otherwise.
3358 *
3359 * This function can be used to check whether the daemon is currently suspended
3360 * or not.
3361 */
3362 gboolean
rig_daemon_get_suspend(void)3363 rig_daemon_get_suspend (void)
3364 {
3365 return suspended;
3366 }
3367