/************************************************************************************ * Copyright (C) 2008 by Politehnica University of Bucharest and Rutgers University * All rights reserved. * Refer to LICENSE for terms and conditions of use. ***********************************************************************************/ package vnsim.vehicular.routePlan.selfRouted; import java.util.Date; import vnsim.applications.trafficview.SimulatedCarInfo; import vnsim.applications.vitp.CarRunningVITP; import vnsim.applications.vitp.utils.VITPRequest; import vnsim.map.object.Globals; import vnsim.vehicular.simulator.CarInstance; import vnsim.vehicular.simulator.RouteSegment; public class QueryGeneration{ public static void generateQueryForCar(CarInstance car){ if ((car.routingType % 2 == 1) && (car.queryTime == Globals.engine.crtTime % 3000)) { //System.out.println("Car "+car.ID+"gen query"); SimulatedCarInfo myCar = Globals.engine.getCarIdx(car.ID); if (myCar != null) { RouteSegment nextHop = null; int ah,pt1,pt2; for (ah = 0; ah < Globals.routePlanConstants.HOW_FAR_AHEAD; ah++) { // nextHop = getNextSegmentFromRoute(car,(ah + 1)); if (nextHop != null) { pt1 = nextHop.pt1; pt2 = nextHop.pt2; if (pt1 < pt2) { if (pt2 - 4 > pt1) { pt1 = pt2 - 4; } } else { if (pt2 + 4 < pt1) { pt1 = pt2 + 4; } } VITPRequest req = new VITPRequest( (short) nextHop.roadIndex, (short) pt1, (short) pt2, (short) -1, (short) -1, (short) -1, new Date(), new Date(), "none", -1, "RI ", "GET", "/Route/Time?[cnt=3&tout=30000msec]"); try { ((CarRunningVITP) myCar).p .postMessageFromAbove(req); car.sentMsgCount++; } catch (Exception e) { e.printStackTrace(); } // } } } } } public static RouteSegment getNextSegmentFromRoute(CarInstance car, int far) { RouteSegment rez = null; if (car.routeIndex + far < car.route.length) { try { rez = car.route[car.routeIndex + far]; } catch (Exception e) { // no more streets } } return rez; } }