void tcp_cli_app1_init(void)
{
    UIP_CONN *tcp_conn=NULL;
    uip_ipaddr_t raddr;
    uint8 iot_srv_ip[MAC_IP_LEN] = TCP_CLI_APP1_IOT_SRV_IP;

    uip_ipaddr(raddr, iot_srv_ip[0],iot_srv_ip[1], iot_srv_ip[2],iot_srv_ip[3]);

    /* Specify remote address and port here. */
    tcp_conn = uip_connect(&raddr, HTONS(TCP_CLI_APP1_REMOTE_PORT));

    if (tcp_conn) {
        tcp_conn->lport = HTONS(TCP_CLI_APP1_LOCAL_PORT);
    } else {
        printf_high("connect fail\n");
    }
}
Exemple #2
0
bool TCPIP_Connect(void)
{
	// Connect to the remote machine (www.example.com)
	uip_ipaddr(&RemoteIPAddress, 192, 0, 32, 10);	
	TCPConnection = uip_connect(&RemoteIPAddress, UIP_HTONS(80));

	if (TCPConnection != NULL)
	{
		Debug_Print("Connecting to host\r\n");
		return true;
	}
	else
	{
		Debug_Print("Failed to Connect\r\n");
		return false;
	}
}
Exemple #3
0
struct uip_conn *
tcp_connect(uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
{
  struct uip_conn *c;
  
  c = uip_connect(ripaddr, port);
  if(c == NULL) {
    return NULL;
  }

  c->appstate.p = PROCESS_CURRENT();
  c->appstate.state = appstate;
  
  tcpip_poll_tcp(c);
  
  return c;
}
Exemple #4
0
struct uip_conn *
tcp_connect(uip_ipaddr_t *ripaddr, uint16_t port, void *appstate)
{
  struct uip_conn *c;
  
  c = uip_connect(ripaddr, port);
  if(c == NULL) {
    return NULL;
  }

  c->appstate.state = appstate;
  c->appstate.conn_id = last_conn_id++;
  
  tcpip_poll_tcp(c);
  
  return c;
}
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;
}
static void fs20_dns_query_cb(char *name, uip_ipaddr_t *ipaddr)  // Callback for DNS query
{
#ifdef DEBUG_FS20_SENDER
	char buf[50];
	print_ipaddr(ipaddr, buf, 50);
    FS20S_DEBUG ("got dns response, connecting %s:%d\n", buf, CONF_FS20_PORT);
#endif

    uip_conn_t *conn = uip_connect(ipaddr, HTONS(CONF_FS20_PORT), fs20_net_main);  // create new connection with ipaddr found
    
    if (conn)  // if connection succesfully created
    {
        conn->appstate.fs20.state = FS20_CONNSTATE_NEW; // Set connection state to new, as data still has to be send
    } 
    else 
    {
        fs20_sendstate = 2;  // if no connection initiated, set state to Retry
    }
}
Exemple #7
0
static void dhcpd_address_assigned() {
#ifdef USE_UDP
  if (app_conn) uip_udp_remove(app_conn);
  printf("setting up app connection ");

  app_conn = uip_udp_new(&dhcpd_client_ipaddr, HTONS(1208) /* remote port */);
  if (app_conn != NULL) {
    uip_udp_bind(app_conn, HTONS(1208) /* local port */);
  }
  bc_conn = uip_udp_new(&dhcpd_broadcast_ipaddr, HTONS(1208) /* remote port */);
  if (bc_conn != NULL) {
    uip_udp_bind(bc_conn, HTONS(1208) /* local port */);
  }
#else
  // we can only close the current connection, so we can't do it here; must do it in a poll handler or something
  //if (app_conn) uip_close(app_conn);
  printf("setting up app connection ");
  app_conn = uip_connect(&dhcpd_client_ipaddr, HTONS(1208) /* remote port */);
#endif
}
/******************************************************************************
* void setup_server_connection(void)
* 
* Open a TCP socket to the Exosite server
* 
******************************************************************************/
char setup_server_connection(void)
{
  uip_ipaddr_t ipaddr;
  struct uip_conn *conn;

  uip_ipaddr(ipaddr, s.server_ip[0], s.server_ip[1], s.server_ip[2], s.server_ip[3]);  // m2.exosite.com 
  conn = uip_connect(&ipaddr, htons(s.port));  
  if (conn == NULL) {
    volatile unsigned char i;
    i = 0;
    return 0;
  }
  
  *s.rxdata = 0;        //clear the first byte of our rx bufffer
  s.httprequestleft = 1;//set to a non-zero value 
  s.httprequestptr = 0;
  s.httpheaderlineptr = 0;
    
  return 1;
}
/*-----------------------------------------------------------------------------------*/
unsigned char webclient_get(char *host, u16_t port, char *file)
{
	struct uip_conn *conn;
	uip_ipaddr_t ipaddr;

	uip_ipaddr(&ipaddr, host[0],host[1],host[2],host[3]);

	conn = uip_connect(&ipaddr, htons(port));

	if(conn == NULL) {
		return 0;
	}

	s.port = port;
	strncpy(s.file, file, sizeof(s.file));
	strncpy(s.host, host, sizeof(s.host));

	init_connection();
	return 1;
}
Exemple #10
0
void
jabber_init(void)
{
  JABDEBUG("initializing client\n");

  uip_ipaddr_t ip;
  set_CONF_JABBER_IP(&ip);
  jabber_conn = uip_connect(&ip, HTONS(5222), jabber_main);

  if (!jabber_conn)
  {
    JABDEBUG("no uip_conn available.\n");
    return;
  }

#ifdef JABBER_EEPROM_SUPPORT
  eeprom_restore(jabber_username, &jabber_user, JABBER_VALUESIZE);
  eeprom_restore(jabber_password, &jabber_pass, JABBER_VALUESIZE);
  eeprom_restore(jabber_resource, &jabber_resrc, JABBER_VALUESIZE);
  eeprom_restore(jabber_hostname, &jabber_host, JABBER_VALUESIZE);
#endif
}
Exemple #11
0
/**
 * Send an e-mail.
 *
 * \param to The e-mail address of the receiver of the e-mail.
 * \param cc The e-mail address of the CC: receivers of the e-mail.
 * \param from The e-mail address of the sender of the e-mail.
 * \param subject The subject of the e-mail.
 * \param msg The actual e-mail message.
 * \param msglen The length of the e-mail message.
 */
unsigned char
smtp_send(char *to, char *cc, char *from,
	  char *subject, char *msg, u16_t msglen)
{
  struct uip_conn *conn;

  conn = uip_connect(smtpserver, HTONS(25));
  if(conn == NULL) {
    return 0;
  }
  s.connected = 1;
  s.to = to;
  s.cc = cc;
  s.from = from;
  s.subject = subject;
  s.msg = msg;
  s.msglen = msglen;

  PSOCK_INIT(&s.psock, s.inputbuffer, sizeof(s.inputbuffer));
  
  return 1;
}
int
UIPClient::connect(IPAddress ip, uint16_t port)
{
  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)
        {
          UIPEthernetClass::tick();
          if ((conn->tcpstateflags & UIP_TS_MASK) == UIP_ESTABLISHED)
            {
              data = (uip_userdata_t*) conn->appstate;
#ifdef UIPETHERNET_DEBUG_CLIENT
              Serial.print(F("connected, state: "));
              Serial.print(data->state);
              Serial.print(F(", first packet in: "));
              Serial.println(data->packets_in[0]);
#endif
              return 1;
            }
#if UIP_CONNECT_TIMEOUT > 0
          if (((int32_t)(millis() - timeout)) > 0)
            {
              conn->tcpstateflags = UIP_CLOSED;
              break;
            }
#endif
        }
    }
  return 0;
}
Exemple #13
0
int uip_broadcast(void *buf, size_t buf_len)
{
	int err;
	int fd;
	iscsid_uip_rsp_t rsp;
	int flags;
	int count;

	err = uip_connect(&fd);
	if (err) {
		log_warning("uIP daemon is not up");
		return err;
	}

	log_debug(3, "connected to uIP daemon");

	/*  Send the data to uIP */
	err = write(fd, buf, buf_len);
	if (err != buf_len) {
		log_error("got write error (%d/%d), daemon died?",
			  err, errno);
		close(fd);
		return ISCSI_ERR_ISCSID_COMM_ERR;
	}

	log_debug(3, "send iface config to uIP daemon");

	/*  Set the socket to a non-blocking read, this way if there are
	 *  problems waiting for uIP, iscsid can bailout early */
	flags = fcntl(fd, F_GETFL, 0);
	if (flags == -1)
		flags = 0;
	err = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
	if (err) {
		log_error("could not set uip broadcast to non-blocking: %d",
			  errno);
		close(fd);
		return ISCSI_ERR;
	}

#define MAX_UIP_BROADCAST_READ_TRIES 3
	for (count = 0; count < MAX_UIP_BROADCAST_READ_TRIES; count++) {
		/*  Wait for the response */
		err = read(fd, &rsp, sizeof(rsp));
		if (err == sizeof(rsp)) {
			log_debug(3, "Broadcasted to uIP with length: %ld "
				     "cmd: 0x%x rsp: 0x%x", buf_len,
				     rsp.command, rsp.err);
			err = 0;
			break;
		} else if ((err == -1) && (errno == EAGAIN)) {
			usleep(250000);
			continue;
		} else {
			log_error("Could not read response (%d/%d), daemon "
				  "died?", err, errno);
			err = ISCSI_ERR;
			break;
		}
	}

	if (count == MAX_UIP_BROADCAST_READ_TRIES) {
		log_error("Could not broadcast to uIP after %d tries",
			  count);
		err = ISCSI_ERR_AGAIN;
	} else if (rsp.err != ISCSID_UIP_MGMT_IPC_DEVICE_UP) {
		log_debug(3, "Device is not ready");
		err = ISCSI_ERR_AGAIN;
	}

	close(fd);
	return err;
}
/**
 * \brief Connects a socket to a remote host on a given address and port. Standard BSD connect() with internal name.
 * \param[in] desc socket descriptor created with socket()
 * \param[in] address must contain the address and port of the remote host. Must be in IPv6 format with current implementation.
 * \param[in] len is the length of \p address structure. (Unused parameter with current implementation. Assumes IPv6 structures length.)
 * \details connect() must be used in a TCP \b client application. The function call blocks until the connection is established.
 * \return On connection success, zero is returned. On error, -1 is returned.
 * \callgraph
 */
