Fix send_raw and add some debug to it

https://github.com/Hamlib/Hamlib/issues/1157
pull/1161/head
Mike Black W9MDB 2022-11-25 17:39:35 -06:00
rodzic af6d4d03e3
commit a0711bfa71
3 zmienionych plików z 50 dodań i 12 usunięć

1
NEWS
Wyświetl plik

@ -18,6 +18,7 @@ Version 4.6
Version 4.5.1
* 2022-XX-XX
* Added send_raw to rigctl
* Fix AGC Level dumpcaps on most rigs
* Fix rig_send_raw to return bytes read, fill buffer, and also work with fixed length response/null terminator
* Change all Kenwood rigs to 500ms serial timeout

Wyświetl plik

@ -7414,11 +7414,15 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
int nbytes;
ENTERFUNC;
if (rig->caps->rig_model == RIG_MODEL_DUMMY || rig->caps->rig_model == RIG_MODEL_NONE)
if (rig->caps->rig_model == RIG_MODEL_DUMMY
|| rig->caps->rig_model == RIG_MODEL_NONE)
{
rig_debug(RIG_DEBUG_ERR, "%s: not implemented for model %s\n", __func__, rig->caps->model_name);
rig_debug(RIG_DEBUG_ERR, "%s: not implemented for model %s\n", __func__,
rig->caps->model_name);
return -RIG_ENAVAIL;
}
rig_debug(RIG_DEBUG_VERBOSE, "%s: writing %d bytes\n", __func__, send_len);
int retval = write_block_sync(&rs->rigport, send, send_len);
if (retval < 0)
@ -7440,16 +7444,20 @@ HAMLIB_EXPORT(int) rig_send_raw(RIG *rig, const unsigned char *send,
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,
1, 0, 1);
}

Wyświetl plik

@ -371,7 +371,7 @@ static struct test_table test_list[] =
{ 0xa1, "get_separator", ACTION(get_separator), ARG_NOVFO, "Separator" },
{ 0xa2, "set_lock_mode", ACTION(set_lock_mode), ARG_IN | ARG_NOVFO, "Locked" },
{ 0xa3, "get_lock_mode", ACTION(get_lock_mode), ARG_NOVFO, "Locked" },
{ 0xa4, "send_raw", ACTION(send_raw), ARG_NOVFO | ARG_IN | ARG_OUT, "Send raw command" },
{ 0xa4, "send_raw", ACTION(send_raw), ARG_NOVFO | ARG_IN | ARG_OUT, "Send raw answer" },
{ 0x00, "", NULL },
};
@ -5352,36 +5352,65 @@ static int parse_hex(const char *s, unsigned char *buf, int len)
int i;
buf[0] = 0;
char *s2 = strdup(s);
char *p = strtok(s2,";");
while(p)
char *p = strtok(s2, ";");
while (p)
{
unsigned int val;
sscanf(p,"0x%x", &val);
sscanf(p, "0x%x", &val);
buf[i++] = val;
p = strtok(NULL, ";");
}
free(s2);
return i;
}
/* 0xa4 */
declare_proto_rig(send_raw)
{
int retval;
int reply_len;
unsigned char term[] = ";";
unsigned char buf[100];
unsigned char send[100];
unsigned char *sendp = (unsigned char*)arg1;
unsigned char *sendp = (unsigned char *)arg1;
int arg1_len = strlen(arg1);
int hex_flag = 0;
if (strncmp(arg1, "0x", 2)==0) {
arg1_len = parse_hex(arg1,send,sizeof(send));
if (strncmp(arg1, "0x", 2) == 0)
{
arg1_len = parse_hex(arg1, send, sizeof(send));
sendp = send;
hex_flag = 1;
}
rig_debug(RIG_DEBUG_TRACE, "%s:\n", __func__);
retval = rig_send_raw(rig, (unsigned char*)sendp, arg1_len, buf, sizeof(buf),term);
reply_len = rig_send_raw(rig, (unsigned char *)sendp, arg1_len, buf,
sizeof(buf), term);
if ((interactive && prompt) || (interactive && !prompt && ext_resp))
{
fprintf(fout, "%s: ", cmd->arg1);
}
return retval;
if (reply_len == 0)
{
fprintf(fout, "No answer\n");
}
else if (hex_flag)
{
int i;
for (i = 0; i < reply_len; ++i)
{
fprintf(fout, "0x%02x ", buf[i]);
}
fprintf(fout, "\n");
}
else
{
fprintf(fout, "%s\n", buf);
}
return RIG_OK;
}