Ejemplo n.º 1
0
//checks whether an alert is within range
static int is_alert_in_range(const RoadMapGpsPosition *gps_position, const PluginLine *line){
   int i;
   int j;
   unsigned int speed;
   int distance; // will hold the distance of the alert
   RoadMapPosition gps_pos;
   int square;
   int squares[9];
   int count_squares;
   const char * street_name; // the current street name.
   char current_street_name[512];
   RoadMapPosition context_save_pos;
   zoom_t context_save_zoom;
   int alert_index; // will hold the index in the provider of the alert
   int priorities [] = {ALERTER_PRIORITY_HIGH,ALERTER_PRIORITY_MEDIUM,ALERTER_PRIORITY_LOW};
   int num_priorities = sizeof(priorities)/sizeof(int);
   int alert_providor_ind;
   int square_ind = -1;
   BOOL found_alert = FALSE;
   gps_pos.latitude = gps_position->latitude;
   gps_pos.longitude = gps_position->longitude;

   roadmap_math_get_context(&context_save_pos, &context_save_zoom);
   roadmap_math_set_context((RoadMapPosition *)&gps_pos, 20);

   count_squares = roadmap_square_find_neighbours (&gps_pos, 0, squares);
   // get the street infromation of the current position.
   get_street_from_line(line->square,line->line_id, &street_name);
   strncpy_safe (current_street_name, street_name, sizeof (current_street_name));
   // go over priorities one by one from highest to lowest.
   for (j=0; (j< num_priorities); j++){

      if ( found_alert )   // Removed from the "for" condition due to some problem in android gcc AGA
         break;

		// loop all the providers for an alert
		for (i = 0 ; ((i < RoadMapAlertProviders.count)&&(!found_alert)); i++){

		   // if provider doesn't have a high enough priority skip him, we'll get to him later.
	      if(RoadMapAlertProviders.provider[i]->get_priority()!=priorities[j])
	  	       continue;

			/*
		    * If not enough distance has been passed from last check, provider can order to ignore
		    * if alert is active, always perform check, so distance will be updated
		    */
	  	   if(!alert_should_be_visible){
		       if(!(* (RoadMapAlertProviders.provider[i]->distance_check))(gps_pos))
		          continue;
		   }

			if ((* (RoadMapAlertProviders.provider[i]->is_square_dependent))()){
			/*
			* This provider has different alerts for each square, so we need to loop over all
			* these squares and check. (Speed cams in tiles for example, as opposed to RealTimeAlerts).
			*/
	         for (square = 0; ((square < count_squares)&&(!found_alert)); square++) {
	            roadmap_square_set_current(squares[square]);
	            if(is_alert_in_range_provider(RoadMapAlertProviders.provider[i],
	                     gps_position, line, &alert_index,&distance, current_street_name))
	            {
	               square_ind = square;
	               alert_providor_ind = i;
	               found_alert = TRUE;
	            }
	         }

	      } else {
	           if(is_alert_in_range_provider(RoadMapAlertProviders.provider[i],
	                   gps_position, line, &alert_index,&distance,current_street_name))
	           {
	             	square_ind = -1;
	             	alert_providor_ind = i;
	             	found_alert = TRUE;
	           }
	      }
		}
   }

   if(found_alert){
      speed = (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_speed))(alert_index);
      // if driving speed is over the speed limit - it's an ALERT, otherwise it's a WARNING
      if ((unsigned int)roadmap_math_to_speed_unit(gps_position->speed) < speed) {
         the_active_alert.alert_type = WARN;
         the_active_alert.distance_to_alert 	= distance;
         the_active_alert.active_alert_id 	=  (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_id))(alert_index);
         the_active_alert.alert_provider = alert_providor_ind;
         if (square_ind != -1)
            the_active_alert.square = squares[square_ind];
         else
            the_active_alert.square = line->square;

         roadmap_math_set_context(&context_save_pos, context_save_zoom);
         return TRUE;
      }
      else{
         the_active_alert.alert_type = ALERT;
         the_active_alert.distance_to_alert 	= distance;
         the_active_alert.active_alert_id 	= (* (RoadMapAlertProviders.provider[alert_providor_ind]->get_id))(alert_index);
         the_active_alert.alert_provider = alert_providor_ind;
         if (square_ind != -1)
            the_active_alert.square = squares[square_ind];
         else
            the_active_alert.square = line->square;
         roadmap_math_set_context(&context_save_pos, context_save_zoom);
         return TRUE;
      }
   }

   roadmap_math_set_context(&context_save_pos, context_save_zoom);
   return FALSE;
}
Ejemplo n.º 2
0
/**
 * [IN] alert_position - the position of the alert
 * [IN] alert_location_info - The old location_info of the alert. Will be updated if necessary
 * [OUT] pNew_Info - the location_info of this alert, to be calculated.
 * returns TRUE iff successful in finding relevant location info for this alert
 * - D.F.
 */
