From 818ceef8df5b0421f69a22ef6b3846613fb9d97c Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Tue, 16 May 2017 21:10:51 +0200 Subject: [PATCH] cleaned repo for prod --- Makefile | 4 +- ctrlTerm/c-emul/main.c | 524 ------------------ ctrlTerm/{commandTerm.jar => ctrlTerm.jar} | Bin .../src/ControlTerminal/ControlTerminal.java | 204 ------- .../ControlTerminal/InvalidFlagException.java | 18 - ctrlTerm/src/ControlTerminal/Pinger.java | 46 -- ctrlTerm/src/ControlTerminal/Plane.java | 125 ----- .../src/ControlTerminal/PlaneContainer.java | 91 --- ctrlTerm/src/ControlTerminal/Printer.java | 54 -- .../AsynchronousDatagramSocket.java | 89 --- .../DatagramSocket/SynchronizedBuffer.java | 46 -- plane/lib/network/udp/client.c | 46 -- plane/lib/network/udp/client.h | 50 -- sgca/install/install.sh | 21 - sgca/install/sgca.service | 10 - sgca/install/uninstall.sh | 15 - .../AsynchronousDatagramSocket.java | 89 --- .../DatagramSocket/SynchronizedBuffer.java | 46 -- .../ViewTerminal/InvalidFlagException.java | 18 - viewTerm/src/ViewTerminal/Plane.java | 108 ---- viewTerm/src/ViewTerminal/PlaneContainer.java | 98 ---- viewTerm/src/ViewTerminal/Printer.java | 53 -- viewTerm/src/ViewTerminal/ViewTerminal.java | 102 ---- 23 files changed, 2 insertions(+), 1855 deletions(-) delete mode 100644 ctrlTerm/c-emul/main.c rename ctrlTerm/{commandTerm.jar => ctrlTerm.jar} (100%) delete mode 100644 ctrlTerm/src/ControlTerminal/ControlTerminal.java delete mode 100644 ctrlTerm/src/ControlTerminal/InvalidFlagException.java delete mode 100644 ctrlTerm/src/ControlTerminal/Pinger.java delete mode 100644 ctrlTerm/src/ControlTerminal/Plane.java delete mode 100644 ctrlTerm/src/ControlTerminal/PlaneContainer.java delete mode 100644 ctrlTerm/src/ControlTerminal/Printer.java delete mode 100644 ctrlTerm/src/DatagramSocket/AsynchronousDatagramSocket.java delete mode 100644 ctrlTerm/src/DatagramSocket/SynchronizedBuffer.java delete mode 100644 plane/lib/network/udp/client.c delete mode 100644 plane/lib/network/udp/client.h delete mode 100755 sgca/install/install.sh delete mode 100644 sgca/install/sgca.service delete mode 100755 sgca/install/uninstall.sh delete mode 100644 viewTerm/src/DatagramSocket/AsynchronousDatagramSocket.java delete mode 100644 viewTerm/src/DatagramSocket/SynchronizedBuffer.java delete mode 100644 viewTerm/src/ViewTerminal/InvalidFlagException.java delete mode 100644 viewTerm/src/ViewTerminal/Plane.java delete mode 100644 viewTerm/src/ViewTerminal/PlaneContainer.java delete mode 100644 viewTerm/src/ViewTerminal/Printer.java delete mode 100644 viewTerm/src/ViewTerminal/ViewTerminal.java diff --git a/Makefile b/Makefile index 7eeb330..fbaf220 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ link-viewTerm: link-ctrlTerm: @echo "(5) Linking CTRL TERMINAL executable"; - @echo -e "#!/bin/bash\n\njava -jar ./ctrlTerm/commandTerm.jar;\n" > ./x-ctrlTerm; + @echo -e "#!/bin/bash\n\njava -jar ./ctrlTerm/ctrlTerm.jar;\n" > ./x-ctrlTerm; @chmod ug+x ./x-ctrlTerm; @@ -44,4 +44,4 @@ clean: @find ./x-viewTerm > /dev/null 2>&1 && rm ./x-viewTerm || return 0; @find ./x-ctrlTerm > /dev/null 2>&1 && rm ./x-ctrlTerm || return 0; @make clean --directory=./sgca > /dev/null; - @make clean --directory=./plane > /dev/null; \ No newline at end of file + @make clean --directory=./plane > /dev/null; diff --git a/ctrlTerm/c-emul/main.c b/ctrlTerm/c-emul/main.c deleted file mode 100644 index bedfb5d..0000000 --- a/ctrlTerm/c-emul/main.c +++ /dev/null @@ -1,524 +0,0 @@ -#include -#include -#include -#include -#include -#include // close -#include -#include // getaddrinfo, getnameinfo -#include - - -#define TERMREQ_FBK 0x01 -#define TERMREQ_CAP 0x02 -#define TERMREQ_SPD 0x04 -#define TERMREQ_ALT 0x08 - -#define PLANE_LEN ( sizeof(char)*6+sizeof(int)*5 ) -struct plane{ - char code[6]; - int x; - int y; - int z; - int cap; - int spd; - char online; -}; - -struct plane_update{ - char flags; - int z; - int cap; - int spd; - char done; -}; - -#define TERMREQ_LEN ( sizeof(char)+PLANE_LEN ) -struct term_req{ - char flags; - struct plane update; -}; - -struct term_res{ - char flags; - char n; - struct plane* data; -}; - - -#define BINDHDR_LEN ( sizeof(char)+sizeof(in_addr_t)+sizeof(unsigned short) ) -#define BINDHEAD_UDP 0x01 // is terminal (ask for UDP socket) -#define BINDHEAD_TCP 0x02 // is plane (ask for TCP socket) -#define BINDHEAD_CTL 0x04 // is ctrlTerm (else: viewTerm) - -struct bind_header{ - char flags; - in_addr_t addr; - unsigned short port; -}; - - - - -int main(int argc, char* argv[]){ - - socklen_t len; - int msocket, csocket; - struct sockaddr_in mcast, server; - char buffer[512]; - struct bind_header bh; - struct in_addr ip; - struct term_req tr; - struct term_res trs; - int i, nb; - struct plane tmp; - int count, last; - - strcpy(tmp.code, "\0"); - - /************************************************ - **** DEMANDE MULTICAST **** - ************************************************/ - printf("\n\nDEMANDE MCAST\n=============\n"); - if( 1 ){ - - /* [1] Initialisation socket - =========================================================*/ - /* 1. Création socket */ - msocket = socket(AF_INET, SOCK_DGRAM, 0); - - if( msocket == -1 ) - return EXIT_FAILURE; - - /* 2. Reset des valeurs */ - bzero(&mcast, sizeof(struct sockaddr_in)); - - /* 3. On définit les infos */ - mcast.sin_family = AF_INET; - mcast.sin_port = htons(4446); - mcast.sin_addr.s_addr = inet_addr("224.0.0.3"); - - - /* [2] On demande une socket de communication - =========================================================*/ - /* 1. Création de la requête */ - len = sizeof(struct sockaddr_in); - if( sendto(msocket, "\5\1\2\3\4\0\1", sizeof(char)*7, 0, (struct sockaddr*) &mcast, len) < 0 ){ - printf("cannot send multicast message.\n"); - return EXIT_FAILURE; - } - - /* [3] On récupère la réponse - =========================================================*/ - /* 1. On récupère la réponse */ - if( recvfrom(msocket, buffer, 512, 0, (struct sockaddr*) &mcast, &len) < BINDHDR_LEN ){ - printf("cannot receive multicast response.\n"); - return EXIT_FAILURE; - } - - /* 2. On parse la réponse */ - memcpy(&bh.flags, buffer, sizeof(char)); - memcpy(&bh.addr, buffer+sizeof(char), sizeof(in_addr_t)); - memcpy(&bh.port, buffer+sizeof(char)+sizeof(in_addr_t), sizeof(unsigned short)); - // bh.addr = ntohl(bh.addr); - bh.port = ntohs(bh.port); - ip.s_addr = bh.addr; - printf("Received: { flags: %d, addr: %x/'%s', port: %d}\n", bh.flags, bh.addr, inet_ntoa(ip), bh.port); - - close(msocket); - - } - - - - - - /************************************************ - **** CONNECTION UDP **** - ************************************************/ - printf("\n\nCONNECTION UDP\n==============\n"); - if( 1 ){ - - /* [1] Initialisation socket - =========================================================*/ - /* 1. Création socket */ - csocket = socket(AF_INET, SOCK_DGRAM, 0); - - if( csocket == -1 ) - return EXIT_FAILURE; - - /* 2. Reset des valeurs */ - bzero(&server, sizeof(struct sockaddr_in)); - - /* 3. On définit les infos */ - server.sin_family = AF_INET; - server.sin_port = htons(bh.port); - server.sin_addr.s_addr = ip.s_addr; - - - /* [2] Initialisation de la connexion - =========================================================*/ - if( sendto(csocket, "0", 1, 0, (struct sockaddr*) &server, len) < 0 ){ - printf("Cannot send message through command socket.\n"); - return EXIT_FAILURE; - } - printf("Connected to UDP socket\n"); - - } - - - sleep(1); - - - - /************************************************ - **** DEMANDE INFO CLASSIQUE **** - ************************************************/ - if( 1 ){ - printf("\n\nDEMANDE DES DONNEES UNIQUEMENT\n==============================\n"); - - /* [1] Preparing request - =========================================================*/ - tr.flags = TERMREQ_FBK; - strcpy(tr.update.code, "CODE1"); - tr.update.x = 1; - tr.update.y = 2; - tr.update.z = 3; - tr.update.cap = 4; - tr.update.spd = 5; - printf("Sending { flags: %d; plane: #%s { z=%d; cap=%d; speed=%d} }\n", tr.flags, tr.update.code, tr.update.z, tr.update.cap, tr.update.spd); - - tr.update.x = htonl(tr.update.x); - tr.update.y = htonl(tr.update.y); - tr.update.z = htonl(tr.update.z); - tr.update.cap = htonl(tr.update.cap); - tr.update.spd = htonl(tr.update.spd); - - /* [2] Filling buffer - =========================================================*/ - bzero(buffer, 512); - memcpy(buffer+sizeof(char)*0+sizeof(int)*0, &tr.flags, sizeof(char)); - memcpy(buffer+sizeof(char)*1+sizeof(int)*0, &tr.update.code, sizeof(char)*6); - memcpy(buffer+sizeof(char)*7+sizeof(int)*0, &tr.update.x, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*1, &tr.update.y, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*2, &tr.update.z, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*3, &tr.update.cap, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*4, &tr.update.spd, sizeof(int)); - - - /* [3] Sending request - =========================================================*/ - if( sendto(csocket, buffer, 7+sizeof(int)*5+1, 0, (struct sockaddr*) &server, len) < 0 ){ - printf("Cannot ask for simple data.\n"); - return EXIT_FAILURE; - } - - /* [4] Fetch & print data - =========================================================*/ - /* 1. On récupère la réponse */ - len = sizeof(struct sockaddr_in); - nb = recvfrom(csocket, buffer, 512, 0, (struct sockaddr*) &server, &len); - - printf("%d bytes received\n", nb); - - if( nb < 2 ){ - printf("Error receiving simple data.\n"); - return EXIT_FAILURE; - } - - /* 2. On parse la réponse */ - count = 0; last = sizeof(char); memcpy(&trs.flags, buffer+count, last); - count += last; last = sizeof(char); memcpy(&trs.n, buffer+count, last); - - trs.data = malloc( sizeof(struct plane) * trs.n ); - - - for( i = 0 ; i < trs.n ; i++ ){ - count += last; last = sizeof(char)*6; memcpy(&trs.data[i].code, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].x, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].y, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].z, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].cap, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].spd, buffer+count, last); - - trs.data[i].x = ntohl(trs.data[i].x); - trs.data[i].y = ntohl(trs.data[i].y); - trs.data[i].z = ntohl(trs.data[i].z); - trs.data[i].cap = ntohl(trs.data[i].cap); - trs.data[i].spd = ntohl(trs.data[i].spd); - - printf("Plane[%s@%d] { (%d,%d,%d), cap: %d, spd: %d}\n", trs.data[i].code, i, trs.data[i].x, trs.data[i].y, trs.data[i].z, trs.data[i].cap, trs.data[i].spd); - } - - if( trs.n > 0 ) - memcpy(&tmp, &trs.data[0], sizeof(struct plane)); - - - } - - - sleep(1); - - /************************************************ - **** DEMANDE MISE A JOUR SIMPLE **** - ************************************************/ - if( 1 ){ - printf("\n\nDEMANDE D'UPDATE SIMPLE\n=======================\n"); - - if( trs.n < 1 ){ - printf("No plane to update.\n"); - return EXIT_FAILURE; - } - - - /* [1] Preparing request - =========================================================*/ - tr.flags = TERMREQ_SPD; - memcpy(&tr.update, &tmp, sizeof(struct plane)); - tr.update.spd = 1000; - - printf("Update req { flags: %d; plane: #%s { z=%d; cap=%d; speed=%d} }\n", tr.flags, tr.update.code, tr.update.z, tr.update.cap, tr.update.spd); - tr.update.x = htonl(tr.update.x); - tr.update.y = htonl(tr.update.y); - tr.update.z = htonl(tr.update.z); - tr.update.cap = htonl(tr.update.cap); - tr.update.spd = htonl(tr.update.spd); - - /* [2] Filling buffer - =========================================================*/ - bzero(buffer, 512); - memcpy(buffer+sizeof(char)*0+sizeof(int)*0, &tr.flags, sizeof(char)); - memcpy(buffer+sizeof(char)*1+sizeof(int)*0, &tr.update.code, sizeof(char)*6); - memcpy(buffer+sizeof(char)*7+sizeof(int)*0, &tr.update.x, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*1, &tr.update.y, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*2, &tr.update.z, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*3, &tr.update.cap, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*4, &tr.update.spd, sizeof(int)); - - - /* [3] Sending request - =========================================================*/ - if( sendto(csocket, buffer, 7+sizeof(int)*5+1, 0, (struct sockaddr*) &server, len) < 0 ){ - printf("Cannot ask for simple update.\n"); - return EXIT_FAILURE; - } - - /* [4] Fetch & print data - =========================================================*/ - /* 1. On récupère la réponse */ - len = sizeof(struct sockaddr_in); - nb = recvfrom(csocket, buffer, 512, 0, (struct sockaddr*) &server, &len); - - printf("%d bytes received\n", nb); - - if( nb < 1 ){ - printf("Error receiving simple update.\n"); - return EXIT_FAILURE; - } - - - /* 2. On parse la réponse */ - count = 0; last = sizeof(char); memcpy(&trs.flags, buffer+count, last); - count += last; last = sizeof(char); memcpy(&trs.n, buffer+count, last); - printf("Flag received : %d\n", trs.flags); - - trs.data = malloc( sizeof(struct plane) * trs.n ); - - - for( i = 0 ; i < trs.n ; i++ ){ - count += last; last = sizeof(char)*6; memcpy(&trs.data[i].code, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].x, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].y, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].z, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].cap, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].spd, buffer+count, last); - - trs.data[i].x = ntohl(trs.data[i].x); - trs.data[i].y = ntohl(trs.data[i].y); - trs.data[i].z = ntohl(trs.data[i].z); - trs.data[i].cap = ntohl(trs.data[i].cap); - trs.data[i].spd = ntohl(trs.data[i].spd); - - printf("Plane[%s@%d] { (%d,%d,%d), cap: %d, spd: %d}\n", trs.data[i].code, i, trs.data[i].x, trs.data[i].y, trs.data[i].z, trs.data[i].cap, trs.data[i].spd); - } - - - } - - - sleep(1); - - /************************************************ - **** DEMANDE MISE A JOUR SIMPLE + DATA **** - ************************************************/ - if( 1 ){ - printf("\n\nDEMANDE D'UPDATE SIMPLE + DATA\n==============================\n"); - - - - /* [1] Preparing request - =========================================================*/ - tr.flags = TERMREQ_FBK|TERMREQ_ALT; - memcpy(&tr.update, &tmp, sizeof(struct plane)); - tr.update.z = 500; - - printf("Update req { flags: %d; plane: #%s { z=%d; cap=%d; speed=%d} }\n", tr.flags, tr.update.code, tr.update.z, tr.update.cap, tr.update.spd); - tr.update.x = htonl(tr.update.x); - tr.update.y = htonl(tr.update.y); - tr.update.z = htonl(tr.update.z); - tr.update.cap = htonl(tr.update.cap); - tr.update.spd = htonl(tr.update.spd); - - /* [2] Filling buffer - =========================================================*/ - bzero(buffer, 512); - memcpy(buffer+sizeof(char)*0+sizeof(int)*0, &tr.flags, sizeof(char)); - memcpy(buffer+sizeof(char)*1+sizeof(int)*0, &tr.update.code, sizeof(char)*6); - memcpy(buffer+sizeof(char)*7+sizeof(int)*0, &tr.update.x, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*1, &tr.update.y, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*2, &tr.update.z, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*3, &tr.update.cap, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*4, &tr.update.spd, sizeof(int)); - - - /* [3] Sending request - =========================================================*/ - if( sendto(csocket, buffer, 7+sizeof(int)*5+1, 0, (struct sockaddr*) &server, len) < 0 ){ - printf("Cannot ask for simple update.\n"); - return EXIT_FAILURE; - } - - /* [4] Fetch & print data - =========================================================*/ - /* 1. On récupère la réponse */ - len = sizeof(struct sockaddr_in); - nb = recvfrom(csocket, buffer, 512, 0, (struct sockaddr*) &server, &len); - - printf("%d bytes received\n", nb); - - if( nb < 1 ){ - printf("Error receiving simple update.\n"); - return EXIT_FAILURE; - } - - - /* 2. On parse la réponse */ - count = 0; last = sizeof(char); memcpy(&trs.flags, buffer+count, last); - count += last; last = sizeof(char); memcpy(&trs.n, buffer+count, last); - printf("Flag received : %d\n", trs.flags); - - trs.data = malloc( sizeof(struct plane) * trs.n ); - - - for( i = 0 ; i < trs.n ; i++ ){ - count += last; last = sizeof(char)*6; memcpy(&trs.data[i].code, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].x, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].y, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].z, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].cap, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].spd, buffer+count, last); - - trs.data[i].x = ntohl(trs.data[i].x); - trs.data[i].y = ntohl(trs.data[i].y); - trs.data[i].z = ntohl(trs.data[i].z); - trs.data[i].cap = ntohl(trs.data[i].cap); - trs.data[i].spd = ntohl(trs.data[i].spd); - - printf("Plane[%s@%d] { (%d,%d,%d), cap: %d, spd: %d}\n", trs.data[i].code, i, trs.data[i].x, trs.data[i].y, trs.data[i].z, trs.data[i].cap, trs.data[i].spd); - } - - - } - - sleep(1); - - /************************************************ - **** DEMANDE MISE A JOUR COMBINEE **** - ************************************************/ - if( 1 ){ - printf("\n\nDEMANDE D'UPDATE MULTIPLE + DATA\n================================\n"); - - - - /* [1] Preparing request - =========================================================*/ - tr.flags = TERMREQ_FBK|TERMREQ_ALT|TERMREQ_CAP|TERMREQ_SPD; - memcpy(&tr.update, &tmp, sizeof(struct plane)); - tr.update.z = 2001; - tr.update.cap = 21; - tr.update.spd = 201; - - printf("Update req { flags: %d; plane: #%s { z=%d; cap=%d; speed=%d} }\n", tr.flags, tr.update.code, tr.update.z, tr.update.cap, tr.update.spd); - tr.update.x = htonl(tr.update.x); - tr.update.y = htonl(tr.update.y); - tr.update.z = htonl(tr.update.z); - tr.update.cap = htonl(tr.update.cap); - tr.update.spd = htonl(tr.update.spd); - - /* [2] Filling buffer - =========================================================*/ - bzero(buffer, 512); - memcpy(buffer+sizeof(char)*0+sizeof(int)*0, &tr.flags, sizeof(char)); - memcpy(buffer+sizeof(char)*1+sizeof(int)*0, &tr.update.code, sizeof(char)*6); - memcpy(buffer+sizeof(char)*7+sizeof(int)*0, &tr.update.x, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*1, &tr.update.y, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*2, &tr.update.z, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*3, &tr.update.cap, sizeof(int)); - memcpy(buffer+sizeof(char)*7+sizeof(int)*4, &tr.update.spd, sizeof(int)); - - - /* [3] Sending request - =========================================================*/ - if( sendto(csocket, buffer, 7+sizeof(int)*5+1, 0, (struct sockaddr*) &server, len) < 0 ){ - printf("Cannot ask for simple update.\n"); - return EXIT_FAILURE; - } - - /* [4] Fetch & print data - =========================================================*/ - /* 1. On récupère la réponse */ - len = sizeof(struct sockaddr_in); - nb = recvfrom(csocket, buffer, 512, 0, (struct sockaddr*) &server, &len); - - printf("%d bytes received\n", nb); - - if( nb < 1 ){ - printf("Error receiving simple update.\n"); - return EXIT_FAILURE; - } - - - /* 2. On parse la réponse */ - count = 0; last = sizeof(char); memcpy(&trs.flags, buffer+count, last); - count += last; last = sizeof(char); memcpy(&trs.n, buffer+count, last); - printf("Flag received : %d\n", trs.flags); - - trs.data = malloc( sizeof(struct plane) * trs.n ); - - - for( i = 0 ; i < trs.n ; i++ ){ - count += last; last = sizeof(char)*6; memcpy(&trs.data[i].code, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].x, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].y, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].z, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].cap, buffer+count, last); - count += last; last = sizeof(int); memcpy(&trs.data[i].spd, buffer+count, last); - - trs.data[i].x = ntohl(trs.data[i].x); - trs.data[i].y = ntohl(trs.data[i].y); - trs.data[i].z = ntohl(trs.data[i].z); - trs.data[i].cap = ntohl(trs.data[i].cap); - trs.data[i].spd = ntohl(trs.data[i].spd); - - printf("Plane[%s@%d] { (%d,%d,%d), cap: %d, spd: %d}\n", trs.data[i].code, i, trs.data[i].x, trs.data[i].y, trs.data[i].z, trs.data[i].cap, trs.data[i].spd); - } - - - } - - - - - - return EXIT_SUCCESS; -} \ No newline at end of file diff --git a/ctrlTerm/commandTerm.jar b/ctrlTerm/ctrlTerm.jar similarity index 100% rename from ctrlTerm/commandTerm.jar rename to ctrlTerm/ctrlTerm.jar diff --git a/ctrlTerm/src/ControlTerminal/ControlTerminal.java b/ctrlTerm/src/ControlTerminal/ControlTerminal.java deleted file mode 100644 index fea2a93..0000000 --- a/ctrlTerm/src/ControlTerminal/ControlTerminal.java +++ /dev/null @@ -1,204 +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 ControlTerminal; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -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 java.util.ArrayList; -import java.util.Scanner; - -import DatagramSocket.AsynchronousDatagramSocket; - -/** - * - * @author lmascaro - */ -public class ControlTerminal { - - 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){ - 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)(0x05)); - - 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() == 5){ - 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(); - Pinger pinger = new Pinger(socket,InetAddress.getByName(addressString),port); - - //bind them - socket.bindContainer(container); - container.bindPrinter(printer); - container.bindSocket(socket); - printer.bindContainer(container); - - - //send first packet - InetAddress SGCAaddress = InetAddress.getByName(addressString); - DatagramPacket p = new DatagramPacket(new byte[13],13,SGCAaddress,port); - socket.send(p); - System.out.println("First packet sent"); - - //send first feedback packet - ByteBuffer buf = ByteBuffer.allocate(27); - buf.put((byte) 0x01); - p = new DatagramPacket(buf.array(),buf.array().length,SGCAaddress,port); - socket.send(p); - System.out.println("Feedback request sent"); - - System.out.println("length: "+"aze".getBytes().length); - - //run Pinger - new Thread(pinger).start(); - - //now we let the objects do the job - Scanner s = new Scanner(System.in); - int planeNumber; - int data; - Plane plane; - ArrayList keys; - byte flags; - while(true){ - - String input = s.nextLine(); - if(input.length() == 0){ - //if empty line, we send a feedback request - buf = ByteBuffer.allocate(27); - buf.put((byte) 0x01); - p = new DatagramPacket(buf.array(),buf.array().length,SGCAaddress,port); - socket.send(p); - System.out.println("Request sent, waiting for response"); - - }else if(input.equals("u")){ - System.out.println("Please enter plane number"); - try{ - planeNumber = s.nextInt(); - }catch(Exception e){ - System.out.println("Wrong input please retry"); - s.nextLine(); - continue; - } - - try{ - keys = new ArrayList(container.getMap().keySet()); - plane = container.getMap().get(keys.get(planeNumber-1)); - }catch(Exception e){ - System.out.println("Unknown plane please retry"); - s.nextLine(); - continue; - } - flags = 0x01; - while(true){ - System.out.println("Enter the information you want to update (1: alt,2:cap,3:speed)"); - try{ - data = s.nextInt(); - switch(data){ - case 1: - System.out.println("Enter the new altitude"); - data = s.nextInt(); - plane.setZ(data); - flags = (byte) (flags|0x08); - break; - case 2: - System.out.println("Enter the new cap"); - data = s.nextInt(); - plane.setCap(data); - flags = (byte) (flags|0x02); - break; - case 3: - System.out.println("Enter the new speed"); - data = s.nextInt(); - plane.setSpeed(data); - flags = (byte) (flags|0x04); - break; - } - }catch(Exception e){ - System.out.println("Wrong input please retry"); - s.nextLine(); - continue; - - } - System.out.println("Do you want to update more data on this plane (y/n)"); - - if(s.next().equals("n")){ - break; - } - } - System.out.println("flags: "+flags); - buf = ByteBuffer.allocate(27); - buf.put(flags); - buf.put(plane.toBytes()); - p = new DatagramPacket(buf.array(),buf.array().length,SGCAaddress,port); - socket.send(p); - System.out.println("Request sent, waiting for response"); - s.nextLine(); - }else{ - System.out.println("Unknown command, please retry"); - } - - } - - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - -} diff --git a/ctrlTerm/src/ControlTerminal/InvalidFlagException.java b/ctrlTerm/src/ControlTerminal/InvalidFlagException.java deleted file mode 100644 index a315a66..0000000 --- a/ctrlTerm/src/ControlTerminal/InvalidFlagException.java +++ /dev/null @@ -1,18 +0,0 @@ -package ControlTerminal; - -public class InvalidFlagException extends Exception { - - /** - * - */ - private static final long serialVersionUID = 1L; - - public InvalidFlagException(){ - super(); - } - - public InvalidFlagException(String message){ - super(message); - } - -} diff --git a/ctrlTerm/src/ControlTerminal/Pinger.java b/ctrlTerm/src/ControlTerminal/Pinger.java deleted file mode 100644 index 3d8f690..0000000 --- a/ctrlTerm/src/ControlTerminal/Pinger.java +++ /dev/null @@ -1,46 +0,0 @@ -package ControlTerminal; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.InetAddress; -import java.nio.ByteBuffer; - -import DatagramSocket.AsynchronousDatagramSocket; - -public class Pinger implements Runnable{ - - private AsynchronousDatagramSocket socket; - private InetAddress addr; - private int port; - - public Pinger(AsynchronousDatagramSocket socket,InetAddress addr,int port){ - this.socket = socket; - this.addr = addr; - this.port = port; - } - - @Override - public void run() { - DatagramPacket p; - ByteBuffer buf = ByteBuffer.allocate(27); - while(true){ - try { - Thread.sleep(8000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - p = new DatagramPacket(buf.array(),buf.array().length,this.addr,this.port); - try { - this.socket.send(p); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - } - -} diff --git a/ctrlTerm/src/ControlTerminal/Plane.java b/ctrlTerm/src/ControlTerminal/Plane.java deleted file mode 100644 index a437024..0000000 --- a/ctrlTerm/src/ControlTerminal/Plane.java +++ /dev/null @@ -1,125 +0,0 @@ -package ControlTerminal; - -import java.io.Serializable; -import java.nio.ByteBuffer; - -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 ""; - } - } - - public byte[] toBytes(){ - ByteBuffer buf = ByteBuffer.allocate(26); - buf.put(this.code.getBytes()); - //EOL char - buf.put((byte)0); - buf.putInt(this.x); - buf.putInt(this.y); - buf.putInt(this.z); - buf.putInt(this.cap); - buf.putInt(this.speed); - - return buf.array(); - } - -} diff --git a/ctrlTerm/src/ControlTerminal/PlaneContainer.java b/ctrlTerm/src/ControlTerminal/PlaneContainer.java deleted file mode 100644 index fdbb4b4..0000000 --- a/ctrlTerm/src/ControlTerminal/PlaneContainer.java +++ /dev/null @@ -1,91 +0,0 @@ -package ControlTerminal; - -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 == 0){ - //this is a ping response - return; - }else if((flag&(byte)0x01) != 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/ctrlTerm/src/ControlTerminal/Printer.java b/ctrlTerm/src/ControlTerminal/Printer.java deleted file mode 100644 index 8cb0c22..0000000 --- a/ctrlTerm/src/ControlTerminal/Printer.java +++ /dev/null @@ -1,54 +0,0 @@ -package ControlTerminal; - -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 No plane connected \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]); - } - } - System.out.println("Please enter your command (ENTER to update data, u to update a plane)"); - } -} diff --git a/ctrlTerm/src/DatagramSocket/AsynchronousDatagramSocket.java b/ctrlTerm/src/DatagramSocket/AsynchronousDatagramSocket.java deleted file mode 100644 index 3ab59d6..0000000 --- a/ctrlTerm/src/DatagramSocket/AsynchronousDatagramSocket.java +++ /dev/null @@ -1,89 +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 DatagramSocket; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -import java.net.SocketException; -import java.util.logging.Level; -import java.util.logging.Logger; - -import ControlTerminal.InvalidFlagException; -import ControlTerminal.PlaneContainer; - -/** - * - * @author lmascaro - */ -public class AsynchronousDatagramSocket implements Runnable, AutoCloseable{ - - 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<>(); - this.socket = new DatagramSocket(); - new Thread(this).start(); - } - - public AsynchronousDatagramSocket(int port) throws SocketException{ - this.buf = new SynchronizedBuffer<>(); - this.socket = new DatagramSocket(port); - new Thread(this).start(); - } - - public void bindContainer(PlaneContainer c){ - this.container = c; - } - - public void send(DatagramPacket dp) throws IOException{ - this.socket.send(dp); - } - - public boolean asynchronousReceive(DatagramPacket dp){ - if(this.buf.available() == 0){ - return false; - }else{ - dp = this.buf.removeElement(false); - return true; - } - } - - public DatagramPacket synchronousReceive(){ - return this.buf.removeElement(true); - } - - public boolean available(){ - return this.buf.available()>0; - } - - @Override - public void close(){ - this.socket.close(); - } - - @Override - public void run() { - 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/ctrlTerm/src/DatagramSocket/SynchronizedBuffer.java b/ctrlTerm/src/DatagramSocket/SynchronizedBuffer.java deleted file mode 100644 index 2f28f9c..0000000 --- a/ctrlTerm/src/DatagramSocket/SynchronizedBuffer.java +++ /dev/null @@ -1,46 +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 DatagramSocket; - -import java.util.LinkedList; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author lmascaro - */ -public class SynchronizedBuffer{ - - private LinkedList elements = new LinkedList(); - - public synchronized T removeElement(boolean sync){ - if(!sync && this.elements.isEmpty()){ - return null; - } - - while(this.elements.isEmpty()){ - try { - this.wait(); - } catch (InterruptedException ex) { - Logger.getLogger(SynchronizedBuffer.class.getName()).log(Level.SEVERE, null, ex); - } - } - - return this.elements.removeFirst(); - } - - public synchronized void addElement(T elem){ - this.elements.add(elem); - this.notifyAll(); - } - - public synchronized int available(){ - return this.elements.size(); - } - -} diff --git a/plane/lib/network/udp/client.c b/plane/lib/network/udp/client.c deleted file mode 100644 index 3bf0ee8..0000000 --- a/plane/lib/network/udp/client.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "client.h" - - - -int UDP_SOCKET(int* pSocket, const char* pAddr, const int pPort, struct sockaddr_in* pInfo){ - - /* [0] Initialisation des variables - =========================================================*/ - *pSocket = -1; - struct timeval timeout; - - - /* [1] Création de la socket - =======================================================*/ - /* 1. Création de la socket */ - *pSocket = socket(AF_INET, SOCK_DGRAM, 0); - - /* 2. Gestion erreur */ - if( *pSocket < 0 ) - return -1; - - /* 3. Timeout */ - timeout.tv_sec = SOCK_TIMEOUT; - timeout.tv_usec = 0; - - if( setsockopt(*pSocket, SOL_SOCKET, SO_RCVTIMEO|SO_SNDTIMEO, (char*) &timeout, sizeof(struct timeval) ) < 0 ){ - close(*pSocket); - return -1; - } - - - /* [2] On définit les infos de la socket - =========================================================*/ - /* (1) Reset des valeurs */ - bzero(pInfo, sizeof(struct sockaddr_in)); - - /* (2) On définit les infos */ - pInfo->sin_family = AF_INET; - pInfo->sin_port = htons(pPort); - pInfo->sin_addr.s_addr = inet_addr(pAddr); - - - /* [n] Code succès - =========================================================*/ - return 0; -} diff --git a/plane/lib/network/udp/client.h b/plane/lib/network/udp/client.h deleted file mode 100644 index 8c1eeaa..0000000 --- a/plane/lib/network/udp/client.h +++ /dev/null @@ -1,50 +0,0 @@ -/************************** -* UDP Client Dependency * -*************************** -* Designed & Developed by * -* Adrien Marquès * -* * -*************************** -* doowap31@gmail.com * -**************************/ -#ifndef _LIB_NETWORK_UDP_CLIENT_H_ - #define _LIB_NETWORK_UDP_CLIENT_H_ - - - /* Remarque: - * - * Il s'agit en réalité d'un serveur UDP, mais en multicast les membres du groupe pour qui sont copiées les requêtes - * sont par habitude appelés clients - * - */ - - - - #include "../../header.h" - - - /* Créée une socket UDP + crée le sockaddr_in pour la suite - * - * ==IN== - * @pAddr Adresse du groupe multicast UDP - * @pPort Port d'écoute UDP - * - * ==OUT== - * @pSocket Pointeur sur le à rempliR => contiendra un pointeur sur la socket créée - * @pInfo Pointeur sur le à remplir => contiendra un pointeur sur les infos server - * - * ==RETURN== - * @status -1 si erreur, sinon 0 - * - * @history - * [1] Création de la socket - * [2] On définit les infos de la socket - * [3] On crée la socket - * - * - */ - int UDP_SOCKET(int* pSocket, const char* pAddr, const int pPort, struct sockaddr_in* pInfo); - - - -#endif \ No newline at end of file diff --git a/sgca/install/install.sh b/sgca/install/install.sh deleted file mode 100755 index 644685f..0000000 --- a/sgca/install/install.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# [1] Create script file -cd `pwd`/..; -make all; -cp boot install/sgca; -make clean; -cd install; - - -# [2] Create service target (boot) -sudo ln -s $(pwd)/sgca /usr/sbin/sgca; - -# [3] Create service unit -sudo ln -s $(pwd)/sgca.service /lib/systemd/system/sgca.service; - -# [4] Enable service (optional if no [Install]) -sudo systemctl enable sgca.service; - -# [5] Create log file -sudo touch /var/log/sgca; diff --git a/sgca/install/sgca.service b/sgca/install/sgca.service deleted file mode 100644 index 8be41b5..0000000 --- a/sgca/install/sgca.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Systeme de Gestion du Controle Aerien -Requires=network.target - - -[Service] -Type=simple -User=root -Group=root -ExecStart=/usr/sbin/sgca diff --git a/sgca/install/uninstall.sh b/sgca/install/uninstall.sh deleted file mode 100755 index f6628b2..0000000 --- a/sgca/install/uninstall.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -# [1] Remove service target (boot) -sudo rm /usr/sbin/sgca; - -# [2] Disable service -sudo systemctl stop sgca.service; -sudo systemctl disable sgca.service; - -# [3] Remove service unit -sudo rm /lib/systemd/system/sgca.service; - -# [4] Remove log file -sudo rm /var/log/sgca; - diff --git a/viewTerm/src/DatagramSocket/AsynchronousDatagramSocket.java b/viewTerm/src/DatagramSocket/AsynchronousDatagramSocket.java deleted file mode 100644 index c112bad..0000000 --- a/viewTerm/src/DatagramSocket/AsynchronousDatagramSocket.java +++ /dev/null @@ -1,89 +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 DatagramSocket; - -import java.io.IOException; -import java.net.DatagramPacket; -import java.net.DatagramSocket; -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{ - - 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<>(); - this.socket = new DatagramSocket(); - new Thread(this).start(); - } - - public AsynchronousDatagramSocket(int port) throws SocketException{ - this.buf = new SynchronizedBuffer<>(); - this.socket = new DatagramSocket(port); - new Thread(this).start(); - } - - public void bindContainer(PlaneContainer c){ - this.container = c; - } - - public void send(DatagramPacket dp) throws IOException{ - this.socket.send(dp); - } - - public boolean asynchronousReceive(DatagramPacket dp){ - if(this.buf.available() == 0){ - return false; - }else{ - dp = this.buf.removeElement(false); - return true; - } - } - - public DatagramPacket synchronousReceive(){ - return this.buf.removeElement(true); - } - - public boolean available(){ - return this.buf.available()>0; - } - - @Override - public void close(){ - this.socket.close(); - } - - @Override - public void run() { - 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/viewTerm/src/DatagramSocket/SynchronizedBuffer.java b/viewTerm/src/DatagramSocket/SynchronizedBuffer.java deleted file mode 100644 index 2f28f9c..0000000 --- a/viewTerm/src/DatagramSocket/SynchronizedBuffer.java +++ /dev/null @@ -1,46 +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 DatagramSocket; - -import java.util.LinkedList; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * - * @author lmascaro - */ -public class SynchronizedBuffer{ - - private LinkedList elements = new LinkedList(); - - public synchronized T removeElement(boolean sync){ - if(!sync && this.elements.isEmpty()){ - return null; - } - - while(this.elements.isEmpty()){ - try { - this.wait(); - } catch (InterruptedException ex) { - Logger.getLogger(SynchronizedBuffer.class.getName()).log(Level.SEVERE, null, ex); - } - } - - return this.elements.removeFirst(); - } - - public synchronized void addElement(T elem){ - this.elements.add(elem); - this.notifyAll(); - } - - public synchronized int available(){ - return this.elements.size(); - } - -} diff --git a/viewTerm/src/ViewTerminal/InvalidFlagException.java b/viewTerm/src/ViewTerminal/InvalidFlagException.java deleted file mode 100644 index e4fbc91..0000000 --- a/viewTerm/src/ViewTerminal/InvalidFlagException.java +++ /dev/null @@ -1,18 +0,0 @@ -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/viewTerm/src/ViewTerminal/Plane.java b/viewTerm/src/ViewTerminal/Plane.java deleted file mode 100644 index 0e11ede..0000000 --- a/viewTerm/src/ViewTerminal/Plane.java +++ /dev/null @@ -1,108 +0,0 @@ -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/viewTerm/src/ViewTerminal/PlaneContainer.java b/viewTerm/src/ViewTerminal/PlaneContainer.java deleted file mode 100644 index 64a3cba..0000000 --- a/viewTerm/src/ViewTerminal/PlaneContainer.java +++ /dev/null @@ -1,98 +0,0 @@ -package ViewTerminal; - -import java.io.IOException; -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.allocate(1); - buf.put((byte)16); - DatagramPacket ping = new DatagramPacket(buf.array(),buf.array().length,packet.getAddress(),packet.getPort()); - try { - this.socket.send(ping); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - 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/viewTerm/src/ViewTerminal/Printer.java b/viewTerm/src/ViewTerminal/Printer.java deleted file mode 100644 index 2dd779b..0000000 --- a/viewTerm/src/ViewTerminal/Printer.java +++ /dev/null @@ -1,53 +0,0 @@ -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/viewTerm/src/ViewTerminal/ViewTerminal.java b/viewTerm/src/ViewTerminal/ViewTerminal.java deleted file mode 100644 index 74f1a29..0000000 --- a/viewTerm/src/ViewTerminal/ViewTerminal.java +++ /dev/null @@ -1,102 +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 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(); - } - - } - -}