| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 
 | #include "socketcan_peak.h"
 
 
struct ifreq ifr;
 
 
/**************************************
*
* ssyCANSendMsg
*
*/
int ssyCANSendMsg(int s,char *sMsg, int nMsgSize, char idsend) 
{
TPCANMsg frame;
int ret,i;
//printf("j'envoie un message");
 
frame.ID = idsend;				//identifiant du message
frame.LEN = nMsgSize;			//taille du message
strcpy(frame.DATA, sMsg);		//copy sMsg dans frame.data
 
/*for(i=0; i < sizeof(frame.data);i++)
{
printf("sMsg=%X",sMsg[i]);
}
printf("\n");*/
ret = CAN_Write(s, &frame);		//ecrit 
	if( ret == -1 ) {
	perror("write");
			}
printf("Envoie sMsg=%x %x ident= %x\n",sMsg[0],sMsg[1],idsend);	
printf("Envoie frame.DATA=%x %x ident= %x\n",frame.DATA[0],frame.DATA[1],idsend);			
return SSY_DEF_SOCK_OK;
}
 
/**************************************
*
* ssyCANReceiveMsg
*
*/
int ssyCANReceiveMsg (int s, char *sMsg, int nMsgSize,int *ident)
{
int ret,i;
TPCANMsg frame;
/*
for(i=0; i < sizeof(frame.data);i++)
{
frame.data[i]=0;
}*/
 
//printf("je suis dans receive message\n");
 
ret = CAN_Read(s, &frame);	//lecture du socket
	if( ret == -1 ) {
	perror("write");
			}
 
 
memcpy(sMsg, &frame.DATA,nMsgSize);		//copie de frame.data dans sMsg
*ident=frame.ID;			//copie de l'identifiant du message dans ident
//printf("Reception sMsg=%x %x ident=%x \n",sMsg[0],sMsg[1],&ident);
//printf("je suis dans receive message3\n");
  return SSY_DEF_SOCK_OK;
}
 
/**************************************
*
* ssyCreateInetSocket
*
*/
 
int ssyCreateInetSocket()
{
/*
int family = PF_CAN, type = SOCK_RAW, proto = CAN_RAW, s;
struct sockaddr_can addr;
 
 
	if ((s = socket(family, type, proto)) < 0) {	//création du socket 
		perror("socket");
		return 1;
	}
 
	addr.can_family = family;			//protocol can
	strcpy(ifr.ifr_name, "can0");
	if( ioctl(s, SIOCGIFINDEX, &ifr) ) {
		perror("ioctl");
		return 1;
	}
	addr.can_ifindex = ifr.ifr_ifindex;
 
	if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {	//rattachement du protocol can au socket
		perror("bind");
		return 1;
	}
return (s);*/
}
/**************************************
*
* ssySocketClose
*
*/
int ssySocketClose(int s)
{
 CAN_Close(s);	//ferme le socket s
}
 
/**************************************
*
* ssyCANServerOpen
*
*/
int ssyCANServerOpen(int *s)
{
  const char  *szDevNode = DEFAULT_NODE;
 
  *s = LINUX_CAN_Open(szDevNode, O_RDWR); 		//ouvre le socket	
 
  return 0;
}
 
 
/**************************************
*
* ssyCANClose
*
*/
int ssyCANClose(int s)
{
 
  return(ssySocketClose(s));	//ferme le CAN
} |