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 4354c61..2e32a8b 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterService.java @@ -52,6 +52,7 @@ public class BRouterService extends Service { if ( configInput != null ) try { configInput.close(); } catch (Exception ee) {} } + worker.baseDir = baseDir; worker.segmentDir = baseDir + "/brouter/segments4"; String remoteProfile = params.getString( "remoteProfile" ); @@ -98,6 +99,7 @@ public class BRouterService extends Service ServiceModeConfig smc = new ServiceModeConfig( line ); if ( !smc.mode.equals( mode_key ) ) continue; + worker.profileName = smc.profile; worker.profilePath = baseDir + "/brouter/profiles2/" + smc.profile + ".brf"; worker.rawTrackPath = baseDir + "/brouter/modes/" + mode_key + "_rawtrack.dat"; @@ -127,6 +129,7 @@ public class BRouterService extends Service private String getConfigForRemoteProfile( BRouterWorker worker, String baseDir, String remoteProfile ) { + worker.profileName = "remote"; worker.profilePath = baseDir + "/brouter/profiles2/remote.brf"; worker.rawTrackPath = baseDir + "/brouter/modes/remote_rawtrack.dat"; diff --git a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java index 54c8e02..6586d4f 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterView.java @@ -61,6 +61,7 @@ public class BRouterView extends View private String profileName; private String sourceHint; private boolean waitingForSelection = false; + private String rawTrackPath; private boolean needsViaSelection; private boolean needsNogoSelection; @@ -238,6 +239,15 @@ public class BRouterView extends View if ( fileName.equals( "lookups.dat" ) ) lookupsFound = true; } + + // add a "last timeout" dummy profile + File lastTimeoutFile = new File( modesDir + "/timeoutdata.txt" ); + long lastTimeoutTime = lastTimeoutFile.lastModified(); + if ( lastTimeoutTime > 0 && System.currentTimeMillis() - lastTimeoutTime < 300000 ) + { + profiles.add( 0, "" ); + } + if ( !lookupsFound ) { throw new IllegalArgumentException( "The profile-directory " + profileDir + " does not contain the lookups.dat file." @@ -380,8 +390,46 @@ public class BRouterView extends View needsWaypointSelection = false; } + private List readWpList( BufferedReader br, boolean isNogo ) throws Exception + { + int cnt = Integer.parseInt( br.readLine() ); + List res = new ArrayList(cnt); + for( int i=0; i".equals( profile ) ) + { + needsViaSelection = needsNogoSelection = needsWaypointSelection = false; + try + { + File lastTimeoutFile = new File( modesDir + "/timeoutdata.txt" ); + BufferedReader br = new BufferedReader( new FileReader( lastTimeoutFile ) ); + profile = br.readLine(); + rawTrackPath = br.readLine(); + wpList = readWpList( br, false ); + nogoList = readWpList( br, true ); + br.close(); + } + catch( Exception e ) + { + AppLogger.log( AppLogger.formatThrowable( e ) ); + ( (BRouterActivity) getContext() ).showErrorMessage( e.toString() ); + } + } + else if ( "remote".equals( profileName ) ) + { + rawTrackPath = modesDir + "/remote_rawtrack.dat"; + } + profilePath = profileDir + "/" + profile + ".brf"; profileName = profile; @@ -467,11 +515,8 @@ public class BRouterView extends View rc.prepareNogoPoints( nogoList ); rc.nogopoints = nogoList; - // for profile remote, use ref-track logic same as service interface - if ( "remote".equals( profileName ) ) - { - rc.rawTrackPath = modesDir + "/remote_rawtrack.dat"; - } + // for profile remote, use ref-track logic same as service interface + rc.rawTrackPath = rawTrackPath; cr = new RoutingEngine( tracksDir + "/brouter", null, segmentDir, wpList, rc ); cr.start(); @@ -709,12 +754,9 @@ public class BRouterView extends View rawTrack = cr.getFoundRawTrack(); // for profile "remote", always persist referencetrack - if ( cr.getAlternativeIndex() == 0 ) + if ( cr.getAlternativeIndex() == 0 && rawTrackPath != null ) { - if ( "remote".equals( profileName ) ) - { - writeRawTrackToMode( "remote" ); - } + writeRawTrackToPath( rawTrackPath ); } String title = "Success"; @@ -828,10 +870,13 @@ public class BRouterView extends View return basedir.getAbsolutePath(); } - public void writeRawTrackToMode( String mode ) + private void writeRawTrackToMode( String mode ) + { + writeRawTrackToPath( modesDir + "/" + mode + "_rawtrack.dat" ); + } + + private void writeRawTrackToPath( String rawTrackPath ) { - // plus eventually the raw track for re-use - String rawTrackPath = modesDir + "/" + mode + "_rawtrack.dat"; if ( rawTrack != null ) { try 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 9efe93c..dc82b9f 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java @@ -1,21 +1,27 @@ package btools.routingapp; +import java.io.BufferedWriter; import java.io.File; +import java.io.FileWriter; import java.util.ArrayList; import java.util.List; import android.os.Bundle; -import btools.router.RoutingEngine; import btools.router.OsmNodeNamed; +import btools.router.OsmPathElement; import btools.router.OsmTrack; import btools.router.RoutingContext; +import btools.router.RoutingEngine; public class BRouterWorker { + public String baseDir; public String segmentDir; + public String profileName; public String profilePath; public String rawTrackPath; + public List waypoints; public List nogoList; public String getTrackFromParams(Bundle params) @@ -60,9 +66,10 @@ public class BRouterWorker rc.nogopoints = nogoList; } - readNogos( params ); // add interface provides nogos + readNogos( params ); // add interface provided nogos + waypoints = readPositions(params); - RoutingEngine cr = new RoutingEngine( null, null, segmentDir, readPositions(params), rc ); + RoutingEngine cr = new RoutingEngine( null, null, segmentDir, waypoints, rc ); cr.quite = true; cr.doRun( maxRunningTime ); @@ -79,6 +86,14 @@ public class BRouterWorker if ( cr.getErrorMessage() != null ) { + if ( cr.getErrorMessage().indexOf( "timeout" ) >= 0 ) + { + try + { + writeTimeoutData( rc ); + } + catch( Exception e ) {} + } return cr.getErrorMessage(); } @@ -150,4 +165,28 @@ public class BRouterWorker nogoList.add( n ); } } + + private void writeTimeoutData( RoutingContext rc ) throws Exception + { + String timeoutFile = baseDir + "/brouter/modes/timeoutdata.txt"; + + BufferedWriter bw = new BufferedWriter( new FileWriter( timeoutFile ) ); + bw.write( profileName ); + bw.write( "\n" ); + bw.write( rc.rawTrackPath ); + bw.write( "\n" ); + writeWPList( bw, waypoints ); + writeWPList( bw, nogoList ); + bw.close(); + } + + private void writeWPList( BufferedWriter bw, List wps ) throws Exception + { + bw.write( wps.size() + "\n" ); + for( OsmNodeNamed wp : wps ) + { + bw.write( wp.toString() ); + bw.write( "\n" ); + } + } }