kopia lustrzana https://github.com/Hamlib/Hamlib
Fix bugs in \send_raw command and add possibility to specify any command terminator character. Add \stop_morse to Dummy rig.
rodzic
c80d45378a
commit
92215dfd2a
|
@ -2125,6 +2125,13 @@ static int dummy_send_morse(RIG *rig, vfo_t vfo, const char *msg)
|
|||
RETURNFUNC(RIG_OK);
|
||||
}
|
||||
|
||||
static int dummy_stop_morse(RIG *rig, vfo_t vfo)
|
||||
{
|
||||
ENTERFUNC;
|
||||
|
||||
RETURNFUNC(RIG_OK);
|
||||
}
|
||||
|
||||
static int dummy_send_voice_mem(RIG *rig, vfo_t vfo, int ch)
|
||||
{
|
||||
ENTERFUNC;
|
||||
|
@ -2490,6 +2497,7 @@ struct rig_caps dummy_caps =
|
|||
.send_dtmf = dummy_send_dtmf,
|
||||
.recv_dtmf = dummy_recv_dtmf,
|
||||
.send_morse = dummy_send_morse,
|
||||
.stop_morse = dummy_stop_morse,
|
||||
.send_voice_mem = dummy_send_voice_mem,
|
||||
.set_channel = dummy_set_channel,
|
||||
.get_channel = dummy_get_channel,
|
||||
|
|
44
src/rig.c
44
src/rig.c
|
@ -7722,6 +7722,8 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
|
|||
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: writing %d bytes\n", __func__, send_len);
|
||||
|
||||
set_transaction_active(rig);
|
||||
|
||||
if (simulate)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: simulating response for model %s\n",
|
||||
|
@ -7735,21 +7737,12 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
|
|||
if (retval < 0)
|
||||
{
|
||||
// TODO: error handling? can writing to a pipe really fail in ways we can recover from?
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: write_block_sync() failed, result=%d\n", __func__,
|
||||
retval);
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: write_block_sync() failed, result=%d\n", __func__, retval);
|
||||
}
|
||||
}
|
||||
|
||||
if (reply)
|
||||
{
|
||||
// we have to have terminating char or else we can't read the response
|
||||
if (term == NULL)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: term==NULL, must have terminator to read reply\n",
|
||||
__func__);
|
||||
RETURNFUNC(-RIG_EINVAL);
|
||||
}
|
||||
|
||||
if (simulate)
|
||||
{
|
||||
// Simulate a response by copying the command
|
||||
|
@ -7758,37 +7751,37 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
|
|||
}
|
||||
else
|
||||
{
|
||||
if (*term == 0xfd) // then we want an Icom frame
|
||||
if (term == NULL)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: reading binary frame\n", __func__);
|
||||
retval = read_string(&rs->rigport, buf, reply_len, NULL, 0, 0, 1);
|
||||
}
|
||||
else if (*term == 0xfd) // then we want an Icom frame
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: reading icom frame\n", __func__);
|
||||
retval = read_icom_frame(&rs->rigport, buf, sizeof(buf));
|
||||
nbytes = retval;
|
||||
}
|
||||
else if (term == NULL)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: reading binary frame\n", __func__);
|
||||
nbytes = read_string_direct(&rs->rigport, buf, reply_len, (const char *)term,
|
||||
1, 0, 1);
|
||||
}
|
||||
else // we'll assume the provided terminator works
|
||||
{
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: reading frame terminated by '%s'\n", __func__,
|
||||
term);
|
||||
nbytes = read_string_direct(&rs->rigport, buf, sizeof(buf), (const char *)term,
|
||||
rig_debug(RIG_DEBUG_VERBOSE, "%s: reading frame terminated by 0x%x\n", __func__, *term);
|
||||
retval = read_string(&rs->rigport, buf, sizeof(buf), (const char *)term,
|
||||
1, 0, 1);
|
||||
}
|
||||
|
||||
if (retval < RIG_OK)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: read_string_direct, result=%d\n", __func__,
|
||||
retval);
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: read_string, result=%d\n", __func__, retval);
|
||||
set_transaction_inactive(rig);
|
||||
RETURNFUNC(retval);
|
||||
}
|
||||
|
||||
nbytes = retval;
|
||||
|
||||
if (nbytes >= reply_len)
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: reply_len(%d) less than reply from rig(%d)\n",
|
||||
__func__, reply_len, nbytes);
|
||||
set_transaction_inactive(rig);
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
}
|
||||
|
@ -7797,12 +7790,15 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
|
|||
}
|
||||
else
|
||||
{
|
||||
set_transaction_inactive(rig);
|
||||
RETURNFUNC(retval);
|
||||
}
|
||||
|
||||
set_transaction_inactive(rig);
|
||||
|
||||
ELAPSED2;
|
||||
|
||||
RETURNFUNC(nbytes > 0 ? nbytes : -RIG_EPROTO);
|
||||
RETURNFUNC(nbytes >= 0 ? nbytes : -RIG_EPROTO);
|
||||
}
|
||||
|
||||
HAMLIB_EXPORT(int) rig_set_lock_mode(RIG *rig, int mode)
|
||||
|
|
|
@ -5024,7 +5024,6 @@ declare_proto_rig(send_cmd)
|
|||
fwrite("\n", 1, 1, fout);
|
||||
}
|
||||
|
||||
|
||||
if (retval > 0 || retval == -RIG_ETIMEOUT)
|
||||
{
|
||||
retval = RIG_OK;
|
||||
|
@ -5421,13 +5420,15 @@ extern int netrigctl_send_raw(RIG *rig, char *s);
|
|||
/* 0xa4 */
|
||||
declare_proto_rig(send_raw)
|
||||
{
|
||||
int result;
|
||||
int reply_len;
|
||||
unsigned char term[1];
|
||||
unsigned char buf[100];
|
||||
unsigned char send[100];
|
||||
unsigned char termbyte[1];
|
||||
unsigned char *term = NULL;
|
||||
unsigned char buf[200];
|
||||
unsigned char send[200];
|
||||
unsigned char *sendp = (unsigned char *)arg2;
|
||||
int arg2_len = strlen(arg2);
|
||||
int hex_flag = 0;
|
||||
int is_binary = 0;
|
||||
int buf_len = sizeof(buf);
|
||||
int val = 0;
|
||||
|
||||
|
@ -5441,15 +5442,31 @@ declare_proto_rig(send_raw)
|
|||
return retval;
|
||||
}
|
||||
|
||||
if (strcmp(arg1, ";") == 0) { term[0] = ';'; }
|
||||
else if (strcasecmp(arg1, "CR")) { term[0] = 0x0d; }
|
||||
else if (strcasecmp(arg1, "LF")) { term[0] = 0x0a; }
|
||||
else if (strcasecmp(arg1, "ICOM")) { term[0] = 0xfd; }
|
||||
else if (sscanf(arg1, "%d", &val) == 1) { term[0] = 0; buf_len = val;}
|
||||
if (strcmp(arg1, ";") == 0) { termbyte[0] = ';'; term = termbyte; }
|
||||
else if (strcasecmp(arg1, "CR") == 0) { termbyte[0] = 0x0d; term = termbyte; }
|
||||
else if (strcasecmp(arg1, "LF") == 0) { termbyte[0] = 0x0a; term = termbyte; }
|
||||
else if (strcasecmp(arg1, "ICOM") == 0) { termbyte[0] = 0xfd; term = termbyte; }
|
||||
else if (sscanf(arg1, "0x%x", &val) == 1) { termbyte[0] = val; term = termbyte; }
|
||||
else if (sscanf(arg1, "%d", &val) == 1)
|
||||
{
|
||||
if (val < buf_len - 1)
|
||||
{
|
||||
// Reserve one byte more to allow padding with null
|
||||
buf_len = val + 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: response length %d is larger than maximum of %d bytes",
|
||||
__func__, val, buf_len);
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rig_debug(RIG_DEBUG_ERR,
|
||||
"%s: unknown arg1 val=%s, expected ';' 'CR' 'LF' 'ICOM' or # of bytes where 0 means no reply and -1 means unknown",
|
||||
"%s: unknown arg1 val=%s, expected ';', 'CR', 'LF', 'ICOM', 0xFF (hex byte) or "
|
||||
"# of bytes where 0 means no reply and -1 means unknown",
|
||||
__func__, arg1);
|
||||
return -RIG_EINVAL;
|
||||
}
|
||||
|
@ -5458,12 +5475,18 @@ declare_proto_rig(send_raw)
|
|||
{
|
||||
arg2_len = parse_hex(arg2, send, sizeof(send));
|
||||
sendp = send;
|
||||
hex_flag = 1;
|
||||
is_binary = 1;
|
||||
}
|
||||
|
||||
rig_debug(RIG_DEBUG_TRACE, "%s:\n", __func__);
|
||||
reply_len = rig_send_raw(rig, (unsigned char *)sendp, arg2_len, buf,
|
||||
buf_len, term);
|
||||
|
||||
result = rig_send_raw(rig, (unsigned char *)sendp, arg2_len, buf,buf_len, term);
|
||||
if (result < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
reply_len = result;
|
||||
buf[buf_len + 1] = 0; // null terminate in case it's a string
|
||||
|
||||
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
|
||||
|
@ -5475,7 +5498,7 @@ declare_proto_rig(send_raw)
|
|||
{
|
||||
fprintf(fout, "No answer\n");
|
||||
}
|
||||
else if (hex_flag)
|
||||
else if (is_binary)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue