#ifndef __TS590_h__ #define __TS590_h__ #include #include "DSP.h" #include "Rig.h" #include "TR.h" /**********************************************************************/ // uncomment to use TS-590SG / comment to use TS-590S #define USE_TS590SG #define TS590_COMMAND_MAX_LENGTH 50 // including terminator (which will get converted to null) const int ts590CommandMaxLength = TS590_COMMAND_MAX_LENGTH; void ts590SendCommand(const char*, ...); /*! * @brief Send a syntax error response to the PC via CAT. */ inline void ts590SyntaxError() { ts590SendCommand("?"); } /*! * @brief Send a communications error response to the PC via CAT. */ inline void ts590CommError() { ts590SendCommand("E"); } /*! * @brief Send a processing error response to the PC via CAT. */ inline void ts590ProcessError() { ts590SendCommand("O"); } enum TS590Error { NoError, SyntaxError, CommError, ProcessError }; /**********************************************************************/ /*! * @brief A TS590S/SG "CAT" command. This is the base class for all * CAT commands. */ class TS590Command { public: TS590Command(const char* pre); virtual ~TS590Command() = 0; /*! * @brief Return the 2-character prefix for the command. * @return The 2-character prefix for the command. */ inline const char* prefix() const { return &myPrefix[0]; } /*! * @brief Return the rig that this command will be used to control. */ inline UBitxRig* rig() const { return theRig; } /*! * @brief Return the DSP that this command will be used to control. */ inline UBitxDSP* dsp() const { return theDSP; } /*! * @brief Return the T/R that this command will be used to control. */ inline UBitxDSP* tr() const { return theTR; } /*! * @brief Handle the provided Set command. If the Set command * results in an error, then set the appropriate flag with * setSyntaxError(), setCommError(), or setProcessError(). * @param cmd * The current command string received from the PC via CAT. * It should be null-terminated, and should no longer have * the terminator (;). */ virtual void handleCommand(const char* cmd) = 0; /*! * @brief Send a response back to the PC. This assumes a * successful command (no errors). */ virtual void sendResponse(const char* cmd) = 0; virtual bool isReadCommand(const char* cmd) const; void process(const char* cmd); static void setSyntaxError(); static void setCommError(); static void setProcessError(); static void setRig(UBitxRig* r); static void setDSP(UBitxDSP* d); static void setTR(UBitxTR* t); private: char myPrefix[3] = "\0\0"; static TS590Error theError; static UBitxRig* theRig; static UBitxDSP* theDSP; }; /**********************************************************************/ /*! * @brief CAT command for setting or reading the VFO A/B frequency. */ template class TS590_FAB : public TS590Command { public: TS590_FAB(): TS590Command(VFOA ? "FA" : "FB") {} virtual void handleCommand(const char* cmd) { if (strlen(cmd) == 13) { unsigned long freq = strtoul(&cmd[2], NULL, 10); if (VFOA) { rig()->setFreqA(freq); } else { rig()->setFreqB(freq); } } else { setSyntaxError(); } } virtual void sendResponse(const char* cmd) { ts590SendCommand(VFOA ? "FA%011u" : "FB%011u", VFOA ? rig()->getFreqA() : rig()->getFreqB()); } }; typedef TS590_FAB TS590_FA; typedef TS590_FAB TS590_FB; /**********************************************************************/ /*! * @brief CAT command for setting the receiver VFO. This will always * disable split mode, if it was previously enabled. */ class TS590_FR : public TS590Command { public: TS590_FR(): TS590Command("FR") {} virtual void handleCommand(const char* cmd); virtual void sendResponse(const char* cmd); }; /**********************************************************************/ /*! * @brief CAT command for setting the transmitter VFO. If it is * different than the receiver VFO, then split mode will be * automatically enabled. */ class TS590_FT : public TS590Command { public: TS590_FT(): TS590Command("FT") {} virtual void handleCommand(const char* cmd); virtual void sendResponse(const char* cmd); }; /**********************************************************************/ /*! * @brief CAT command for setting the mode. */ class TS590_MD : public TS590Command { public: TS590_MD(): TS590Command("MD") {} virtual void handleCommand(const char* cmd); virtual void sendResponse(const char* cmd); }; /**********************************************************************/ /*! * @brief CAT command for setting the receiver high-cut frequency. */ class TS590_SH : public TS590Command { public: TS590_SH(): TS590Command("SH") {} virtual void handleCommand(const char* cmd); virtual void sendResponse(const char* cmd); private: unsigned index; }; /*! * @brief CAT command for setting the receiver low-cut frequency. */ class TS590_SL : public TS590Command { public: TS590_SL(): TS590Command("SL") {} virtual void handleCommand(const char* cmd); virtual void sendResponse(const char* cmd); private: unsigned index; }; /*! * @brief CAT command to start transmitting. */ class TS590_TX : public TS590Command { public: TS590_TX(): TS590Command("TX") {} virtual void handleCommand(const char* cmd); virtual void sendResponse(const char* cmd); }; /**********************************************************************/ class TS590EXCommand : public TS590Command { public: TS590EXCommand(const char *P1); virtual ~TS590EXCommand() = 0; inline const char* menu() const { return &myMenu[0]; } virtual const char* getReturnValue() const = 0; virtual void sendResponse(const char* cmd); private: char myMenu[4] = "\0\0\0"; }; /**********************************************************************/ /*! * @brief CAT command for setting the sidetone pitch/frequency. */ class TS590_EX034 : public TS590EXCommand { public: TS590_EX034(): TS590EXCommand("034") {} virtual void handleCommand(const char* cmd); virtual const char* getReturnValue(); private: uint8_t index; }; /*! * @brief CAT command for selecting the data input line. */ class TS590_EX063 : public TS590EXCommand { public: TS590_EX063(): TS590EXCommand("063") {} virtual void handleCommand(const char* cmd); virtual const char* getReturnValue(); }; /**********************************************************************/ /*! * @brief CAT command for setting USB/Line audio input levels. */ template class TS590_EXDataAudioInLevel : public TS590EXCommand { public: TS590_EXDataAudioInLevel(): TS590EXCommand(USB ? (SG ? "071" : "064") : (SG ? "073" : "066")) {} virtual void handleCommand(const char* cmd) { if (strlen(cmd) == 10) { uint8_t val = (cmd[9] - 48) % 10; if (USB) { // set USB input level } else { // set Line input level } } else { setSyntaxError(); } } virtual const char* getReturnValue() { static char str[2] = "\0"; // get input level - decimal 0 to 9 ... str[1] = ... return str; } }; #ifdef USE_TS590SG typedef TS590_EXDataAudioInLevel TS590_EX071; typedef TS590_EXDataAudioInLevel TS590_EX073; #else typedef TS590_EXDataAudioInLevel TS590_EX064; typedef TS590_EXDataAudioInLevel TS590_EX066; #endif /**********************************************************************/ /*! * @brief CAT command for setting USB/Line audio output levels. */ template class TS590_EXDataAudioOutLevel : public TS590EXCommand { public: TS590_EXDataAudioOutLevel(): TS590EXCommand(USB ? (SG ? "072" : "065") : (SG ? "074" : "067")) {} virtual void handleCommand(const char* cmd) { if (strlen(cmd) == 10) { uint8_t val = (cmd[9] - 48) % 10; if (USB) { // set USB output level } else { // set Line output level } } else { setSyntaxError(); } } virtual const char* getReturnValue() { static char str[2] = "\0"; // get output level - decimal 0 to 9 ... str[1] = ... return str; } }; #ifdef USE_TS590SG typedef TS590_EXDataAudioOutLevel TS590_EX072; typedef TS590_EXDataAudioOutLevel TS590_EX074; #else typedef TS590_EXDataAudioOutLevel TS590_EX065; typedef TS590_EXDataAudioOutLevel TS590_EX067; #endif /**********************************************************************/ class UBitxTS590 { public: UBitxTS590(TS590Command** cmds, int len): commands(cmds), numCommands(len) {} void begin(); void update(); private: void processCommand(); char buf[ts590CommandMaxLength] = {0}; int bufLen = 0; TS590Command** commands; int numCommands; }; extern UBitxTS590 TS590; #endif /**********************************************************************/