static void handle_omhucast_reception_ack (const event_t *e) // Handle the TCP reception ack, which occurs before the REPLICA_ACK // The REPLICA_ACK occurs after the chunk replica is written. // The tcp ack is sent once the chunk has been received. { const tcp_reception_ack_t *tra = (const tcp_reception_ack_t *)e; chunkput_omhucast_t *cp = (chunkput_omhucast_t *)tra->cp; chunkput_t *new_cp; tick_t next_tcp_time; remove_tcp_reception_target(cp,tra->target_num); if (tra->max_ongoing_rx > cp->max_ongoing_rx) cp->max_ongoing_rx = tra->max_ongoing_rx; next_tcp_time = e->tllist.time; next_tcp_time -= 3*config.cluster_trip_time; if (next_tcp_time <= now) next_tcp_time = now+1; if (++cp->acked < config.n_replicas) next_tcp_replica_xmit(cp,next_tcp_time); else if ((new_cp = next_cp(cp->cp.gateway,omhucast_prot.cp_size)) != NULL) insert_next_chunk_put_ready(new_cp,next_tcp_time); }
void update_map() { static U8 ready=FALSE; static int last_pos_x = 0; static int last_pos_y = 0; //Stores the average value of walls static int count_front_walls = 0; static int count_left_walls = 0; static int count_right_walls = 0; // If not ready (not enough inside the cell), return if(!ready) { if(is_inside_square(get_realX(),get_realY(),MAPPING_RES)) ready=TRUE; return; } int pos_x = get_x(); int pos_y = get_y(); // If out of the map, return if (is_out_of_map(pos_x,pos_y)) return; U8 data; // If just enter in a new cell if ( ( last_pos_y != pos_y ) || ( last_pos_x != pos_x ) ) { count_front_walls = 0; count_left_walls = 0; count_right_walls = 0; ready=FALSE; if(pos_x<__min_x) __min_x=pos_x; else if(pos_x>__max_x) __max_x=pos_x; if(pos_y<__min_y) __min_y=pos_y; else if(pos_y>__max_y) __max_y=pos_y; int direction = direction_of_next_cell(pos_x,pos_y,last_pos_x,last_pos_y); last_pos_x = pos_x; last_pos_y = pos_y; coord_to_table_index(&pos_x,&pos_y); data = _map[pos_x][pos_y]; if(direction != NO_CARD) { set_wall_state(&data, direction, NO_WALL); _map[pos_x][pos_y]=data; } return; } else { coord_to_table_index(&pos_x,&pos_y); data = _map[pos_x][pos_y]; } int cardinal_point = get_cardinal_point(); // Do measurements only if in a good direction if(is_cp(cardinal_point)) { int left_wall = detect_wall(get_distanceL()); int right_wall = detect_wall(get_distanceR()); int front_wall = detect_wall(get_distanceF()); //Add plus one for is wall and substract one for no wall count_front_walls = front_wall ? count_front_walls + 1 : count_front_walls - 1; count_left_walls = left_wall ? count_left_walls + 1 : count_left_walls - 1; count_right_walls = right_wall ? count_right_walls + 1 : count_right_walls - 1; if(count_front_walls>0) set_wall_state(&data, cardinal_point, IS_WALL); else set_wall_state(&data, cardinal_point, NO_WALL); if(count_right_walls>0) set_wall_state(&data, next_cp(cardinal_point), IS_WALL); else set_wall_state(&data, next_cp(cardinal_point), NO_WALL); if(count_left_walls>0) set_wall_state(&data, previous_cp(cardinal_point), IS_WALL); else set_wall_state(&data, previous_cp(cardinal_point), NO_WALL); } _map[pos_x][pos_y]=data; }