⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 seriallog.c

📁 Gcomm is a serial communications program similar to seyon, but more modern, and easier to use. Works
💻 C
字号:
#ifndef	lintstatic const char rcsid[] = "$Id: seriallog.c,v 1.2 2001/10/25 23:56:29 efalk Exp $" ;#endif/* seriallog routines.  Write data to log file, tagged with timestamp * and channel. */#include <stdio.h>#include <string.h>#include <errno.h>#include <fcntl.h>#include <signal.h>#include <sys/types.h>#include <sys/uio.h>#include <sys/time.h>#include "seriallog.h"static	struct timeval	timestamp = {0,0} ;#define	DTIME	1500		/* timeout, milliseconds */static	int	which = -1 ;	/* last transmitted */static	char	obuf[4096] ;static	int	olen = -1 ;	FILE	*SerialLogFile = NULL ;	/* flush out buffered text */voidSerialLogFlush(){	int	i ;	if( SerialLogFile == NULL )	  return ;	if( which != -1 && olen > 0 )	{	  i = fwrite((char *)&which, sizeof(int), 1, SerialLogFile) ;	  i = fwrite((char *)&timestamp, sizeof(timestamp), 1, SerialLogFile) ;	  i = fwrite((char *)&olen, sizeof(int), 1, SerialLogFile) ;	  i = fwrite(obuf, 1, olen, SerialLogFile) ;	}	fflush(SerialLogFile) ;	which = -1 ;	olen = 0 ;}voidSerialLog(const void *data, int len, int w){	struct timezone	z ;	struct timeval	time ;	int	dt ;	int	i ;	if( SerialLogFile == NULL )	  return ;	gettimeofday(&time, &z) ;	dt = (time.tv_sec - timestamp.tv_sec)*1000 +	     (time.tv_usec - timestamp.tv_usec)/1000 ;	if( w != which || dt > DTIME ) {	  SerialLogFlush() ;	  which = w ;	  timestamp = time ;	}	while( len > 0 )	{	  if( olen+len > sizeof(obuf) )	    SerialLogFlush() ;	  i = len > sizeof(obuf) ? sizeof(obuf) : len ;	  bcopy(data, obuf+olen, i) ;	  olen += i ;	  len -= i ;	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -