Hamlib  4.2
rigclass.h
1 /*
2  * Hamlib C++ bindings - API header
3  * Copyright (c) 2001-2002 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 #ifndef _RIGCLASS_H
23 #define _RIGCLASS_H 1
24 
25 #include <hamlib/rig.h>
26 #include <iostream>
27 
28 
30 class HAMLIB_CPP_IMPEXP Rig
31 {
32 private:
33  RIG *theRig; // Global ref. to the rig
34 
35 protected:
36 public:
37  explicit Rig(rig_model_t rig_model);
38 
39  virtual ~Rig();
40 
41  Rig(const Rig&) = default;
42  Rig(Rig&&) = default;
43  Rig& operator=(const Rig&) = default;
44  Rig& operator=(Rig&&) = default;
45 
46  const struct rig_caps *caps;
47 
48  // This method opens the communication port to the rig
49  void open(void);
50 
51  // This method closes the communication port to the rig
52  void close(void);
53 
54  void setConf(token_t token, const char *val);
55  void setConf(const char *name, const char *val);
56  void getConf(token_t token, char *val);
57  void getConf(const char *name, char *val);
58  token_t tokenLookup(const char *name);
59 
60  void setFreq(freq_t freq, vfo_t vfo = RIG_VFO_CURR);
61  freq_t getFreq(vfo_t vfo = RIG_VFO_CURR);
62  void setMode(rmode_t,
64  vfo_t vfo = RIG_VFO_CURR);
65 
66  rmode_t getMode(pbwidth_t&, vfo_t vfo = RIG_VFO_CURR);
67  void setVFO(vfo_t);
68  vfo_t getVFO();
69 
70  void setPTT(ptt_t ptt, vfo_t vfo = RIG_VFO_CURR);
71  ptt_t getPTT(vfo_t vfo = RIG_VFO_CURR);
72  dcd_t getDCD(vfo_t vfo = RIG_VFO_CURR);
73 
74  void setLevel(setting_t level, int vali, vfo_t vfo = RIG_VFO_CURR);
75  void setLevel(setting_t level, float valf, vfo_t vfo = RIG_VFO_CURR);
76  void getLevel(setting_t level, int& vali, vfo_t vfo = RIG_VFO_CURR);
77  void getLevel(setting_t level, float& valf, vfo_t vfo = RIG_VFO_CURR);
78  int getLevelI(setting_t level, vfo_t vfo = RIG_VFO_CURR);
79  float getLevelF(setting_t level, vfo_t vfo = RIG_VFO_CURR);
80  bool hasGetLevel(setting_t level);
81  bool hasSetLevel(setting_t level);
82 
83  void setParm(setting_t parm, int vali);
84  void setParm(setting_t parm, float valf);
85  void getParm(setting_t parm, int& vali);
86  void getParm(setting_t parm, float& valf);
87  int getParmI(setting_t parm);
88  float getParmF(setting_t parm);
89  bool hasGetParm(setting_t parm);
90  bool hasSetParm(setting_t parm);
91 
92  void setFunc(setting_t func, bool status, vfo_t vfo = RIG_VFO_CURR);
93  bool getFunc(setting_t func, vfo_t vfo = RIG_VFO_CURR);
94  bool hasGetFunc(setting_t func);
95  bool hasSetFunc(setting_t func);
96 
97  void VFOop(vfo_op_t op, vfo_t vfo = RIG_VFO_CURR);
98  bool hasVFOop(vfo_op_t op);
99 
100  void scan(scan_t scan, int ch, vfo_t vfo = RIG_VFO_CURR);
101  bool hasScan(scan_t scan);
102 
103  const char * getInfo(void);
104  pbwidth_t passbandNormal(rmode_t);
105  pbwidth_t passbandNarrow(rmode_t);
106  pbwidth_t passbandWide(rmode_t);
107 
108  void setRptrShift(rptr_shift_t rptr_shift, vfo_t vfo = RIG_VFO_CURR);
109  rptr_shift_t getRptrShift(vfo_t vfo = RIG_VFO_CURR);
110  void setRptrOffs(shortfreq_t rptr_offs, vfo_t vfo = RIG_VFO_CURR);
111  shortfreq_t getRptrOffs(vfo_t vfo = RIG_VFO_CURR);
112  void setTs(shortfreq_t ts, vfo_t vfo = RIG_VFO_CURR);
113  shortfreq_t getTs(vfo_t vfo = RIG_VFO_CURR);
114 
115  void setCTCSS(tone_t tone, vfo_t vfo = RIG_VFO_CURR);
116  tone_t getCTCSS(vfo_t vfo = RIG_VFO_CURR);
117  void setDCS(tone_t code, vfo_t vfo = RIG_VFO_CURR);
118  tone_t getDCS(vfo_t vfo = RIG_VFO_CURR);
119 
120  void setCTCSSsql(tone_t tone, vfo_t vfo = RIG_VFO_CURR);
121  tone_t getCTCSSsql(vfo_t vfo = RIG_VFO_CURR);
122  void setDCSsql(tone_t tone, vfo_t vfo = RIG_VFO_CURR);
123  tone_t getDCSsql(vfo_t vfo = RIG_VFO_CURR);
124 
125 
126  unsigned int power2mW(float power, freq_t freq, rmode_t mode);
127  float mW2power(unsigned int mwpower, freq_t freq, rmode_t mode);
128  void setTrn(int trn);
129  int getTrn(void);
130  void setBank(int bank, vfo_t vfo = RIG_VFO_CURR);
131  void setMem(int ch, vfo_t vfo = RIG_VFO_CURR);
132  int getMem(vfo_t vfo = RIG_VFO_CURR);
133 
134  void setChannel(const channel_t *chan, vfo_t vfo);
135  void getChannel(channel_t *chan, vfo_t vfo, int readOnly);
136 
137  void setPowerStat(powerstat_t status);
138  powerstat_t getPowerStat(void);
139  rmode_t RngRxModes(freq_t freq);
140  rmode_t RngTxModes(freq_t freq);
141 
142  void setSplitFreq(freq_t tx_freq, vfo_t vfo = RIG_VFO_CURR);
143  freq_t getSplitFreq(vfo_t vfo = RIG_VFO_CURR);
144  void setSplitMode(rmode_t,
146  vfo_t vfo = RIG_VFO_CURR);
147 
148  rmode_t getSplitMode(pbwidth_t&, vfo_t vfo = RIG_VFO_CURR);
149  void setSplitFreqMode(freq_t, rmode_t,
151  vfo_t vfo = RIG_VFO_CURR);
152 
153  freq_t getSplitFreqMode(rmode_t&, pbwidth_t&, vfo_t vfo = RIG_VFO_CURR);
154  void setSplitVFO(split_t split,
155  vfo_t vfo = RIG_VFO_CURR,
156  vfo_t tx_vfo = RIG_VFO_CURR);
157 
158  split_t getSplitVFO(vfo_t& tx_vfo, vfo_t vfo = RIG_VFO_CURR);
159 
160  void setRit(shortfreq_t rit, vfo_t vfo = RIG_VFO_CURR);
161  shortfreq_t getRit(vfo_t vfo = RIG_VFO_CURR);
162  void setXit(shortfreq_t xit, vfo_t vfo = RIG_VFO_CURR);
163  shortfreq_t getXit(vfo_t vfo = RIG_VFO_CURR);
164 
165  void setAnt(value_t option, ant_t ant, vfo_t vfo = RIG_VFO_CURR);
166  ant_t getAnt(ant_t &ant_rx, ant_t &ant_tx, ant_t ant, value_t &option, ant_t &ant_curr, vfo_t vfo = RIG_VFO_CURR);
167 
168  void sendDtmf(const char *digits, vfo_t vfo = RIG_VFO_CURR);
169  int recvDtmf(char *digits, vfo_t vfo = RIG_VFO_CURR);
170  void sendMorse(const char *msg, vfo_t vfo = RIG_VFO_CURR);
171 
172 
173  shortfreq_t getResolution(rmode_t mode);
174  void reset(reset_t reset);
175 
176  // callbacks available in your derived object
177  virtual int FreqEvent(vfo_t, freq_t, rig_ptr_t) const
178  {
179  return RIG_OK;
180  }
181  virtual int ModeEvent(vfo_t, rmode_t, pbwidth_t, rig_ptr_t) const
182  {
183  return RIG_OK;
184  }
185  virtual int VFOEvent(vfo_t, rig_ptr_t) const
186  {
187  return RIG_OK;
188  }
189  virtual int PTTEvent(vfo_t, ptt_t, rig_ptr_t) const
190  {
191  return RIG_OK;
192  }
193  virtual int DCDEvent(vfo_t, dcd_t, rig_ptr_t) const
194  {
195  return RIG_OK;
196  }
197 };
199 
200 
201 #ifdef __GNUG__
202 # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
203 # if HAVE_TYPEINFO
204 # include <typeinfo>
205 # endif
206 # endif
207 #endif
208 
209 #if defined(__GNUG__)
210 # if HAVE_BUILTIN_H || HAVE_GXX_BUILTIN_H || HAVE_GPP_BUILTIN_H
211 # if ETIP_NEEDS_MATH_H
212 # if ETIP_NEEDS_MATH_EXCEPTION
213 # undef exception
214 # define exception math_exception
215 # endif
216 # include <math.h>
217 # endif
218 # undef exception
219 # define exception builtin_exception
220 # if HAVE_GPP_BUILTIN_H
221 # include <gpp/builtin.h>
222 # elif HAVE_GXX_BUILTIN_H
223 # include <g++/builtin.h>
224 # else
225 # include <builtin.h>
226 # endif
227 # undef exception
228 # endif
229 #elif defined (__SUNPRO_CC)
230 # include <generic.h>
231 # include <string.h>
232 #else
233 # include <string.h>
234 #endif
235 
236 
237 extern "C" {
238 #if HAVE_VALUES_H
239 # include <values.h>
240 #endif
241 
242 #include <assert.h>
243 #include <errno.h>
244 }
245 
246 #include <iostream>
247 #if !(defined(__GNUG__)||defined(__SUNPRO_CC)||defined(_WIN32))
248 extern "C" void exit(int);
249 #endif
250 
251 
253 // Forward Declarations
254 class HAMLIB_CPP_IMPEXP RigException
255 {
256 public:
257  const char *message;
258  int errorno;
259 
260  explicit RigException(const char *msg, int err)
261  : message(msg), errorno(err)
262  {};
263 
264  explicit RigException(int err)
265  : message(rigerror(err)), errorno(err)
266  {};
267 
268  explicit RigException(const char *msg)
269  : message(msg), errorno(-RIG_EINTERNAL)
270  {};
271 
272  virtual ~RigException()
273  {};
274 
275  void print() const
276  {
277  std::cerr << "Rig exception: " << message << std::endl;
278  }
279  virtual const char *classname() const
280  {
281  return "Rig";
282  }
283 };
285 
286 
287 inline void THROW(const RigException *e)
288 {
289 #if defined(__GNUG__)
290 # if ((__GNUG__ <= 2) && (__GNUC_MINOR__ < 8))
291  (*lib_error_handler)(e ? e->classname() : "", e ? e->message : "");
292 #else
293  throw *e;
294 #endif
295 #elif defined(__SUNPRO_CC)
296  genericerror(1, ((e != 0) ? (char *)(e->message) : ""));
297 #else
298 
299  if (e) {
300  std::cerr << e->message << std::endl;
301  }
302 
303  exit(0);
304 #endif
305 }
306 
307 #define THROWS(s)
308 
309 
310 #endif // _RIGCLASS_H
unsigned int vfo_t
VFO definition.
Definition: rig.h:413
uint64_t rmode_t
Radio mode.
Definition: rig.h:1147
shortfreq_t pbwidth_t
Definition: rig.h:540
split_t
Split mode.
Definition: rig.h:342
rptr_shift_t
Repeater shift type.
Definition: rig.h:332
uint64_t setting_t
Setting.
Definition: rig.h:992
powerstat_t
Radio power state.
Definition: rig.h:602
enum dcd_e dcd_t
DCD status.
scan_t
Rig Scan operation.
Definition: rig.h:664
#define RIG_VFO_CURR
currVFO – current "tunable channel"/VFO
Definition: rig.h:465
double freq_t
Frequency type,.
Definition: rig.h:353
ptt_t
PTT status.
Definition: rig.h:573
#define RIG_PASSBAND_NORMAL
Macro for bandpass to be set to normal.
Definition: rig.h:529
vfo_op_t
VFO operation.
Definition: rig.h:638
signed long shortfreq_t
Short frequency type.
Definition: rig.h:375
long token_t
configuration token
Definition: rig.h:680
unsigned int ant_t
Antenna typedef.
Definition: rig.h:801
reset_t
Reset operation.
Definition: rig.h:614
@ RIG_OK
Definition: rig.h:123
@ RIG_EINTERNAL
Definition: rig.h:130
Hamlib rig data structures.
Channel structure.
Definition: rig.h:1355
The Rig structure.
Definition: rig.h:2330
Universal approach for passing values.
Definition: rig.h:856