diff --git a/brouter-codec/pom.xml b/brouter-codec/pom.xml index 38174aa..c6fc243 100644 --- a/brouter-codec/pom.xml +++ b/brouter-codec/pom.xml @@ -5,7 +5,7 @@ org.btools brouter - 1.4.2 + 1.4.3 ../pom.xml brouter-codec diff --git a/brouter-core/pom.xml b/brouter-core/pom.xml index ce02833..de5383c 100644 --- a/brouter-core/pom.xml +++ b/brouter-core/pom.xml @@ -5,7 +5,7 @@ org.btools brouter - 1.4.2 + 1.4.3 ../pom.xml brouter-core diff --git a/brouter-core/src/main/java/btools/router/OsmTrack.java b/brouter-core/src/main/java/btools/router/OsmTrack.java index dd12910..9e8ef2c 100644 --- a/brouter-core/src/main/java/btools/router/OsmTrack.java +++ b/brouter-core/src/main/java/btools/router/OsmTrack.java @@ -18,6 +18,7 @@ import java.io.FileOutputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import btools.mapaccess.OsmPos; @@ -31,6 +32,7 @@ public final class OsmTrack public MatchedWaypoint endPoint; public long[] nogoChecksums; + public long profileTimestamp; public boolean isDirty; private static class OsmPathElementHolder @@ -160,10 +162,11 @@ public final class OsmTrack dos.writeLong( nogoChecksums[1] ); dos.writeLong( nogoChecksums[2] ); dos.writeBoolean( isDirty ); + dos.writeLong( profileTimestamp ); dos.close(); } - public static OsmTrack readBinary( String filename, OsmNodeNamed newEp, long[] nogoChecksums, StringBuilder debugInfo ) + public static OsmTrack readBinary( String filename, OsmNodeNamed newEp, long[] nogoChecksums, long profileChecksum, StringBuilder debugInfo ) { OsmTrack t = null; if ( filename != null ) @@ -177,7 +180,12 @@ public final class OsmTrack MatchedWaypoint ep = MatchedWaypoint.readFromStream( dis ); int dlon = ep.waypoint.ilon - newEp.ilon; int dlat = ep.waypoint.ilat - newEp.ilat; - if ( dlon < 20 && dlon > -20 && dlat < 20 && dlat > -20 ) + boolean targetMatch = dlon < 20 && dlon > -20 && dlat < 20 && dlat > -20; + if ( debugInfo != null ) + { + debugInfo.append( "target-delta = " + dlon + "/" + dlat + " targetMatch=" + targetMatch ); + } + if ( targetMatch ) { t = new OsmTrack(); t.endPoint = ep; @@ -192,31 +200,40 @@ public final class OsmTrack } t.cost = last_pe.cost; t.buildMap(); - } - long[] al = new long[3]; - try - { - al[0] = dis.readLong(); - al[1] = dis.readLong(); - al[2] = dis.readLong(); - } - catch (EOFException eof) { /* kind of expected */ } - try - { - boolean isDirty = dis.readBoolean(); - if ( t != null ) t.isDirty = isDirty; - } - catch (EOFException eof) { /* kind of expected */ } - dis.close(); - boolean nogoCheckOk = Math.abs( al[0] - nogoChecksums[0] ) <= 20 - && Math.abs( al[1] - nogoChecksums[1] ) <= 20 - && Math.abs( al[2] - nogoChecksums[2] ) <= 20; - if ( debugInfo != null ) - { - debugInfo.append( "target-delta = " + dlon + "/" + dlat + " nogoCheckOk=" + nogoCheckOk ); + // check cheecksums, too + long[] al = new long[3]; + long pchecksum = 0; + try + { + al[0] = dis.readLong(); + al[1] = dis.readLong(); + al[2] = dis.readLong(); + } + catch (EOFException eof) { /* kind of expected */ } + try + { + t.isDirty = dis.readBoolean(); + } + catch (EOFException eof) { /* kind of expected */ } + try + { + pchecksum = dis.readLong(); + } + catch (EOFException eof) { /* kind of expected */ } + boolean nogoCheckOk = Math.abs( al[0] - nogoChecksums[0] ) <= 20 + && Math.abs( al[1] - nogoChecksums[1] ) <= 20 + && Math.abs( al[2] - nogoChecksums[2] ) <= 20; + boolean profileCheckOk = pchecksum == profileChecksum; + + if ( debugInfo != null ) + { + debugInfo.append( " nogoCheckOk=" + nogoCheckOk + " profileCheckOk=" + profileCheckOk ); + debugInfo.append( " al=" + formatLongs(al) + " nogoChecksums=" + formatLongs(nogoChecksums) ); + } + if ( !(nogoCheckOk && profileCheckOk) ) return null; } - if ( !nogoCheckOk ) return null; + dis.close(); } catch (Exception e) { @@ -227,6 +244,20 @@ public final class OsmTrack return t; } + private static String formatLongs( long[] al ) + { + StringBuilder sb = new StringBuilder(); + sb.append( '{' ); + for( long l : al ) + { + sb.append( l ); + sb.append( ' ' ); + } + sb.append( '}' ); + return sb.toString(); + } + + public void addNodes( OsmTrack t ) { for ( OsmPathElement n : t.nodes ) @@ -343,7 +374,7 @@ public final class OsmTrack } else { - sb.append( " creator=\"BRouter-1.4.2\" version=\"1.1\">\n" ); + sb.append( " creator=\"BRouter-1.4.3\" version=\"1.1\">\n" ); } if ( turnInstructionMode == 3) // osmand style diff --git a/brouter-core/src/main/java/btools/router/ProfileCache.java b/brouter-core/src/main/java/btools/router/ProfileCache.java index e02ccfe..17d3cdf 100644 --- a/brouter-core/src/main/java/btools/router/ProfileCache.java +++ b/brouter-core/src/main/java/btools/router/ProfileCache.java @@ -40,6 +40,7 @@ public final class ProfileCache profileDir = new File( profileBaseDir ); profileFile = new File( profileDir, rc.localFunction + ".brf" ) ; } + rc.profileTimestamp = profileFile.lastModified(); File lookupFile = new File( profileDir, "lookups.dat" ); // check for re-use @@ -47,7 +48,7 @@ public final class ProfileCache { if ( profileFile.equals( lastProfileFile ) && lookupFile.equals( lastLookupFile ) ) { - if ( profileFile.lastModified() == lastProfileTimestamp + if ( rc.profileTimestamp == lastProfileTimestamp && lookupFile.lastModified() == lastLookupTimestamp ) { rc.expctxWay = expctxWay; diff --git a/brouter-core/src/main/java/btools/router/RoutingContext.java b/brouter-core/src/main/java/btools/router/RoutingContext.java index 940fd3f..2f444c4 100644 --- a/brouter-core/src/main/java/btools/router/RoutingContext.java +++ b/brouter-core/src/main/java/btools/router/RoutingContext.java @@ -27,6 +27,7 @@ public final class RoutingContext implements DistanceChecker } public int alternativeIdx = 0; public String localFunction; + public long profileTimestamp; public String rawTrackPath; diff --git a/brouter-core/src/main/java/btools/router/RoutingEngine.java b/brouter-core/src/main/java/btools/router/RoutingEngine.java index f71a12f..ceb47f5 100644 --- a/brouter-core/src/main/java/btools/router/RoutingEngine.java +++ b/brouter-core/src/main/java/btools/router/RoutingEngine.java @@ -305,10 +305,10 @@ public class RoutingEngine extends Thread // check for a track for that target OsmTrack nearbyTrack = null; - if ( refTracks[waypoints.size()-2] == null ) + if ( lastTracks[waypoints.size()-2] == null ) { StringBuilder debugInfo = hasInfo() ? new StringBuilder() : null; - nearbyTrack = OsmTrack.readBinary( routingContext.rawTrackPath, waypoints.get( waypoints.size()-1), routingContext.getNogoChecksums(), debugInfo ); + nearbyTrack = OsmTrack.readBinary( routingContext.rawTrackPath, waypoints.get( waypoints.size()-1), routingContext.getNogoChecksums(), routingContext.profileTimestamp, debugInfo ); if ( nearbyTrack != null ) { nUnmatched--; @@ -532,7 +532,10 @@ public class RoutingEngine extends Thread dirtyMessage = iae; logInfo( "using fast partial recalc" ); } - maxRunningTime += System.currentTimeMillis() - startTime; // reset timeout... + if ( maxRunningTime > 0 ) + { + maxRunningTime += System.currentTimeMillis() - startTime; // reset timeout... + } } } @@ -560,6 +563,7 @@ public class RoutingEngine extends Thread foundRawTrack = mergeTrack( matchPath, track ); foundRawTrack.endPoint = endWp; foundRawTrack.nogoChecksums = routingContext.getNogoChecksums(); + foundRawTrack.profileTimestamp = routingContext.profileTimestamp; foundRawTrack.isDirty = true; } throw iae; @@ -589,6 +593,7 @@ public class RoutingEngine extends Thread logInfo( "supplying new reference track, dirty=" + isDirty ); track.endPoint = endWp; track.nogoChecksums = routingContext.getNogoChecksums(); + track.profileTimestamp = routingContext.profileTimestamp; track.isDirty = isDirty; foundRawTrack = track; } diff --git a/brouter-expressions/pom.xml b/brouter-expressions/pom.xml index 7d141c2..81d1e28 100644 --- a/brouter-expressions/pom.xml +++ b/brouter-expressions/pom.xml @@ -5,7 +5,7 @@ org.btools brouter - 1.4.2 + 1.4.3 ../pom.xml brouter-expressions diff --git a/brouter-map-creator/pom.xml b/brouter-map-creator/pom.xml index 71a148b..033850a 100644 --- a/brouter-map-creator/pom.xml +++ b/brouter-map-creator/pom.xml @@ -5,7 +5,7 @@ org.btools brouter - 1.4.2 + 1.4.3 ../pom.xml brouter-map-creator diff --git a/brouter-mapaccess/pom.xml b/brouter-mapaccess/pom.xml index 2c7c0fd..910c3f7 100644 --- a/brouter-mapaccess/pom.xml +++ b/brouter-mapaccess/pom.xml @@ -5,7 +5,7 @@ org.btools brouter - 1.4.2 + 1.4.3 ../pom.xml brouter-mapaccess diff --git a/brouter-mem-router/pom.xml b/brouter-mem-router/pom.xml index 03916e3..14cb12a 100644 --- a/brouter-mem-router/pom.xml +++ b/brouter-mem-router/pom.xml @@ -5,7 +5,7 @@ org.btools brouter - 1.4.2 + 1.4.3 ../pom.xml brouter-mem-router diff --git a/brouter-routing-app/AndroidManifest.xml b/brouter-routing-app/AndroidManifest.xml index 6f15b66..20180d1 100644 --- a/brouter-routing-app/AndroidManifest.xml +++ b/brouter-routing-app/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="14" + android:versionName="1.4.3" package="btools.routingapp"> org.btools brouter - 1.4.2 + 1.4.3 ../pom.xml brouter-routing-app @@ -60,9 +60,9 @@ ${project.build.directory}/${project.artifactId}.apk \sign\mystore - abrensch - peru1511 - peru1511 + myalias + mypass + mypass true diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java index c667fb6..4354c61 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java @@ -2,9 +2,14 @@ package btools.routingapp; import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.FileReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; import java.util.ArrayList; import android.app.Service; @@ -24,85 +29,201 @@ public class BRouterService extends Service return myBRouterServiceStub; } - private IBRouterService.Stub myBRouterServiceStub = new IBRouterService.Stub() + private IBRouterService.Stub myBRouterServiceStub = new IBRouterService.Stub() { - @Override - public String getTrackFromParams(Bundle params) throws RemoteException - { - BRouterWorker worker = new BRouterWorker(); + @Override + public String getTrackFromParams( Bundle params ) throws RemoteException + { + BRouterWorker worker = new BRouterWorker(); - // get base dir from private file - String baseDir = null; - InputStream configInput = null; - try - { - configInput = openFileInput( "config.dat" ); - BufferedReader br = new BufferedReader( new InputStreamReader (configInput ) ); - baseDir = br.readLine(); - } - catch( Exception e ) {} - finally - { - if ( configInput != null ) try { configInput.close(); } catch( Exception ee ) {} - } - - String fast = params.getString( "fast" ); - boolean isFast = "1".equals( fast ) || "true".equals( fast ) || "yes".equals( fast ); - String mode_key = params.getString( "v" ) + "_" + (isFast ? "fast" : "short"); + // get base dir from private file + String baseDir = null; + InputStream configInput = null; + try + { + configInput = openFileInput( "config.dat" ); + BufferedReader br = new BufferedReader( new InputStreamReader( configInput ) ); + baseDir = br.readLine(); + } + catch (Exception e) + { + } + finally + { + if ( configInput != null ) try { configInput.close(); } catch (Exception ee) {} + } + worker.segmentDir = baseDir + "/brouter/segments4"; - boolean configFound = false; - - BufferedReader br = null; - try - { - String modesFile = baseDir + "/brouter/modes/serviceconfig.dat"; - br = new BufferedReader( new FileReader (modesFile ) ); - worker.segmentDir = baseDir + "/brouter/segments4"; - for(;;) - { - String line = br.readLine(); - if ( line == null ) break; - ServiceModeConfig smc = new ServiceModeConfig( line ); - if ( !smc.mode.equals( mode_key ) ) continue; - worker.profilePath = baseDir + "/brouter/profiles2/" + smc.profile + ".brf"; - worker.rawTrackPath = baseDir + "/brouter/modes/" + mode_key + "_rawtrack.dat"; - - CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir ); - worker.nogoList = new ArrayList(); - // veto nogos by profiles veto list - for(OsmNodeNamed nogo : cor.nogopoints ) - { - if ( !smc.nogoVetos.contains( nogo.ilon + "," + nogo.ilat ) ) - { - worker.nogoList.add( nogo ); - } - } - configFound = true; - } - } - catch( Exception e ) - { - return "no brouter service config found, mode " + mode_key; - } - finally - { - if ( br != null ) try { br.close(); } catch( Exception ee ) {} - } - - if ( !configFound ) - { - return "no brouter service config found for mode " + mode_key; - } + String remoteProfile = params.getString( "remoteProfile" ); + + if ( remoteProfile == null ) + { + remoteProfile = checkForTestDummy( baseDir ); + } + + String errMsg = remoteProfile == null + ? getConfigFromMode( worker, baseDir, params.getString( "v" ), params.getString( "fast" ) ) + : getConfigForRemoteProfile( worker, baseDir, remoteProfile ); + + if ( errMsg != null ) + { + return errMsg; + } + + try + { + return worker.getTrackFromParams( params ); + } + catch (IllegalArgumentException iae) + { + return iae.getMessage(); + } + } + + private String getConfigFromMode( BRouterWorker worker, String baseDir, String mode, String fast ) + { + boolean isFast = "1".equals( fast ) || "true".equals( fast ) || "yes".equals( fast ); + String mode_key = mode + "_" + ( isFast ? "fast" : "short" ); + + BufferedReader br = null; + try + { + String modesFile = baseDir + "/brouter/modes/serviceconfig.dat"; + br = new BufferedReader( new FileReader( modesFile ) ); + for ( ;; ) + { + String line = br.readLine(); + if ( line == null ) + break; + ServiceModeConfig smc = new ServiceModeConfig( line ); + if ( !smc.mode.equals( mode_key ) ) + continue; + worker.profilePath = baseDir + "/brouter/profiles2/" + smc.profile + ".brf"; + worker.rawTrackPath = baseDir + "/brouter/modes/" + mode_key + "_rawtrack.dat"; + + CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir ); + worker.nogoList = new ArrayList(); + // veto nogos by profiles veto list + for ( OsmNodeNamed nogo : cor.nogopoints ) + { + if ( !smc.nogoVetos.contains( nogo.ilon + "," + nogo.ilat ) ) + { + worker.nogoList.add( nogo ); + } + } + return null; + } + } + catch (Exception e) + { + return "no brouter service config found, mode " + mode_key; + } + finally + { + if ( br != null ) try { br.close(); } catch( Exception ee ) {} + } + return "no brouter service config found for mode " + mode_key; + } + + private String getConfigForRemoteProfile( BRouterWorker worker, String baseDir, String remoteProfile ) + { + worker.profilePath = baseDir + "/brouter/profiles2/remote.brf"; + worker.rawTrackPath = baseDir + "/brouter/modes/remote_rawtrack.dat"; + + // store profile only if not identical (to preserve timestamp) + byte[] profileBytes = remoteProfile.getBytes(); + File profileFile = new File( worker.profilePath ); + + try + { + // add nogos from waypoint database + CoordinateReader cor = CoordinateReader.obtainValidReader( baseDir, worker.segmentDir ); + worker.nogoList = new ArrayList( cor.nogopoints ); + + if ( !fileEqual( profileBytes, profileFile ) ) + { + OutputStream os = null; + try + { + os = new FileOutputStream( profileFile ); + os.write( profileBytes ); + } + finally + { + if ( os != null ) try { os.close(); } catch( IOException io ) {} + } + } + } + catch( Exception e ) + { + return "error caching remote profile: " + e; + } + return null; + } + + private boolean fileEqual( byte[] fileBytes, File file ) throws Exception + { + if ( !file.exists() ) + { + return false; + } + int nbytes = fileBytes.length; + int pos = 0; + int blen = 8192; + byte[] buf = new byte[blen]; + InputStream is = null; + try + { + is = new FileInputStream( file ); + while( pos < nbytes ) + { + int len = is.read( buf, 0, blen ); + if ( len <= 0 ) return false; + if ( pos + len > nbytes ) return false; + for( int j=0; j 0 ) title += " / " + cr.getAlternativeIndex() + ". Alternative"; diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java index 1877cad..9efe93c 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java @@ -67,7 +67,7 @@ public class BRouterWorker cr.doRun( maxRunningTime ); // store new reference track if any - // (can exist fot timeed-out search) + // (can exist for timed-out search) if ( cr.getFoundRawTrack() != null ) { try diff --git a/brouter-routing-app/src/main/java/btools/routingapp/IBRouterService.aidl b/brouter-routing-app/src/main/java/btools/routingapp/IBRouterService.aidl index 0f092b1..119d20e 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/IBRouterService.aidl +++ b/brouter-routing-app/src/main/java/btools/routingapp/IBRouterService.aidl @@ -17,6 +17,7 @@ interface IBRouterService { // "nogoRadi"-->double[] array of nogo radius in meters; may be null. // "fast"-->[0|1] // "v"-->[motorcar|bicycle|foot] + // "remoteProfile"--> (String), net-content of a profile. If remoteProfile != null, v+fast are ignored //return null if all ok and no path given, the track if ok and path given, an error message if it was wrong //call in a background thread, heavy task! diff --git a/brouter-server/pom.xml b/brouter-server/pom.xml index e80122a..f6277ed 100644 --- a/brouter-server/pom.xml +++ b/brouter-server/pom.xml @@ -5,7 +5,7 @@ org.btools brouter - 1.4.2 + 1.4.3 ../pom.xml brouter-server @@ -51,11 +51,11 @@ brouter-map-creator ${project.version} - + junit junit diff --git a/brouter-server/src/main/java/btools/server/BRouter.java b/brouter-server/src/main/java/btools/server/BRouter.java index 3dc52f2..ec361f7 100644 --- a/brouter-server/src/main/java/btools/server/BRouter.java +++ b/brouter-server/src/main/java/btools/server/BRouter.java @@ -88,7 +88,7 @@ public class BRouter } System.exit(0); } - System.out.println("BRouter 1.4.2 / 16052016 / abrensch"); + System.out.println("BRouter 1.4.3 / 06082016 / abrensch"); if ( args.length < 6 ) { System.out.println("Find routes in an OSM map"); diff --git a/brouter-server/src/main/java/btools/server/RouteServer.java b/brouter-server/src/main/java/btools/server/RouteServer.java index 783e008..a786e9a 100644 --- a/brouter-server/src/main/java/btools/server/RouteServer.java +++ b/brouter-server/src/main/java/btools/server/RouteServer.java @@ -155,7 +155,7 @@ public class RouteServer extends Thread public static void main(String[] args) throws Exception { - System.out.println("BRouter 1.4.2 / 16052016"); + System.out.println("BRouter 1.4.3 / 06082016"); if ( args.length != 5 ) { System.out.println("serve BRouter protocol"); diff --git a/brouter-util/pom.xml b/brouter-util/pom.xml index 39d18f0..f086584 100644 --- a/brouter-util/pom.xml +++ b/brouter-util/pom.xml @@ -5,7 +5,7 @@ org.btools brouter - 1.4.2 + 1.4.3 ../pom.xml brouter-util diff --git a/pom.xml b/pom.xml index 2bbacdf..dd352a6 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 org.btools brouter - 1.4.2 + 1.4.3 pom http://brouter.de/brouter/ brouter @@ -17,7 +17,7 @@ brouter-mapaccess brouter-core brouter-map-creator - + brouter-mem-router brouter-server brouter-routing-app