1 /*
2 * Hamlib TAPR backend - main file
3 * Copyright (c) 2003 by Stephane Fillod
4 *
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 *
20 */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <stdlib.h>
27 #include <string.h> /* String function definitions */
28 #include <unistd.h> /* UNIX standard function definitions */
29
30 #include "hamlib/rig.h"
31 #include "register.h"
32 #include "serial.h"
33
34 #include "tapr.h"
35
36 #define ESC '$'
37 #define CMD_LEN 6
38
39 #define CMD7 7
40
41 #define NU1 1
42 #define NU2 2
43 #define NU3 3
44 #define NU4 4
45
46 /*
47 * tapr_cmd
48 * We assume that rig!=NULL, rig->state!= NULL, data!=NULL
49 * Otherwise, you'll get a nice seg fault. You've been warned!
50 * TODO: error case handling
51 */
tapr_cmd(RIG * rig,unsigned char cmd,unsigned char c1,unsigned char c2,unsigned char c3,unsigned char c4)52 static int tapr_cmd(RIG *rig, unsigned char cmd, unsigned char c1,
53 unsigned char c2, unsigned char c3, unsigned char c4)
54 {
55 int retval;
56 struct rig_state *rs;
57 unsigned char cmdbuf[CMD_LEN];
58
59 rs = &rig->state;
60
61 rig_flush(&rs->rigport);
62
63 cmdbuf[0] = ESC;
64 cmdbuf[1] = cmd;
65 cmdbuf[2] = c1;
66 cmdbuf[3] = c2;
67 cmdbuf[4] = c3;
68 cmdbuf[5] = c4;
69
70 retval = write_block(&rs->rigport, (char *) cmdbuf, 6);
71
72 if (retval != RIG_OK)
73 {
74 return retval;
75 }
76
77 return RIG_OK;
78 }
79
80
81
82 /*
83 * tapr_set_freq
84 * Assumes rig!=NULL
85 */
tapr_set_freq(RIG * rig,vfo_t vfo,freq_t freq)86 int tapr_set_freq(RIG *rig, vfo_t vfo, freq_t freq)
87 {
88 unsigned int dsp_dph, dsp_deltap_lo, dsp_deltap_hi;
89 int retval;
90
91 return -RIG_ENIMPL; /* FIXME! */
92
93 dsp_dph = (unsigned int)(1.365333333 * (double)(freq - MHz(144) + 15000UL));
94 dsp_deltap_lo = 0xff & dsp_dph;
95 dsp_deltap_hi = 0xff & (dsp_dph >> 8);
96 retval = tapr_cmd(rig, CMD7, 0, NU1, dsp_deltap_lo, dsp_deltap_hi);
97
98 return retval;
99 }
100
101
102 /*
103 * tapr_set_mode
104 * Assumes rig!=NULL
105 */
tapr_set_mode(RIG * rig,vfo_t vfo,rmode_t mode,pbwidth_t width)106 int tapr_set_mode(RIG *rig, vfo_t vfo, rmode_t mode, pbwidth_t width)
107 {
108 return -RIG_ENIMPL;
109 }
110
111
112 /*
113 * initrigs_tapr is called by rig_backend_load
114 */
DECLARE_INITRIG_BACKEND(tapr)115 DECLARE_INITRIG_BACKEND(tapr)
116 {
117 rig_debug(RIG_DEBUG_VERBOSE, "%s: _init called\n", __func__);
118
119 rig_register(&dsp10_caps);
120
121 return RIG_OK;
122 }
123
124
125