Fix serial I/O error checking

git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2337 7ae35d74-ebe9-4afe-98af-79ac388436b8
Hamlib-1.2.8
Martin Ewing, AA6E 2008-05-01 21:30:28 +00:00
rodzic 6e4ed42cca
commit 32be6d0e81
1 zmienionych plików z 42 dodań i 40 usunięć

Wyświetl plik

@ -2,7 +2,7 @@
* Hamlib TenTenc backend - TT-565 description * Hamlib TenTenc backend - TT-565 description
* Copyright (c) 2004-2008 by Stephane Fillod & Martin Ewing * Copyright (c) 2004-2008 by Stephane Fillod & Martin Ewing
* *
* $Id: orion.c,v 1.24 2008-02-15 23:04:51 aa6e Exp $ * $Id: orion.c,v 1.25 2008-05-01 21:30:28 aa6e Exp $
* *
* This library is free software; you can redistribute it and/or modify * This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as * it under the terms of the GNU Library General Public License as
@ -117,7 +117,7 @@ int tt565_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *d
#ifdef TT565_TIME #ifdef TT565_TIME
double ft1, ft2; double ft1, ft2;
#endif #endif
passcount++; // for debugging passcount++; // for debugging
/* Capture buffer length for possible read re-try. */ /* Capture buffer length for possible read re-try. */
data_len_init = (data && data_len) ? *data_len : 0; data_len_init = (data && data_len) ? *data_len : 0;
/* Allow transaction re-tries according to capabilities. */ /* Allow transaction re-tries according to capabilities. */
@ -130,52 +130,54 @@ int tt565_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *d
/* no data expected, TODO: flush input? */ /* no data expected, TODO: flush input? */
if (!data || !data_len) { if (!data || !data_len) {
if (*cmd != '*') { // i.e. was not a 'write' to rig... if (*cmd != '*') { // i.e. was not a 'write' to rig...
rig_debug(RIG_DEBUG_ERR,"reject 1\n"); rig_debug(RIG_DEBUG_ERR,"cmd reject 1\n");
return -RIG_ERJCTED; // bad news! return -RIG_ERJCTED;
} }
return RIG_OK; /* normal exit if no read */ return RIG_OK; /* normal exit if write, but no read */
} }
#ifdef TT565_TIME #ifdef TT565_TIME
ft1 = tt565_timenow(); ft1 = tt565_timenow();
#endif #endif
*data_len = data_len_init; /* restore orig. buffer length */ *data_len = data_len_init; /* restore orig. buffer length */
*data_len = read_string(&rs->rigport, data, *data_len, *data_len = read_string(&rs->rigport, data, *data_len,
EOM, strlen(EOM)); EOM, strlen(EOM));
if (!strncmp(data,"Z!",2)) { // command unrecognized?? if (!strncmp(data,"Z!",2)) { // command unrecognized??
rig_debug(RIG_DEBUG_ERR,"reject 2\n"); rig_debug(RIG_DEBUG_ERR,"cmd reject 2\n");
return -RIG_ERJCTED; // what is a better error return? return -RIG_ERJCTED; // what is a better error return?
} }
if (cmd[0] != '?') { // was this a write to the rig? /* XX and ?V are oddball commands. Thanks, Ten-Tec! */
rig_debug(RIG_DEBUG_ERR,"reject 3\n"); if (!strncmp(cmd,"XX",2)) { // Was it a firmware reset cmd?
return -RIG_ERJCTED; // terrible, can't get here?? return RIG_OK; // Then we accept the response.
} }
else { // no, it was a 'read', phew! if (!strncmp(cmd,"?V",2)) { // Was it a read firmware version cmd?
if (!strncmp(cmd,"?V",2)) { return RIG_OK; // ditto
return RIG_OK; // special case for ?V command }
} if (cmd[0] != '?') { // was this a read cmd?
if (!strncmp(data+1,cmd+1,cmd_len-2)) { //reponse matches cmd? rig_debug(RIG_DEBUG_ERR,"cmd reject 3\n");
return RIG_OK; // all is well, normal exit return -RIG_ERJCTED; // No, but it should have been!
} }
else { else { // Yes, it was a 'read', phew!
/* The command read back does not match the command that if (!strncmp(data+1,cmd+1,cmd_len-2)) { //reponse matches cmd?
was written. What to do? We report the problem if debugging, return RIG_OK; // all is well, normal exit
and issue another read in hopes that }
will make it sync up right. else { /* The command read back does not match the command that
*/ was written. We report the problem if debugging,
rig_debug(RIG_DEBUG_ERR, and issue another read in hopes of eventual success.
"** retry after delay (io=%d, retry=%d) **\n", */
passcount, itry); rig_debug(RIG_DEBUG_ERR,
*data_len = data_len_init; /* restore orig. buffer length */ "** retry after delay (io=%d, retry=%d) **\n",
read_string(&rs->rigport, data, *data_len, passcount, itry);
EOM, strlen(EOM)); // purge the input stream... *data_len = data_len_init; /* restore orig. buffer length */
continue; // now go retry the full command read_string(&rs->rigport, data, *data_len,
} EOM, strlen(EOM)); // purge the input stream...
} continue; // now go retry the full command
}
}
#ifdef TT565_TIME #ifdef TT565_TIME
ft2 = tt565_timenow(); ft2 = tt565_timenow();
if (*data_len == -RIG_ETIMEOUT) if (*data_len == -RIG_ETIMEOUT)
rig_debug(RIG_DEBUG_ERR,"Timeout %d: Elapsed = %f secs.\n", rig_debug(RIG_DEBUG_ERR,"Timeout %d: Elapsed = %f secs.\n",
itry, ft2-ft1); itry, ft2-ft1);
else else
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"Other Error #%d, itry=%d: Elapsed = %f secs.\n", "Other Error #%d, itry=%d: Elapsed = %f secs.\n",
@ -183,7 +185,7 @@ int tt565_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *d
#endif #endif
} /* end of itry loop */ } /* end of itry loop */
rig_debug(RIG_DEBUG_ERR,"** Ran out of retries io=%d **\n", rig_debug(RIG_DEBUG_ERR,"** Ran out of retries io=%d **\n",
passcount); passcount);
return -RIG_ETIMEOUT; return -RIG_ETIMEOUT;
} }