diff --git a/command-terminal/CommandTerminal/build.xml b/command-terminal/CommandTerminal/build.xml deleted file mode 100644 index e14409b..0000000 --- a/command-terminal/CommandTerminal/build.xml +++ /dev/null @@ -1,73 +0,0 @@ - - - - - - - - - - - Builds, tests, and runs the project CommandTerminal. - - - diff --git a/command-terminal/CommandTerminal/manifest.mf b/command-terminal/CommandTerminal/manifest.mf deleted file mode 100644 index 328e8e5..0000000 --- a/command-terminal/CommandTerminal/manifest.mf +++ /dev/null @@ -1,3 +0,0 @@ -Manifest-Version: 1.0 -X-COMMENT: Main-Class will be added automatically by build - diff --git a/command-terminal/CommandTerminal/nbproject/build-impl.xml b/command-terminal/CommandTerminal/nbproject/build-impl.xml deleted file mode 100644 index c50f26c..0000000 --- a/command-terminal/CommandTerminal/nbproject/build-impl.xml +++ /dev/null @@ -1,1413 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set src.dir - Must set test.src.dir - Must set build.dir - Must set dist.dir - Must set build.classes.dir - Must set dist.javadoc.dir - Must set build.test.classes.dir - Must set build.test.results.dir - Must set build.classes.excludes - Must set dist.jar - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - No tests executed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must set JVM to use for profiling in profiler.info.jvm - Must set profiler agent JVM arguments in profiler.info.jvmargs.agent - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - To run this application from the command line without Ant, try: - - java -jar "${dist.jar.resolved}" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - Must select one file in the IDE or set run.class - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set debug.class - - - - - Must select one file in the IDE or set debug.class - - - - - Must set fix.includes - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - Must select one file in the IDE or set profile.class - This target only works when run from inside the NetBeans IDE. - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - This target only works when run from inside the NetBeans IDE. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select one file in the IDE or set run.class - - - - - - Must select some files in the IDE or set test.includes - - - - - Must select one file in the IDE or set run.class - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Must select some files in the IDE or set javac.includes - - - - - - - - - - - - - - - - - - - - Some tests failed; see details above. - - - - - - - - - Must select some files in the IDE or set test.includes - - - - Some tests failed; see details above. - - - - Must select some files in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - Some tests failed; see details above. - - - - - Must select one file in the IDE or set test.class - - - - Must select one file in the IDE or set test.class - Must select some method in the IDE or set test.method - - - - - - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - Must select one file in the IDE or set applet.url - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/command-terminal/CommandTerminal/nbproject/genfiles.properties b/command-terminal/CommandTerminal/nbproject/genfiles.properties deleted file mode 100644 index b22b9e6..0000000 --- a/command-terminal/CommandTerminal/nbproject/genfiles.properties +++ /dev/null @@ -1,8 +0,0 @@ -build.xml.data.CRC32=fdad8e2e -build.xml.script.CRC32=1cd81838 -build.xml.stylesheet.CRC32=8064a381@1.74.1.48 -# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. -# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. -nbproject/build-impl.xml.data.CRC32=fdad8e2e -nbproject/build-impl.xml.script.CRC32=95faf5a3 -nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.74.1.48 diff --git a/command-terminal/CommandTerminal/nbproject/project.properties b/command-terminal/CommandTerminal/nbproject/project.properties deleted file mode 100644 index 9645bed..0000000 --- a/command-terminal/CommandTerminal/nbproject/project.properties +++ /dev/null @@ -1,73 +0,0 @@ -annotation.processing.enabled=true -annotation.processing.enabled.in.editor=false -annotation.processing.processor.options= -annotation.processing.processors.list= -annotation.processing.run.all.processors=true -annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output -build.classes.dir=${build.dir}/classes -build.classes.excludes=**/*.java,**/*.form -# This directory is removed when the project is cleaned: -build.dir=build -build.generated.dir=${build.dir}/generated -build.generated.sources.dir=${build.dir}/generated-sources -# Only compile against the classpath explicitly listed here: -build.sysclasspath=ignore -build.test.classes.dir=${build.dir}/test/classes -build.test.results.dir=${build.dir}/test/results -# Uncomment to specify the preferred debugger connection transport: -#debug.transport=dt_socket -debug.classpath=\ - ${run.classpath} -debug.test.classpath=\ - ${run.test.classpath} -# Files in build.classes.dir which should be excluded from distribution jar -dist.archive.excludes= -# This directory is removed when the project is cleaned: -dist.dir=dist -dist.jar=${dist.dir}/CommandTerminal.jar -dist.javadoc.dir=${dist.dir}/javadoc -excludes= -includes=** -jar.compress=false -javac.classpath= -# Space-separated list of extra javac options -javac.compilerargs= -javac.deprecation=false -javac.processorpath=\ - ${javac.classpath} -javac.source=1.8 -javac.target=1.8 -javac.test.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -javac.test.processorpath=\ - ${javac.test.classpath} -javadoc.additionalparam= -javadoc.author=false -javadoc.encoding=${source.encoding} -javadoc.noindex=false -javadoc.nonavbar=false -javadoc.notree=false -javadoc.private=false -javadoc.splitindex=true -javadoc.use=true -javadoc.version=false -javadoc.windowtitle= -main.class=commandterminal.CommandTerminal -manifest.file=manifest.mf -meta.inf.dir=${src.dir}/META-INF -mkdist.disabled=false -platform.active=default_platform -run.classpath=\ - ${javac.classpath}:\ - ${build.classes.dir} -# Space-separated list of JVM arguments used when running the project. -# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value. -# To set system properties for unit tests define test-sys-prop.name=value: -run.jvmargs= -run.test.classpath=\ - ${javac.test.classpath}:\ - ${build.test.classes.dir} -source.encoding=UTF-8 -src.dir=src -test.src.dir=test diff --git a/command-terminal/CommandTerminal/nbproject/project.xml b/command-terminal/CommandTerminal/nbproject/project.xml deleted file mode 100644 index 30bb371..0000000 --- a/command-terminal/CommandTerminal/nbproject/project.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - org.netbeans.modules.java.j2seproject - - - CommandTerminal - - - - - - - - - diff --git a/command-terminal/CommandTerminal/src/commandterminal/CommandTerminal.java b/command-terminal/CommandTerminal/src/commandterminal/CommandTerminal.java deleted file mode 100644 index 013377a..0000000 --- a/command-terminal/CommandTerminal/src/commandterminal/CommandTerminal.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -package commandterminal; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.InetAddress; -import java.net.SocketException; -import java.net.UnknownHostException; -import java.nio.ByteBuffer; - -/** - * - * @author lmascaro - */ -public class CommandTerminal { - - private final static int SGCA_MULTICAST_PORT = 4446; - private final static String SCGA_MULTICAST_ADDRESS = "224.0.0.3"; - - /** - * @param args the command line arguments - */ - public static void main(String[] args){ - - /* - * Handshake - */ - - try { - DatagramSocket socket = new DatagramSocket(); - ByteBuffer buf = ByteBuffer.allocate(21); - buf.clear(); - buf.put((byte)(0x01|0x02)); - - DatagramPacket payload = new DatagramPacket(buf.array(),buf.array().length,InetAddress.getByName(SCGA_MULTICAST_ADDRESS),SGCA_MULTICAST_PORT); - socket.send(payload); - - socket.receive(payload); - - buf = ByteBuffer.wrap(payload.getData()); - - if(buf.get() == 3){ - System.out.println("--Connection request successful"); - byte address[] = new byte[15]; - buf = buf.get(address,0,15); - String addressString = new String(address); - InetAddress sgcaAddress = InetAddress.getByName(addressString); - //emulate an unsigned short - char cast = buf.getChar(); - int port = (int) cast; - System.out.println("----Address : "+sgcaAddress.getHostAddress()); - System.out.println("----Port : "+port); - } - - } catch ( IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - - } - -} diff --git a/command-terminal/CommandTerminal/src/commandterminal/OpCode.java b/command-terminal/CommandTerminal/src/commandterminal/OpCode.java deleted file mode 100644 index 3183b8c..0000000 --- a/command-terminal/CommandTerminal/src/commandterminal/OpCode.java +++ /dev/null @@ -1,20 +0,0 @@ -/* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. - */ - -package commandterminal; - -/** - * - * @author lmascaro - */ -public enum OpCode { - ISALIVE, - CAP, - ALT, - SPEED, - SUCCESS, - ERROR -} diff --git a/command-terminal/commandTerm.jar b/command-terminal/commandTerm.jar new file mode 100644 index 0000000..dc9885c Binary files /dev/null and b/command-terminal/commandTerm.jar differ diff --git a/command-terminal/CommandTerminal/src/DatagramSocket/AsynchronousDatagramSocket.java b/viewer-terminal/src/DatagramSocket/AsynchronousDatagramSocket.java similarity index 63% rename from command-terminal/CommandTerminal/src/DatagramSocket/AsynchronousDatagramSocket.java rename to viewer-terminal/src/DatagramSocket/AsynchronousDatagramSocket.java index 86f45e3..c112bad 100644 --- a/command-terminal/CommandTerminal/src/DatagramSocket/AsynchronousDatagramSocket.java +++ b/viewer-terminal/src/DatagramSocket/AsynchronousDatagramSocket.java @@ -13,16 +13,20 @@ import java.net.SocketException; import java.util.logging.Level; import java.util.logging.Logger; +import ViewTerminal.InvalidFlagException; +import ViewTerminal.PlaneContainer; + /** * * @author lmascaro */ public class AsynchronousDatagramSocket implements Runnable, AutoCloseable{ - private final static int MAX_MESSAGE_SIZE = 300; + public final static int MAX_MESSAGE_SIZE = 300; private SynchronizedBuffer buf; private DatagramSocket socket; + private PlaneContainer container; public AsynchronousDatagramSocket() throws SocketException{ this.buf = new SynchronizedBuffer<>(); @@ -36,6 +40,10 @@ public class AsynchronousDatagramSocket implements Runnable, AutoCloseable{ new Thread(this).start(); } + public void bindContainer(PlaneContainer c){ + this.container = c; + } + public void send(DatagramPacket dp) throws IOException{ this.socket.send(dp); } @@ -49,8 +57,8 @@ public class AsynchronousDatagramSocket implements Runnable, AutoCloseable{ } } - public void synchronousReceive(DatagramPacket dp){ - dp = this.buf.removeElement(true); + public DatagramPacket synchronousReceive(){ + return this.buf.removeElement(true); } public boolean available(){ @@ -64,12 +72,18 @@ public class AsynchronousDatagramSocket implements Runnable, AutoCloseable{ @Override public void run() { - DatagramPacket packet = new DatagramPacket(new byte[MAX_MESSAGE_SIZE],MAX_MESSAGE_SIZE); - try { - this.socket.receive(packet); - this.buf.addElement(packet); - } catch (IOException ex) { - Logger.getLogger(AsynchronousDatagramSocket.class.getName()).log(Level.SEVERE, null, ex); + DatagramPacket packet; + while(true){ + packet = new DatagramPacket(new byte[MAX_MESSAGE_SIZE],MAX_MESSAGE_SIZE); + try { + this.socket.receive(packet); + this.buf.addElement(packet); + this.container.notifyReceive(); + } catch (IOException ex) { + Logger.getLogger(AsynchronousDatagramSocket.class.getName()).log(Level.SEVERE, null, ex); + } catch (InvalidFlagException e) { + System.out.println("\033[01;31m Unexpected flag received \033[0m"); + } } } } diff --git a/command-terminal/CommandTerminal/src/DatagramSocket/SynchronizedBuffer.java b/viewer-terminal/src/DatagramSocket/SynchronizedBuffer.java similarity index 100% rename from command-terminal/CommandTerminal/src/DatagramSocket/SynchronizedBuffer.java rename to viewer-terminal/src/DatagramSocket/SynchronizedBuffer.java diff --git a/viewer-terminal/src/ViewTerminal/InvalidFlagException.java b/viewer-terminal/src/ViewTerminal/InvalidFlagException.java new file mode 100644 index 0000000..e4fbc91 --- /dev/null +++ b/viewer-terminal/src/ViewTerminal/InvalidFlagException.java @@ -0,0 +1,18 @@ +package ViewTerminal; + +public class InvalidFlagException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public InvalidFlagException(){ + super(); + } + + public InvalidFlagException(String message){ + super(message); + } + +} diff --git a/viewer-terminal/src/ViewTerminal/Plane.java b/viewer-terminal/src/ViewTerminal/Plane.java new file mode 100644 index 0000000..0e11ede --- /dev/null +++ b/viewer-terminal/src/ViewTerminal/Plane.java @@ -0,0 +1,108 @@ +package ViewTerminal; + +public class Plane { + + private String code; + private int x; + private int y; + private int z; + private int cap; + private int speed; + + private boolean isDead; + + public Plane(String code,int x, int y, int z, int cap, int speed){ + this.code = code; + this.x = x; + this.y = y; + this.z = z; + this.cap = cap; + this.speed = speed; + this.isDead = false; + } + + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public int getX() { + return x; + } + + public void setX(int x) { + this.x = x; + } + + public int getY() { + return y; + } + + public void setY(int y) { + this.y = y; + } + + public int getZ() { + return z; + } + + public void setZ(int z) { + this.z = z; + } + + public int getCap() { + return cap; + } + + public boolean isDead(){ + return this.isDead; + } + + public void setCap(int cap) { + this.cap = cap; + } + + public int getSpeed() { + return speed; + } + + public void setSpeed(int speed) { + this.speed = speed; + } + + //Die Motherfucker + public void die(){ + this.isDead = true; + } + + public String getLine(int i){ + switch(i){ + case 0: + return "--------------------------------"; + case 1: + if(this.isDead){ + return "\033[4;37;41m Code: "+this.code+"\t\t\t|"; + }else{ + return "\033[4;37;42m Code: "+this.code+"\t\t\t|"; + } + case 2: + return "\033[0m --Coords: {"+this.x+";"+this.y+";"+this.z+"} \t|"; + case 3: + return "\033[0m --Cap: "+this.cap+"\t\t\t|"; + case 4: + if(this.isDead){ + return "\033[4;37;41m ATTENTION: avion hors ligne\t|\033[0m"; + }else if(this.speed<50){ + return "\033[5;37;41m --Speed: "+this.speed+"\t\t\t|\033[0m"; + }else{ + return "\033[0m --Speed: "+this.speed+"\t\t\t|"; + } + default: + return ""; + } + } + +} diff --git a/viewer-terminal/src/ViewTerminal/PlaneContainer.java b/viewer-terminal/src/ViewTerminal/PlaneContainer.java new file mode 100644 index 0000000..98740f5 --- /dev/null +++ b/viewer-terminal/src/ViewTerminal/PlaneContainer.java @@ -0,0 +1,88 @@ +package ViewTerminal; + +import java.net.DatagramPacket; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashMap; + +import DatagramSocket.AsynchronousDatagramSocket; + +public class PlaneContainer { + + private HashMap map; + private AsynchronousDatagramSocket socket; + private Printer printer; + + public PlaneContainer(){ + this.map = new HashMap(); + } + + public void bindSocket(AsynchronousDatagramSocket s){ + this.socket = s; + } + + public void bindPrinter(Printer p){ + this.printer = p; + } + + public void notifyReceive() throws InvalidFlagException{ + DatagramPacket packet = this.socket.synchronousReceive(); + + ByteBuffer buf = ByteBuffer.wrap(packet.getData()); + + byte flag; + byte nbrPlane; + ArrayList codes; + + flag = buf.get(); + nbrPlane = buf.get(); + + codes = new ArrayList(nbrPlane); + + //System.out.println("Processing "+nbrPlane+" planes"); + + if(flag != 1){ + throw new InvalidFlagException("Flag is not a feedback flag :"+flag); + }else{ + String code; + byte rawCode[] = new byte[5]; + Plane plane; + for(int i = 0;i getMap(){ + return this.map; + } +} diff --git a/viewer-terminal/src/ViewTerminal/Printer.java b/viewer-terminal/src/ViewTerminal/Printer.java new file mode 100644 index 0000000..2dd779b --- /dev/null +++ b/viewer-terminal/src/ViewTerminal/Printer.java @@ -0,0 +1,53 @@ +package ViewTerminal; + +import java.util.HashMap; + +public class Printer { + + private PlaneContainer container; + + public Printer(){ + + } + + public void bindContainer(PlaneContainer c){ + this.container = c; + } + + public void notifyReceive(){ + System.out.println("\033[2J \033[H"); + HashMap map = this.container.getMap(); + int i = 0; + + String lines[] = new String[5]; + for(int k = 0;k<5;k++){ + lines[k] = ""; + } + + if(map.keySet().size() == 0){ + System.out.println("\033[37;43m Aucun avion connecté au système \033[0m"); + }else{ + for(String code : map.keySet()){ + if(i <= 1){ + for(int k = 0;k<5;k++){ + lines[k] += map.get(code).getLine(k); + } + i++; + }else{ + for(int k = 0;k<5;k++){ + System.out.println(lines[k]); + lines[k] = ""; + } + for(int k = 0;k<5;k++){ + lines[k] += map.get(code).getLine(k); + } + i=1; + } + } + for(int k = 0;k<5;k++){ + System.out.println(lines[k]); + } + } + + } +} diff --git a/viewer-terminal/src/ViewTerminal/ViewTerminal.java b/viewer-terminal/src/ViewTerminal/ViewTerminal.java new file mode 100644 index 0000000..74f1a29 --- /dev/null +++ b/viewer-terminal/src/ViewTerminal/ViewTerminal.java @@ -0,0 +1,102 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package ViewTerminal; + +import java.io.IOException; +import java.net.DatagramPacket; +import java.net.DatagramSocket; +import java.net.InetAddress; +import java.net.SocketException; +import java.net.UnknownHostException; +import java.nio.ByteBuffer; + +import DatagramSocket.AsynchronousDatagramSocket; + +/** + * + * @author lmascaro + */ +public class ViewTerminal { + + private final static int SGCA_MULTICAST_PORT = 4445; + private final static String SCGA_MULTICAST_ADDRESS = "224.0.0.2"; + + /** + * @param args the command line arguments + */ + public static void main(String[] args){ + System.out.println("\033[2J"); + + /* + * Handshake + */ + int port = 0; + String addressString = "0.0.0.0"; + + try { + DatagramSocket socket = new DatagramSocket(); + ByteBuffer buf = ByteBuffer.allocate(21); + buf.clear(); + buf.put((byte)(0x01)); + + DatagramPacket payload = new DatagramPacket(buf.array(),buf.array().length,InetAddress.getByName(SCGA_MULTICAST_ADDRESS),SGCA_MULTICAST_PORT); + socket.send(payload); + + socket.receive(payload); + + buf = ByteBuffer.wrap(payload.getData()); + if(buf.get() == 1){ + System.out.println("--Connection request successful"); + byte address[] = new byte[4]; + buf = buf.get(address,0,4); + InetAddress addressObj = InetAddress.getByAddress(address); + addressString = addressObj.getHostAddress(); + //emulate an unsigned short + char cast = buf.getChar(); + port = (int) cast; + System.out.println("----Address : "+addressString); + System.out.println("----Port : "+port); + } + + } catch ( IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return; + } + + /* + * Opening final socket + */ + try { + //create all objects + AsynchronousDatagramSocket socket = new AsynchronousDatagramSocket(); + PlaneContainer container = new PlaneContainer(); + Printer printer = new Printer(); + + //bind them + socket.bindContainer(container); + container.bindPrinter(printer); + container.bindSocket(socket); + printer.bindContainer(container); + + //send first packet + DatagramPacket p = new DatagramPacket(new byte[13],13,InetAddress.getByName(addressString),port); + socket.send(p); + + //now we let the objects do the job + while(true){ + + } + + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + +} diff --git a/viewer-terminal/viewTerm.jar b/viewer-terminal/viewTerm.jar index a1b6ac6..af0702d 100644 Binary files a/viewer-terminal/viewTerm.jar and b/viewer-terminal/viewTerm.jar differ