コード例 #1
0
ファイル: birdsv.c プロジェクト: kczajkow/pcbird
int handle_client(int id)
{
    uint8_t rx_cmd;
    
    int nrx = recv(client_tab[id].fd, &rx_cmd, 1, 0);
    
    if(nrx<0) return -1;
    if(nrx == 0) return 0;
    
    switch(rx_cmd)
    {
	case SVCMD_POS:
//	    fprintf(stderr,"Send!\n");

	    return send_position(client_tab[id].fd, last_pos);

	case SVCMD_START_STREAMING:
	    client_tab[id].state = CLIENT_STATE_STREAMING;
	    return 0;

	case SVCMD_STOP_STREAMING:
	    client_tab[id].state = CLIENT_STATE_IDLE;
	    return 0;
	    
	case SVCMD_END_SESSION: return -1;
	default: return -1;
    }
    
}
コード例 #2
0
ファイル: indoor_navigation.c プロジェクト: guswangqi/nav
void navigate_path(){
	int bool;
	struct timespec wait;
	wait.tv_sec = 0;
	wait.tv_nsec = SLEEP_DURATION;
	reset_timer();
	set_direction(&current);
	set_distance(&current);
	send_direction(&current.current_destination.angle);
	send_distance(&current.current_destination.distance);
	while(running == 1){//Infinite loop until it reaches point or collision avoidance occurs.
		printf("%d\n", current.num);
		update_position(&current);
		send_position(&current.current_point);
		if(check(current.current_point, current.current_destination) == 1){
			if(check(current.current_point, current.ending_point) == 1){
				current.path[current.num] = current.current_destination;
				current.num++;
				count++;
				current.path = realloc(current.path, sizeof(position) * (current.num+1));
			    	if(current.path == NULL){
			    		printf("!!!!!\n");
			    		send_stop();
			    	}
				send_stop();
				bool = 0;
				free(current.path);
				free(route.path);
				break;
			}
			else{
			   current.path[current.num] = current.current_destination;
			   current.num++;
			   count++;
			   printf("%d\n", sizeof(position) * (current.num+1));
			   current.path = realloc(current.path, sizeof(position) * (current.num+1));
			    	if(current.path == NULL){
			    		printf("!!!!!\n");
			    		send_stop();
			    	}
			   current.current_destination = route.path[count];
			   bool = 1;
			   break;
			}
		}
コード例 #3
0
ファイル: com_avance.c プロジェクト: CyrilPivec/teck3
int		com_avance(t_server *s, char **tab, int sock)
{
  t_client	*client;

  UNUSED(tab);
  client = s->client;
  while (client != NULL)
    {
      if (client->sock == sock && client->type == 1)
	{
	  avance(s, client);
	  if (s->sock_graph > 0)
	    send_position(client, s->sock_graph);
	  return (return_ok(sock));
	}
      client = client->next;
    }
  return (0);
}
コード例 #4
0
ファイル: birdsv.c プロジェクト: kczajkow/pcbird
void handle_streaming()
{
    int i=0, j, npos = 0;
    struct pos_ang pos_buf[POS_QUEUE_DEPTH];

    pthread_mutex_lock(&pos_queue_lock);
    while(!pos_queue_get(&pos_buf[npos])) npos++;
    pthread_mutex_unlock(&pos_queue_lock);

    if(npos)
    {
	memcpy(&last_pos, &pos_buf[npos-1], sizeof(struct pos_ang));

	for(i=0; i<MAX_CLIENTS; i++) 
	{
	    if(client_tab[i].state == CLIENT_STATE_STREAMING && client_tab[i].fd>0)
	    {

	        for(j=0;j<npos;j++)
	    	    send_position(client_tab[i].fd, pos_buf[j]);
	    }
	}
    }
}