Exemplo n.º 1
0
int RF24Client::connect(IPAddress ip, uint16_t port) {

#if UIP_ACTIVE_OPEN > 0

  stop();
  uip_ipaddr_t ipaddr;
  uip_ip_addr(ipaddr, ip);

  struct uip_conn* conn = uip_connect(&ipaddr, htons(port));

  if (conn){

	#if UIP_CONNECT_TIMEOUT > 0
    int32_t timeout = millis() + 1000 * UIP_CONNECT_TIMEOUT;
    #endif

    while((conn->tcpstateflags & UIP_TS_MASK) != UIP_CLOSED) {
      RF24EthernetClass::tick();
	
	  if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED) {
	    data = (uip_userdata_t*) conn->appstate;
	    IF_RF24ETHERNET_DEBUG_CLIENT( Serial.print(F("connected, state: ")); Serial.print(data->state); Serial.print(F(", first packet in: ")); Serial.println(data->packets_in);  );
	    return 1;
	  }	  
	
	#if UIP_CONNECT_TIMEOUT > 0
	  if (((int32_t)(millis() - timeout)) > 0) {
	    conn->tcpstateflags = UIP_CLOSED;
	    break;
	  }
	#endif
    
	}
Exemplo n.º 2
0
int
UIPClient::connect(IPAddress ip, uint16_t port)
{
  uip_ipaddr_t ipaddr;
  uip_ip_addr(ipaddr, ip);
  _uip_conn = uip_connect(&ipaddr, htons(port));
  if (_uip_conn)
    {
      while((_uip_conn->tcpstateflags & UIP_TS_MASK) != UIP_CLOSED)
        {
          UIPEthernet.tick();
          if ((_uip_conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)
            {
#ifdef UIPETHERNET_DEBUG_CLIENT
              Serial.print("connected, state: ");
              Serial.print(((uip_userdata_t *)_uip_conn->appstate.user)->state);
              Serial.print(", first packet in: ");
              Serial.println(((uip_userdata_t *)_uip_conn->appstate.user)->packets_in[0]);
#endif
              return 1;
            }
        }
    }
  return 0;
}
Exemplo n.º 3
0
int
UIPClient::connect(IPAddress ip, uint16_t port)
{
  uip_ipaddr_t ipaddr;
  uip_ip_addr(ipaddr, ip);
  _uip_conn = uip_connect(&ipaddr, htons(port));
  return _uip_conn ? 1 : 0;
}
Exemplo n.º 4
0
int
UIPClient::connect(IPAddress ip, uint16_t port)
{
  uip_ipaddr_t ipaddr;
  uip_ip_addr(ipaddr, ip);
  _uip_conn = uip_connect(&ipaddr, htons(port));
  if (_uip_conn)
    {
      while((_uip_conn->tcpstateflags & UIP_TS_MASK) != UIP_CLOSED)
        {
          UIPEthernet.tick();
          if ((_uip_conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)
            return 1;
        }
    }
  return 0;
}
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
int
UIPUDP::beginPacket(IPAddress ip, uint16_t port)
{
  UIPEthernetClass::tick();
  if (ip && port)
    {
      uip_ipaddr_t ripaddr;
      uip_ip_addr(&ripaddr, ip);
#ifdef UIPETHERNET_DEBUG_UDP
      Serial.print(F("udp beginPacket, "));
#endif
      if (_uip_udp_conn)
        {
          _uip_udp_conn->rport = htons(port);
          uip_ipaddr_copy(_uip_udp_conn->ripaddr, &ripaddr);
        }
      else
        {
          _uip_udp_conn = uip_udp_new(&ripaddr,htons(port));
          if (_uip_udp_conn)
            {
#ifdef UIPETHERNET_DEBUG_UDP
              Serial.print(F("new connection, "));
#endif
              _uip_udp_conn->appstate = &appdata;
            }
          else
            {
#ifdef UIPETHERNET_DEBUG_UDP
              Serial.println(F("failed to allocate new connection"));
#endif
              return 0;
            }
        }
#ifdef UIPETHERNET_DEBUG_UDP
          Serial.print(F("rip: "));
          Serial.print(ip);
          Serial.print(F(", port: "));
          Serial.println(port);
#endif
    }
  if (_uip_udp_conn)
    {
      if (appdata.packet_out == NOBLOCK)
        {
          appdata.packet_out = Enc28J60Network::allocBlock(UIP_UDP_MAXPACKETSIZE);
          appdata.out_pos = UIP_UDP_PHYH_LEN;
          if (appdata.packet_out != NOBLOCK)
            return 1;
#ifdef UIPETHERNET_DEBUG_UDP
          else
            Serial.println(F("failed to allocate memory for packet"));
#endif
        }
#ifdef UIPETHERNET_DEBUG_UDP
      else
        Serial.println(F("previous packet on that connection not sent yet"));
#endif
    }
  return 0;
}