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

📄 tjtool.c

📁 usb手柄电话usb驱动袁代码
💻 C
字号:
/*  * TigerJet Network USB device utility for driver interface  *  * Written by Ping Liu <pliu@tjnet.com> *  * Copyright (C) 2003 TigerJet Network Inc. * * All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. *  * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. *  *  http://www.gnu.org/licenses/gpl.txt */#include <sys/time.h>#include <stdio.h> #include <getopt.h>#include <string.h>#include <stdarg.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <fcntl.h>#include <errno.h>#include "tjusb.h"static int ftj = -1;unsigned short  StrToData(char *Ass){	int data;	if((Ass[0] == '0') && (Ass[1] == 'x'))		sscanf(Ass + 2,"%x", &data);	else sscanf(Ass, "%d", &data);	return (unsigned short) data;}int main(int argc, char *argv[]){	struct tj560_regs trg;	struct proslic_regs pro;	int i;                /* check if the device has plugged in */		ftj = open("/dev//usb/tjusb0", O_RDWR);	if (ftj < 0) {		fprintf(stderr,"Unable to open /dev/usb/tjusb0: %s\n", strerror(errno));		exit(1);	}        /* parse the command */		if((argc < 2) || atoi(argv[1])){		fprintf(stderr,"\n"			"Usage:tjtool [options]\n"			"      Valid options are:\n"			"	-r [Index] <Length>	--Read tj560 register data from Index\n"			"	-w [Index] [Value]	--Write data into tj560 register Index\n"			"	-d [Address] <Value>	--Read/Write proslic direct register \n"			"	-i [Address] <Value>	--Read/Write proslic indeirect register\n"			"\n");		close(ftj);		exit(1);	}        	memset(&trg,0,sizeof(trg));	memset(&pro,0,sizeof(pro));        /* Read tj560 register value */		if(!strcmp(argv[1],"-r") && (argc > 2)){		trg.index = (unsigned char) StrToData(argv[2]);                if (argc > 3) trg.len = (unsigned char) StrToData(argv[3]);	                else trg.len = 1;		if(ioctl(ftj,TJ_RD_REG,&trg) < 0 ) {			fprintf(stderr,"Unable to read tj: %s\n", strerror(errno));			close(ftj);			exit(1);		}		for (i = 0; i< trg.len; i++)		        fprintf(stderr,"Read tj560 reg %x = %02x\n",trg.index + i, trg.data[i]);	}        /* Write tj560 register value */		if(!strcmp(argv[1],"-w") && (argc > 3)){		trg.index = (unsigned char) StrToData(argv[2]);		trg.data[0] = (unsigned char) StrToData(argv[3]);                trg.len = 1;		if(ioctl(ftj,TJ_WR_REG,&trg) < 0){			fprintf(stderr,"Unable to write tj: %s\n", strerror(errno));			close(ftj);			exit(1);		}		for (i = 0; i< trg.len; i++)		        fprintf(stderr,"Write reg %x = %02x\n",trg.index + i, trg.data[i]);	}        /* Read proslic direct register value */		if(!strcmp(argv[1],"-d") && (argc == 3)){		pro.address = (unsigned char) StrToData(argv[2]);		if(ioctl(ftj,TJ_RDPS_DREG,&pro) < 0 ) {			fprintf(stderr,"Unable to read proslic: %s\n", strerror(errno));			close(ftj);			exit(1);		}	        fprintf(stderr,"Read proslic reg %x = %02x\n",pro.address, pro.data);	}        /* Read Proslic Indirect register value */		if(!strcmp(argv[1],"-i") && (argc == 3)){		pro.address = (unsigned char) StrToData(argv[2]);		if(ioctl(ftj,TJ_RDPS_IDREG,&pro) < 0 ) {			fprintf(stderr,"Unable to read proslic inderect: %s\n", strerror(errno));			close(ftj);			exit(1);		}	        fprintf(stderr,"Read proslic indirect reg %x = %04x\n",pro.address, pro.indata);	}        /* Write Proslic Direct register value */		if(!strcmp(argv[1],"-d") && (argc > 3)){		pro.address = (unsigned char) StrToData(argv[2]);		pro.data = (unsigned char) StrToData(argv[3]);		if(ioctl(ftj,TJ_WRPS_DREG,&pro) < 0){			fprintf(stderr,"Unable to write proslic: %s\n", strerror(errno));			close(ftj);			exit(1);		}	        fprintf(stderr,"Write proslic reg %x = %02x\n",pro.address, pro.data);	}        /* Write Proslic Indirect register value */		if(!strcmp(argv[1],"-i") && (argc > 3)){		pro.address = (unsigned char) StrToData(argv[2]);		pro.indata = StrToData(argv[3]);		if(ioctl(ftj,TJ_WRPS_IDREG,&pro) < 0){			fprintf(stderr,"Unable to write proslic indirect: %s\n", strerror(errno));			close(ftj);			exit(1);		}	        fprintf(stderr,"Write proslic indirect reg %x = %04x\n",pro.address, pro.indata);	}	close(ftj);	exit(0);	return 0;}

⌨️ 快捷键说明

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