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;
double SleepUntil=0;
int quiet = 0;
+int use_select = 0;
long tmGet() {
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
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;
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)
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;
}
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);