fix proprer read_string() return code error handling

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2003 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.5
Stéphane Fillod, F8CFE 2005-04-10 21:47:14 +00:00
rodzic fe3eb0b51f
commit 74c6d2ba61
13 zmienionych plików z 121 dodań i 51 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Alinco backend - main file
* Copyright (c) 2001-2005 by Stephane Fillod
*
* $Id: alinco.c,v 1.26 2005-01-25 00:19:38 fillods Exp $
* $Id: alinco.c,v 1.27 2005-04-10 21:47:12 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
@ -109,28 +109,33 @@ int alinco_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *
retval = write_block(&rs->rigport, cmd, cmd_len);
if (retval != RIG_OK)
return retval;
return retval;
/*
* Transceiver sends an echo of cmd followed by a CR/LF
* TODO: check whether cmd and echobuf match (optional)
*/
retval = read_string(&rs->rigport, echobuf, BUFSZ, LF, strlen(LF));
/* if (retval <= 3)
return retval; */
if (retval < 0)
return retval;
/* no data expected, check for OK returned */
if (!data || !data_len) {
retval = read_string(&rs->rigport, echobuf, BUFSZ, LF, strlen(LF));
if (retval < 0)
return retval;
retval -= 2;
echobuf[retval] = 0;
if (strcmp(echobuf, "OK") == 0)
return RIG_OK;
else
return RIG_ERJCTED;
return -RIG_ERJCTED;
}
*data_len = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF));
retval = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF));
if (retval < 0)
return retval;
*data_len = retval;
/* strip CR/LF from string
*/

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib AOR backend - AR3000 description
* Copyright (c) 2000-2005 by Stephane Fillod
*
* $Id: ar3000.c,v 1.8 2005-02-26 22:28:19 fillods Exp $
* $Id: ar3000.c,v 1.9 2005-04-10 21:47:12 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
@ -74,7 +74,7 @@ const struct rig_caps ar3000a_caps = {
.rig_model = RIG_MODEL_AR3000A,
.model_name = "AR3000A",
.mfg_name = "AOR",
.version = "0.3",
.version = "0.4",
.copyright = "LGPL",
.status = RIG_STATUS_BETA,
.rig_type = RIG_TYPE_SCANNER,
@ -205,7 +205,13 @@ static int ar3k_transaction(RIG *rig, const char *cmd, int cmd_len, char *data,
if (!data || !data_len)
return RIG_OK;
*data_len = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM));
retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM));
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
return RIG_OK;
}

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib AOR backend - AR3030 description
* Copyright (c) 2000-2005 by Stephane Fillod
*
* $Id: ar3030.c,v 1.8 2005-04-03 19:40:15 fillods Exp $
* $Id: ar3030.c,v 1.9 2005-04-10 21:47:12 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
@ -100,7 +100,7 @@ const struct rig_caps ar3030_caps = {
.rig_model = RIG_MODEL_AR3030,
.model_name = "AR3030",
.mfg_name = "AOR",
.version = "0.2",
.version = "0.3",
.copyright = "LGPL",
.status = RIG_STATUS_UNTESTED,
.rig_type = RIG_TYPE_RECEIVER,
@ -230,7 +230,12 @@ static int ar3030_transaction(RIG *rig, const char *cmd, int cmd_len, char *data
if (!data || !data_len)
return RIG_OK;
*data_len = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM));
retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM));
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
return RIG_OK;
}

Wyświetl plik

