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

minor changes

parent 4ae0c32e
Branches
No related tags found
No related merge requests found
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
......@@ -6,7 +6,7 @@ public class Properties {
public final static int PORT = 23456;
// Setting ports and defining size of the buffers
public final static int IN_BUFFER_SIZE = 6; // First byte: start-byte, second and third byte: accessory-ID, fourth byte: command, fifth and sixth byte: potential parameters
public final static int IN_BUFFER_SIZE = 5; // First and second byte: accessory-ID, third byte: command, fourth and fifth byte: potential parameters
public final static int OUT_BUFFER_SIZE = 1024;
// Defining client-commands
......
......@@ -193,7 +193,8 @@ class ClientThread implements Runnable {
System.out.println("Conenction to client "+CLIENT.getRemoteSocketAddress()+" aborted!");
return;
}
else if (buffer == Properties.SEPERATOR) {
else if ((byte) buffer == (byte) Properties.SEPERATOR) {
System.out.println("New datagram starts!");
for (int i = 0; i < IN_BUFFER_SIZE; i++) {
buffer = IN_STREAM.read();
if (buffer == Properties.SESSION_ABORT) {
......@@ -235,7 +236,7 @@ class HandleThread implements Runnable {
public void run() {
try {
System.out.println(DatatypeConverter.printHexBinary(data));
switch (data[3]) {
switch (data[2]) {
case Properties.SYSTEM_STOP:
System.out.println("System stop");
//serverInstance.emergencyStop();
......@@ -250,16 +251,17 @@ class HandleThread implements Runnable {
break;
case Properties.ENGINE_SET_SPEED:
for (Engine train : Engine.engines) {
if (train.getEngineID() == data[1]<<8+data[2]) {
System.out.println(""+(((data[0]&0x7f)<<8)+(data[0]>>7)*(1<<16)+(data[1]&0x7f)+(data[1]>>7)*(1<<8))+" "+train.getEngineID());
if (train.getEngineID() == (((data[0]&0x7f)<<8)+(data[0]>>7)*(1<<16)+(data[1]&0x7f)+(data[1]>>7)*(1<<8))) {
System.out.println("Set engine speed");
//train.setEngineSpeed(data[4]<<8+data[5]);
//train.setEngineSpeed((((data[3]&0x7f)<<8)+(data[3]>>7)*(1<<16)+(data[4]&0x7f)+(data[4]>>7)*(1<<8)));
break;
}
}
break;
case Properties.ENGINE_INCREASE_SPEED:
for (Engine train : Engine.engines) {
if (train.getEngineID() == data[1]<<8+data[2]) {
if (train.getEngineID() == (((data[0]&0x7f)<<8)+(data[0]>>7)*(1<<16)+(data[1]&0x7f)+(data[1]>>7)*(1<<8))) {
System.out.println("Increase engine speed");
//train.increaseEngineSpeed();
break;
......@@ -268,7 +270,7 @@ class HandleThread implements Runnable {
break;
case Properties.ENGINE_DECREASE_SPEED:
for (Engine train : Engine.engines) {
if (train.getEngineID() == data[1]<<8+data[2]) {
if (train.getEngineID() == (((data[0]&0x7f)<<8)+(data[0]>>7)*(1<<16)+(data[1]&0x7f)+(data[1]>>7)*(1<<8))) {
System.out.println("Decrease engine speed");
//train.decreaseEngineSpeed();
break;
......@@ -277,34 +279,34 @@ class HandleThread implements Runnable {
break;
case Properties.ENGINE_SET_DIRECTION:
for (Engine train : Engine.engines) {
if (train.getEngineID() == data[1]<<8+data[2]) {
if (train.getEngineID() == (((data[0]&0x7f)<<8)+(data[0]>>7)*(1<<16)+(data[1]&0x7f)+(data[1]>>7)*(1<<8))) {
System.out.println("Set engine direction");
//train.setEngineDirection(data[4]);
//train.setEngineDirection(data[3]);
break;
}
}
break;
case Properties.ENGINE_SWITCH_DIRECTION:
for (Engine train : Engine.engines) {
if (train.getEngineID() == data[1]<<8+data[2]) {
if (train.getEngineID() == (((data[0]&0x7f)<<8)+(data[0]>>7)*(1<<16)+(data[1]&0x7f)+(data[1]>>7)*(1<<8))) {
System.out.println("Switch engine direction");
//train.setEngineDirection(3);
break;
}
}
break;
case (byte) Properties.SWITCH_SET_DIRECTION:
case Properties.SWITCH_SET_DIRECTION:
for (Switch sw : Switch.switches) {
if (sw.getSwitchID() == data[1]<<8+data[2]) {
if (sw.getSwitchID() == (((data[0]&0x7f)<<8)+(data[0]>>7)*(1<<16)+(data[1]&0x7f)+(data[1]>>7)*(1<<8))) {
System.out.println("Set switch direction");
//sw.setSwitchDirection(data[4]);
//sw.setSwitchDirection(data[3]);
break;
}
break;
}
case Properties.SWITCH_SWITCH_DIRECTION:
for (Switch sw : Switch.switches) {
if (sw.getSwitchID() == data[1]<<8+data[2]) {
if (sw.getSwitchID() == (((data[0]&0x7f)<<8)+(data[0]>>7)*(1<<16)+(data[1]&0x7f)+(data[1]>>7)*(1<<8))) {
System.out.println("Switch switch direction");
//sw.changeSwitchDirection();
break;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment