beautypg.com

Ktam3874/pitx software guide – Kontron KTAM3874-pITX User Manual

Page 80

background image

KTD-S0057-I

Page 76 Linux® Programming Examples (DebianTM)


KTAM3874/pITX Software Guide

or with (transmit part shortened, 'lo' implies 'Local Loopback')

# cat /proc/net/dev

Inter-|

Receive

|

Transmit

face

| bytes

packets

errs drop fifo frame

compr. multicast |bytes packets ..

lo:

???

???

0 0 0 0 0 0 ???

???

....

can0:

0 0 0 0 0 0 0 0

32 4

....

can1:

32 4

0 0 0 0 0 0 0 0

....

eth0:

0 0 0 0 0 0 0 0 0 0

....

eth1:

0 0 0 0 0 0 0 0 0 0

....


The socket interface offers an REC(EI)V(E)_OWN_MSGS option which does not work properly. The call of the
following routine has no effect.

int enable_own_msgs (void)
{

int own_msgs = 1;

return setsockopt (skt, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, &own_msgs, sizeof (own_msgs));

}

After entering some commands this option is still available.

sudo ifconfig can0 down
sudo ip link set can0 type can loopback on
sudo ip link set can0 up type can bitrate 125000


Now you can expand/change the previous example (extract):

#define DELAY_TIME

100

/* 100 us */

#define MAX_LOOPS

10000

/* Overall 1 second */


int detect_can_frame (void)
{

struct sockaddr_can addr;

struct can_frame frame;

socklen_t skt_len = sizeof (addr);

if (recvfrom (skt, &frame, sizeof (struct can_frame), MSG_DONTWAIT | MSG_PEEK,

(struct sockaddr *) &addr, &skt_len) < 0)

return

-1;

if (frame.can_dlc > 0)

return

0;

return

-1;

}


int main (void)
{

int i, data_len;

char name [MAX_NAME_LEN];

unsigned char data [MAX_CAN_LEN];

This manual is related to the following products: