From 54a7ad6b9d55fe611722810945374c2ae70f3ac3 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Wed, 2 Nov 2022 09:37:12 +0100 Subject: [PATCH 1/5] update lib part one --- .../main/java/btools/router/OsmNodeNamed.java | 1 + .../btools/mapaccess/MatchedWaypoint.java | 1 + .../btools/routingapp/IBRouterService.aidl | 7 ++++-- .../java/btools/routingapp/BRouterWorker.java | 23 +++++++++++++++++-- .../main/java/btools/server/RouteServer.java | 6 +++++ .../btools/server/request/ServerHandler.java | 7 ++++++ 6 files changed, 41 insertions(+), 4 deletions(-) diff --git a/brouter-core/src/main/java/btools/router/OsmNodeNamed.java b/brouter-core/src/main/java/btools/router/OsmNodeNamed.java index ff0b789..633d428 100644 --- a/brouter-core/src/main/java/btools/router/OsmNodeNamed.java +++ b/brouter-core/src/main/java/btools/router/OsmNodeNamed.java @@ -13,6 +13,7 @@ public class OsmNodeNamed extends OsmNode { public double radius; // radius of nogopoint (in meters) public double nogoWeight; // weight for nogopoint public boolean isNogo = false; + public boolean direct = false; // mark direct routing public OsmNodeNamed() { } diff --git a/brouter-mapaccess/src/main/java/btools/mapaccess/MatchedWaypoint.java b/brouter-mapaccess/src/main/java/btools/mapaccess/MatchedWaypoint.java index ccc2909..f084f3f 100644 --- a/brouter-mapaccess/src/main/java/btools/mapaccess/MatchedWaypoint.java +++ b/brouter-mapaccess/src/main/java/btools/mapaccess/MatchedWaypoint.java @@ -18,6 +18,7 @@ public final class MatchedWaypoint { public OsmNode waypoint; public String name; // waypoint name used in error messages public double radius; // distance in meter between waypoint and crosspoint + public boolean direct; // from this point go direct to next = beeline routing public boolean hasUpdate; diff --git a/brouter-routing-app/src/main/aidl/btools/routingapp/IBRouterService.aidl b/brouter-routing-app/src/main/aidl/btools/routingapp/IBRouterService.aidl index 97fccd0..c29ab16 100644 --- a/brouter-routing-app/src/main/aidl/btools/routingapp/IBRouterService.aidl +++ b/brouter-routing-app/src/main/aidl/btools/routingapp/IBRouterService.aidl @@ -20,6 +20,9 @@ interface IBRouterService { // "remoteProfile"--> (String), net-content of a profile. If remoteProfile != null, v+fast are ignored // // "lonlats" = lon,lat|... (unlimited list of lon,lat waypoints separated by |) + // variantes: lon,lat,d|... (from this point to the next do a direct line) + // lon,lat,name|... (route point has a name and should not be ignored) + // "straight" = idx1,idx2,.. (optional, minimum one value, index of a direct routing point in the waypoint list) // "nogos" = lon,lat,radius|... (optional, radius in meters) // "polylines" = lon,lat,lon,lat,...,weight|... (unlimited list of lon,lat and weight (optional), lists separated by |) // "polygons" = lon,lat,lon,lat,...,weight|... (unlimited list of lon,lat and weight (optional), lists separated by |) @@ -28,9 +31,9 @@ interface IBRouterService { // "exportWaypoints" = 1 to export them (optional, default is no export) // "pois" = lon,lat,name|... (optional) // "extraParams" = Bundle key=value list for a profile setup (like "profile:") - // "timode" = turnInstructionMode [0=none, 1=auto-choose, 2=locus-style, 3=osmand-style, 4=comment-style, 5=gpsies-style, 6=orux-style] default 0 + // "timode" = turnInstructionMode [0=none, 1=auto-choose, 2=locus-style, 3=osmand-style, 4=comment-style, 5=gpsies-style, 6=orux-style, 7=locus-new-style, 8=cruiser-stylem, 9=brouter-intern] default 0 // "heading" = angle (optional to give a route a start direction) - // "direction" = (deprecated) angle + // "direction" = angle (optional, used on recalculation, only used by Locus) // return null if all ok and no path given, the track if ok and path given, an error message if it was wrong // the resultas string when 'pathToFileResult' is null, this should be default when Android Q or later 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 82bfe64..43111cc 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java @@ -57,7 +57,7 @@ public class BRouterWorker { if ("osmand".equalsIgnoreCase(tiFormat)) { rc.turnInstructionMode = 3; } else if ("locus".equalsIgnoreCase(tiFormat)) { - rc.turnInstructionMode = 2; + rc.turnInstructionMode = 7; } } if (params.containsKey("timode")) { @@ -112,7 +112,19 @@ public class BRouterWorker { String key = tk2.nextToken(); if (tk2.hasMoreTokens()) { String value = tk2.nextToken(); - rc.keyValues.put(key, value); + if (key.equals("straight")) { + try { + String[] sa = value.split(","); + for ( int i = 0; i v) waypoints.get(v).direct = true; + } + } catch (Exception e) { + System.err.println("error " + e.getStackTrace()[0].getLineNumber() + " " + e.getStackTrace()[0] + "\n" +e); + } + } else { + rc.keyValues.put(key, value); + } } } } @@ -226,6 +238,13 @@ public class BRouterWorker { if (lonLat.length < 2) throw new IllegalArgumentException("we need two lat/lon points at least!"); wplist.add(readPosition(lonLat[0], lonLat[1], "via" + i)); + if (lonLat.length > 2) { + if (lonLat[2].equals("d")) { + wplist.get(wplist.size()-1).direct = true; + } else { + wplist.get(wplist.size()-1).name = lonLat[2]; + } + } } wplist.get(0).name = "from"; diff --git a/brouter-server/src/main/java/btools/server/RouteServer.java b/brouter-server/src/main/java/btools/server/RouteServer.java index 62c74e5..a40b864 100644 --- a/brouter-server/src/main/java/btools/server/RouteServer.java +++ b/brouter-server/src/main/java/btools/server/RouteServer.java @@ -218,6 +218,12 @@ public class RouteServer extends Thread implements Comparable { rc.keyValues = new HashMap(); } rc.keyValues.put(e.getKey().substring(8), e.getValue()); + } else if (e.getKey().equals("straight")) { + String[] sa = e.getValue().split(","); + for (int i = 0; i v) wplist.get(v).direct = true; + } } } cr = new RoutingEngine(null, null, serviceContext.segmentDir, wplist, rc); diff --git a/brouter-server/src/main/java/btools/server/request/ServerHandler.java b/brouter-server/src/main/java/btools/server/request/ServerHandler.java index 2c3897c..73641be 100644 --- a/brouter-server/src/main/java/btools/server/request/ServerHandler.java +++ b/brouter-server/src/main/java/btools/server/request/ServerHandler.java @@ -95,6 +95,13 @@ public class ServerHandler extends RequestHandler { if (lonLat.length < 2) throw new IllegalArgumentException("we need two lat/lon points at least!"); wplist.add(readPosition(lonLat[0], lonLat[1], "via" + i)); + if (lonLat.length > 2) { + if (lonLat[2].equals("d")) { + wplist.get(wplist.size()-1).direct = true; + } else { + wplist.get(wplist.size()-1).name = lonLat[2]; + } + } } wplist.get(0).name = "from"; From f6d4eee7638853463ca153d96540d50c1e6121be Mon Sep 17 00:00:00 2001 From: afischerdev Date: Sun, 13 Nov 2022 15:55:38 +0100 Subject: [PATCH 2/5] update description for direction --- .../src/main/aidl/btools/routingapp/IBRouterService.aidl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/brouter-routing-app/src/main/aidl/btools/routingapp/IBRouterService.aidl b/brouter-routing-app/src/main/aidl/btools/routingapp/IBRouterService.aidl index c29ab16..9c4039a 100644 --- a/brouter-routing-app/src/main/aidl/btools/routingapp/IBRouterService.aidl +++ b/brouter-routing-app/src/main/aidl/btools/routingapp/IBRouterService.aidl @@ -33,7 +33,7 @@ interface IBRouterService { // "extraParams" = Bundle key=value list for a profile setup (like "profile:") // "timode" = turnInstructionMode [0=none, 1=auto-choose, 2=locus-style, 3=osmand-style, 4=comment-style, 5=gpsies-style, 6=orux-style, 7=locus-new-style, 8=cruiser-stylem, 9=brouter-intern] default 0 // "heading" = angle (optional to give a route a start direction) - // "direction" = angle (optional, used on recalculation, only used by Locus) + // "direction" = angle (optional, used like "heading" on a recalculation request by Locus as start direction) // return null if all ok and no path given, the track if ok and path given, an error message if it was wrong // the resultas string when 'pathToFileResult' is null, this should be default when Android Q or later From f6afafb46cd804bedc694ab5ca49f9962a3b2b62 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Sun, 13 Nov 2022 16:08:16 +0100 Subject: [PATCH 3/5] reformat BRouterWorker --- .../src/main/java/btools/routingapp/BRouterWorker.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 43111cc..e6e3783 100644 --- a/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java +++ b/brouter-routing-app/src/main/java/btools/routingapp/BRouterWorker.java @@ -115,12 +115,12 @@ public class BRouterWorker { if (key.equals("straight")) { try { String[] sa = value.split(","); - for ( int i = 0; i v) waypoints.get(v).direct = true; } } catch (Exception e) { - System.err.println("error " + e.getStackTrace()[0].getLineNumber() + " " + e.getStackTrace()[0] + "\n" +e); + System.err.println("error " + e.getStackTrace()[0].getLineNumber() + " " + e.getStackTrace()[0] + "\n" + e); } } else { rc.keyValues.put(key, value); @@ -240,9 +240,9 @@ public class BRouterWorker { wplist.add(readPosition(lonLat[0], lonLat[1], "via" + i)); if (lonLat.length > 2) { if (lonLat[2].equals("d")) { - wplist.get(wplist.size()-1).direct = true; + wplist.get(wplist.size() - 1).direct = true; } else { - wplist.get(wplist.size()-1).name = lonLat[2]; + wplist.get(wplist.size() - 1).name = lonLat[2]; } } } From 5c970ed71f082f0677bb9335ab2a1b9b26f78a25 Mon Sep 17 00:00:00 2001 From: afischerdev Date: Sun, 13 Nov 2022 16:14:56 +0100 Subject: [PATCH 4/5] reformat RouteServer --- .../main/java/btools/server/RouteServer.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/brouter-server/src/main/java/btools/server/RouteServer.java b/brouter-server/src/main/java/btools/server/RouteServer.java index a40b864..7a846f0 100644 --- a/brouter-server/src/main/java/btools/server/RouteServer.java +++ b/brouter-server/src/main/java/btools/server/RouteServer.java @@ -220,7 +220,7 @@ public class RouteServer extends Thread implements Comparable { rc.keyValues.put(e.getKey().substring(8), e.getValue()); } else if (e.getKey().equals("straight")) { String[] sa = e.getValue().split(","); - for (int i = 0; i v) wplist.get(v).direct = true; } @@ -265,17 +265,17 @@ public class RouteServer extends Thread implements Comparable { } finally { cr = null; if (br != null) try { - br.close(); - } catch (Exception e) { - } + br.close(); + } catch (Exception e) { + } if (bw != null) try { - bw.close(); - } catch (Exception e) { - } + bw.close(); + } catch (Exception e) { + } if (clientSocket != null) try { - clientSocket.close(); - } catch (Exception e) { - } + clientSocket.close(); + } catch (Exception e) { + } terminated = true; synchronized (threadPoolSync) { threadPoolSync.notifyAll(); From cebcd566c63fc176b2ff6bd3a992492eebaee56b Mon Sep 17 00:00:00 2001 From: afischerdev Date: Sun, 13 Nov 2022 16:27:37 +0100 Subject: [PATCH 5/5] reformat RouteServer again --- .editorconfig | 1 + .../main/java/btools/server/RouteServer.java | 27 ++++++++++--------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/.editorconfig b/.editorconfig index 26238e9..2b939e7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,6 +3,7 @@ root = true [*] end_of_line = lf insert_final_newline = true +trim_trailing_whitespace = true [*.java] indent_style = space diff --git a/brouter-server/src/main/java/btools/server/RouteServer.java b/brouter-server/src/main/java/btools/server/RouteServer.java index 7a846f0..0d681ad 100644 --- a/brouter-server/src/main/java/btools/server/RouteServer.java +++ b/brouter-server/src/main/java/btools/server/RouteServer.java @@ -264,18 +264,21 @@ public class RouteServer extends Thread implements Comparable { e.printStackTrace(); } finally { cr = null; - if (br != null) try { - br.close(); - } catch (Exception e) { - } - if (bw != null) try { - bw.close(); - } catch (Exception e) { - } - if (clientSocket != null) try { - clientSocket.close(); - } catch (Exception e) { - } + if (br != null) + try { + br.close(); + } catch (Exception e) { + } + if (bw != null) + try { + bw.close(); + } catch (Exception e) { + } + if (clientSocket != null) + try { + clientSocket.close(); + } catch (Exception e) { + } terminated = true; synchronized (threadPoolSync) { threadPoolSync.notifyAll();