]> rtime.felk.cvut.cz Git - lincan.git/commitdiff
Updated BFAD contributed can-proxy from latest changes by T.Motylewski
authorppisa <ppisa>
Fri, 22 Aug 2003 13:21:03 +0000 (13:21 +0000)
committerppisa <ppisa>
Fri, 22 Aug 2003 13:21:03 +0000 (13:21 +0000)
lincan/utils/can-proxy.c

index ab9bee864418116653a60d6796d9cddbc2f003ac..99ca2e1c0ff1a460a5170437aff09969c24d9e47 100644 (file)
@@ -89,10 +89,7 @@ int fdError;
 int fdIn;
 FILE * fLog;
 long iBusFlags;
-int bBusLock=0;
 time_t tsStarted;
-long tmWhenLocked;
-long tmDurationLocked;
 long tmLastVerified=0;
 long tmNow;  // current time, global, will be updated in many places
 long tmLastSentReceived=0;
@@ -102,6 +99,7 @@ double time0;
 double SleepUntil=0;
 
 int quiet = 0;
+int use_select = 0;
 
 
 long tmGet() {
@@ -168,7 +166,17 @@ int ReadNet(int fd, void * msg, int size) {
        return ret;
 }
 
-
+void show_usage(void) {
+       printf("can-proxy options:\n"
+       "-i     : intercative (send CAN packets typed by user)\n"
+       "-o file.log : log all traffic to a file\n"
+       "-p port : send CAN packets arriving at UDP port\n"
+       "-c     : use select() for CAN (driver can-0.7.1-pi3.4 or newer)\n"
+       "-q     : quiet\n"
+       "-h     : this help\n"
+       "UDP arriving at specified port causes can-proxy to forward all CAN\n"
+       "traffic back to the sender, establishing bi-directional communication.\n");
+}
 
 /**
        handling command line options, calling functions, main program loop 
@@ -189,13 +197,12 @@ int main(int argc, char * argv[]) {
        fLog = NULL;
        
        iBusFlags = 0;
-       tmWhenLocked = tmDurationLocked = 0;
        time0 = gettime();
        tsStarted = tvNow.tv_sec;
        tvSelectTimeout.tv_sec = 0;
        tvSelectTimeout.tv_usec = 500000; // wake up every 0.5 s even without data
 
-       while((opt=getopt(argc, argv, "io:p:c:l"))>0) {
+       while((opt=getopt(argc, argv, "io:p:ch"))>0) {
                switch(opt) {
                case 'i': // interactive or stdin
                        fdIn = 0;
@@ -208,20 +215,21 @@ int main(int argc, char * argv[]) {
                        break;
                case 'c':
                        fdCanDev = open(optarg,O_RDWR/*|O_NONBLOCK - select supported*/);
-                       break;
-               case 'l': // lock the bus during dispense
-                       bBusLock = 1;
+                       use_select++;
                        break;
                case 'q':
                        quiet ++;
                        break;
+               case 'h':
+                       show_usage();
+                       break;
                default:
                        break;
                }
        }
 
        if(!quiet)
-               fprintf(stderr, "can-proxy v0.7.1-pi3.3 (C) 2002 BFAD GmbH http://www.getembedded.de/ (GPL) \n");
+               fprintf(stderr, "can-proxy v0.7.1-pi3.5 (C) 2002 BFAD GmbH http://www.getembedded.de/ (GPL) \n");
 
        
        if(fdCanDev<0)
@@ -288,7 +296,8 @@ int main(int argc, char * argv[]) {
                if(fdIn>=0 && FD_ISSET(fdIn, &readsel)) {
                        ReadInput(fdIn);
                }
-//             usleep(20000); //can driver does select(), no need for delay
+               if(!use_select)
+                       usleep(20000);
        }
        return 0;       
 }
@@ -498,14 +507,6 @@ int ReadCommand(char *buf) {
                        sscanf(ptr,"%i", &usSleep);
                SleepUntil = gettime()-time0 + usSleep/1000000.0;
                break;
-       case 'l':
-               strtok(buf, " \t");
-               printf("bus locking is %s", (bBusLock ? "ON" : "OFF"));
-               ptr = strtok(NULL, " \t");
-               if(ptr)
-                       sscanf(ptr,"%i", &bBusLock);
-               printf(" switched to %s\n", (bBusLock ? "ON" : "OFF"));
-               break;
        case 'w':
                if(BuildCanMsg(buf, &msg) == 0) {
                        SendCanMsg(&msg);