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

📄 cap_net.c

📁 足球机器人自动程序
💻 C
字号:
#include "cam.h"#include "net.h"int main(int argc, char *argv[]) {	int id = 0;	int skip = 6;	char ip[16] = "127.0.0.1";	int port = 8000;	int sa = 0;	int agc = -1;	struct pwc_whitebalance wb;	struct cam c;	struct net nc;	for (;;) {		int t = getopt(argc, argv, "d:f:a:p:t:h");		if (t == -1) {			break;		}		switch (t) {			case 'd':				if (sscanf(optarg, "%d", &id) != 1) {					fprintf(stderr, "error optarg: %s\n", optarg);					exit(-1);				}				break;			case 'f':				if (sscanf(optarg, "%d", &t) != 1) {					fprintf(stderr, "error optarg: %s\n", optarg);					exit(-1);				}				if (t <= 0 || t > 30) {					fprintf(stderr, "framerate should be (0, 30]\n");					exit(-1);				}				skip = (60 / t + 1) >> 1;				break;			case 'a':				if (sscanf(optarg, "%s", ip) != 1) {					fprintf(stderr, "error optarg: %s\n", optarg);					exit(-1);				}				break;			case 'p':				if (sscanf(optarg, "%d", &port) != 1) {					fprintf(stderr, "error optarg: %s\n", optarg);					exit(-1);				}				break;			case 't':				if (sscanf(optarg, "%d", &sa) != 1) {					fprintf(stderr, "error optarg: %s\n", optarg);					exit(-1);				}				if (sa <=0) {					fprintf(stderr, "show auto time should be positive\n");					exit(-1);				}				break;			case 'h':				fprintf(stderr, "Usage: %s [option]\n"					"-d n\tset cam id n (default 0)\n"					"-f n\tset framerate n (default 5)\n"					"-a s\tset addr s (default 127.0.0.1)\n"					"-p n\tset port n (default 8000)\n"					"-t n\tshow auto value with interval n\n"					"-h\tprint this help\n", argv[0]);				return 0;			case '?':				break;			default:				fprintf(stderr, "option error: %d\n", t);				exit(-1);		}	}	if (optind != argc) {		fprintf(stderr, "command line error\n");		exit(-1);	}	cam_init(&c, id);	printf("using video%d skip %d (framerate %f)\n", id, skip, 30.0 / skip);	if (sa) {		wb.mode =  PWC_WB_AUTO;		if (ioctl(c.fd, VIDIOCPWCGAGC, &agc) < 0) {			perror("VIDIOCPWCGAGC");			exit(-1);		}		if (ioctl(c.fd, VIDIOCPWCSAWB, &wb) < 0) {			perror("VIDIOCPWCSAWB");			exit(-1);		}		printf("show auto value with interval %d\n", sa);	}	cam_capture(&c);	netc_init(&nc, ip, port);	printf("using ip %s port %d\n", ip, port);		int i = 0;	int j = skip;	int k = sa;	for (;;) {		cam_sync(&c);		cam_capture(&c);		if (++j >= skip) {			j = 0;			if (net_send(c.src, RAW_SIZE, &nc) != RAW_SIZE) {				fprintf(stderr, "netc_send error\n");				exit(-1);			}			if (!sa) fprintf(stderr, "\r%d", ++i);		}		if (sa && ++k >= sa) {			k = 0;			if (ioctl(c.fd,  VIDIOCPWCGAGC, &agc) < 0) {				perror("VIDIOCPWCGAGC");				exit(-1);			}			if (ioctl(c.fd, VIDIOCPWCGAWB, &wb) < 0) {				perror("VIDIOCPWCGAWB");				exit(-1);			}			fprintf(stderr, "\ragc=%5d  red=%5d  blue=%5d", agc, wb.read_red, wb.read_blue);		}	}	return 0;}

⌨️ 快捷键说明

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