int _sys_sock_connect(int fd, struct _sockaddr *address,int len){
#if defined (__KERNEL_NET_IPSTACK) && defined (USE_UIP_CORE)
   pid_t pid;
   kernel_pthread_t* pthread_ptr;
   struct uip_conn * uip_conn;
   desc_t desc;
   hsock_t hsock  = 0;


   if(!(pthread_ptr = kernel_pthread_self())){
      __set_kernel_pthread_errno(ESRCH);
      return -1;
   }
   if((pid=pthread_ptr->pid)<=0){
      __set_kernel_pthread_errno(ESRCH);
      return -1;
   }
   //
   if(fd<0){
      __set_kernel_pthread_errno (EBADF);
      return -1;
   }
   //
   desc = process_lst[pid]->desc_tbl[fd];
   if(desc<0){
      __set_kernel_pthread_errno (EBADF);
      return -1;
   }
   if(!ofile_lst[desc].used){
      __set_kernel_pthread_errno (EBADF);
      return -1;
   }
   if(! (hsock  = ofile_lst[desc].p) ){
      __set_kernel_pthread_errno (ENOTSOCK);
      return -1;
   }
   if( ((socket_t*)(hsock))->state==STATE_SOCKET_CLOSED){
     __set_kernel_pthread_errno (ENOTCONN);
     return -1;
   }
   if( ((socket_t*)(hsock))->state==STATE_SOCKET_ABORTED){
     __set_kernel_pthread_errno (ECONNABORTED);
     return -1;
   }
   if(((socket_t*)hsock)->protocol!=IPPROTO_TCP){
      __set_kernel_pthread_errno (EPROTONOSUPPORT);
      return -1;
   }
   //lock
   __lock_io(ofile_lst[desc].owner_pthread_ptr_write,desc,O_WRONLY);
   __lock_io(ofile_lst[desc].owner_pthread_ptr_read,desc,O_RDONLY);
   //
   ((socket_t*)hsock)->state = STATE_SOCKET_CONNECT;
   //
   #if UIP_CONF_IPV6
   memcpy(&((socket_t*)hsock)->addr_in,address,sizeof(struct _sockaddr_in6));
   //
   uip_conn = uip_connect((uip_ipaddr_t*)(&((socket_t*)hsock)->addr_in.sin6_addr.s6_addr),
                  (u16_t)( ((socket_t*)hsock)->addr_in.sin6_port));
   #else
   ((socket_t*)hsock)->addr_in.sin_port = ((struct _sockaddr_in*)address)->sin_port;
   ((socket_t*)hsock)->addr_in.sin_addr.s_addr = ((struct _sockaddr_in*)address)->sin_addr.s_addr;
   //
   uip_conn = uip_connect((uip_ipaddr_t*)(&((socket_t*)hsock)->addr_in.sin_addr.s_addr),
                  (u16_t)( ((socket_t*)hsock)->addr_in.sin_port));
   #endif
   
   //
   if(!uip_conn){
      //unlock
      __unlock_io(ofile_lst[desc].owner_pthread_ptr_write,desc,O_WRONLY);
      __unlock_io(ofile_lst[desc].owner_pthread_ptr_read,desc,O_RDONLY);
      return -1;
   }
   //
   ((socket_t*)hsock)->r =0;
   ((socket_t*)hsock)->w =0;
   // 
   ((socket_t*)hsock)->socksconn = (struct socksconn_state *)(uip_conn->appstate.state);
   //
   ((socket_t*)hsock)->socksconn->__r  = 0;
   ((socket_t*)hsock)->socksconn->_r   = 0;
   ((socket_t*)hsock)->socksconn->_w   = 0;
   //
   ((socket_t*)hsock)->socksconn->hsocks = hsock;
   //unlock
   __unlock_io(ofile_lst[desc].owner_pthread_ptr_write,desc,O_WRONLY);
   __unlock_io(ofile_lst[desc].owner_pthread_ptr_read,desc,O_RDONLY);
   
   //to do:lepton
   //Wake ip_stack????
   //to do:lepton: syscall kernel
   //OS_WakeTask(_OS_TASK_TCB(os_ipStack));
   //Wait uip_connected();
    uip_core_queue_put(UIP_POLL_REQUEST,desc,(void*)address,len);
    //
   __WAIT_SOCKET_EVENT(pthread_ptr,hsock);
   if(((socket_t*)hsock)->state != STATE_SOCKET_WAIT)
      return -1;
   //
   __set_kernel_pthread_errno (0);
   //
   return 0;
#else
   return -1;
#endif
} //end of _sys_sock_connect()
Exemple #15
0
// po³¹cz ze zdalnym serwerem
unsigned char telnet_connect() {
    telnet_server_conn = uip_connect(&telnet_server_ip, HTONS(telnet_server_port));
    return (!telnet_server_conn) ? 0 : 1;
}
Exemple #16
0
asmlinkage void sys_uip_connect_k(unsigned long ip_address, unsigned long port, unsigned long gos_id, unsigned long sock_id)
{
  uip_connect(&ip_address, htons(port), gos_id, sock_id);
  return;
}
Exemple #17
0
// Task for reactivision output processing
void vServoTask( void)
{
    u16_t ripaddr[2];
    portBASE_TYPE xStatus;

    xTuioQueuePacket xValueRead;

    xTuioQueuePacket xDistanceValue[6];

    // Tracking Variables
    short sPosX = 0;
    short sPosY = 0;
    short sDegreesX = servoMIN_DEGREES;
    short sDegreesY = (servoMIN_DEGREES+servoMAX_DEGREES)/4;

    vServo_ConfigurePwm(sDegreesX, sDegreesY);

    sX = 0;
    sY = 0;
    sZ = 0;

    // Uip connect
    vTaskDelay(1000);
    uip_ipaddr(ripaddr, 192,168,0,1);
    uip_connect(ripaddr, HTONS(3000));

    xTuioQueue = xQueueCreate(20, sizeof(xTuioQueuePacket));

    vSemaphoreCreateBinary(xControlServo);

    short sFlightPlanStage = servotaskFLIGHT_PLAN_1;
    short sGoalPoint;
    short sGoalCounter;

    // Servo control loop
    for (;;) {

        //Read from TUIO queue.
        xStatus = xQueueReceive(xTuioQueue, &xValueRead, 10);     // Block task for 10ms when waiting for the Queue

        if (xStatus == pdPASS) {   // Process received value

            // values are between 0 and 1
            sPosX = (short) (xValueRead.position_x*100.0f);
            sPosY = (short) (xValueRead.position_y*100.0f);

            short sId = xValueRead.class_id-servoFIDUCIAL_SET;

            // If the middle fiducial marker, track it with the camera
            if (sId >= 0 && sId <= 5) {
                // Remember, position is taken from TOP LEFT
                if (sPosX < servoBOUNDING_BOX_MIN && sDegreesX < servoMAX_DEGREES) {
                    sDegreesX++;
                } else if (sPosX > servoBOUNDING_BOX_MAX && sDegreesX > servoMIN_DEGREES) {
                    sDegreesX--;
                }

                if (sPosY < servoBOUNDING_BOX_MIN && sDegreesY < servoMAX_DEGREES) {
                    sDegreesY++;
                } else if (sPosY > servoBOUNDING_BOX_MAX && sDegreesY > servoMIN_DEGREES) {
                    sDegreesY--;
                }

                // Set the fiducial to being used, and the value to the current packet
                sDistanceUsed[sId] = 1;
                xDistanceValue[sId] = xValueRead;

                // If there is an ID to compare to, calculate distance
                if (sGetId(sId) != -1 && sTask5) {
                    short sNextId = sGetId(sId);

                    // Print markers used for distancing
                    //debug_printf("markers: %d %d\r\n", xValueRead.class_id, xDistanceValue[sNextId].class_id);

                    // Compute the distance to the fiducial
                    double dD = sApproxSqrt(sPow(sPosX-(short) (xDistanceValue[sNextId].position_x*100.0f),2) +
                                           sPow(sPosY-(short) (xDistanceValue[sNextId].position_y*100.0f),2));

                    dD = (33379*sPow((short) dD,2) - 2288800*dD + 44475000)/10000;

                    //debug_printf(">> Distance: %d\r\n", (short) dD);

                    // Calculate the XYZ coordinates.
                    double dDegX = sDegreesX - servoMIN_DEGREES - (servoMIN_DEGREES+servoMAX_DEGREES)/2;
                    double dDegY = sDegreesY - servoMIN_DEGREES;

                    sX = (short) (dD*(sin((double) (dDegX/180.0f*3.14f))));
                    sY = (short) (dD*(sin((double) (dDegY/180.0f*3.14f))));
                    sZ = (short) (dD*(cos((double) (dDegX/180.0f*3.14f))));

                    //debug_printf(">> Angles: %d %d\r\n", (short) dDegX, (short) dDegY);
                    //debug_printf(">> Point: %d %d %d\r\n", sX, sY, sZ);

                    // On detecting the blimp, set the goal to 1.5m in X and flight plan to 2
                    if (sId < 3 && sFlightPlanStage == servotaskFLIGHT_PLAN_1) {
                        sGoalPoint = sX + 1500;
                        sGoalCounter = 0;
                        sFlightPlanStage = servotaskFLIGHT_PLAN_2;
                        debug_printf("Starting stage 2\t\t\ Goal: %d\r\n", sGoalPoint);
                    // If in stage 2, check if it has reached it's goal point. if this is confirmed
                    // using a counter, move to stage 3
                    } else if (sFlightPlanStage == servotaskFLIGHT_PLAN_2) {
                        sSetSpeed(0xFF);

                        if (sX > sGoalPoint) {
                            sGoalCounter++;
                        }

                        if (sGoalCounter > 10) {
                            sFlightPlanStage = servotaskFLIGHT_PLAN_3;
                            debug_printf("Starting stage 3\r\n");
                        }

                    // Set the goal point 1.5m back in x and move to stage 4
                    } else if (sFlightPlanStage == servotaskFLIGHT_PLAN_3) {
                        sRequestTurnLeft();

                        if (sId > 2) {
                            sGoalPoint = sX - 1500;
                            sGoalCounter = 0;
                            sFlightPlanStage = servotaskFLIGHT_PLAN_4;
                            debug_printf("Starting stage 4\t\t\ Goal: %d\r\n", sGoalPoint);
                        }
void sambungan_connect(int no)
{
	struct uip_conn *conn;
	struct sambungan_state *samb3;
	uip_ipaddr_t ip_modul;
	int i;
	char ipne[32];
	
	if (sumber[no].status == 1 && status[no].stat == 0)	// harus diaktfikan lagi
	{
		#ifdef DEBUG
		printf("Init sumber %d : %10s : ", (no+1), sumber[no].nama);
		printf("%d.%d.%d.%d\r\n", sumber[no].IP0, sumber[no].IP1, sumber[no].IP2, sumber[no].IP3);
		#endif
		
		uip_ipaddr(ip_modul, sumber[no].IP0, sumber[no].IP1, sumber[no].IP2, sumber[no].IP3);	
		
		conn = uip_connect(ip_modul, HTONS(PORT_MONITA));
		if (conn == NULL)
		{
			debug_out_h("ERR: Koneksi Penuh");	
			return ;
		}
		//printf("..%X..L=%d, R=%d .. OK\r\n", conn, conn->lport, conn->rport);
		
		conn->nomer_sambung = no;
		status[no].stat = 1;
		status[no].lport = conn->lport;
		status[no].timer = 0;
		status[no].reply_lama = 0;
		/* rport akan selalu sama */
		//debug_out_h("init %d lport %d, rport %d\n", no+1, status[no].lport, conn->rport);
		sprintf(ipne, " [%d][%d]:%d.%d.%d.%d", no+1, uip_conn->rport, \
			sumber[no].IP0, sumber[no].IP1, sumber[no].IP2, sumber[no].IP3);
		
		debug_out_h("Konek %s", ipne);	
		
		return;
	}
	else if (sumber[no].status == 1 && status[no].stat != 0)
	{
		/* 
		 * kemungkinan tidak close, tidak dpt acknoledge dll, 
		 * di increment reply_lama
		 * jika sudah lebih dari 60 detik dipaksa untuk konek lagi
		 */	
		
		status[no].reply_lama++;
		if (status[no].reply_lama > 60)
		{
			/* cari dulu koneksi yang lama
			 * dan set menjadi belum konek */
			debug_out_h("forced to connect ");
			for(i = 0; i < UIP_CONNS; i++) 
			{
		  		if (uip_conns[i].nomer_sambung == no && uip_conn[i].lport == HTONS(PORT_MONITA))
				{
					uip_conns[i].tcpstateflags = UIP_CLOSED;
		  			uip_conns[i].nomer_sambung = 0;
					
					//printf("con %d ", i);
					debug_out_h("con %d ", i);
				}
	  		}
			
			status[no].stat = 0;
			status[no].timer = 0;
			status[no].reply_lama = 0;
			
			debug_out_h("rekonek sumber %d :", no+1);
			debug_out_h("  %d.%d.%d.%d", sumber[no].IP0, sumber[no].IP1, sumber[no].IP2, sumber[no].IP3);	
		}
	}
	/* daytime server, harusnya hanya ada 1 server */
	else if (sumber[no].status == 5 && status[no].stat == 0)	// harus diaktfikan lagi
	{
		#ifdef DEBUG
		printf("Init daytime %d : %10s : ", (no+1), sumber[no].nama);
		printf("%d.%d.%d.%d\r\n", sumber[no].IP0, sumber[no].IP1, sumber[no].IP2, sumber[no].IP3);
		#endif
		uip_ipaddr(ip_modul, sumber[no].IP0, sumber[no].IP1, sumber[no].IP2, sumber[no].IP3);	
		
		conn = uip_connect(ip_modul, HTONS(PORT_DAYTIME));
		if (conn == NULL)
		{
			debug_out_h("ERR: Koneksi Penuh");	
			return ;
		}
		//printf("..%X..L=%d, R=%d .. OK\r\n", conn, conn->lport, conn->rport);

		conn->nomer_sambung = no;
		status[no].stat = 1;
		status[no].lport = conn->lport;
		status[no].timer = 0;
		status[no].reply_lama = 0;
	
		return;
	}
	return;
}
Exemple #19
0
void appSendSyn(u16_t * ipaddr)
{
     uip_connect(ipaddr, HTONS(memoryData.porta));
}
Exemple #20
0
static void tcp_client_reconnect(void)
{
    uip_ipaddr_t ipaddr;
    uip_ipaddr(&ipaddr, ipAddr[0], ipAddr[1], ipAddr[2], ipAddr[3]);
    uip_connect(&ipaddr, HTONS(9090));
}
Exemple #21
0
void UIP_APPCALL(void) {
  if (uip_poll()) {
    tcp_idle_time++;

    if (tcp_idle_time > 10) { /* half second units */
      printf("{{{Too much idle time in TCP connection}}}");
      uip_close();
      tcp_idle_time = 0;
      app_conn = uip_connect(&dhcpd_client_ipaddr, HTONS(1208) /* remote port */); /* try again */
    }
  }

  if (uip_acked()) {
    tcp_idle_time = 0;
    if (tcp_reply) {
      printf("{{{ACKED, sending reply to a request <%c>}}}",tcp_reply);
      tcp_tx_buffer[0] = tcp_reply;
      tcp_tx_len = 1;
      uip_send(tcp_tx_buffer, tcp_tx_len);
    } else {
      printf("{{{ACKED, idle}}}");
      tcp_tx_len = 0;
    }
  }

  if (uip_aborted() || uip_closed() || uip_timedout()) {
    printf("{{{TIMEDOUT,CLOSED,ABORTED}}}");
    uip_close();
    tcp_idle_time = 0;
    app_conn = uip_connect(&dhcpd_client_ipaddr, HTONS(1208) /* remote port */); /* try again */
  }

  if (uip_rexmit()) {
    printf("{{{REXMIT}}}");
    uip_send(tcp_tx_buffer, tcp_tx_len);
  }

  if (uip_newdata()) {
    printf("<<<TCP: UIP NEWDATA len=%d firstchar=%c>>>", uip_len,
        ((uint8_t*) uip_appdata)[0]);
    tcp_idle_time = 0;
    appHandlePacket();
    if (tcp_tx_len == 0) {
      tcp_tx_len = 1;
      tcp_tx_buffer[0] = ((uint8_t*) uip_appdata)[0];
      uip_send(tcp_tx_buffer, tcp_tx_len);
    } else {
      // we'll send it when the packet we are now sending is acked
      tcp_reply = ((uint8_t*) uip_appdata)[0];
      printf("...setting tcp reply to <%c>", tcp_reply);
    }
  }

  /*
   * if we put this before the test for new data,
   * it causes the message we send here to appear
   * as new data.
   */
  if (uip_connected()) {
    tcp_idle_time = 0;
    printf("{{{CONNECTED}}}");
    tcp_tx_len = 26;
    memcpy(tcp_tx_buffer,"iLPC 2148 Education Board\0", tcp_tx_len);
    uip_send(tcp_tx_buffer, tcp_tx_len);
  }


}
Exemple #22
0
unsigned char webclient_get(char *host, u16_t port, char *file)
{
	int gg=0;
  struct uip_conn *conn;
  uip_ipaddr_t *ipaddr;
  static uip_ipaddr_t addr;

  uip_ipaddr_t ip_modul;
	unsigned int ret_ip;
	ret_ip = baca_ip(host);	

  //uip_ipaddr(ip_modul, 192,168, 1, 75);
  uip_ipaddr(ip_modul, (uchr)(ret_ip >> 24), (uchr)(ret_ip >> 16), (uchr)(ret_ip >> 8), (uchr)(ret_ip));

  /* First check if the host is an IP address. */
  ipaddr = &addr; 
  
  /*
  if(uiplib_ipaddrconv(host, (unsigned char *)addr) == 0) {
	// ipaddr = (uip_ipaddr_t *)resolv_lookup(host);
    printf("Perlu diresolve !\r\n");
	
    if(ipaddr == NULL) {
      return 0;
    }
  }*/

	conn = uip_connect( ip_modul, htons(port));
	if (conn == NULL) {
		return 0;
	} else {
		//printf("uip_connect bukan NULL\r\n");
	}

	s.port = port;
	strncpy(s.file, file, sizeof(s.file));
	strncpy(s.host, host, sizeof(s.host));
  
	//printf("___%s(): host: %s, port %d, %s, strlen(s.file): %d\r\n", __FUNCTION__,host, port, file, strlen(s.file));
  
	init_connection();

	#if 0
	//printf("rport: %d\r\n",uip_conn->rport);
	//printf("port: %d, host: %s, file: %s\r\n",s.port, s.host, s.file);

	//printf("___%s(): %s, host %s, port %d, file: %s, pjg: %d, sizeof(s.file): %d\r\n", __FUNCTION__,host, port, s.file, strlen(s.file), sizeof(s.file));
  
	//printf("___%s(): host: %s, port %d, %s, strlen(s.file): %d, len: %d\r\n", __FUNCTION__,host, port, file, strlen(s.file), uip_len);
	
	
	for (gg=0; gg<40; gg++) {
		if (gg%16==0) { 
			printf("\r\n");
		} else if (gg%8==0) {
			printf("  "); 
		}
		printf("%02x ", uip_buf[gg]);
	}
	printf("\r\n\r\n");
	#endif 
	
	return 1;
}
void tcpip_periodic_timer()
{
    int i;

    if (timer_expired(&periodic_timer)) {
        timer_reset(&periodic_timer);
        for (i = 0; i < UIP_CONNS; i++) {
            uip_periodic(i);
            /* If the above function invocation resulted in data that
            should be sent out on the network, the global variable
            uip_len is set to a value > 0. */
            if (uip_len > 0) {
                uip_arp_out();
                mt76xx_dev_send();
            }
        }

#if UIP_UDP
        for (i = 0; i < UIP_UDP_CONNS; i++) {
            uip_udp_periodic(i);
            /* If the above function invocation resulted in data that
            should be sent out on the network, the global variable
            uip_len is set to a value > 0. */
            if (uip_len > 0) {
                uip_arp_out();
                mt76xx_dev_send();
            }
        }
#endif /* UIP_UDP */

        /* Call the ARP timer function every 10 seconds. */
        if (timer_expired(&arp_timer)) {
            timer_reset(&arp_timer);
            uip_arp_timer();
        }
		
#if UIP_CLOUD_SERVER_SUPPORT
		cloud_tcp_conn_check();
#endif
    }

    if (timer_expired(&cli_timer)) {
        clk = (clk > (CLOCK_SECOND*60))?clk:(clk*2);
        timer_set(&cli_timer, clk);

        if ((cli_fd == -1) &&
            memcmp(uip_hostaddr, 0x00000000, sizeof(uip_hostaddr))) {
            UIP_CONN *conn = NULL;
            uip_ipaddr_t srv_ip;

            uip_ipaddr(srv_ip, IoTpAd.ComCfg.IoT_ServeIP[0], IoTpAd.ComCfg.IoT_ServeIP[1],
                       IoTpAd.ComCfg.IoT_ServeIP[2], IoTpAd.ComCfg.IoT_ServeIP[3]);
            conn = uip_connect(&srv_ip, HTONS(IoTpAd.ComCfg.IoT_TCP_Srv_Port));
            if (conn) {
                conn->lport = HTONS(7682);
                cli_fd = conn->fd;
            } else {
                printf("connect fail\n");
            }
        }
    }
}
Exemple #24
0
int netSockConnect(UosFile* file, uip_ipaddr_t* ip, int port)
{
  struct uip_conn* tcp;
  struct uip_udp_conn* udp;

  P_ASSERT("netSockConnect", file->fs->cf == &netFSConf);
  NetSock* sock = (NetSock*)file->fsPriv;

#if UIP_ACTIVE_OPEN == 1
  P_ASSERT("sockConnect", (sock->state == NET_SOCK_UNDEF_TCP || sock->state == NET_SOCK_UNDEF_UDP ||
                           sock->state == NET_SOCK_BOUND || sock->state == NET_SOCK_BOUND_UDP));
#else
  P_ASSERT("sockConnect", (sock->state == NET_SOCK_UNDEF_UDP || NET_SOCK_BOUND_UDP));
#endif

  if (sock->state == NET_SOCK_UNDEF_TCP)  {

#if UIP_ACTIVE_OPEN == 1

    posMutexLock(uipMutex);
    tcp = uip_connect(ip, uip_htons(port));
    if (tcp == NULL) {

      posMutexUnlock(uipMutex);
      return -1;
    }

    tcp->appstate.file = file;

    posMutexLock(sock->mutex);
    sock->state = NET_SOCK_CONNECT;
    posMutexUnlock(uipMutex);

    while (sock->state == NET_SOCK_CONNECT) {

      posMutexUnlock(sock->mutex);
      posFlagGet(sock->uipChange, POSFLAG_MODE_GETMASK);
      posMutexLock(sock->mutex);
    }

    if (sock->state == NET_SOCK_PEER_CLOSED || sock->state == NET_SOCK_PEER_ABORTED) {
  
      posMutexUnlock(sock->mutex);
      uosFileClose(file);
      return -1;
    }

    P_ASSERT("sockConnect", sock->state == NET_SOCK_CONNECT_OK);
    sock->state = NET_SOCK_BUSY;
#endif
  }
  else {

#if UIP_CONF_UDP == 1

    posMutexLock(uipMutex);
    udp = uip_udp_new(ip, uip_htons(port));
    if (udp == NULL) {

      posMutexUnlock(uipMutex);
      return -1;
    }

    udp->appstate.file = file;
    if (sock->state == NET_SOCK_BOUND_UDP)
      uip_udp_bind(udp, sock->port);

    sock->state = NET_SOCK_BUSY;
    posMutexUnlock(uipMutex);
#endif
  }

  return 0;
}
Exemple #25
0
// Task for reactivision output processing
void vReactivision_Task( void)
{
    u16_t ripaddr[2];
    portBASE_TYPE xStatus;

    xTuioPacket xValueRead;
    xTuioPacket xDistanceRead;

    // Tracking Variables
    short sPosX = 0;
    short sPosY = 0;
    short sDegreesX = (servoMIN_DEGREES+servoMAX_DEGREES)/2;
    short sDegreesY = servoMAX_DEGREES;

    // Load up the log file and get this sessions log number
    short sFileNo;
    sFileNo = sSdCard_GetLogNo();
    debug_printf("Fileno %d\r\n", sFileNo);
    vSdCard_CreateLogFile(sFileNo);

    //Make TCP connection
    uip_ipaddr(ripaddr, 192,168,0,1);
    uip_connect(ripaddr, HTONS(3000));

    //Make TCP connection for remote logger
    uip_ipaddr(ripaddr, 192,168,0,1);
    uip_connect(ripaddr, HTONS(3010));

    //Create queue
    xTuioQueue = xQueueCreate(5, sizeof(xTuioPacket));
    xLogQueue = xQueueCreate(20, sizeof(xLogStruct));

    vSemaphoreCreateBinary(xControlServo);

    // Servo control loop
    for (;;) {
        if (xSemaphoreTake(xControlServo, 10) == pdFALSE) {
            continue;
        }

        //Read from TUIO queue.
        xStatus = xQueueReceive(xTuioQueue, &xValueRead, 10);     // Block task for 10ms when waiting for the Queue

        if (xStatus == pdPASS) {    // Process received value

            // values are between 0 and 1
            sPosX = (short) (xValueRead.position_x*100.0f);
            sPosY = (short) (xValueRead.position_y*100.0f);

            // Calculate distance
            if (sFiducialDistance) {
                // Loop until two values are set for the fiducial marker
                while (sFiducialDistance && !(xQueueReceive(xTuioQueue, &xDistanceRead, 10) == pdPASS
                                             && xValueRead.class_id != xDistanceRead.class_id));
                if (sFiducialDistance) {
                    // Compute the distance
                    short sX = sApproxSqrt(sPow(sPosX-(short) (xDistanceRead.position_x*100.0f),2) +
                                                sPow(sPosY-(short) (xDistanceRead.position_y*100.0f),2));

                    sprintf(ucRemoteBuffer, ">> Z-dist: %d\r\n", (1849*sPow(sX,2) - 297690*sX + 14309000)/10000);
                    remote_printf(ucRemoteBuffer);
                }

            // Track servo
            } else {

               // Remember, position is taken from TOP LEFT
               if (sPosX < mainBOUNDING_BOX_MIN && sDegreesX < servoMAX_DEGREES) {
                   sDegreesX++;
               } else if (sPosX > mainBOUNDING_BOX_MAX && sDegreesX > servoMIN_DEGREES) {
                   sDegreesX--;
               }

               if (sPosY < mainBOUNDING_BOX_MIN && sDegreesY > servoMIN_DEGREES) {
                   sDegreesY--;
               } else if (sPosY > mainBOUNDING_BOX_MAX && sDegreesY < servoMAX_DEGREES) {
                   sDegreesY++;
               }

               vSdCard_LogData(sFileNo,
                               (unsigned long) xTaskGetTickCount(),
                               sPosX,
                               sPosY,
                               sDegreesX,
                               sDegreesY);
            }
        }
        // Set the servos and give the semaphore
        vServo_SetPan(sDegreesX);
        vServo_SetTilt(sDegreesY);

        xSemaphoreGive(xControlServo);

        vTaskDelay(10);
    }
}
Exemple #26
0
static void
pachube_dns_query_cb(char *name, uip_ipaddr_t *ipaddr) {
  if(!uip_connect(ipaddr, HTONS(80), pachube_net_main)) {
  }

}