Skip to content
Snippets Groups Projects
Commit 696ab211 authored by Lukas Friedrichsen's avatar Lukas Friedrichsen
Browse files

only update-functionality and testing missing

parent 68820627
Branches
No related tags found
No related merge requests found
...@@ -2,5 +2,6 @@ ...@@ -2,5 +2,6 @@
<classpath> <classpath>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="/home/lukas/VInf/Praktikum/VINF_MaerklinProject/controlsfx-8.40.12.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
...@@ -3,6 +3,12 @@ package maerklinProject_GUI; ...@@ -3,6 +3,12 @@ package maerklinProject_GUI;
import java.io.*; import java.io.*;
import java.net.Socket; import java.net.Socket;
import org.controlsfx.control.ToggleSwitch;
import javafx.application.Platform;
import javafx.beans.value.*;
import javafx.collections.FXCollections;
import javafx.fxml.*; import javafx.fxml.*;
import javafx.scene.control.*; import javafx.scene.control.*;
...@@ -14,19 +20,87 @@ public class maerklinProject_GUIController { ...@@ -14,19 +20,87 @@ public class maerklinProject_GUIController {
private InputStream in; private InputStream in;
private OutputStream out; private OutputStream out;
private int selectedEngine;
private boolean connectionEstablished;
@FXML @FXML
TextField serverIP; TextField serverIP;
@FXML @FXML
Button connectButton; Button connectButton;
private boolean connectionEstablished = false; @FXML
ChoiceBox<String> engineChoiceBox;
@FXML
Slider engineSpeed;
@FXML
ToggleSwitch swToggle04;
ToggleSwitch swToggle05;
ToggleSwitch swToggle06;
ToggleSwitch swToggle08;
ToggleSwitch swToggle09;
ToggleSwitch swToggle10;
ToggleSwitch swToggle12;
ToggleSwitch swToggle13;
ToggleSwitch swToggle14;
ToggleSwitch swToggle15;
@FXML
protected void initialize () {
connectionEstablished = false;
selectedEngine = ProjectProperties.ICE_ID;
swToggle04.selectedProperty().addListener(new switchListener(this, swToggle04));
swToggle05.selectedProperty().addListener(new switchListener(this, swToggle05));
swToggle06.selectedProperty().addListener(new switchListener(this, swToggle06));
swToggle08.selectedProperty().addListener(new switchListener(this, swToggle08));
swToggle09.selectedProperty().addListener(new switchListener(this, swToggle09));
swToggle10.selectedProperty().addListener(new switchListener(this, swToggle10));
swToggle12.selectedProperty().addListener(new switchListener(this, swToggle12));
swToggle13.selectedProperty().addListener(new switchListener(this, swToggle13));
swToggle14.selectedProperty().addListener(new switchListener(this, swToggle14));
swToggle15.selectedProperty().addListener(new switchListener(this, swToggle15));
engineChoiceBox.setItems(FXCollections.observableArrayList("ICE", "Lok", "Reichsbahn"));
engineChoiceBox.setValue("ICE");
engineChoiceBox.getSelectionModel().selectedIndexProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed (ObservableValue<? extends Number> ov, Number value, Number new_value) {
switch (new_value.intValue()) {
case 0:
selectedEngine = ProjectProperties.ICE_ID;
break;
case 1:
selectedEngine = ProjectProperties.LOK_ID;
break;
case 2:
selectedEngine = ProjectProperties.REICHSBAHN_ID;
break;
}
}
});
engineSpeed.valueProperty().addListener(new ChangeListener<Number>() {
@Override
public void changed (ObservableValue<? extends Number> ov,
Number old_val, Number new_val) {
engineSetSpeed(new_val.intValue()*10);
}
});
}
@FXML @FXML
protected void establishConnetion () { protected void establishConnetion () {
if (connectionEstablished) { if (connectionEstablished) {
try { try {
byte[] datagram = {(byte) 0x00, (byte) ProjectProperties.SESSION_ABORT}; byte[] datagram = {(byte) 0x00, (byte) ProjectProperties.SESSION_ABORT, (byte) 0x00, (byte) 0x00};
out.write(datagram); out.write(datagram);
client.close(); client.close();
connectionEstablished = false; connectionEstablished = false;
...@@ -49,6 +123,7 @@ public class maerklinProject_GUIController { ...@@ -49,6 +123,7 @@ public class maerklinProject_GUIController {
serverIP.setStyle("-fx-background-color: green"); serverIP.setStyle("-fx-background-color: green");
connectButton.setText("Verbindung trennen"); connectButton.setText("Verbindung trennen");
System.out.println("Verbindung zu "+client.getRemoteSocketAddress()+" aufgebaut!"); System.out.println("Verbindung zu "+client.getRemoteSocketAddress()+" aufgebaut!");
Platform.runLater(new updateThread(this));
} }
catch (Exception e) { catch (Exception e) {
System.out.println("Error at: establishConnection (establishing connection"); System.out.println("Error at: establishConnection (establishing connection");
...@@ -61,7 +136,174 @@ public class maerklinProject_GUIController { ...@@ -61,7 +136,174 @@ public class maerklinProject_GUIController {
protected void emergencyStop () { protected void emergencyStop () {
if (connectionEstablished) { if (connectionEstablished) {
try { try {
byte[] datagram = {(byte) 0x00, (byte) ProjectProperties.SYSTEM_STOP}; byte[] datagram = {(byte) 0x00, (byte) ProjectProperties.SYSTEM_STOP, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void turntableTurnClockwise () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.TURNTABLE_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void turntableTurnCounterClockwise () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.TURNTABLE_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void engineSetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) selectedEngine, (byte) ProjectProperties.ENGINE_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void engineSetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) selectedEngine, (byte) ProjectProperties.ENGINE_SET_DIRECTION, (byte) 0x02, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
protected void engineSetSpeed (int newEngineSpeed) {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) selectedEngine, (byte) ProjectProperties.ENGINE_SET_SPEED, (byte) ((newEngineSpeed/(1<<8))%(1<<8)), (byte) (newEngineSpeed%(1<<8))};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
protected void switchSetDirection (int switchID, int newSwitchDirection) {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) switchID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) newSwitchDirection, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
/*@FXML
protected void switch04SetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH4_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch04SetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH4_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch05SetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH5_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch05SetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH5_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch06SetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH6_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch06SetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH6_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch08SetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH8_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram); out.write(datagram);
} catch (Exception e) { } catch (Exception e) {
System.out.println("Error at: emergencyStop"); System.out.println("Error at: emergencyStop");
...@@ -70,4 +312,215 @@ public class maerklinProject_GUIController { ...@@ -70,4 +312,215 @@ public class maerklinProject_GUIController {
} }
} }
@FXML
protected void switch08SetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH8_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch09SetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH9_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch09SetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH9_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch10SetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH10_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch10SetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH10_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch12SetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH12_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch12SetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH12_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch13SetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH13_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch13SetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH13_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch14SetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH14_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch14SetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH14_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch15SetDirectionRight () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH15_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}
@FXML
protected void switch15SetDirectionLeft () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ProjectProperties.SWITCH15_ID, (byte) ProjectProperties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
System.out.println("Error at: emergencyStop");
e.printStackTrace();
}
}
}*/
}
class switchListener implements ChangeListener<Boolean> {
private maerklinProject_GUIController controllerInstance;
private ToggleSwitch node;
private int switchID;
private int newSwitchDirection;
switchListener (maerklinProject_GUIController controller, ToggleSwitch element) {
controllerInstance = controller;
node = element;
}
@Override
public void changed (ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
switchID = Integer.parseInt(""+node.getId().charAt(8)+node.getId().charAt(9));
if (newValue) {
newSwitchDirection = 1;
}
else {
newSwitchDirection = 0;
}
controllerInstance.switchSetDirection(switchID, newSwitchDirection);
}
}
class updateThread implements Runnable {
maerklinProject_GUIController controllerInstance;
updateThread (maerklinProject_GUIController controller) {
controllerInstance = controller;
}
@Override
public void run() {
// TODO Auto-generated method stub
}
} }
...@@ -96,6 +96,7 @@ public class MaerklinServer{ ...@@ -96,6 +96,7 @@ public class MaerklinServer{
protocol.systemStop(); protocol.systemStop();
ice.setEngineSpeed(0); ice.setEngineSpeed(0);
lok.setEngineSpeed(0); lok.setEngineSpeed(0);
reichsbahn.setEngineSpeed(0);
} }
// Emergency stop // Emergency stop
...@@ -323,6 +324,8 @@ class UpdateThread implements Runnable { ...@@ -323,6 +324,8 @@ class UpdateThread implements Runnable {
public void run() { public void run() {
int position = 0; int position = 0;
try { try {
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff;
for (Engine train : Engine.engines) { for (Engine train : Engine.engines) {
if (position <= 1016) { if (position <= 1016) {
Exception e = new Exception("Overload of registered elements! Update-buffer too small!"); Exception e = new Exception("Overload of registered elements! Update-buffer too small!");
...@@ -337,6 +340,7 @@ class UpdateThread implements Runnable { ...@@ -337,6 +340,7 @@ class UpdateThread implements Runnable {
} }
outgoingData[position++] = (byte) 0xff; outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff; outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff;
for (Switch sw : Switch.switches) { for (Switch sw : Switch.switches) {
if (position >= 1018) { if (position >= 1018) {
Exception e = new Exception("Overload of registered elements! Update-buffer too small!"); Exception e = new Exception("Overload of registered elements! Update-buffer too small!");
...@@ -349,6 +353,8 @@ class UpdateThread implements Runnable { ...@@ -349,6 +353,8 @@ class UpdateThread implements Runnable {
} }
outgoingData[position++] = (byte) 0xff; outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff; outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff;
} }
catch (Exception e) { catch (Exception e) {
System.out.println(e.getMessage()); System.out.println(e.getMessage());
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment