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

debugging in progress...

parent d85d251f
Branches
No related tags found
No related merge requests found
/server/
/gui/
/common/
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -10,6 +10,8 @@ public class Properties {
public final static int OUT_BUFFER_SIZE = 1024;
// Defining client-commands
public final static byte SEPERATOR = (byte) 0xFF;
public final static int SESSION_ABORT = -1;
public final static byte SYSTEM_STOP = 0x00;
......
......@@ -197,12 +197,14 @@ public class MainApp extends Application {
if (connectionEstablished) {
try {
if (running) {
byte[] datagram = {(byte) 0x00, (byte) 0x00, (byte) Properties.SYSTEM_STOP, (byte) 0x00, (byte) 0x00};
byte[] datagram = {Properties.SEPERATOR, (byte) 0x00, (byte) 0x00, (byte) Properties.SYSTEM_STOP, (byte) 0x00, (byte) 0x00};
out.write(datagram);
running = false;
}
else {
byte[] datagram = {(byte) 0x00, (byte) 0x00, (byte) Properties.SYSTEM_GO, (byte) 0x00, (byte) 0x00};
byte[] datagram = {Properties.SEPERATOR, (byte) 0x00, (byte) 0x00, (byte) Properties.SYSTEM_GO, (byte) 0x00, (byte) 0x00};
out.write(datagram);
running = true;
}
} catch (Exception e) {
setStatus("Error at: emergencyStop");
......@@ -224,7 +226,7 @@ public class MainApp extends Application {
else
dir = (byte) 0x02;
byte[] datagram = {(byte) ((eng.getMaerklinID().get()/(1<<8))%(1<<8)), (byte) (eng.getMaerklinID().get()%(1<<8)), (byte) Properties.ENGINE_SET_DIRECTION, dir, (byte) 0x00};
byte[] datagram = {Properties.SEPERATOR, (byte) ((eng.getMaerklinID().get()/(1<<8))%(1<<8)), (byte) (eng.getMaerklinID().get()%(1<<8)), (byte) Properties.ENGINE_SET_DIRECTION, dir, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
setStatus("Error at: engineSetDirectionRight");
......@@ -237,7 +239,7 @@ public class MainApp extends Application {
if (connectionEstablished) {
try {
int newEngineSpeed = eng.getSpeed().get();
byte[] datagram = {(byte) ((eng.getMaerklinID().get()/(1<<8))%(1<<8)), (byte) (eng.getMaerklinID().get()%(1<<8)), (byte) Properties.ENGINE_SET_SPEED, (byte) ((newEngineSpeed/(1<<8))%(1<<8)), (byte) (newEngineSpeed%(1<<8))};
byte[] datagram = {Properties.SEPERATOR, (byte) ((eng.getMaerklinID().get()/(1<<8))%(1<<8)), (byte) (eng.getMaerklinID().get()%(1<<8)), (byte) Properties.ENGINE_SET_SPEED, (byte) ((newEngineSpeed/(1<<8))%(1<<8)), (byte) (newEngineSpeed%(1<<8))};
out.write(datagram);
} catch (Exception e) {
setStatus("engineSetSpeed");
......@@ -255,7 +257,7 @@ public class MainApp extends Application {
else //krumm
dir = (byte) 0x00;
byte[] datagram = {(byte) ((sw.getMaerklinID().get()/(1<<8))%(1<<8)), (byte) (sw.getMaerklinID().get()%(1<<8)), (byte) Properties.SWITCH_SET_DIRECTION, dir, (byte) 0x00};
byte[] datagram = {Properties.SEPERATOR, (byte) ((sw.getMaerklinID().get()/(1<<8))%(1<<8)), (byte) (sw.getMaerklinID().get()%(1<<8)), (byte) Properties.SWITCH_SET_DIRECTION, dir, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
setStatus("Error at: setSwitchState");
......@@ -267,7 +269,7 @@ public class MainApp extends Application {
public void turntableTurnCW () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ((turntable.getMaerklinID().get()/(1<<8))%(1<<8)), (byte) (turntable.getMaerklinID().get()%(1<<8)), (byte) Properties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
byte[] datagram = {Properties.SEPERATOR, (byte) ((turntable.getMaerklinID().get()/(1<<8))%(1<<8)), (byte) (turntable.getMaerklinID().get()%(1<<8)), (byte) Properties.SWITCH_SET_DIRECTION, (byte) 0x00, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
setStatus("Error at: turntableTurnCW");
......@@ -279,7 +281,7 @@ public class MainApp extends Application {
public void turntableTurnCCW () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) ((turntable.getMaerklinID().get()/(1<<8))%(1<<8)), (byte) (turntable.getMaerklinID().get()%(1<<8)), (byte) Properties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
byte[] datagram = {Properties.SEPERATOR, (byte) ((turntable.getMaerklinID().get()/(1<<8))%(1<<8)), (byte) (turntable.getMaerklinID().get()%(1<<8)), (byte) Properties.SWITCH_SET_DIRECTION, (byte) 0x01, (byte) 0x00};
out.write(datagram);
} catch (Exception e) {
setStatus("Error at: turntableTurnCCW");
......@@ -291,7 +293,7 @@ public class MainApp extends Application {
public void establishConnetion () {
if (connectionEstablished) {
try {
byte[] datagram = {(byte) 0x00, (byte) 0x00, (byte) Properties.SESSION_ABORT, (byte) 0x00, (byte) 0x00};
byte[] datagram = {Properties.SEPERATOR, (byte) 0x00, (byte) 0x00, (byte) Properties.SESSION_ABORT, (byte) 0x00, (byte) 0x00};
out.write(datagram);
client.close();
connectionEstablished = false;
......@@ -403,7 +405,7 @@ public class MainApp extends Application {
if (stopCounter == 1) {
startByte = true;
}
if (buffer[counter%Properties.OUT_BUFFER_SIZE] == 0xff && dataCounter != 3) {
if (buffer[counter%Properties.OUT_BUFFER_SIZE] == Properties.SEPERATOR && dataCounter != 3) {
dataCounter = 0;
stopCounter++;
}
......
......@@ -170,8 +170,6 @@ class ClientThread implements Runnable {
private final int IN_BUFFER_SIZE;
private final MaerklinServer SERVER_INSTANCE;
byte[] data;
int[] dataRaw;
int counter;
// Constructor
ClientThread (MaerklinServer server, Socket socket, InputStream in, int bufferSize) {
......@@ -181,8 +179,6 @@ class ClientThread implements Runnable {
SERVER_INSTANCE = server;
SERVER_INSTANCE.clients.add(socket);
data = new byte[IN_BUFFER_SIZE];
dataRaw = new int[IN_BUFFER_SIZE];
counter = 0;
}
@Override
......@@ -197,15 +193,20 @@ class ClientThread implements Runnable {
System.out.println("Conenction to client "+CLIENT.getRemoteSocketAddress()+" aborted!");
return;
}
else {
dataRaw[counter++] = buffer;
}
if (counter == IN_BUFFER_SIZE) {
else if (buffer == Properties.SEPERATOR) {
for (int i = 0; i < IN_BUFFER_SIZE; i++) {
data[i] = (byte) (dataRaw[i]%(1<<8));
buffer = IN_STREAM.read();
if (buffer == Properties.SESSION_ABORT) {
SERVER_INSTANCE.clients.remove(CLIENT);
CLIENT.close();
System.out.println("Conenction to client "+CLIENT.getRemoteSocketAddress()+" aborted!");
return;
}
else {
data[i] = (byte) (buffer%(1<<8));
}
(new Thread(new HandleThread(SERVER_INSTANCE, data))).start();
counter = 0;
}
}
}
catch (Exception e) {
......@@ -335,8 +336,8 @@ class UpdateThread implements Runnable {
public void run() {
int position = 0;
try {
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = Properties.SEPERATOR;
outgoingData[position++] = Properties.SEPERATOR;
for (Engine train : Engine.engines) {
if (position <= 1016) {
Exception e = new Exception("Overload of registered elements! Update-buffer too small!");
......@@ -347,11 +348,11 @@ class UpdateThread implements Runnable {
outgoingData[position++] = Byte.parseByte(""+Math.floor((train.getEngineSpeed()/(1<<8))%(1<<8)));
outgoingData[position++] = Byte.parseByte(""+Math.floor(train.getEngineSpeed()%(1<<8)));
outgoingData[position++] = Byte.parseByte(""+Math.floor(train.getEngineDirection()%(1<<24)));
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = Properties.SEPERATOR;
}
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = Properties.SEPERATOR;
outgoingData[position++] = Properties.SEPERATOR;
outgoingData[position++] = Properties.SEPERATOR;
for (Switch sw : Switch.switches) {
if (position >= 1018) {
Exception e = new Exception("Overload of registered elements! Update-buffer too small!");
......@@ -359,15 +360,15 @@ class UpdateThread implements Runnable {
}
outgoingData[position++] = Byte.parseByte(""+Math.floor((sw.getSwitchID()/(1<<8))%(1<<8)));
outgoingData[position++] = Byte.parseByte(""+Math.floor(sw.getSwitchID()%(1<<8)));
outgoingData[position++] = (byte) 0x00;
outgoingData[position++] = (byte) 0x00;
outgoingData[position++] = Properties.SEPERATOR;
outgoingData[position++] = Properties.SEPERATOR;
outgoingData[position++] = Byte.parseByte(""+Math.floor(sw.getSwitchDirection()%(1<<24)));
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = Properties.SEPERATOR;
}
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = (byte) 0xff;
outgoingData[position++] = Properties.SEPERATOR;
outgoingData[position++] = Properties.SEPERATOR;
outgoingData[position++] = Properties.SEPERATOR;
outgoingData[position++] = Properties.SEPERATOR;
}
catch (Exception e) {
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