-#ifndef _CANMSG_T_H
-#define _CANMSG_T_H
+#ifndef _CAN_DRVAPI_T_H
+#define _CAN_DRVAPI_T_H
+#ifdef __KERNEL__
+
+#include <linux/time.h>
#include <linux/types.h>
#include <linux/ioctl.h>
-#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 <sys/time.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
-/* 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<<MSG_FILT_MASK_SHIFT)
-#define MSG_EXT_MASK (MSG_EXT<<MSG_FILT_MASK_SHIFT)
-#define MSG_LOCAL_MASK (MSG_LOCAL<<MSG_FILT_MASK_SHIFT)
-#define MSG_PROCESSLOCAL (MSG_OVR<<MSG_FILT_MASK_SHIFT)
+#include "./canmsg.h"
-
-/* Can message ID mask */
-#define MSG_ID_MASK ((1l<<29)-1)
+#ifdef __cplusplus
+extern "C" {
+#endif
/* CAN ioctl magic number */
#define CAN_IOC_MAGIC 'd'
#define CANQUE_FILTER _IOW(CAN_IOC_MAGIC, 10, struct canfilt_t)
#define CANQUE_FLUSH _IO(CAN_IOC_MAGIC, 11)
-#endif /*_CANMSG_T_H*/
+#ifdef __cplusplus
+} /* extern "C"*/
+#endif
+
+#endif /*_CAN_DRVAPI_T_H*/
#ifndef _CAN_QUEUE_H
#define _CAN_QUEUE_H
-#include "./can.h"
+#include "./canmsg.h"
#include "./constants.h"
#include "./can_sysdep.h"
--- /dev/null
+#ifndef _CANMSG_T_H
+#define _CANMSG_T_H
+
+#ifdef __KERNEL__
+
+#include <linux/time.h>
+#include <linux/types.h>
+
+#else /* __KERNEL__ */
+
+#include <sys/time.h>
+#include <sys/types.h>
+
+#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<<MSG_FILT_MASK_SHIFT)
+#define MSG_EXT_MASK (MSG_EXT<<MSG_FILT_MASK_SHIFT)
+#define MSG_LOCAL_MASK (MSG_LOCAL<<MSG_FILT_MASK_SHIFT)
+#define MSG_PROCESSLOCAL (MSG_OVR<<MSG_FILT_MASK_SHIFT)
+
+/* Can message ID mask */
+#define MSG_ID_MASK ((1l<<29)-1)
+
+#ifdef __cplusplus
+} /* extern "C"*/
+#endif
+
+#endif /*_CANMSG_T_H*/
* Version lincan-0.2 9 Jul 2003
*/
-#ifdef __CONSTANTS_H__
-#else
+#ifndef __CONSTANTS_H__
#define __CONSTANTS_H__
/* Device name as it will appear in /proc/devices */
#define DEVICE_NAME "can"
+/* Version of the driver reported by */
+
+
/* Default driver major number, see /usr/src/linux/Documentation/devices.txt */
#define CAN_MAJOR 91
-/* Timeout in jiffies before the system calls return with an error */
-#define CANTIMEOUT (4*HZ)
-
/* Definition of the maximum number of concurrent supported hardware boards,
* chips per board, total number of chips, interrupts and message objects.
* Obviously there are no 32 different interrupts, but each chip can have its
* Version lincan-0.2 9 Jul 2003
*/
-#include "./can.h"
+#include "./canmsg.h"
#include "./can_sysdep.h"
#include "./constants.h"
#include "./can_queue.h"
#include "../include/can_iortl.h"
#endif /*CAN_WITH_RTL*/
-#define EXPORT_SYMTAB
-
can_spinlock_t canuser_manipulation_lock;
/* Module parameters, some must be supplied at module loading time */
id = can_read_reg(chip, SJARXID0) | (can_read_reg(chip, SJARXID1)<<8);
obj->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;
#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);
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);
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;
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);
{
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;
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);
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];
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<message.length; i++) {
printf("Enter data byte [%d] ",i);
scanf("%x",(int *)&message.data[i]);
printf("Id : %lx\n",message.id);
printf("length : %d\n",message.length);
printf("flags : 0x%02x\n", message.flags);
+ #ifdef CAN_MSG_VERSION_2
+ printf("time : %lds %ldusec\n", message.timestamp.tv_sec,
+ message.timestamp.tv_usec);
+ #else /* CAN_MSG_VERSION_2 */
printf("time : %ld\n", message.timestamp);
+ #endif /* CAN_MSG_VERSION_2 */
for (i=0; i<message.length; i++)
printf("data%d : %02x\n",i,
message.data[i]);
{
int i=0, fd=0, ret=0;
unsigned long bits;
+ int msglen;
char specialfile[MAXL+1]="/dev/can0", buf[MAXL+1];
struct canmsg_t message;
printf("Enter the starting Message ID ");
scanf("%lx",&message.id);
printf("Enter the Message Length ");
- scanf("%d",&message.length);
+ scanf("%d",&msglen);
+ message.length=msglen;
for (i=0; i<message.length; i++) {
printf("Enter data byte [%d] ",i);
scanf("%x",(int *)&message.data[i]);
};
int opt;
+ #ifdef CAN_MSG_VERSION_2
+ struct canmsg_t sendmsg={0,0,5,{0,0},8,{1,2,3,4,5,6,7,8}};
+ #else /* CAN_MSG_VERSION_2 */
struct canmsg_t sendmsg={0,0,5,0,8,{1,2,3,4,5,6,7,8}};
+ #endif /* CAN_MSG_VERSION_2 */
int fd, ret,i,j;
while ((opt = getopt_long(argc, argv, "d:i:f:sw:b:c:p:Vh",
int sendburst_main(void *arg)
{
+ #ifdef CAN_MSG_VERSION_2
+ struct canmsg_t sendmsg={0,0,5,{0,0},8,{1,2,3,4,5,6,7,8}};
+ #else /* CAN_MSG_VERSION_2 */
struct canmsg_t sendmsg={0,0,5,0,8,{1,2,3,4,5,6,7,8}};
+ #endif /* CAN_MSG_VERSION_2 */
int fd, ret,i,j;