tangibleInterface.c 1.53 KB
#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)
{
  uint8_t mac[MAC_SIZE] = {0xA0,0xBD,0xCD,0xDD,0xED,0xFD};
  uint8_t ip[IPV4_SIZE] = {172,26,145,205};
  uint8_t gateway[4] = {172,26,145,254};
  uint8_t mask[4] = {255,255,255,0};

  const char answer [16] = "I'm ok";
  
  uint8 buf[16];
  uint8_t addr[IPV4_SIZE];
  uint16_t port;

  uint8_t addrpifou[IPV4_SIZE]={172,26,145,35};
  uint16 size;
  SOCKET sUDP=0;
  SOCKET sTCP=1;
    init_printf();
    ethernet_init(mac,ip,gateway,mask); 
  if (!socket(sUDP,Sn_MR_UDP,2020,0))
    {
      return -1;
    }
  if (!socket(sTCP,Sn_MR_TCP,2020,0))
    {
      return -1;
    }

  while(1)
    {
      if (listen(sTCP))
      	{
      	  if (accept(sTCP))
      	    {
	      printf("test\n");
      	      /* if(recv(sTCP, buf,(uint16)sizeof(buf))!=-1) */
      	      /* 	{ */
      	      send(sTCP,(uint8*)answer, (uint16)sizeof(answer));
     	      /* 	} */
      	    }
	  else
	    {
	      close(sTCP);
	      if (!socket(sTCP,Sn_MR_TCP,2020,0))
		{
		  return -1;
		}
	    }
      	}
      else
	{
	  close(sTCP);
	  if (!socket(sTCP,Sn_MR_TCP,2020,0))
	    {
	      return -1;
	    }
	  
	}
    }
  close(sTCP);
  close(sUDP);
  return 0;
}
 



//sendto(sUDP,(uint8*)answer,(uint16)sizeof(answer), addrpifou, 2020);
      /* if (recvfrom(sUDP,buf,sizeof(buf),addr,&port) !=0 ) */
      /* 	{ */
      /* 	  printf("Size : %d \n",size); */
      /* 	} */