Skip to content

kenwood_transaction() is erroneously stripping eol characters, breaking hamlib for tm-d710/tm-v71a devices. #1767

Description

@larsks

I was seeing the symptoms reported in #1698. I spent some time debugging the code, and the problem is that by the time we reach this block of code:

if (strchr(cmdtrm_str, buffer[strlen(buffer) - 1]) == NULL)
{
rig_debug(RIG_DEBUG_ERR, "%s: Command is not correctly terminated '%s'\n",
__func__, buffer);
if (retry_read++ < rp->retry)
{
goto transaction_write;
}
retval = -RIG_EPROTO;
goto transaction_quit;
}

We have already called remove_nonprint(buffer) at line 448:

// this fixes the case when some corrupt data is returned
// let's us be a little more robust about funky serial data
remove_nonprint(buffer);

This strips the command termination character (\r), causing the "Check that command termination is correct" to always fail, effectively breaking hamlib for all TM-D710/TM-V71 type devices.


We can confirm this behavior by inspecting the value of buffer before and after the call to remove_nonprint:

Breakpoint 3, kenwood_transaction (rig=rig@entry=0x435d60, cmdstr=cmdstr@entry=0x7ffff740176e "ID", data=data@entry=0x7fffffffc300 "",
    datasize=datasize@entry=128) at kenwood.c:443
443         rig_debug(RIG_DEBUG_TRACE, "%s: read_string len=%d '%s'\n", __func__,
(gdb) p buffer
$1 = "ID TM-V71\r", '\000' <repeats 117 times>

This is the rig_debug call just before the call to remove_nonprint; we can see that the buffer has the \r command termination character. After calling remove_nonprint...

(gdb) until 450
kenwood_transaction (rig=rig@entry=0x435d60, cmdstr=cmdstr@entry=0x7ffff740176e "ID", data=data@entry=0x7fffffffc300 "", datasize=datasize@entry=128)
    at kenwood.c:450
450         if (retval < 0)
(gdb) p buffer
$2 = "ID TM-V71", '\000' <repeats 118 times>

...we see that the termination character has been dropped.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions