Exemple #1
0
int roadmap_line_length (int line) {

   RoadMapPosition p1;
   RoadMapPosition p2;
   int length = 0;

   int first_shape;
   int last_shape;
   int i;

   roadmap_line_from (line, &p1);

   if (roadmap_line_shapes (line, &first_shape, &last_shape) > 0) {

      p2 = p1;
      for (i = first_shape; i <= last_shape; i++) {

         roadmap_shape_get_position (i, &p2);
         length += roadmap_math_distance (&p1, &p2);
         p1 = p2;
      }
   }

   roadmap_line_to (line, &p2);
   length += roadmap_math_distance (&p1, &p2);

   return length;
}
int editor_line_length (int line) {

   RoadMapPosition p1;
   RoadMapPosition p2;
   editor_db_line *line_db;
   int length = 0;
   int trk_from;
   int first_shape;
   int last_shape;
   int i;

   line_db = (editor_db_line *) editor_db_get_item
                           (ActiveLinesDB, line, 0, NULL);

   editor_trkseg_get (line_db->trkseg,
                      &trk_from, &first_shape, &last_shape, NULL);

   editor_point_position (line_db->point_from, &p1);

   if (first_shape > -1) {
      editor_point_position (trk_from, &p2);

      for (i=first_shape; i<=last_shape; i++) {

         editor_shape_position (i, &p2);
         length += roadmap_math_distance (&p1, &p2);
         p1 = p2;
      }
   }

   editor_point_position (line_db->point_to, &p2);
   length += roadmap_math_distance (&p1, &p2);

   return length;
}
int editor_track_draw_current_new_direction_road(){
  	RoadMapPen layer_pens[LAYER_PROJ_AREAS];
 	NavigateSegment segment;
 	RoadMapPosition intersection;
 	int distance;
 	int i;
 	
  	if (points_count < 1) return 0;
  		
  	roadmap_square_set_current(TrackConfirmedLine.line.square);
  	if (!roadmap_line_route_is_low_weight (TrackConfirmedLine.line.line_id)) {
  	   return 0;
	}

	segment.square = TrackConfirmedLine.line.square;
	segment.line = TrackConfirmedLine.line.line_id;
	roadmap_line_from(TrackConfirmedLine.line.line_id, &segment.from_pos);
	roadmap_line_to(TrackConfirmedLine.line.line_id, &segment.to_pos);

	roadmap_line_shapes (TrackConfirmedLine.line.line_id, &segment.first_shape, &segment.last_shape);
	segment.shape_initial_pos = segment.from_pos;
   
   	for (i = 0; i < LAYER_PROJ_AREAS; i++) {
      			layer_pens[i] = roadmap_layer_get_pen (roadmap_line_cfcc(TrackConfirmedLine.line.line_id),1, i);
	}
	
	navigate_instr_fix_line_end(track_point_pos(points_count - 1), &segment,
							TrackConfirmedStreet.line_direction == ROUTE_DIRECTION_WITH_LINE ? LINE_END : LINE_START);
	
   	if (!editor_override_exists(TrackConfirmedLine.line.line_id, TrackConfirmedLine.line.square)){
   		distance =
            roadmap_math_get_distance_from_segment
            (track_point_pos(points_count - 1), &segment.from_pos, &segment.to_pos, &intersection, NULL);
	
						
		if (TrackConfirmedStreet.line_direction == ROUTE_DIRECTION_WITH_LINE)
   			distance = roadmap_math_distance (&intersection, &segment.from_pos);
   		else
   			distance = roadmap_math_distance (&intersection, &segment.to_pos);
	    roadmap_ticker_set_last_event(road_munching_event);
   		editor_points_display(distance);
   	}
   roadmap_screen_draw_one_line
               (&segment.from_pos, &segment.to_pos, 0, &segment.shape_initial_pos, segment.first_shape, segment.last_shape,
                NULL, layer_pens, LAYER_PROJ_AREAS, -1, 0, 0, 0);
                
	return 0;              
}
Exemple #4
0
static void roadmap_gps_update
(time_t gps_time,
 const RoadMapGpsPrecision *dilution,
 const RoadMapGpsPosition *gps_position){
   int i, distance;
   RoadMapPosition gps_pos;

   gps_pos.latitude = gps_position->latitude;
   gps_pos.longitude = gps_position->longitude;


   for (i=0; i<ReminderTable.iCount; i++) {
      if (!ReminderTable.reminder[i].in_use){
         continue;
      }

      if (ReminderTable.reminder[i].displayed){
         continue;
      }

      // check that the reminder distanc
      distance = roadmap_math_distance(&ReminderTable.reminder[i].position, &gps_pos);

      if (distance <= ReminderTable.reminder[i].distance){
         play_remider_sound();
         show_reminder(i, distance);
         ReminderTable.reminder[i].displayed = TRUE;
      }
   }

}
Exemple #5
0
/***********************************************************
 *	Name 		: roadmap_device_backlight_monitor
 *	Purpose 	: Monitors the movement of the device according to gps positions. If staying in the same point and
 *					backlight is off - use the device settings. Otherwise keep the screen bright
 *
 */
static void roadmap_device_backlight_monitor( time_t gps_time, const RoadMapGpsPrecision *dilution, const RoadMapGpsPosition *position)
{
    RoadMapPosition last_pos;
    RoadMapPosition cur_pos;
    int cur_distance;

    /*
     * If ALWAYS ON - Nothing to do
     */
    if ( roadmap_config_match( &RoadMapConfigBackLight, "yes" ) )
    {
        gsLastMovementTime = 0;
        return;
    }

    /* First point */
    if ( gsLastMovementTime == 0 )
    {
        gsLastMovementPos = *position;
        gsLastMovementTime = gps_time;
        return;
    }

    memcpy( &last_pos, &gsLastMovementPos, sizeof( RoadMapPosition ) );
    memcpy( &cur_pos, position, sizeof( RoadMapPosition ) );
    cur_distance = roadmap_math_distance( &last_pos, &cur_pos );

    if ( gsBacklightOnActive ) /* Currently set on - check if still moving */
    {
        if ( cur_distance < RM_BACKLIGHT_AUTO_OFF_MOVEMENT &&
                ( ( gps_time - gsLastMovementTime ) > RM_BACKLIGHT_AUTO_OFF_TIMEOUT ) )
        {
            /* Switch the state to off (system settings) */
            roadmap_device_set_backlight_( RM_BACKLIGHT_OFF );
        }
    }
    else	/* Currently backlight is off - check if started to move */
    {
        if ( cur_distance > RM_BACKLIGHT_AUTO_OFF_MOVEMENT )
        {
            /* Switch the state to on */
            roadmap_device_set_backlight_( RM_BACKLIGHT_ON );
        }
    }

    /* Set the last movement point and time */
    if ( cur_distance > RM_BACKLIGHT_AUTO_OFF_MOVEMENT )
    {
        gsLastMovementPos = *position;
        gsLastMovementTime = gps_time;
    }
    return;
}
Exemple #6
0
BOOL RealtimeBonus_distance_check(RoadMapPosition gps_pos){
	static RoadMapPosition last_checked_position = {0,0};
	int distance;
	if(!last_checked_position.latitude){ // first time
		last_checked_position = gps_pos;
		return TRUE;
	}

	distance = roadmap_math_distance(&gps_pos, &last_checked_position);
	if (distance < MINIMUM_DISTANCE_TO_CHECK)
		return FALSE;
	else{
		last_checked_position = gps_pos;
		return TRUE;
	}
}
Exemple #7
0
RoadMapFuzzy roadmap_fuzzy_connected (const RoadMapNeighbour *street,
                                      const RoadMapNeighbour *reference,
                                      int               prev_direction,
                                      int               direction,
                                      RoadMapPosition  *connection) {
   
   /* The logic for the connection membership function is that
    * the line is the most connected to itself, is well connected
    * to lines to which it share a common point and is not well
    * connected to other lines.
    * The weight of each state is a matter fine tuning.
    */
   RoadMapPosition line_point[2];
   RoadMapPosition reference_point[2];
   int allowed;
   int i, j;
   
   
   if (roadmap_plugin_same_db_line (&street->line, &reference->line)) {
      *connection = street->from;
      return (FUZZY_TRUTH_MAX * 4) / 4;
   }
   
   allowed = allowed_turn (reference, prev_direction, street, direction);
   if (allowed == 1) {
      //printf("==>found valid turn\n");
      if (prev_direction == ROUTE_DIRECTION_AGAINST_LINE)
         *connection = street->from;
      else
         *connection = street->to;
      
      return (FUZZY_TRUTH_MAX * 4) / 4;
   } else if (allowed == -1) {
      //printf("--> found shared node\n");
      if (prev_direction == ROUTE_DIRECTION_AGAINST_LINE)
         *connection = street->from;
      else
         *connection = street->to;
      
      return (FUZZY_TRUTH_MAX * 3) / 4;
   }
   
   roadmap_street_extend_line_ends (&street->line,&(line_point[0]), &(line_point[1]), FLAG_EXTEND_BOTH, NULL, NULL); 
   roadmap_street_extend_line_ends (&reference->line,&(reference_point[0]), &(reference_point[1]), FLAG_EXTEND_BOTH, NULL, NULL); 
   
   if (direction == ROUTE_DIRECTION_AGAINST_LINE) {
      i = 1;
   } else {
      i = 0;
   }
   
   if (prev_direction == ROUTE_DIRECTION_AGAINST_LINE) {
      j = 0;
   } else {
      j = 1;
   }
   
   if ((line_point[i].latitude == reference_point[j].latitude) &&
       (line_point[i].longitude == reference_point[j].longitude)) {
      
      *connection = line_point[i];
      
      return (FUZZY_TRUTH_MAX * 4) / 4;
   } else if ((line_point[!i].latitude == reference_point[j].latitude) &&
              (line_point[!i].longitude == reference_point[j].longitude)) {
      
      *connection = line_point[!i];
      
      return FUZZY_TRUTH_MAX / 2;
      
   } else {
      RoadMapPosition pos1;
      RoadMapPosition pos2;
      
      pos1 = line_point[i];
      pos2 = reference_point[j];
      
      if (roadmap_math_distance (&pos1, &pos2) < 50) {
         connection->latitude  = 0;
         connection->longitude = 0;
         
         return FUZZY_TRUTH_MAX * 2 / 3;
      }
   }
   
   connection->latitude  = 0;
   connection->longitude = 0;
   
   return FUZZY_TRUTH_MAX / 3;
}
int editor_track_known_end_segment (PluginLine *previous_line,
                                    int last_point_id,
                                    PluginLine *line,
                                    RoadMapTracking *street,
                                    int is_new_track) {
   //TODO: add stuff
   //Notice that previous_line may not be valid (only at first)
   //
   //check for low confidence & in static update, do not use a trkseg with low confidence!

   RoadMapPosition from;
   RoadMapPosition to;
   RoadMapPosition *current;
   int trkseg;
   int trkseg_line_id;
   int trkseg_plugin_id;
   int trkseg_square;
   int line_length;
   int segment_length;
   int percentage;
   int flags = 0;

   editor_log_push ("editor_track_end_known_segment");

   assert (last_point_id != 0);
   if (!last_point_id) return 0;

   if (editor_db_activate (line->fips) == -1) {
      editor_db_create (line->fips);
      if (editor_db_activate (line->fips) == -1) {
         editor_log_pop ();
         return 0;
      }
   }

	roadmap_street_extend_line_ends (line, &from, &to, FLAG_EXTEND_BOTH, NULL, NULL);
   trkseg_plugin_id = roadmap_plugin_get_id (line);
   trkseg_line_id = roadmap_plugin_get_line_id (line);
   trkseg_square = roadmap_plugin_get_square (line);
   
   line_length = editor_track_util_get_line_length (line);
   segment_length = editor_track_util_length (0, last_point_id);

   editor_log
      (ROADMAP_INFO,
         "Ending line %d (plugin_id:%d). Line length:%d, Segment length:%d",
         trkseg_line_id, trkseg_plugin_id, line_length, segment_length);

   /* End current segment if we really passed through it
    * and not only touched a part of it.
    */

	/*SRUL*: avoid this problem, see above comment 
   assert (line_length > 0);

   if (line_length == 0) {
      editor_log (ROADMAP_ERROR, "line %d (plugin_id:%d) has length of zero.",
            trkseg_line_id, trkseg_plugin_id);
      editor_log_pop ();
      return 0;
   }
	*/
   if (line_length <= 0) line_length = 1;
	
   current = track_point_pos (last_point_id);
   if (roadmap_math_distance (current, &to) >
       roadmap_math_distance (current, &from)) {

      flags = ED_TRKSEG_OPPOSITE_DIR;
#if DEBUG_TRACKS
	   printf ("Closing trkseg from %d.%06d,%d.%06d to %d.%06d,%d.%06d",
	   			to.longitude / 1000000, to.longitude % 1000000,
	   			to.latitude / 1000000, to.latitude % 1000000,
	   			from.longitude / 1000000, from.longitude % 1000000,
	   			from.latitude / 1000000, from.latitude % 1000000);

   } else {
      
	   printf ("Closing trkseg from %d.%06d,%d.%06d to %d.%06d,%d.%06d",
	   			from.longitude / 1000000, from.longitude % 1000000,
	   			from.latitude / 1000000, from.latitude % 1000000,
	   			to.longitude / 1000000, to.longitude % 1000000,
	   			to.latitude / 1000000, to.latitude % 1000000);
#endif
   }
   	
#if DEBUG_TRACKS
   printf (" %d/%d", segment_length, line_length);
#endif
   		
   if (is_new_track) {
      flags |= ED_TRKSEG_NEW_TRACK;
#if DEBUG_TRACKS
      printf (" NEW");
#endif
   }

	if (!editor_ignore_new_roads ()) {
		flags |= ED_TRKSEG_RECORDING_ON;
	}
	
   percentage = 100 * segment_length / line_length;
   if (percentage < 70) {
      editor_log (ROADMAP_INFO, "segment is too small to consider: %d%%",
            percentage);
      if (segment_length > (editor_track_point_distance ()*1.5)) {

         trkseg = editor_track_util_create_trkseg
                     (trkseg_square, trkseg_line_id, trkseg_plugin_id, 0, last_point_id,
                      flags|ED_TRKSEG_LOW_CONFID);

         editor_track_add_trkseg
            (line, trkseg, ROUTE_DIRECTION_NONE, ROUTE_CAR_ALLOWED);
         editor_log_pop ();
#if DEBUG_TRACKS
         printf (" LOW (percentage)\n");
#endif
         return 1;
      } else {

         trkseg = editor_track_util_create_trkseg
                  (trkseg_square, trkseg_line_id, trkseg_plugin_id,
                   0, last_point_id, flags|ED_TRKSEG_IGNORE);
         editor_track_add_trkseg
            (line, trkseg, ROUTE_DIRECTION_NONE, ROUTE_CAR_ALLOWED);
         editor_log_pop ();
#if DEBUG_TRACKS
         printf (" IGNORE\n");
#endif
         return 0;
      }
   }

#if 0
   if (!roadmap_fuzzy_is_good (street->entry_fuzzyfied) ||
      !roadmap_fuzzy_is_good (street->cur_fuzzyfied)) {

      flags |= ED_TRKSEG_LOW_CONFID;
#if DEBUG_TRACKS
      printf (" LOW");
      if (!roadmap_fuzzy_is_good (street->entry_fuzzyfied))
      	printf (" (entry)");
      if (!roadmap_fuzzy_is_good (street->cur_fuzzyfied))
      	printf (" (cur)");
#endif
   }
#endif

   if (trkseg_plugin_id != ROADMAP_PLUGIN_ID) flags |= ED_TRKSEG_LOW_CONFID;

   trkseg =
      editor_track_util_create_trkseg
         (trkseg_square, trkseg_line_id, trkseg_plugin_id, 0, last_point_id, flags);

   if (flags & ED_TRKSEG_OPPOSITE_DIR) {
      
      editor_log (ROADMAP_INFO, "Updating route direction: to -> from");
      editor_track_add_trkseg
         (line, trkseg, ROUTE_DIRECTION_AGAINST_LINE, ROUTE_CAR_ALLOWED);
   } else {

      editor_log (ROADMAP_INFO, "Updating route direction: from -> to");
      editor_track_add_trkseg
         (line, trkseg, ROUTE_DIRECTION_WITH_LINE, ROUTE_CAR_ALLOWED);
   }


   editor_log_pop ();

#if DEBUG_TRACKS
	printf ("\n");
#endif
   return 1;
}
//checks whether an alert is within range
static int is_alert_in_range(const RoadMapGpsPosition *gps_position, const PluginLine *line) {

    int count;
    int i;
    int distance ;
    int steering;
    RoadMapPosition pos;
    int azymuth;
    int delta;
    int j;
    unsigned int speed;
    RoadMapPosition gps_pos;
    int square;
    int squares[9];
    int count_squares;

    gps_pos.latitude = gps_position->latitude;
    gps_pos.longitude = gps_position->longitude;
    count_squares = roadmap_square_find_neighbours (&gps_pos, 0, squares);

    for (square = 0; square < count_squares; square++) {

        roadmap_square_set_current(squares[square]);

        // loop alll prvidor for an alert
        for (j = 0 ; j < RoadMapAlertProvidors.count; j++) {

            count =  (* (RoadMapAlertProvidors.providor[j]->count)) ();


            // no alerts for this providor
            if (count == 0) {
                continue;
            }

            for (i=0; i<count; i++) {

                // if the alert is not alertable, continue. (dummy speed cams, etc.)
                if (!(* (RoadMapAlertProvidors.providor[j]->is_alertable))(i)) {
                    continue;
                }

                (* (RoadMapAlertProvidors.providor[j]->get_position)) (i, &pos, &steering);

                // check that the alert is within alert distance
                distance = roadmap_math_distance(&pos, &gps_pos);

                if (distance > (*(RoadMapAlertProvidors.providor[j]->get_distance))(i)) {
                    continue;
                }


                // check if the alert is on the navigation route
                if (!alert_is_on_route (&pos, steering)) {

                    // check that the alert is in the direction of driving
                    delta = azymuth_delta(gps_position->steering, steering);
                    if (delta > AZYMUTH_DELTA || delta < (0-AZYMUTH_DELTA)) {
                        continue;
                    }

                    // check that we didnt pass the alert
                    azymuth = roadmap_math_azymuth (&gps_pos, &pos);
                    delta = azymuth_delta(azymuth, steering);
                    if (delta > 90|| delta < (-90)) {
                        continue;

                    }

                    // check that the alert is on the same street
                    if (!check_same_street(line, &pos)) {
                        continue;
                    }
                }

                speed = (* (RoadMapAlertProvidors.providor[j]->get_speed))(i);
                // check that the driving speed is over the allowed speed for that alert
                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 	=  (* (RoadMapAlertProvidors.providor[j]->get_id))(i);
                    the_active_alert.alert_providor = j;
                    return TRUE;
                }
                else {
                    the_active_alert.alert_type = ALERT;
                    the_active_alert.alert_providor = j;
                    the_active_alert.distance_to_alert 	= distance;
                    the_active_alert.active_alert_id 	= (* (RoadMapAlertProvidors.providor[j]->get_id))(i);
                    return TRUE;
                }
            }
        }
    }

    return FALSE;
}
Exemple #10
0
/*
 * searches for relevant alerts in the given param provider - D.F.
 */
static BOOL is_alert_in_range_provider(roadmap_alert_provider* provider,
      const RoadMapGpsPosition *gps_position, const PluginLine* line,
      int * pAlert_index, int * pDistance, const char* cur_street_name){
   int i;
   int steering;
   RoadMapPosition pos;
   int azymuth;
   int delta;
   int square_current;
   int count = 0;
   const char *street_name;
   roadmap_alerter_location_info location_info;
   roadmap_alerter_location_info * pAlert_location_info = NULL;
   RoadMapPosition gps_pos;
   gps_pos.latitude = gps_position->latitude;
   gps_pos.longitude = gps_position->longitude;
   square_current = roadmap_square_active ();
   count =  (* (provider->count)) ();

   // no alerts for this provider
   if (count == 0) {
      return FALSE;
   }

   for (i=0; i<count; i++) {

      roadmap_square_set_current (square_current);
      // if the alert is not alertable, continue. (dummy speed cams, etc.)
      if (!(* (provider->is_alertable))(i)) {
         continue;
      }

      (* (provider->get_position)) (i, &pos, &steering);

      // check that the alert is within alert distance
      * pDistance = roadmap_math_distance(&pos, &gps_pos);

      if (*pDistance > (*(provider->get_distance))(i))
         continue;

      // Let the provider handle the Alert.
      if ((* (provider->handle_event))((* (provider->get_id))(i)))
         continue;

      // get this alerts cached location info
      pAlert_location_info = (*(provider->get_location_info))(i);

      // retrieve the current location info for this alert ( square id, line id... )
      if(!get_alert_location_info(&pos,&location_info,pAlert_location_info))
         continue; // could not find relevant location.

      // check if the alert is on the navigation route
      if (!alert_is_on_route (&location_info, steering)) {

         roadmap_square_set_current (square_current);
         if ((* (provider->check_same_street))(i)){

            // check that the alert is in the direction of driving
            delta = azymuth_delta(gps_position->steering, steering);
            if (delta > AZYMUTH_DELTA || delta < (0-AZYMUTH_DELTA)) {
               continue;
            }

            // check that we didnt pass the alert
            azymuth = roadmap_math_azymuth (&gps_pos, &pos);
            delta = azymuth_delta(azymuth, steering);
            if (delta > 90|| delta < (-90))
               continue;

            // get the street name of the alert
            get_street_from_line(location_info.square_id,location_info.line_id, &street_name);

            // if same street found an alert infront of us
            if(strcmp(street_name,cur_street_name))
               continue; // not the same street.

         }
      }

      // if we got until here, then we found a valid alert
      * pAlert_index = i;
      roadmap_square_set_current (square_current);
      return TRUE;

   }

   roadmap_square_set_current (square_current);
   return FALSE;
}