00001
00002
00003
00004
00010 #include <stdlib.h>
00011 #include <stdio.h>
00012 #include <string.h>
00013 #include <sys/ioctl.h>
00014 #include <unistd.h>
00015 #include <sys/types.h>
00016 #include <asm/types.h>
00017 #include <sys/stat.h>
00018 #include <fcntl.h>
00019 #include <signal.h>
00020 #include <sched.h>
00021 #include <sys/resource.h>
00022 #include <sys/io.h>
00023 #include <E12user.h>
00024 #include <packet.h>
00025 #include <coprocessor.h>
00026
00027 #define ARGCHECK(num){if(argc!=num){printf("invalid number of arguements\n");help();return -1;}}
00028
00029 #define OPENDEV(filed,dev){if((filed = open(dev, O_RDWR))<=0){printf("couldn't open %s\n",dev);return -1;}}
00030
00031
00032 static int help(void)
00033 {
00034 const char *help_table = "****************************************************
00035 *E12_Serial *
00036 *Nathan Z. Gustavson *
00037 *Emac.inc *
00038 *"__DATE__" *
00039 *usage: *
00040 *E12_Serial device 422/232 r/w/b chars/string/baud *
00041 * *
00042 *ex: *
00043 *E12_Serial /dev/37e12 232 r 2 *
00044 *reads 2 characters from the 232 port *
00045 * *
00046 *E12_Serial /dev/37e12 422 w hello *
00047 *writes hello to the 422 port *
00048 * *
00049 *E12_Serial /dev/37e12 232 b 9600 *
00050 *sets the baud rate of the 232 port to zero *
00051 ****************************************************\n";
00052 printf("%s",help_table);
00053 return 0;
00054 }
00055
00056 int main(int argc, char *argv[])
00057 {
00058 int fd;
00059 int device=0;
00060 int command;
00061 int chars;
00062 char *string=NULL;
00063 int baud;
00064 Cop_Data *Cop;
00065 unsigned char buffer[100];
00066 int charnum;
00067
00068 ARGCHECK(5);
00069 OPENDEV(fd,argv[1]);
00070
00071 if(!strcmp("232",argv[2]))
00072 device = RS232PORT;
00073 else
00074 {
00075 if(!strcmp("422",argv[2]))
00076 device = RS422PORT;
00077 else
00078 {
00079 printf("invalid device, %s\n",argv[2]);
00080 help();
00081 }
00082 }
00083
00084 switch(command=*argv[3])
00085 {
00086 case 'r':
00087 chars = strtoul(argv[4],NULL,0);
00088 Cop = CopDeviceCreate(0);
00089
00090 switch(device)
00091 {
00092 case RS232PORT:
00093 string = Cop->RS232_string;
00094 break;
00095 case RS422PORT:
00096 string = Cop->RS422_string;
00097 break;
00098 }
00099
00100 while(strlen(string)<chars)
00101 {
00102 charnum = read(fd,buffer,sizeof(buffer));
00103 E12_Packet_Route(Cop, buffer, sizeof(buffer));
00104 }
00105 string[chars] = 0;
00106 printf("%s\n",string);
00107 break;
00108
00109 case 'w':
00110 string = argv[4];
00111 E12_Serial_Write(fd, device, strlen(string), string);
00112 break;
00113
00114 case 'b':
00115 baud = strtoul(argv[4],NULL,0);
00116 E12_Serial_Config(fd, device, baud, EIGHT_BIT);
00117 break;
00118
00119 }
00120
00121
00122 return 0;
00123 }
00124
00125