BOOL get_alert_location_info(const RoadMapPosition *alert_position,roadmap_alerter_location_info *pNew_Info,
      roadmap_alerter_location_info *alert_location_info){

   int alert_square_time_stamp;
   int layers_count;
   int count;
   int layers[128];
   RoadMapNeighbour neighbours;
   int square;
   int context_save_zoom;
   RoadMapPosition context_save_pos;

   if (alert_location_info){

      // check if this alert was tagged as invalid in the past - Could locate a street next to it, eventhough
      // its tile already exists.
      if (alert_location_info->square_id == ALERTER_SQUARE_ID_INVALID)
         return FALSE;

      // if alert info is already initialized and has an up to date timestamp, use its info.
      if(alert_location_info->square_id!=ALERTER_SQUARE_ID_UNINITIALIZED){
         alert_square_time_stamp = roadmap_square_version(alert_location_info->square_id);
         if(alert_square_time_stamp==alert_location_info->time_stamp){
            pNew_Info->line_id = alert_location_info->line_id;
            pNew_Info->square_id = alert_location_info->square_id;
            pNew_Info->time_stamp = alert_location_info->time_stamp;
            return TRUE;
         }
      }
   }

   // did not return so far - so no cached valid location info was found, need to cacluate it.
   layers_count =  roadmap_layer_all_roads (layers, 128);
   if (layers_count > 0) {
      square = roadmap_tile_get_id_from_position(0,alert_position);
      if(!roadmap_square_set_current(square)){
         return FALSE; // do no have this alert's tile, return FALSE;
      }

      roadmap_math_get_context(&context_save_pos, &context_save_zoom);
      roadmap_math_set_context((RoadMapPosition *)alert_position, 20);
      count = roadmap_street_get_closest(alert_position, 0, layers, layers_count, 1, &neighbours, 1);
      roadmap_math_set_context(&context_save_pos, context_save_zoom);
      if(count>0&&neighbours.distance <= MAX_DISTANCE_FROM_ROAD){

         // found valid information
         pNew_Info->line_id = neighbours.line.line_id;
         pNew_Info->square_id = neighbours.line.square;
         pNew_Info->time_stamp  = roadmap_square_version(pNew_Info->square_id);

      }else{
         // We have the alert's tile, yet still we could not locate it satisfactorily on
         // a street. Tag this alert so it will not be checked in the future.
         if(alert_location_info){
            alert_location_info->square_id = ALERTER_SQUARE_ID_INVALID;
         }

         return FALSE;
      }
   }

   if(alert_location_info){ // update the information of the alert, for future calls.
      alert_location_info->line_id = pNew_Info->line_id;
      alert_location_info->square_id = pNew_Info->square_id;
      alert_location_info->time_stamp = pNew_Info->time_stamp;
   }
   return TRUE;
}
Ejemplo n.º 3
0
/**
 * [IN] alert_position - the position of the alert
 * [IN] alert_location_info - The old location_info of the alert. Will be updated if necessary
 * [OUT] pNew_Info - the location_info of this alert, to be calculated.
 * returns TRUE iff successful in finding relevant location info for this alert
 * - D.F.
 */
