RigCAT user commands

* Added user definable RigCAT user strings as Macros
    <RIGCAT: hex hex:retnbr>
    <RIGCAT: "string":retnbr>
    where:
      hex hex ... are sequential hexadecimal values
      string is Ascii char sequence
      retnbr is number of bytes in xcvr response
      ':retnbr' is optional; retnbr set to 0 if missing
pull/1/head
Dennis Engdahl 2013-08-02 08:05:26 -05:00 zatwierdzone przez David Freese
rodzic 96b8a49fb0
commit 24b9c70dd1
4 zmienionych plików z 80 dodań i 3 usunięć

Wyświetl plik

@ -9,6 +9,8 @@ extern Cserial rigio;
extern bool hexout(const std::string&);
extern bool sendCommand(std::string, int retnbr);
extern long long rigCAT_getfreq(int retries, bool &failed);
extern void rigCAT_setfreq(long long);

Wyświetl plik

@ -183,6 +183,9 @@ void loadBrowser(Fl_Widget *widget) {
w->add(_("<RISE:nn.n>\tCW rise time"));
w->add(_("<WPM:NN>\tCW WPM"));
w->add(LINE_SEP);
w->add(_("<RIGCAT:[\"text\"][hex ...]:ret>\tsend CAT cmd"));
w->add(LINE_SEP);
w->add(_("<AFC:on|off|t>\tAFC on,off,toggle"));
w->add(_("<LOCK:on|off|t>\tLOCK on,off,toggle"));

Wyświetl plik

@ -845,6 +845,75 @@ static void pTXRX(std::string &s, size_t &i, size_t endbracket)
ToggleTXRX = true;
}
static std::string hexstr(std::string &s)
{
static std::string hex;
static char val[3];
hex.clear();
for (size_t i = 0; i < s.length(); i++) {
snprintf(val, sizeof(val), "%02x", s[i] & 0xFF);
hex.append("<").append(val).append(">");
}
return hex;
}
static void pRIGCAT(std::string &s, size_t &i, size_t endbracket)
{
if (within_exec) {
s.replace(i, endbracket - i + 1, "");
return;
}
LOG_INFO("cat cmd:retnbr %s", s.c_str());
size_t start = s.find(':', i);
std::basic_string<char> buff;
size_t val = 0;
int retnbr = 0;
char c, ch;
bool asciisw = false;
bool valsw = false;
for (size_t j = start+1 ; j <= endbracket ; j++) {
ch = s[j];
if (ch == '\"') {
asciisw = !asciisw;
continue;
}
// accumulate ascii string
if (asciisw) {
if (isprint(ch)) buff += ch;
continue;
}
// following digits is expected size of CAT response from xcvr
if (ch == ':' && s[j+1] != '>') {
sscanf(&s[j+1], "%d", &retnbr);
}
// accumulate hex string values
if ((ch == ' ' || ch == '>' || ch == ':') && valsw) {
c = char(val);
// LOG_INFO("c=%02x, val=%d", c, val);
buff += c;
val = 0;
valsw = false;
} else {
val *= 16;
ch = toupper(ch);
if (isdigit(ch)) val += ch - '0';
else if (ch >= 'A' && ch <= 'F') val += ch - 'A' + 10;
valsw = true;
}
if (ch == ':') break;
}
LOG_INFO("cat %s", hexstr(buff).c_str());
sendCommand(buff, retnbr);
s.replace(i, endbracket - i + 1, "");
}
static void pVER(std::string &s, size_t &i, size_t endbracket)
{
@ -1739,15 +1808,15 @@ void set_macro_env(void)
// frequencies
char dial_freq[20];
snprintf(dial_freq, sizeof(dial_freq), "%" PRId64, wf->rfcarrier());
snprintf(dial_freq, sizeof(dial_freq), "%lld", (long long)wf->rfcarrier());
env[FLDIGI_DIAL_FREQUENCY].val = dial_freq;
char audio_freq[6];
snprintf(audio_freq, sizeof(audio_freq), "%d", active_modem->get_freq());
env[FLDIGI_AUDIO_FREQUENCY].val = audio_freq;
char freq[20];
snprintf(freq, sizeof(freq), "%" PRId64, wf->rfcarrier() + (wf->USB()
snprintf(freq, sizeof(freq), "%lld", (long long)(wf->rfcarrier() + (wf->USB()
? active_modem->get_freq()
: -active_modem->get_freq()));
: -active_modem->get_freq())));
env[FLDIGI_FREQUENCY].val = freq;
// debugging vars
@ -2103,6 +2172,7 @@ static const MTAGS mtags[] = {
{"<TX>", pTX},
{"<TX/RX>", pTXRX},
{"<VER>", pVER},
{"<RIGCAT:", pRIGCAT},
{"<CNTR>", pCNTR},
{"<DECR>", pDECR},
{"<INCR>", pINCR},

Wyświetl plik

@ -91,6 +91,8 @@ bool sendCommand (string s, int retnbr)
if (retval <= 0)
LOG_VERBOSE("Write error %d", retval);
if (retnbr == 0) return true;
memset(replybuff, 0, RXBUFFSIZE + 1);
numread = 0;
MilliSleep( readafter );