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