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

KTD-S0057-I
Page 74 Linux® Programming Examples (DebianTM)
KTAM3874/pITX Software Guide
for (i = 0; i < frame.can_dlc; i++)
data[i] = frame.data[i];
*data_len = frame.can_dlc;
/* Search for name */
memset (&ifr, 0, sizeof (struct ifreq));
ifr.ifr_ifindex = addr.can_ifindex;
if (ioctl (skt, SIOCGIFNAME, &ifr) < 0)
return
-1;
strncpy (name, ifr.ifr_name, MAX_NAME_LEN);
name[MAX_NAME_LEN-1] = '\0';
for (i = 0; i < strlen (name); i++)
name[i] = toupper (name[i]);
return
0;
}
int main (void)
{
int
data_len;
char name [MAX_NAME_LEN];
unsigned char data [MAX_CAN_LEN];
printf ("\nCAN bus test program\n");
/* For example only the identifier range from 0x200 to 0x2FF is valid.
If there are no restrictions regarding identifiers use init_can_bus (0, 0) */
if (init_can_bus (0x200UL, 0x2FFUL))
{
close_can_bus
();
printf ("Cannot initialize the CAN interface !\n\n");
return
-1;
}
memset (&data, 0, sizeof (data));
data[0] = 0x11;
data[1] = 0x22;
data[2] = 0x33;
data[3] = 0x44;
data[4] = 0x55;
data[5] = 0x66;
data[6] = 0x77;
data[7] = 0x88;
data_len = 8;
if (send_can_frame (CAN0_INDEX, 0x201UL, data, data_len))
{
close_can_bus
();
printf ("Cannot transmit CAN bus data !\n\n");
return
-1;
}
printf ("\nSome data are successfully transmitted from: CAN0\n");
usleep
(WAIT_TIME);