@ -1,8 +1,8 @@
/*
* Hamlib Drake backend - main file
* Copyright (c) 2001-2004 by Stephane Fillod
* Copyright (c) 2001-2005 by Stephane Fillod
*
* $Id: drake.c,v 1.16 2004-09-05 19:15:10 fineware Exp $
* $Id: drake.c,v 1.17 2005-04-10 21:47:12 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
@ -80,7 +80,12 @@ int drake_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *d
if (!data || !data_len)
return 0;
*data_len = read_string(&rs->rigport, data, BUFSZ, LF, 1);
retval = read_string(&rs->rigport, data, BUFSZ, LF, 1);
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
return RIG_OK;
}

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib JRC backend - main file
* Copyright (c) 2001-2005 by Stephane Fillod
*
* $Id: jrc.c,v 1.21 2005-01-25 00:19:41 fillods Exp $
* $Id: jrc.c,v 1.22 2005-04-10 21:47:13 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
@ -85,7 +85,12 @@ int jrc_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat
if (!data || !data_len)
return 0;
*data_len = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM));
retval = read_string(&rs->rigport, data, BUFSZ, EOM, strlen(EOM));
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
return RIG_OK;
}

Wyświetl plik

@ -4,7 +4,7 @@
*
* Copyright (c) 2000-2005 by Stephane Fillod and others
*
* $Id: ic10.c,v 1.4 2005-01-25 00:20:04 fillods Exp $
* $Id: ic10.c,v 1.5 2005-04-10 21:47:13 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
@ -72,8 +72,13 @@ int ic10_transaction (RIG *rig, const char *cmd, int cmd_len, char *data, int *d
if (!data || !data_len)
return 0;
*data_len = read_string(&rs->rigport, data, 50, EOM_KEN, 1);
retval = read_string(&rs->rigport, data, 50, EOM_KEN, 1);
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
return RIG_OK;
}

Wyświetl plik

@ -1,8 +1,8 @@
/*
* Hamlib Lowe backend - main file
* Copyright (c) 2003-2004 by Stephane Fillod
* Copyright (c) 2003-2005 by Stephane Fillod
*
* $Id: lowe.c,v 1.3 2004-08-08 19:42:59 fillods Exp $
* $Id: lowe.c,v 1.4 2005-04-10 21:47:13 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
@ -74,7 +74,12 @@ int lowe_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *da
if (!data || !data_len)
return 0;
*data_len = read_string(&rs->rigport, data, BUFSZ, CR, 1);
retval = read_string(&rs->rigport, data, BUFSZ, CR, 1);
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
return RIG_OK;
}

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib PCR backend - main file
* Copyright (c) 2001-2005 by Stephane Fillod and Darren Hatcher
*
* $Id: pcr.c,v 1.21 2005-01-25 00:20:40 fillods Exp $
* $Id: pcr.c,v 1.22 2005-04-10 21:47:13 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
@ -96,7 +96,7 @@ const int pcr1_ctcss_list[] = {
* Otherwise, you'll get a nice seg fault. You've been warned!
* TODO: error case handling
*/
int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
static int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
{
int retval;
struct rig_state *rs;
@ -107,25 +107,32 @@ int pcr_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat
retval = write_block(&rs->rigport, cmd, cmd_len);
if (retval != RIG_OK)
return retval;
return retval;
/* eat the first ack */
#ifdef WANT_READ_STRING
retval = read_string(&rs->rigport, data, 1, "\x0a", 1);
if (retval < 0)
return retval;
return retval;
if (retval != 1)
return -RIG_EPROTO;
return -RIG_EPROTO;
#else
retval = read_block(&rs->rigport, data, 1);
if (retval < 0)
return retval;
#endif
/* here is the real response */
#ifdef WANT_READ_STRING
*data_len = read_string(&rs->rigport, data, *data_len, "\x0a", 1);
retval = read_string(&rs->rigport, data, *data_len, "\x0a", 1);
#else
*data_len = read_block( &rs->rigport, data, *data_len );
retval = read_block( &rs->rigport, data, *data_len );
#endif
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
return RIG_OK;
}

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib RFT backend - main file
* Copyright (c) 2003 by Thomas B. Ruecker
*
* $Id: rft.c,v 1.1 2003-10-07 22:15:49 fillods Exp $
* $Id: rft.c,v 1.2 2005-04-10 21:47:14 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
@ -64,9 +64,14 @@ int rft_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *dat
/* no data expected, TODO: flush input? */
if (!data || !data_len)
return 0;
return 0;
*data_len = read_string(&rs->rigport, data, BUFSZ, CR, 1);
retval = read_string(&rs->rigport, data, BUFSZ, CR, 1);
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
return RIG_OK;
}

