1 // ---------------------------------------------------------------------------- 2 // Copyright (C) 2014 3 // David Freese, W1HKJ 4 // 5 // This file is part of fldigi 6 // 7 // fldigi is free software; you can redistribute it and/or modify 8 // it under the terms of the GNU General Public License as published by 9 // the Free Software Foundation; either version 3 of the License, or 10 // (at your option) any later version. 11 // 12 // fldigi is distributed in the hope that it will be useful, 13 // but WITHOUT ANY WARRANTY; without even the implied warranty of 14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 // GNU General Public License for more details. 16 // 17 // You should have received a copy of the GNU General Public License 18 // along with this program. If not, see <http://www.gnu.org/licenses/>. 19 // ---------------------------------------------------------------------------- 20 21 #ifndef _RIGCLASS_H 22 #define _RIGCLASS_H 23 24 #include <exception> 25 #include <string> 26 27 #include <hamlib/rig.h> 28 29 30 class RigException : public std::exception 31 { 32 public: 33 RigException(int e = 0) err(e)34 : err(e), msg(rigerror(e)) { } RigException(const char * m)35 RigException(const char* m) 36 : err(0), msg(m) { } RigException(const char * prefix,int e)37 RigException(const char* prefix, int e) 38 : err(e), msg(std::string(prefix).append(": ").append(rigerror(e))) { } ~RigException()39 virtual ~RigException() throw() { } 40 what(void)41 const char* what(void) const throw() { return msg.c_str(); } error(void)42 int error(void) const { return err; } 43 44 protected: 45 int err; 46 std::string msg; 47 }; 48 49 50 class Rig { 51 protected: 52 RIG *rig; // Global ref. to the rig 53 freq_t fnull; 54 public: 55 Rig(); 56 Rig(rig_model_t rig_model); 57 virtual ~Rig(); 58 59 void init(rig_model_t rig_model); 60 isOnLine()61 bool isOnLine() { return rig; } 62 63 // This method open the communication port to the rig 64 void open(void); 65 66 // This method close the communication port to the rig 67 void close(bool abort = false); 68 69 void setFreq(freq_t freq, vfo_t vfo = RIG_VFO_CURR); 70 freq_t getFreq(vfo_t vfo = RIG_VFO_CURR); 71 bool canSetFreq(); 72 bool canGetFreq(); 73 74 void setMode(rmode_t, pbwidth_t width = RIG_PASSBAND_NORMAL, vfo_t vfo = RIG_VFO_CURR); 75 rmode_t getMode(pbwidth_t&, vfo_t vfo = RIG_VFO_CURR); 76 bool canSetMode(); 77 bool canGetMode(); 78 79 void setPTT (ptt_t ptt, vfo_t vfo = RIG_VFO_CURR); 80 ptt_t getPTT (vfo_t vfo = RIG_VFO_CURR); 81 bool canSetPTT(); 82 bool canGetPTT(); 83 84 void setVFO(vfo_t); 85 vfo_t getVFO(); 86 87 void setConf(token_t token, const char *val); 88 void setConf(const char *name, const char *val); 89 void getConf(token_t token, char *val); 90 void getConf(const char *name, char *val); 91 const char *getName(); 92 const struct rig_caps* getCaps(void); 93 94 token_t tokenLookup(const char *name); 95 pbwidth_t passbandNormal (rmode_t mode); 96 pbwidth_t passbandNarrow (rmode_t mode); 97 pbwidth_t passbandWide (rmode_t mode); 98 99 }; 100 101 #endif 102