flexible rmode_t conversion, detect overflow in kenwood_transaction()

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2346 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.8
Stéphane Fillod, F8CFE 2008-05-04 21:19:07 +00:00
rodzic 3d834a4d1f
commit 2514c47659
2 zmienionych plików z 43 dodań i 19 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Kenwood backend - main file
* Copyright (c) 2000-2005 by Stephane Fillod and others
*
* $Id: kenwood.c,v 1.96 2008-03-01 11:20:29 fillods Exp $
* $Id: kenwood.c,v 1.97 2008-05-04 21:19:07 fillods Exp $
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -155,11 +155,6 @@ transaction_write:
retval = write_block(&rs->rigport, cmdstr, strlen(cmdstr));
if (retval != RIG_OK)
goto transaction_quit;
#ifdef TH_ADD_CMDTRM
retval = write_block(&rs->rigport, cmdtrm, strlen(cmdtrm));
if (retval != RIG_OK)
goto transaction_quit;
#endif
}
if (data == NULL || *datasize <= 0) {
@ -185,18 +180,24 @@ transaction_write:
goto transaction_quit;
}
/* Command recognised by rig but invalid data entered. */
if (strlen(data) == 2 && data[0] == 'N') {
rig_debug(RIG_DEBUG_VERBOSE, "%s: NegAck for '%s'\n", __FUNCTION__, cmdstr);
retval = -RIG_ENAVAIL;
goto transaction_quit;
}
/* Command not understood by rig */
if (strlen(data) == 2 && data[0] == '?') {
rig_debug(RIG_DEBUG_ERR, "%s: Unknown command '%s'\n", __FUNCTION__, cmdstr);
retval = -RIG_ERJCTED;
goto transaction_quit;
if (strlen(data) == 2) {
switch (data[0]) {
case 'N':
/* Command recognised by rig but invalid data entered. */
rig_debug(RIG_DEBUG_VERBOSE, "%s: NegAck for '%s'\n", __FUNCTION__, cmdstr);
retval = -RIG_ENAVAIL;
goto transaction_quit;
case 'O':
/* Too many characters send without a carriage return */
rig_debug(RIG_DEBUG_VERBOSE, "%s: Overflow for '%s'\n", __FUNCTION__, cmdstr);
retval = -RIG_EPROTO;
goto transaction_quit;
case '?':
/* Command not understood by rig */
rig_debug(RIG_DEBUG_ERR, "%s: Unknown command '%s'\n", __FUNCTION__, cmdstr);
retval = -RIG_ERJCTED;
goto transaction_quit;
}
}
#define CONFIG_STRIP_CMDTRM 1
@ -230,6 +231,23 @@ transaction_quit:
return retval;
}
rmode_t kenwood2rmode(unsigned char mode, const rmode_t mode_table[])
{
if (mode >= KENWOOD_MODE_TABLE_MAX)
return RIG_MODE_NONE;
return mode_table[mode];
}
char rmode2kenwood(rmode_t mode, const rmode_t mode_table[])
{
int i;
for(i=0; i<KENWOOD_MODE_TABLE_MAX;i++) {
if (mode_table[i] == mode)
return i;
}
return -1;
}
/*
* kenwood_set_vfo

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Kenwood backend - main header
* Copyright (c) 2000-2008 by Stephane Fillod
*
* $Id: kenwood.h,v 1.42 2008-03-01 11:20:29 fillods Exp $
* $Id: kenwood.h,v 1.43 2008-05-04 21:19:07 fillods Exp $
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
@ -28,9 +28,12 @@
#define EOM_KEN ";"
#define EOM_TH "\r"
#define KENWOOD_MODE_TABLE_MAX 8
struct kenwood_priv_caps {
const char *cmdtrm; /* Command termination chars (ken=';' or th='\r') */
int if_len; /* length of IF; anwser */
rmode_t *mode_table;
};
@ -38,6 +41,9 @@ extern const tone_t kenwood38_ctcss_list[];
int kenwood_transaction(RIG *rig, const char *cmd, int cmd_len, char *data,
size_t *data_len);
rmode_t kenwood2rmode(unsigned char mode, const rmode_t mode_table[]);
char rmode2kenwood(rmode_t mode, const rmode_t mode_table[]);
int kenwood_set_vfo(RIG *rig, vfo_t vfo);
int kenwood_get_vfo(RIG *rig, vfo_t *vfo);
int kenwood_set_split_vfo(RIG *rig, vfo_t vfo , split_t split, vfo_t txvfo);