/** \file cansend.c CAN bus monitor for the SJA1000 \author Cristiano Brudna \date 2001, 2002, 2003 University of Ulm, Germany This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include #include #include #include #include #include #include "can.h" #include "canlib.h" int can; void usage(void) { fprintf(stderr,"\nusage: cansend [-b baudrate] <#msgs> [message]\n\n"); fprintf(stderr," message = () {0,8}\n"); fprintf(stderr," type is 's' for standard and 'e' for extended frame \n"); fprintf(stderr," id and data must be in hexadecimal \n"); fprintf(stderr, " -b baud: set baudrate [1000, 500, 250, 125, 20] kbit/s\n"); } int main(int argc, char *argv[]) { char type; int num, k, dat, count, i, j, err; unsigned long baud_rate=B1000; canmsg txmsg; int par, pos = 0; /* pos is 2 if there is a baud rate request, and 0 if not */ /* get the baud rate setting */ if((strcmp(argv[1], "-b") == 0) && (argc > 2)) { pos = 2; par = atoi(argv[2]); switch(par) { case 1000: baud_rate = B1000; break; case 500: baud_rate = B500; break; case 250: baud_rate = B250; break; case 125: baud_rate = B125; break; case 20: baud_rate = B20; break; default: printf("\nBaud rate not supported!!! Using 1Mbit/s instead\n"); } } if(argc <= (3+pos)) { usage(); exit(1); } can = open("/dev/can", O_RDWR); if(can < 0) { perror("Error opening device /dev/can"); exit(1); } showStatus(can); ioctl(can, CAN_IOCSBAUD, &baud_rate); count = 1; if(argc > (2+pos)) { count = atoi(argv[1+pos]); } /* parse comand line */ /* get the message type */ sscanf(argv[2+pos], "%c", &type); if(type == 's') txmsg.type = STANDARD; else txmsg.type = EXTENDED; /* get the id */ sscanf(argv[3+pos], "%x", (unsigned int *) & txmsg.id); if( (txmsg.type == STANDARD) && (txmsg.id > 0x7ff) ) { printf("Error: CAN-ID too big for standard frame \n"); exit(0); } if( (txmsg.type == EXTENDED) && (txmsg.id > 0x1fffffff) ) { printf("Error: CAN-ID too big for extended frame \n"); exit(0); } txmsg.rtr = 0; txmsg.len = argc - (4+pos); if(txmsg.len > 8) txmsg.len = 8; for(k=0; k [ data ] timestamp \n\n"); fflush(stdout); for(i=0; i %x [", txmsg.id); for(j=0; j