BOOL get_alert_location_info(const RoadMapPosition *alert_position, int alert_streering, roadmap_alerter_location_info *pNew_Info,
      roadmap_alerter_location_info *alert_location_info){

   int alert_square_time_stamp;
   int layers_count;
   int count;
   int layers[128];
   RoadMapNeighbour neighbours[2];
   int square;
   zoom_t context_save_zoom;
   RoadMapPosition context_save_pos;

   if (alert_location_info){

      // check if this alert was tagged as invalid in the past - Could locate a street next to it, eventhough
      // its tile already exists.
      if (alert_location_info->square_id == ALERTER_SQUARE_ID_INVALID)
         return FALSE;

      // if alert info is already initialized and has an up to date timestamp, use its info.
      if(alert_location_info->square_id!=ALERTER_SQUARE_ID_UNINITIALIZED){
         alert_square_time_stamp = roadmap_square_version(alert_location_info->square_id);
         if(alert_square_time_stamp==alert_location_info->time_stamp){
            pNew_Info->line_id = alert_location_info->line_id;
            pNew_Info->square_id = alert_location_info->square_id;
            pNew_Info->time_stamp = alert_location_info->time_stamp;
            return TRUE;
         }
      }
   }

   // did not return so far - so no cached valid location info was found, need to cacluate it.
   layers_count =  roadmap_layer_all_roads (layers, 128);
   if (layers_count > 0) {
      square = roadmap_tile_get_id_from_position(0,alert_position);
      if(!roadmap_square_set_current(square)){
         return FALSE; // do no have this alert's tile, return FALSE;
      }

      roadmap_math_get_context(&context_save_pos, &context_save_zoom);
      roadmap_math_set_context((RoadMapPosition *)alert_position, 2);
      count = roadmap_street_get_closest(alert_position, 0, layers, layers_count, 1, &neighbours[0], 2);
      roadmap_math_set_context(&context_save_pos, context_save_zoom);
      if(count>0&&neighbours[0].distance <= MAX_DISTANCE_FROM_ROAD){
         if (count > 1){
            int direction;
            roadmap_square_set_current(neighbours[0].line.line_id);
            direction = roadmap_line_route_get_direction (neighbours[0].line.line_id, ROUTE_CAR_ALLOWED);
            if (direction == ROUTE_DIRECTION_WITH_LINE || direction == ROUTE_DIRECTION_AGAINST_LINE){
               int line_azymuth;
               int delta;
               if (direction == ROUTE_DIRECTION_WITH_LINE)
                  line_azymuth = roadmap_math_azymuth (&neighbours[0].from, &neighbours[0].to);
               else
                  line_azymuth = roadmap_math_azymuth (&neighbours[0].to, &neighbours[0].from);

               delta = azymuth_delta(line_azymuth, alert_streering);
               if (delta > AZYMUTH_DELTA || delta < (0-AZYMUTH_DELTA)) {
                  pNew_Info->line_id = neighbours[1].line.line_id;
                  pNew_Info->square_id = neighbours[1].line.square;
                  pNew_Info->time_stamp  = roadmap_square_version(pNew_Info->square_id);
               }
               else{
                  pNew_Info->line_id = neighbours[0].line.line_id;
                  pNew_Info->square_id = neighbours[0].line.square;
                  pNew_Info->time_stamp  = roadmap_square_version(pNew_Info->square_id);
               }
            }
            else{
               pNew_Info->line_id = neighbours[0].line.line_id;
               pNew_Info->square_id = neighbours[0].line.square;
               pNew_Info->time_stamp  = roadmap_square_version(pNew_Info->square_id);
            }
         }
         else{
            // found valid information
            pNew_Info->line_id = neighbours[0].line.line_id;
            pNew_Info->square_id = neighbours[0].line.square;
            pNew_Info->time_stamp  = roadmap_square_version(pNew_Info->square_id);
         }

      }else{
         // We have the alert's tile, yet still we could not locate it satisfactorily on
         // a street. Tag this alert so it will not be checked in the future.
         if(alert_location_info){
            alert_location_info->square_id = ALERTER_SQUARE_ID_INVALID;
         }

         return FALSE;
      }
   }

   if(alert_location_info){ // update the information of the alert, for future calls.
      alert_location_info->line_id = pNew_Info->line_id;
      alert_location_info->square_id = pNew_Info->square_id;
      alert_location_info->time_stamp = pNew_Info->time_stamp;
   }
   return TRUE;
}