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

📄 dread.c

📁 请在解压时看说明文档 内有详细说明
💻 C
字号:
/************************************************************//*****dread.c, this is a test program for upperdrv.c *****//************************************************************/#include <stdio.h>#include <sys/types.h>#include <sys/stat.h>#include <sys/ioctl.h>#include <stdlib.h>#include <string.h>#include <fcntl.h>#include <unistd.h>#include <errno.h>#include <asm/io.h>#include "softdev.h"/************************************************************//***** define some constants used in upperdrv.c  *****//************************************************************/#ifndef _UPPER_DEVICE_H#define _UPPER_DEVICE_H#include <linux/ioctl.h>#define UPPER_MAJOR 117#define UPPER_LOW2UPPER 1 // change the input string from low to upper characters#define UPPER_UNCHAN 0     //copy the input string to the output#define UPPER_MAGIC UPPER_MAJOR#define UPPER_RESET _IO(UPPER_MAGIC,0)   // reset the data#define UPPER_QUERY_NEW_MSG _IO(UPPER_MAGIC,1) // check for new message#define UPPER_QUERY_MSG_LENGTH _IO(UPPER_MAGIC,2) // get message length#define IOC_NEW_MSG 1#endifchar buf[1512];int main(int argc,char **argv) {	int i;	int fd,len,quit=0;	if(argc!=2) {		printf("syntax: dread + upper \n");		exit(0);	}	fd=open("/dev/upper",O_RDONLY);	if(fd<0) {		printf("Error opening device for reading!\n");		return 0;	}	while(!quit) {		printf("\n read>>");	while(!ioctl(fd,UPPER_QUERY_NEW_MSG))		usleep(1000);// get the msg length	len=ioctl(fd,UPPER_QUERY_MSG_LENGTH,NULL);	if(len) {			printf("msg_len=%d\n",len);			for(i=0;i<1512;i++) buf[i]=0;			len=read(fd,buf,len);			if(len<0) {				printf("Error reading from device!");			}			else if(!strcmp(buf,"exit")) {					ioctl(fd,UPPER_RESET);     // reset				}			else 					printf("%s\n",buf);//			quit=1;		//if the line "quit=1"  is removed, the program exit after receive one mesg			}	}	close(fd);	return 0;}

⌨️ 快捷键说明

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