From: Stephane F. <f4...@us...> - 2000-10-23 19:58:17
|
Update of /cvsroot/hamlib/hamlib/src In directory slayer.i.sourceforge.net:/tmp/cvs-serv22971 Modified Files: serial.c Log Message: * coded in a solution to not have active post_write_delay wait loop Index: serial.c =================================================================== RCS file: /cvsroot/hamlib/hamlib/src/serial.c,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -r1.3 -r1.4 *** serial.c 2000/10/09 01:17:20 1.3 --- serial.c 2000/10/23 19:58:14 1.4 *************** *** 323,326 **** --- 323,328 ---- * count - count of byte to send from the txbuffer * write_delay - write delay in ms between 2 chars + * post_write_delay - minimum delay between two writes + * post_write_date - timeval of last write * * returns: *************** *** 333,344 **** */ ! int write_block(int fd, const unsigned char *txbuffer, size_t count, int write_delay, int post_write_delay) { int i; if (write_delay > 0) { for (i=0; i < count; i++) { if (write(fd, txbuffer+i, 1) < 0) { ! rig_debug(RIG_DEBUG_ERR,"write_block() failed - %s\n", strerror(errno)); return -RIG_EIO; } --- 335,367 ---- */ ! int write_block(int fd, const unsigned char *txbuffer, size_t count, int write_delay, int post_write_delay /* , struct timeval *post_write_date */ ) { int i; + #ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY + if (post_write_date->tv_sec != 0) { + signed int date_delay; /* in us */ + struct timeval tv; + + /* FIXME in Y2038 ... */ + gettimeofday(tv, NULL); + date_delay = post_write_delay*1000 - + ((tv.tv_sec - post_write_date->tv_sec)*1000000 + + (tv.tv_usec - post_write_date->tv_usec)); + if (date_delay > 0) { + /* + * optional delay after last write + */ + usleep(date_delay); + } + post_write_date->tv_sec = 0; + } + #endif + if (write_delay > 0) { for (i=0; i < count; i++) { if (write(fd, txbuffer+i, 1) < 0) { ! rig_debug(RIG_DEBUG_ERR,"write_block() failed - %s\n", ! strerror(errno)); return -RIG_EIO; } *************** *** 349,357 **** } ! if(post_write_delay > 0) usleep(post_write_delay*1000); /* optional delay after last write */ /* otherwise some yaesu rigs get confused */ /* with sequential fast writes*/ ! rig_debug(RIG_DEBUG_TRACE,"TX %d bytes\n",count); dump_hex(txbuffer,count); --- 372,387 ---- } ! if (post_write_delay > 0) { ! #ifdef WANT_NON_ACTIVE_POST_WRITE_DELAY ! #define POST_WRITE_DELAY_TRSHLD 10 ! ! if (post_write_delay > POST_WRITE_DELAY_TRSHLD) ! gettimeofday(post_write_date, NULL); ! else ! #endif usleep(post_write_delay*1000); /* optional delay after last write */ /* otherwise some yaesu rigs get confused */ /* with sequential fast writes*/ ! } rig_debug(RIG_DEBUG_TRACE,"TX %d bytes\n",count); dump_hex(txbuffer,count); |