1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#include <stdlib.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#define SIGNOF(a) (a<0?-1:1)
char readps2(int fd)
{
char ch;
while(read(fd,&ch,1) && (ch==(char)0xfa || ch==(char)0xaa))
{
printf("<%02X>",ch&0xff);
fflush(stdout);
}
return(ch);
}
int main(int argc, char **argv)
{
int fd;
char ch;
int len=3,i,j;
struct timeval tv,tv2;
long t;
if(argc>1)
fd=open(argv[1],O_RDWR,O_NOCTTY|O_SYNC);
else
fd=open("/dev/mouse",O_RDWR,O_NOCTTY|O_SYNC);
if(argc>2)
len=atoi(argv[2]);
gettimeofday(&tv2,NULL);
ch=0xf2;
write(fd,&ch,1);
ch=readps2(fd);
printf("device type=%02X(%4d)\n",ch&0xff,ch);
while(read(fd,&ch,1))
{
gettimeofday(&tv,NULL);
t=(tv.tv_sec-tv2.tv_sec)*1000000L+(tv.tv_usec-tv2.tv_usec);
printf("%10ld (%3dMHz) : ",t,1000000/t);
tv2.tv_sec=tv.tv_sec;
tv2.tv_usec=tv.tv_usec;
for(i=1; i<=len; i++)
{
printf("%02X(%4d",ch&0xff,ch);
if(argc>3 || i>1)
{
printf("=");
for(j=7;j>=0;j--)
printf("%01d",(ch>>j)&1);
printf("=%2d,%2d",(ch>>4), (ch&0x0F)<<28>>28);
printf(") ");
}
if(i<len)
if(!read(fd,&ch,1))
break;
}
//printf("\033[K\033[H");
//fflush(stdout);
printf("\n");
}
close(fd);
return(0);
}
|