From: ppisa Date: Sat, 21 Feb 2004 21:23:47 +0000 (+0000) Subject: Change to CAN_MSG_VERSION_2 and elimination of linux/*.h headers from user space... X-Git-Tag: CLT_COMM_CAN_post_canmsg_change X-Git-Url: http://rtime.felk.cvut.cz/gitweb/lincan.git/commitdiff_plain/c316aed80a2047f337dc0cff35e2458c4cb13eca?hp=f322df49b2f3aa1d8a5ac71a0fba7f8084c26380 Change to CAN_MSG_VERSION_2 and elimination of linux/*.h headers from user space apps. Layout of canmsg_t changed to CAN_MSG_VERSION_2, which is compatible with PORT GmbH can4linux-3.1 implementation. The driver and utilities can be compiled with old version, if definition of CAN_MSG_VERSION_2 is commented out in lincan/include/canmsg.h and canvca/libvca/canmsg.h headers. The change from __u8 .. __u32 types to standard compliant u_int8_t .. u_int32_t types has been required to eliminate linux/*.h files. This can make problems to ancient Linux distributions and some workaround could be necessary. --- diff --git a/lincan/include/can.h b/lincan/include/can.h index 8247c35..3cf633b 100644 --- a/lincan/include/can.h +++ b/lincan/include/can.h @@ -1,84 +1,25 @@ -#ifndef _CANMSG_T_H -#define _CANMSG_T_H +#ifndef _CAN_DRVAPI_T_H +#define _CAN_DRVAPI_T_H +#ifdef __KERNEL__ + +#include #include #include -#ifndef PACKED -#define PACKED __attribute__((packed)) -#endif - -#define CAN_MSG_LENGTH 8 - -/** - * struct canmsg_t - structure representing CAN message - * @flags: message flags - * %MSG_RTR .. message is Remote Transmission Request, - * %MSG_EXT .. message with extended ID, - * %MSG_OVR .. indication of queue overflow condition, - * %MSG_LOCAL .. message originates from this node. - * @cob: communication object number (not used) - * @id: ID of CAN message - * @timestamp: not used - * @length: length of used data - * @data: data bytes buffer - * - * Header: can.h - */ -struct canmsg_t { - short flags; - int cob; - unsigned long id; - unsigned long timestamp; - unsigned int length; - unsigned char data[CAN_MSG_LENGTH]; -} PACKED; +#else /* __KERNEL__ */ -/** - * struct canfilt_t - structure for acceptance filter setup - * @flags: message flags - * %MSG_RTR .. message is Remote Transmission Request, - * %MSG_EXT .. message with extended ID, - * %MSG_OVR .. indication of queue overflow condition, - * %MSG_LOCAL .. message originates from this node. - * there are corresponding mask bits - * %MSG_RTR_MASK, %MSG_EXT_MASK, %MSG_LOCAL_MASK. - * %MSG_PROCESSLOCAL enables local messages processing in the - * combination with global setting - * @queid: CAN queue identification in the case of the multiple - * queues per one user (open instance) - * @cob: communication object number (not used) - * @id: selected required value of cared ID id bits - * @mask: select bits significand for the comparation; - * 1 .. take care about corresponding ID bit, 0 .. don't care - * - * Header: can.h - */ -struct canfilt_t { - int flags; - int queid; - int cob; - unsigned long id; - unsigned long mask; -}; +#include +#include +#include -/* Definitions to use for canmsg_t and canfilt_t flags */ -#define MSG_RTR (1<<0) -#define MSG_OVR (1<<1) -#define MSG_EXT (1<<2) -#define MSG_LOCAL (1<<3) -/* If you change above lines, check canque_filtid2internal function */ +#endif /* __KERNEL__ */ -/* Additional definitions used for canfilt_t only */ -#define MSG_FILT_MASK_SHIFT 8 -#define MSG_RTR_MASK (MSG_RTR< +#include + +#else /* __KERNEL__ */ + +#include +#include + +#endif /* __KERNEL__ */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * CAN_MSG_VERSION_2 enables new canmsg_t layout compatible with + * can4linux project from http://www.port.de/ + * + */ +#define CAN_MSG_VERSION_2 + +/* Number of data bytes in one CAN message */ +#define CAN_MSG_LENGTH 8 + +#ifdef CAN_MSG_VERSION_2 + +typedef struct timeval canmsg_tstamp_t ; + +/** + * struct canmsg_t - structure representing CAN message + * @flags: message flags + * %MSG_RTR .. message is Remote Transmission Request, + * %MSG_EXT .. message with extended ID, + * %MSG_OVR .. indication of queue overflow condition, + * %MSG_LOCAL .. message originates from this node. + * @cob: communication object number (not used) + * @id: ID of CAN message + * @timestamp: not used + * @length: length of used data + * @data: data bytes buffer + * + * Header: canmsg.h + */ +struct canmsg_t { + int flags; + int cob; + unsigned long id; + canmsg_tstamp_t timestamp; + unsigned short length; + unsigned char data[CAN_MSG_LENGTH]; +}; + +#else /*CAN_MSG_VERSION_2*/ +#ifndef PACKED +#define PACKED __attribute__((packed)) +#endif +/* Old, deprecated version of canmsg_t structure */ +struct canmsg_t { + short flags; + int cob; + unsigned long id; + unsigned long timestamp; + unsigned int length; + unsigned char data[CAN_MSG_LENGTH]; +} PACKED; +#endif /*CAN_MSG_VERSION_2*/ + +typedef struct canmsg_t canmsg_t; + +/** + * struct canfilt_t - structure for acceptance filter setup + * @flags: message flags + * %MSG_RTR .. message is Remote Transmission Request, + * %MSG_EXT .. message with extended ID, + * %MSG_OVR .. indication of queue overflow condition, + * %MSG_LOCAL .. message originates from this node. + * there are corresponding mask bits + * %MSG_RTR_MASK, %MSG_EXT_MASK, %MSG_LOCAL_MASK. + * %MSG_PROCESSLOCAL enables local messages processing in the + * combination with global setting + * @queid: CAN queue identification in the case of the multiple + * queues per one user (open instance) + * @cob: communication object number (not used) + * @id: selected required value of cared ID id bits + * @mask: select bits significand for the comparation; + * 1 .. take care about corresponding ID bit, 0 .. don't care + * + * Header: canmsg.h + */ +struct canfilt_t { + int flags; + int queid; + int cob; + unsigned long id; + unsigned long mask; +}; + +typedef struct canfilt_t canfilt_t; + +/* Definitions to use for canmsg_t and canfilt_t flags */ +#define MSG_RTR (1<<0) +#define MSG_OVR (1<<1) +#define MSG_EXT (1<<2) +#define MSG_LOCAL (1<<3) +/* If you change above lines, check canque_filtid2internal function */ + +/* Additional definitions used for canfilt_t only */ +#define MSG_FILT_MASK_SHIFT 8 +#define MSG_RTR_MASK (MSG_RTR<rx_msg.length = len = id & 0x0f; obj->rx_msg.flags = id&ID0_RTR ? MSG_RTR : 0; + #ifdef CAN_MSG_VERSION_2 + obj->rx_msg.timestamp.tv_sec = 0; + obj->rx_msg.timestamp.tv_usec = 0; + #else /* CAN_MSG_VERSION_2 */ obj->rx_msg.timestamp = 0; + #endif /* CAN_MSG_VERSION_2 */ obj->rx_msg.cob = 0; obj->rx_msg.id = id>>5; diff --git a/lincan/utils/can-proxy.c b/lincan/utils/can-proxy.c index 99ca2e1..b602770 100644 --- a/lincan/utils/can-proxy.c +++ b/lincan/utils/can-proxy.c @@ -35,8 +35,6 @@ will forward packets from CAN to the most recent IP/UDP address. #define DEFAULT_CAN_CLIENT_PORT 3008 #define MAX_MSG_SIZE 4000 -typedef struct canmsg_t canmsg_t; - extern int SendCanMsg(canmsg_t * msg); extern int ReceiveCanMsg(canmsg_t * msg); extern int ReadInput(int fd); @@ -378,7 +376,6 @@ int ReceiveCanMsg(canmsg_t * msg) { msg->flags = 0; msg->cob = 0; - msg->timestamp = 0; ret = read(fdCanDev,msg, CAN_MSG_SIZE); if(ret == CAN_MSG_SIZE) { LogMsg("RECV", fLog, msg); diff --git a/lincan/utils/readburst.c b/lincan/utils/readburst.c index 8a6d552..ca67257 100644 --- a/lincan/utils/readburst.c +++ b/lincan/utils/readburst.c @@ -89,7 +89,11 @@ int main(int argc, char *argv[]) int n,ret; unsigned long i=0; + #ifdef CAN_MSG_VERSION_2 + struct canmsg_t readmsg={0,0,5,{0,0},0,{0,}}; + #else /* CAN_MSG_VERSION_2 */ struct canmsg_t readmsg={0,0,5,0,0,{0,}}; + #endif /* CAN_MSG_VERSION_2 */ struct sigaction act; @@ -151,7 +155,6 @@ int main(int argc, char *argv[]) while (1) { readmsg.flags=0; readmsg.cob=0; - readmsg.timestamp=0; #if 1 ret=can_fd_wait(fd, can_wait_sec); printf("%scan_fd_wait returned %d\n", prt_prefix, ret); diff --git a/lincan/utils/readburst_rtl.c b/lincan/utils/readburst_rtl.c index afb0eed..8595eeb 100644 --- a/lincan/utils/readburst_rtl.c +++ b/lincan/utils/readburst_rtl.c @@ -77,7 +77,11 @@ int readburst_main(void *arg) { int n,ret; unsigned long i=0; + #ifdef CAN_MSG_VERSION_2 + struct canmsg_t readmsg={0,0,5,{0,0},0,{0,}}; + #else /* CAN_MSG_VERSION_2 */ struct canmsg_t readmsg={0,0,5,0,0,{0,}}; + #endif /* CAN_MSG_VERSION_2 */ if(canfilt_mask || canfilt_id || canfilt_flags){ canfilt_fl=1; @@ -105,7 +109,6 @@ int readburst_main(void *arg) while (1) { readmsg.flags=0; readmsg.cob=0; - readmsg.timestamp=0; #if 0 ret=can_fd_wait(fd, can_wait_sec); printf("%scan_fd_wait returned %d\n", prt_prefix, ret); diff --git a/lincan/utils/rxtx.c b/lincan/utils/rxtx.c index 5fe75eb..ff611e1 100644 --- a/lincan/utils/rxtx.c +++ b/lincan/utils/rxtx.c @@ -10,6 +10,7 @@ int main(void) { int i=0, fd=0, ret=0, count=0; + int msglen; char loop=0; char ch, transmission[MAXL+1], specialfile[MAXL+1]="/dev/can0", emptystring[MAXL+1]="", buf[MAXL+1]; char remote[MAXL+1]; @@ -58,7 +59,8 @@ int main(void) if(message.id>=(1<<11)) message.flags |= MSG_EXT; printf("Enter the Message Length "); - scanf("%d",&message.length); + scanf("%d",&msglen); + message.length=msglen; for (i=0; i