added a repeat-timeout shortcut
This commit is contained in:
parent
686d693103
commit
acb7c6b16f
3 changed files with 103 additions and 16 deletions
|
@ -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";
|
||||
|
||||
|
|
|
@ -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, "<repeat timeout>" );
|
||||
}
|
||||
|
||||
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<OsmNodeNamed> readWpList( BufferedReader br, boolean isNogo ) throws Exception
|
||||
{
|
||||
int cnt = Integer.parseInt( br.readLine() );
|
||||
List<OsmNodeNamed> res = new ArrayList<OsmNodeNamed>(cnt);
|
||||
for( int i=0; i<cnt; i++ )
|
||||
{
|
||||
OsmNodeNamed wp = OsmNodeNamed.decodeNogo( br.readLine() );
|
||||
wp.isNogo = isNogo;
|
||||
res.add( wp );
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public void startProcessing( String profile )
|
||||
{
|
||||
rawTrackPath = null;
|
||||
if ( "<repeat timeout>".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
|
||||
|
|
|
@ -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<OsmNodeNamed> waypoints;
|
||||
public List<OsmNodeNamed> 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<OsmNodeNamed> wps ) throws Exception
|
||||
{
|
||||
bw.write( wps.size() + "\n" );
|
||||
for( OsmNodeNamed wp : wps )
|
||||
{
|
||||
bw.write( wp.toString() );
|
||||
bw.write( "\n" );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue