ControlTerm - final
This commit is contained in:
parent
821808a420
commit
c8da1b3ba6
Binary file not shown.
|
@ -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());
|
||||
|
|
|
@ -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|";
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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.
Loading…
Reference in New Issue