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
@ -130,10 +130,10 @@ 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();
@ -142,25 +142,27 @@ int tt565_transaction(RIG *rig, const char *cmd, int cmd_len, char *data, int *d
*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?
rig_debug(RIG_DEBUG_ERR,"cmd reject 3\n");
return -RIG_ERJCTED; // No, but it should have been!
}
else { // Yes, it was a 'read', phew!
if (!strncmp(data+1,cmd+1,cmd_len-2)) { //reponse matches cmd? if (!strncmp(data+1,cmd+1,cmd_len-2)) { //reponse matches cmd?
return RIG_OK; // all is well, normal exit return RIG_OK; // all is well, normal exit
} }
else { else { /* The command read back does not match the command that
/* The command read back does not match the command that was written. We report the problem if debugging,
was written. What to do? We report the problem if debugging, and issue another read in hopes of eventual success.
and issue another read in hopes that
will make it sync up right.
*/ */
rig_debug(RIG_DEBUG_ERR, rig_debug(RIG_DEBUG_ERR,
"** retry after delay (io=%d, retry=%d) **\n", "** retry after delay (io=%d, retry=%d) **\n",