Wyświetl plik

@ -1,8 +1,8 @@
/*
* Hamlib Skanti backend - main file
* Copyright (c) 2004 by Stephane Fillod
* Copyright (c) 2004-2005 by Stephane Fillod
*
* $Id: skanti.c,v 1.1 2004-08-18 18:51:24 fillods Exp $
* $Id: skanti.c,v 1.2 2005-04-10 21:47:14 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
@ -76,7 +76,7 @@ static int skanti_transaction(RIG *rig, const char *cmd, int cmd_len, char *data
retval = write_block(&rs->rigport, cmd, cmd_len);
if (retval != RIG_OK)
return retval;
return retval;
/* no data expected, check for OK returned */
@ -85,18 +85,23 @@ static int skanti_transaction(RIG *rig, const char *cmd, int cmd_len, char *data
* Transceiver sends back ">"
*/
retval = read_string(&rs->rigport, retbuf, BUFSZ, PROMPT, strlen(PROMPT));
if (retval < 0 || retval > BUFSZ)
return RIG_ERJCTED;
if (retval < 0)
return retval;
retbuf[retval] = '\0';
if (strstr(retbuf, PROMPT))
return RIG_OK;
else
return RIG_ERJCTED;
return -RIG_ERJCTED;
}
*data_len = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF));
retval = read_string(&rs->rigport, data, BUFSZ, LF, strlen(LF));
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
/* strip CR/LF from string
*/

Wyświetl plik

@ -1,8 +1,8 @@
/*
* Hamlib Tentec backend - main file
* Copyright (c) 2001-2004 by Stephane Fillod
* Copyright (c) 2001-2005 by Stephane Fillod
*
* $Id: tentec.c,v 1.14 2004-05-26 21:30:13 fillods Exp $
* $Id: tentec.c,v 1.15 2005-04-10 21:47:14 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
@ -73,13 +73,18 @@ int tentec_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *
retval = write_block(&rs->rigport, cmd, cmd_len);
if (retval != RIG_OK)
return retval;
return retval;
/* no data expected, TODO: flush input? */
if (!data || !data_len)
return 0;
return 0;
*data_len = read_string(&rs->rigport, data, *data_len, "", 0);
retval = read_string(&rs->rigport, data, *data_len, "", 0);
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
return RIG_OK;
}

Wyświetl plik

@ -95,10 +95,17 @@ tt550_transaction (RIG * rig, const char *cmd, int cmd_len, char *data,
/*
* no data expected, TODO: flush input?
*/
if (!data || !data_len)
if (!data || !data_len) {
Unhold_Decode (rig);
return 0;
}
*data_len = read_string (&rs->rigport, data, *data_len, "", 0);
retval = read_string (&rs->rigport, data, *data_len, "", 0);
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
Unhold_Decode (rig);

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib Uniden backend - main file
* Copyright (c) 2001-2005 by Stephane Fillod
*
* $Id: uniden.c,v 1.10 2005-01-25 00:21:56 fillods Exp $
* $Id: uniden.c,v 1.11 2005-04-10 21:47:14 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
@ -56,7 +56,7 @@
* We assume that rig!=NULL, rig->state!= NULL, data!=NULL, data_len!=NULL
* Otherwise, you'll get a nice seg fault. You've been warned!
*/
int uniden_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
static int uniden_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *data_len)
{
int retval;
struct rig_state *rs;
@ -72,9 +72,14 @@ int uniden_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *
/* no data expected, TODO: flush input? */
if (!data || !data_len)
return 0;
return 0;
*data_len = read_string(&rs->rigport, data, BUFSZ, "\x0a", 1);
retval = read_string(&rs->rigport, data, BUFSZ, "\x0a", 1);
if (retval == -RIG_ETIMEOUT)
retval = 0;
if (retval < 0)
return retval;
*data_len = retval;
return RIG_OK;
}