Browse Source

make robot tcp port configureable

Martin Kunz 5 years ago
parent
commit
84247c4021

+ 10 - 0
pom.xml

@@ -51,6 +51,16 @@
 						</goals>
 						<configuration>
 							<minimizeJar>true</minimizeJar>
+							<filters>
+								<filter>
+									<artifact>*:*</artifact>
+									<excludes>
+										<exclude>META-INF/*.SF</exclude>
+										<exclude>META-INF/*.DSA</exclude>
+										<exclude>META-INF/*.RSA</exclude>
+									</excludes>
+								</filter>
+							</filters>
 						</configuration>
 					</execution>
 				</executions>

+ 4 - 1
src/main/java/at/acdp/urweb/Params.java

@@ -7,7 +7,10 @@ public class Params {
     @picocli.CommandLine.Option(names = { "-w", "--webroot" }, description = "Use webroot from filesystem", defaultValue = "")
     public String webroot = "";
 
-    @picocli.CommandLine.Option(names = { "-r", "--robotip" }, description = "Robot ip address", defaultValue = "")
+    @picocli.CommandLine.Option(names = { "-rip", "--robotip" }, description = "Robot ip address", defaultValue = "")
     public String robotIP = "";
+
+    @picocli.CommandLine.Option(names = { "-rp", "--robotport" }, description = "Robot tcp port", defaultValue = "30001")
+    public int robotPort = 30001;
 }
 

+ 2 - 4
src/main/java/at/acdp/urweb/URBot.java

@@ -7,7 +7,6 @@ import okhttp3.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.awt.*;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.Semaphore;
@@ -23,8 +22,8 @@ public class URBot {
     private Semaphore cmdDoneSem = new Semaphore(0);
     private RobotProgramLabel currentAck;
 
-    public URBot(String ip) {
-        sc = new ScReadThread(ip, this);
+    public URBot(String ip, int port) {
+        sc = new ScReadThread(ip, port, this);
     }
 
     public synchronized void ackNumber(RobotProgramLabel rpl) {
@@ -82,7 +81,6 @@ public class URBot {
             rc.id=id;
             // rc.cmd = String.format("def urweb():\n%s\n$ %s \"URWEB_END\"\nend\n", res, id);
             rc.cmd = res;
-
             this.cmdq.put(rc);
         } catch (InterruptedException e) {
             Thread.currentThread().interrupt();

+ 5 - 2
src/main/java/at/acdp/urweb/sclient/data/ScReadThread.java

@@ -13,11 +13,13 @@ import java.io.IOException;
 public class ScReadThread implements Runnable {
     private static final Logger log = LoggerFactory.getLogger(ScReadThread.class);
     private final String ip;
+    private final int port;
     private final URBot urBot;
     SecondaryClient rde;
 
-    public ScReadThread(String ip, URBot urBot) {
+    public ScReadThread(String ip, int port, URBot urBot) {
         this.ip = ip;
+        this.port = port;
         this.urBot=urBot;
     }
     
@@ -39,8 +41,9 @@ public class ScReadThread implements Runnable {
     }
 
     private void read() throws IOException {
-        rde = new SecondaryClient(ip, 30001, urBot);
+        rde = new SecondaryClient(ip, port, urBot);
         VersionMessage vm = rde.connect();
+        log.info("Connected to: {}:{}");
         while (true) {
             rde.readPackage();
         }

+ 1 - 1
src/main/java/at/acdp/urweb/web/WebServer.java

@@ -19,7 +19,7 @@ public class WebServer {
     }
 
     public void start() {
-        this.urbot=new URBot(params.robotIP);
+        this.urbot=new URBot(params.robotIP, params.robotPort);
         this.urbot.start();
         port(params.port);
         if (!params.webroot.isEmpty())