2021-02-07 23:12:08 +00:00
|
|
|
#ifndef __TS590_h__
|
|
|
|
#define __TS590_h__
|
|
|
|
|
|
|
|
#include <Arduino.h>
|
2021-02-13 04:19:14 +00:00
|
|
|
#include "DSP.h"
|
2021-02-07 23:12:08 +00:00
|
|
|
#include "Rig.h"
|
2021-02-21 06:16:01 +00:00
|
|
|
#include "TR.h"
|
2021-02-07 23:12:08 +00:00
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
2021-02-21 06:16:01 +00:00
|
|
|
// uncomment to use TS-590SG / comment to use TS-590S
|
|
|
|
#define USE_TS590SG
|
|
|
|
|
2021-02-07 23:12:08 +00:00
|
|
|
#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; }
|
|
|
|
|
2021-02-13 04:19:14 +00:00
|
|
|
/*!
|
|
|
|
* @brief Return the DSP that this command will be used to control.
|
|
|
|
*/
|
|
|
|
inline UBitxDSP* dsp() const { return theDSP; }
|
|
|
|
|
2021-02-21 06:16:01 +00:00
|
|
|
/*!
|
|
|
|
* @brief Return the T/R that this command will be used to control.
|
|
|
|
*/
|
|
|
|
inline UBitxDSP* tr() const { return theTR; }
|
|
|
|
|
2021-02-07 23:12:08 +00:00
|
|
|
/*!
|
|
|
|
* @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);
|
2021-02-13 04:19:14 +00:00
|
|
|
static void setDSP(UBitxDSP* d);
|
2021-02-21 06:16:01 +00:00
|
|
|
static void setTR(UBitxTR* t);
|
2021-02-07 23:12:08 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
char myPrefix[3] = "\0\0";
|
|
|
|
static TS590Error theError;
|
|
|
|
static UBitxRig* theRig;
|
2021-02-13 04:19:14 +00:00
|
|
|
static UBitxDSP* theDSP;
|
2021-02-07 23:12:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief CAT command for setting or reading the VFO A/B frequency.
|
|
|
|
*/
|
|
|
|
template<bool VFOA>
|
|
|
|
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) {
|
2021-02-15 05:04:29 +00:00
|
|
|
rig()->setFreqA(freq);
|
2021-02-07 23:12:08 +00:00
|
|
|
} else {
|
2021-02-15 05:04:29 +00:00
|
|
|
rig()->setFreqB(freq);
|
2021-02-07 23:12:08 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
setSyntaxError();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void sendResponse(const char* cmd) {
|
|
|
|
ts590SendCommand(VFOA ? "FA%011u" : "FB%011u", VFOA ? rig()->getFreqA() : rig()->getFreqB());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef TS590_FAB<true> TS590_FA;
|
|
|
|
typedef TS590_FAB<false> 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);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
2021-02-12 05:55:41 +00:00
|
|
|
/*!
|
|
|
|
* @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);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
2021-02-13 04:19:14 +00:00
|
|
|
/*!
|
|
|
|
* @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;
|
|
|
|
};
|
|
|
|
|
2021-02-21 06:16:01 +00:00
|
|
|
/*!
|
|
|
|
* @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<bool USB, bool SG>
|
|
|
|
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<true, true> TS590_EX071;
|
|
|
|
typedef TS590_EXDataAudioInLevel<false, true> TS590_EX073;
|
|
|
|
#else
|
|
|
|
typedef TS590_EXDataAudioInLevel<true, false> TS590_EX064;
|
|
|
|
typedef TS590_EXDataAudioInLevel<true, false> TS590_EX066;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**********************************************************************/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
* @brief CAT command for setting USB/Line audio output levels.
|
|
|
|
*/
|
|
|
|
template<bool USB, bool SG>
|
|
|
|
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<true, true> TS590_EX072;
|
|
|
|
typedef TS590_EXDataAudioOutLevel<false, true> TS590_EX074;
|
|
|
|
#else
|
|
|
|
typedef TS590_EXDataAudioOutLevel<true, false> TS590_EX065;
|
|
|
|
typedef TS590_EXDataAudioOutLevel<true, false> TS590_EX067;
|
|
|
|
#endif
|
|
|
|
|
2021-02-13 04:19:14 +00:00
|
|
|
/**********************************************************************/
|
|
|
|
|
2021-02-07 23:12:08 +00:00
|
|
|
class UBitxTS590 {
|
|
|
|
public:
|
2021-02-10 04:58:07 +00:00
|
|
|
UBitxTS590(TS590Command** cmds, int len): commands(cmds), numCommands(len) {}
|
2021-02-07 23:12:08 +00:00
|
|
|
|
2021-02-10 04:58:07 +00:00
|
|
|
void begin();
|
2021-02-07 23:12:08 +00:00
|
|
|
void update();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void processCommand();
|
|
|
|
|
|
|
|
char buf[ts590CommandMaxLength] = {0};
|
|
|
|
int bufLen = 0;
|
|
|
|
TS590Command** commands;
|
2021-02-10 04:58:07 +00:00
|
|
|
int numCommands;
|
2021-02-07 23:12:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern UBitxTS590 TS590;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**********************************************************************/
|