ControlTerm - final

This commit is contained in:
SeekDaSky 2017-05-18 20:43:32 +02:00
parent 821808a420
commit c8da1b3ba6
6 changed files with 26 additions and 4 deletions

Binary file not shown.

View File

@ -167,6 +167,10 @@ public class ControlTerminal {
plane.setSpeed(data);
flags = (byte) (flags|0x04);
break;
default:
System.out.println("Wrong input please retry");
s.nextLine();
break;
}
}catch(Exception e){
System.out.println("Wrong input please retry");
@ -180,7 +184,7 @@ public class ControlTerminal {
break;
}
}
System.out.println("flags: "+flags);
container.setExpectedFlags(flags);
buf = ByteBuffer.allocate(27);
buf.put(flags);
buf.put(plane.toBytes());

View File

@ -98,7 +98,7 @@ public class Plane{
case 4:
if(this.isDead){
return "\033[4;37;41m ATTENTION: avion hors ligne\t|\033[0m";
}else if(this.speed<50){
}else if(this.speed<300){
return "\033[5;37;41m --Speed: "+this.speed+"\t\t\t|\033[0m";
}else{
return "\033[0m --Speed: "+this.speed+"\t\t\t|";

View File

@ -12,6 +12,7 @@ public class PlaneContainer {
private HashMap<String,Plane> map;
private AsynchronousDatagramSocket socket;
private Printer printer;
private byte expectedFlags = 0x01;
public PlaneContainer(){
this.map = new HashMap<String,Plane>();
@ -25,6 +26,10 @@ public class PlaneContainer {
this.printer = p;
}
public void setExpectedFlags(byte flags){
this.expectedFlags = flags;
}
public void notifyReceive() throws InvalidFlagException{
DatagramPacket packet = this.socket.synchronousReceive();
@ -41,6 +46,19 @@ public class PlaneContainer {
//System.out.println("Processing "+nbrPlane+" planes");
if(this.expectedFlags != flag){
System.out.println("\033[5;37;41m Plane could not apply data \033[0m");
if((flag&(byte)0x10) == 1){
System.out.println("\033[5;37;41m Plane crashed gracefully \033[0m");
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if(flag == 0){
//this is a ping response
return;

View File

@ -95,7 +95,7 @@ public class Plane {
case 4:
if(this.isDead){
return "\033[4;37;41m ATTENTION: avion hors ligne\t|\033[0m";
}else if(this.speed<50){
}else if(this.speed<300){
return "\033[5;37;41m --Speed: "+this.speed+"\t\t\t|\033[0m";
}else{
return "\033[0m --Speed: "+this.speed+"\t\t\t|";

Binary file not shown.