drivers/can_virtual/can_virtual.c
changeset 157 8b45ff4202c3
parent 145 e747d2e26af0
child 193 0487270d441c
equal deleted inserted replaced
156:515d11cb496e 157:8b45ff4202c3
    26 
    26 
    27 #include <stdio.h>
    27 #include <stdio.h>
    28 #include <unistd.h>
    28 #include <unistd.h>
    29 
    29 
    30 #include "can_driver.h"
    30 #include "can_driver.h"
       
    31 #include "def.h"
    31 
    32 
    32 #define MAX_NB_CAN_PIPES 16
    33 #define MAX_NB_CAN_PIPES 16
    33 
    34 
    34 typedef struct {
    35 typedef struct {
    35   char used;
    36   char used;
    46 		return 1;
    47 		return 1;
    47 	}
    48 	}
    48 	return 0;
    49 	return 0;
    49 }
    50 }
    50 
    51 
       
    52 #define MyCase(fc) case fc: printf(#fc);break;
       
    53 void print_message(Message *m)
       
    54 {
       
    55 	int i;
       
    56 	switch(m->cob_id.w >> 7)
       
    57 	{
       
    58 		MyCase(SYNC)
       
    59 		MyCase(TIME_STAMP)
       
    60 		MyCase(PDO1tx)
       
    61 		MyCase(PDO1rx)
       
    62 		MyCase(PDO2tx)
       
    63 		MyCase(PDO2rx)
       
    64 		MyCase(PDO3tx)
       
    65 		MyCase(PDO3rx)
       
    66 		MyCase(PDO4tx)
       
    67 		MyCase(PDO4rx)
       
    68 		MyCase(SDOtx)
       
    69 		MyCase(SDOrx)
       
    70 		MyCase(NODE_GUARD)
       
    71 		MyCase(NMT)
       
    72 	}
       
    73 	printf(" rtr:%d", m->rtr);
       
    74 	printf(" len:%d", m->len);
       
    75 	for (i = 0 ; i < m->len ; i++)
       
    76 		printf(" %02x", m->data[i]);
       
    77 	printf("\n");
       
    78 }
       
    79 
    51 /***************************************************************************/
    80 /***************************************************************************/
    52 UNS8 canSend_driver(CAN_HANDLE fd0, Message *m)
    81 UNS8 canSend_driver(CAN_HANDLE fd0, Message *m)
    53 {
    82 {
    54   int i;
    83   int i;
       
    84   
       
    85   printf("%x->[ ", (CANPipe*)fd0 - &canpipes[0]); 
       
    86   for(i=0; i < MAX_NB_CAN_PIPES; i++)
       
    87   {
       
    88   	if(canpipes[i].used && &canpipes[i] != (CANPipe*)fd0)
       
    89   	{
       
    90 		printf("%x ",i);	
       
    91   	}
       
    92   }
       
    93   printf(" ]");	
       
    94   print_message(m);
       
    95   
    55   // Send to all readers, except myself
    96   // Send to all readers, except myself
    56   for(i=0; i < MAX_NB_CAN_PIPES; i++)
    97   for(i=0; i < MAX_NB_CAN_PIPES; i++)
    57   {
    98   {
    58   	if(canpipes[i].used && &canpipes[i] != (CANPipe*)fd0)
    99   	if(canpipes[i].used && &canpipes[i] != (CANPipe*)fd0)
    59   	{
   100   	{