Blame view

Tangible/tangibleInterface.c 1.42 KB
67b73333   amoreau   Ajout du squelette
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  #include <avr/io.h>
  #include <util/delay.h>
  #include <stdio.h>
  
  #include "serial.h"
  #include "ethernet.h"
  #include "w5100.h"
  #include "socket.h"
  
  #define MAC_SIZE	6
  #define IPV4_SIZE	4
  
  int main(void)
  {
d12f48f7   pifou   Prise en compte d...
15
    uint8 com[4],per[14];
b34a6f00   pifou   modif socket .h .c
16
    uint8_t mac[MAC_SIZE] = {0xA0,0xBD,0xCD,0xDD,0xED,0xFD};
99a83ce4   pifou   Ajout rĂ©ponse TCP...
17
    uint8_t ip[IPV4_SIZE] = {172,26,145,205};
b34a6f00   pifou   modif socket .h .c
18
19
    uint8_t gateway[4] = {172,26,145,254};
    uint8_t mask[4] = {255,255,255,0};
d12f48f7   pifou   Prise en compte d...
20
    int isUDP = 0;
b34a6f00   pifou   modif socket .h .c
21
22
23
24
25
    const char answer [16] = "I'm ok";
    
    uint8 buf[16];
    uint8_t addr[IPV4_SIZE];
    uint16_t port;
d12f48f7   pifou   Prise en compte d...
26
    uint16 datasize;
b34a6f00   pifou   modif socket .h .c
27
    uint8_t addrpifou[IPV4_SIZE]={172,26,145,35};
47ebd24d   pifou   ajout..
28
    uint16 size;
8d95b38e   pifou   update de tangibl...
29
30
    SOCKET sUDP=0;
    SOCKET sTCP=1;
b34a6f00   pifou   modif socket .h .c
31
32
      init_printf();
      ethernet_init(mac,ip,gateway,mask); 
d12f48f7   pifou   Prise en compte d...
33
34
35
36
37
38
39
40
41
42
43
      if (!socket(sUDP,Sn_MR_UDP,2020,0))
        {
  	return -1;
        }
      if (!socket(sTCP,Sn_MR_TCP,2020,0))
        {
  	return -1;
        }
      while(1)
        {
  	if((datasize=recvfrom(sUDP,buf,sizeof(buf),addr,&port)) == 17)
b34a6f00   pifou   modif socket .h .c
44
  	{
d12f48f7   pifou   Prise en compte d...
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
  	  com[0]=buf[0];
  	  com[1]=buf[1];
  	  com[2]=buf[2];
  	  com[3]='\0';
  	  per[0]=buf[3];
  	  per[1]=buf[4];
  	  per[2]=buf[5];
  	  per[3]=buf[6];
  	  per[4]=buf[7];
  	  per[5]=buf[8];
  	  per[6]=buf[9];
  	  per[7]=buf[10];
  	  per[8]=buf[11];
  	  per[9]=buf[12];
  	  per[10]=buf[13];
  	  per[11]=buf[14];
  	  per[12]=buf[15];
  	  per[13]='\0';
  	  printf("Com : %s\n",com);
  	  printf("Per : %s\n",per); 
  	}  
        }
      printf("RESET\n");
      close(sTCP);
      close(sUDP);
      return 0;
67b73333   amoreau   Ajout du squelette
71
  }
8d95b38e   pifou   update de tangibl...
72
  
d12f48f7   pifou   Prise en compte d...
73
  //send(sTCP,(uint8*)answer, (uint16)sizeof(answer));