kopia lustrzana https://github.com/Hamlib/Hamlib
handle nul char in stopset
git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@1019 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.1.3
rodzic
929d4094ad
commit
b26d39f637
|
@ -3,7 +3,7 @@
|
|||
* Copyright (c) 2001,2002 by Stephane Fillod
|
||||
* Contributed by Francois Retief <fgretief@sun.ac.za>
|
||||
*
|
||||
* $Id: easycomm.c,v 1.1 2002-01-16 16:35:22 fgretief Exp $
|
||||
* $Id: easycomm.c,v 1.2 2002-03-10 23:41:39 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
|
||||
|
@ -69,7 +69,7 @@ easycomm_transaction (ROT *rot, const char *cmdstr, char *data, size_t data_len)
|
|||
if (data == NULL || data_len <= 0)
|
||||
return RIG_OK; /* don't want a reply */
|
||||
|
||||
retval = read_string(&rs->rotport, data, data_len, "\n");
|
||||
retval = read_string(&rs->rotport, data, data_len, "\n", 1);
|
||||
if (retval < 0)
|
||||
return retval; /* error */
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Hamlib Kenwood backend - TH handheld primitives
|
||||
* Copyright (c) 2001 by Stephane Fillod
|
||||
*
|
||||
* $Id: th.c,v 1.5 2002-02-27 23:25:42 fillods Exp $
|
||||
* $Id: th.c,v 1.6 2002-03-10 23:41:39 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
|
||||
|
@ -117,7 +117,7 @@ th_transaction (RIG *rig, const char *cmdstr, char *data, size_t datasize)
|
|||
}
|
||||
|
||||
transaction_read:
|
||||
retval = read_string(&rs->rigport, data, datasize, cmdtrm);
|
||||
retval = read_string(&rs->rigport, data, datasize, cmdtrm, strlen(cmdtrm));
|
||||
if (retval < 0)
|
||||
goto transaction_quit;
|
||||
|
||||
|
|
18
src/iofunc.c
18
src/iofunc.c
|
@ -2,7 +2,7 @@
|
|||
* Hamlib Interface - generic file based io functions
|
||||
* Copyright (c) 2000,2001,2002 by Stephane Fillod and Frank Singleton
|
||||
*
|
||||
* $Id: iofunc.c,v 1.1 2002-01-16 22:56:34 fillods Exp $
|
||||
* $Id: iofunc.c,v 1.2 2002-03-10 23:41:39 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
|
||||
|
@ -273,15 +273,14 @@ int fread_block(port_t *p, char *rxbuffer, size_t count)
|
|||
*
|
||||
* Assumes rxbuffer!=NULL
|
||||
*/
|
||||
int read_string(port_t *p, char *rxbuffer, size_t rxmax, const char *stopset)
|
||||
int read_string(port_t *p, char *rxbuffer, size_t rxmax, const char *stopset,
|
||||
int stopset_len)
|
||||
{
|
||||
fd_set rfds;
|
||||
struct timeval tv, tv_timeout;
|
||||
int rd_count, total_count = 0;
|
||||
int retval;
|
||||
|
||||
rxbuffer[0] = '\000';
|
||||
|
||||
FD_ZERO(&rfds);
|
||||
FD_SET(p->fd, &rfds);
|
||||
|
||||
|
@ -291,7 +290,7 @@ int read_string(port_t *p, char *rxbuffer, size_t rxmax, const char *stopset)
|
|||
tv_timeout.tv_sec = p->timeout/1000;
|
||||
tv_timeout.tv_usec = (p->timeout%1000)*1000;
|
||||
|
||||
while (total_count < (rxmax-1)) {
|
||||
while (total_count < rxmax) {
|
||||
tv = tv_timeout; /* select may have updated it */
|
||||
|
||||
retval = select(p->fd+1, &rfds, NULL, NULL, &tv);
|
||||
|
@ -314,10 +313,13 @@ int read_string(port_t *p, char *rxbuffer, size_t rxmax, const char *stopset)
|
|||
return -RIG_EIO;
|
||||
}
|
||||
++total_count;
|
||||
if (stopset && strchr(stopset, rxbuffer[total_count-1]))
|
||||
break;
|
||||
/* Note: This function will always break on a '\000' character. */
|
||||
if (stopset && memchr(stopset, rxbuffer[total_count-1], stopset_len))
|
||||
break;
|
||||
}
|
||||
/*
|
||||
* Doesn't hurt anyway. But be aware, some binary protocols may have
|
||||
* null chars within th received buffer.
|
||||
*/
|
||||
rxbuffer[total_count] = '\000';
|
||||
|
||||
if (total_count == 0) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Hamlib Interface - io function header
|
||||
* Copyright (c) 2000,2001,2002 by Stephane Fillod and Frank Singleton
|
||||
*
|
||||
* $Id: iofunc.h,v 1.1 2002-01-16 22:56:34 fillods Exp $
|
||||
* $Id: iofunc.h,v 1.2 2002-03-10 23:41:39 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
|
||||
|
@ -29,7 +29,7 @@
|
|||
extern HAMLIB_EXPORT(int) read_block(port_t *p, char *rxbuffer, size_t count);
|
||||
extern HAMLIB_EXPORT(int) write_block(port_t *p, const char *txbuffer, size_t count);
|
||||
extern HAMLIB_EXPORT(int) fread_block(port_t *p, char *rxbuffer, size_t count);
|
||||
extern HAMLIB_EXPORT(int) read_string(port_t *p, char *rxbuffer, size_t rxmax, const char *stopset);
|
||||
extern HAMLIB_EXPORT(int) read_string(port_t *p, char *rxbuffer, size_t rxmax, const char *stopset, int stopset_len);
|
||||
|
||||
#endif /* _IOFUNC_H */
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue