//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; }
/* * 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; }