ttys_time.c

来自「足球机器人自动程序」· C语言 代码 · 共 60 行

C
60
字号
#include "cmd.h"#include "tty.h"#include "ctrl.h"#include <sys/poll.h>#include <sys/time.h>#include <time.h>char cmd = RV;int fd;char rbuf[4];int main() {	struct timeval tv, tvo;	double t;	// init ttys	fd = ttys_init(0);	// init ctrl	ctrl_init(fd);	gettimeofday(&tvo, NULL);	if (write(fd, &cmd, 1) != 1) {		fprintf(stderr, "write error\n");		return -1;	}	struct pollfd ufds = {fd, POLLIN};	int n;	int i = 0;	for (; i<300; ++i) {		if (poll(&ufds, 1, -1) <= 0) {			fprintf(stderr, "poll error\n");			return -1;		}		if ((n = read(fd, rbuf, sizeof(rbuf))) <= 0) {			fprintf(stderr, "read error\n");			return -1;		}		gettimeofday(&tv, NULL);		t = tv.tv_sec - tvo.tv_sec;		t += (double)(tv.tv_usec - tvo.tv_usec) / 1e6;		tvo = tv;		printf("%d\t%f\n", n, t);		if (write(fd, &cmd, 1) != 1) {			fprintf(stderr, "write error\n");			return -1;		}	}	return 0;}

⌨️ 快捷键说明

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