Merge remote-tracking branch 'origin/master' into source
This commit is contained in:
commit
760b3b86be
|
@ -0,0 +1,47 @@
|
||||||
|
|
||||||
|
default:
|
||||||
|
@echo "install - will compile and create executables";
|
||||||
|
@echo "clean - will remove executables and clean";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
install-sgca:
|
||||||
|
@echo "(1) Compiling SGCA";
|
||||||
|
@make --directory=./sgca > /dev/null;
|
||||||
|
|
||||||
|
install-plane:
|
||||||
|
@echo "(2) Compiling PLANE";
|
||||||
|
@make --directory=./plane > /dev/null;
|
||||||
|
|
||||||
|
link-sgca:
|
||||||
|
@echo "(3) Linking SGCA executable";
|
||||||
|
@ln -fs ./sgca/boot x-sgca;
|
||||||
|
|
||||||
|
link-plane:
|
||||||
|
@echo "(4) Linking PLANE executable";
|
||||||
|
@ln -fs ./plane/boot x-plane;
|
||||||
|
|
||||||
|
link-viewTerm:
|
||||||
|
@echo "(4) Linking VIEW TERMINAL executable";
|
||||||
|
@echo -e "#!/bin/bash\n\njava -jar ./viewTerm/viewTerm.jar;\n" > ./x-viewTerm;
|
||||||
|
@chmod ug+x ./x-viewTerm;
|
||||||
|
|
||||||
|
link-ctrlTerm:
|
||||||
|
@echo "(5) Linking CTRL TERMINAL executable";
|
||||||
|
@echo -e "#!/bin/bash\n\njava -jar ./ctrlTerm/commandTerm.jar;\n" > ./x-ctrlTerm;
|
||||||
|
@chmod ug+x ./x-ctrlTerm;
|
||||||
|
|
||||||
|
|
||||||
|
install: install-sgca install-plane link-sgca link-plane link-viewTerm link-ctrlTerm
|
||||||
|
@echo;
|
||||||
|
@echo "*** Executables created:";
|
||||||
|
@ls -a . | grep -P "^x-*" | sed 's/^x-/ (*) x-/';
|
||||||
|
|
||||||
|
|
||||||
|
clean:
|
||||||
|
@find ./x-sgca > /dev/null 2>&1 && rm ./x-sgca || return 0;
|
||||||
|
@find ./x-plane > /dev/null 2>&1 && rm ./x-plane || return 0;
|
||||||
|
@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;
|
|
@ -167,6 +167,10 @@ public class ControlTerminal {
|
||||||
plane.setSpeed(data);
|
plane.setSpeed(data);
|
||||||
flags = (byte) (flags|0x04);
|
flags = (byte) (flags|0x04);
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println("Wrong input please retry");
|
||||||
|
s.nextLine();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}catch(Exception e){
|
}catch(Exception e){
|
||||||
System.out.println("Wrong input please retry");
|
System.out.println("Wrong input please retry");
|
||||||
|
@ -180,7 +184,7 @@ public class ControlTerminal {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
System.out.println("flags: "+flags);
|
container.setExpectedFlags(flags);
|
||||||
buf = ByteBuffer.allocate(27);
|
buf = ByteBuffer.allocate(27);
|
||||||
buf.put(flags);
|
buf.put(flags);
|
||||||
buf.put(plane.toBytes());
|
buf.put(plane.toBytes());
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class Plane{
|
||||||
case 4:
|
case 4:
|
||||||
if(this.isDead){
|
if(this.isDead){
|
||||||
return "\033[4;37;41m ATTENTION: avion hors ligne\t|\033[0m";
|
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";
|
return "\033[5;37;41m --Speed: "+this.speed+"\t\t\t|\033[0m";
|
||||||
}else{
|
}else{
|
||||||
return "\033[0m --Speed: "+this.speed+"\t\t\t|";
|
return "\033[0m --Speed: "+this.speed+"\t\t\t|";
|
||||||
|
|
|
@ -12,6 +12,7 @@ public class PlaneContainer {
|
||||||
private HashMap<String,Plane> map;
|
private HashMap<String,Plane> map;
|
||||||
private AsynchronousDatagramSocket socket;
|
private AsynchronousDatagramSocket socket;
|
||||||
private Printer printer;
|
private Printer printer;
|
||||||
|
private byte expectedFlags = 0x01;
|
||||||
|
|
||||||
public PlaneContainer(){
|
public PlaneContainer(){
|
||||||
this.map = new HashMap<String,Plane>();
|
this.map = new HashMap<String,Plane>();
|
||||||
|
@ -25,6 +26,10 @@ public class PlaneContainer {
|
||||||
this.printer = p;
|
this.printer = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setExpectedFlags(byte flags){
|
||||||
|
this.expectedFlags = flags;
|
||||||
|
}
|
||||||
|
|
||||||
public void notifyReceive() throws InvalidFlagException{
|
public void notifyReceive() throws InvalidFlagException{
|
||||||
DatagramPacket packet = this.socket.synchronousReceive();
|
DatagramPacket packet = this.socket.synchronousReceive();
|
||||||
|
|
||||||
|
@ -41,6 +46,29 @@ public class PlaneContainer {
|
||||||
|
|
||||||
//System.out.println("Processing "+nbrPlane+" planes");
|
//System.out.println("Processing "+nbrPlane+" planes");
|
||||||
|
|
||||||
|
if(this.expectedFlags != flag){
|
||||||
|
if((this.expectedFlags&(byte)0x02) == 2 && (flag&(byte)0x02) != 2){
|
||||||
|
System.out.println("\033[5;37;41m Could not apply cap \033[0m");
|
||||||
|
}
|
||||||
|
if((this.expectedFlags&(byte)0x04) == 4 && (flag&(byte)0x04) != 4){
|
||||||
|
System.out.println("\033[5;37;41m Could not apply speed \033[0m");
|
||||||
|
}
|
||||||
|
if((this.expectedFlags&(byte)0x08) == 8 && (flag&(byte)0x08) != 8){
|
||||||
|
System.out.println("\033[5;37;41m Could not apply alt \033[0m");
|
||||||
|
}
|
||||||
|
System.out.println("\033[5;37;41m One or more fields could not be updated \033[0m");
|
||||||
|
if((flag&(byte)0x10) == 1){
|
||||||
|
System.out.println("\033[5;37;41m Plane crashed gracefully \033[0m");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.expectedFlags = 0x01;
|
||||||
|
Thread.sleep(2000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(flag == 0){
|
if(flag == 0){
|
||||||
//this is a ping response
|
//this is a ping response
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -19,9 +19,9 @@ boot: lib/network/tcp/client.o lib/network/udp/server.o plane.h plane.c
|
||||||
|
|
||||||
|
|
||||||
# Run full compilation
|
# Run full compilation
|
||||||
all: clean boot
|
all: boot
|
||||||
|
|
||||||
# cleans the compiled files
|
# cleans the compiled files
|
||||||
clean:
|
clean:
|
||||||
find ./lib/network/**/*.o && rm ./lib/network/**/*.o || return 0;
|
@rm ./lib/network/**/*.o;
|
||||||
find boot && rm boot || return 0;
|
@rm ./boot;
|
||||||
|
|
|
@ -378,4 +378,5 @@ int main(){
|
||||||
// on se déplace une fois toutes les initialisations faites
|
// on se déplace une fois toutes les initialisations faites
|
||||||
printf("\n=== COMMUNICATION PROTOCOL ===\n");
|
printf("\n=== COMMUNICATION PROTOCOL ===\n");
|
||||||
update();
|
update();
|
||||||
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
|
@ -31,11 +31,11 @@ boot: lib/network/common.o lib/network/tcp/server.o lib/network/udp/server.o lib
|
||||||
|
|
||||||
|
|
||||||
# Run full compilation
|
# Run full compilation
|
||||||
all: clean boot
|
all: boot
|
||||||
|
|
||||||
# cleans the compiled files
|
# cleans the compiled files
|
||||||
clean:
|
clean:
|
||||||
find lib/network/*.o && rm lib/network/*.o || return 0;
|
@rm lib/network/*.o;
|
||||||
find lib/network/**/*.o && rm lib/network/**/*.o || return 0;
|
@rm lib/network/**/*.o;
|
||||||
find lib/local/*.o && rm lib/local/*.o || return 0;
|
@rm lib/local/*.o;
|
||||||
find boot && rm boot || return 0;
|
@rm boot;
|
||||||
|
|
|
@ -76,7 +76,8 @@ int main(int argc, char* argv[]){
|
||||||
|
|
||||||
/* [2] On attends la fin de tous les THREADS
|
/* [2] On attends la fin de tous les THREADS
|
||||||
==========================================================*/
|
==========================================================*/
|
||||||
for( char i = 0 ; i < 4 ; i++ )
|
char i;
|
||||||
|
for( i = 0 ; i < 4 ; i++ )
|
||||||
pthread_join(listenManagers[(int)i], NULL);
|
pthread_join(listenManagers[(int)i], NULL);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -215,9 +215,11 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
||||||
int sent; // compteurs d'envoi
|
int sent; // compteurs d'envoi
|
||||||
int i, index = -1; // Compteurs globaux
|
int i, index = -1; // Compteurs globaux
|
||||||
char* buffer = malloc(1); // Buffer d'envoi
|
char* buffer = malloc(1); // Buffer d'envoi
|
||||||
|
int SOCKET;
|
||||||
|
|
||||||
/* 2. On récupère les arguments */
|
/* 2. On récupère les arguments */
|
||||||
struct handler_arg* arg = THREADABLE_ARGS;
|
struct handler_arg* arg = THREADABLE_ARGS;
|
||||||
|
memcpy(&SOCKET, &arg->socket, sizeof(int));
|
||||||
|
|
||||||
/* 3. On récupère le rang dans les "managers" */
|
/* 3. On récupère le rang dans les "managers" */
|
||||||
for( i = 0 ; i < MAX_UDP_THR ; i++ )
|
for( i = 0 ; i < MAX_UDP_THR ; i++ )
|
||||||
|
@ -228,7 +230,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
||||||
|
|
||||||
/* 4. Attente d'un client */
|
/* 4. Attente d'un client */
|
||||||
len = sizeof(struct sockaddr_in);
|
len = sizeof(struct sockaddr_in);
|
||||||
if( recvfrom(arg->socket, buffer, MAX_BUF_LEN*sizeof(char), 0, (struct sockaddr*) &clientInfo, &len) < 0 ){
|
if( recvfrom(SOCKET, buffer, MAX_BUF_LEN*sizeof(char), 0, (struct sockaddr*) &clientInfo, &len) < 0 ){
|
||||||
printf("{udp_vterm}{com}(%d) No terminal detected, exiting\n", index);
|
printf("{udp_vterm}{com}(%d) No terminal detected, exiting\n", index);
|
||||||
loop = 0;
|
loop = 0;
|
||||||
}
|
}
|
||||||
|
@ -248,7 +250,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* 2. Envoi */
|
/* 2. Envoi */
|
||||||
len = sizeof(struct sockaddr_in);
|
len = sizeof(struct sockaddr_in);
|
||||||
sent = sendto(arg->socket, buffer, buflen + 1, 0, (struct sockaddr*) &clientInfo, len);
|
sent = sendto(SOCKET, buffer, buflen + 1, 0, (struct sockaddr*) &clientInfo, len);
|
||||||
|
|
||||||
/* 3. Gestion erreur */
|
/* 3. Gestion erreur */
|
||||||
if( sent <= 0 ){
|
if( sent <= 0 ){
|
||||||
|
@ -261,7 +263,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
/* 1. Réception feedback (0x10) */
|
/* 1. Réception feedback (0x10) */
|
||||||
len = sizeof(struct sockaddr_in);
|
len = sizeof(struct sockaddr_in);
|
||||||
sent = recvfrom(arg->socket, buffer, 1, 0, (struct sockaddr*) &clientInfo, &len);
|
sent = recvfrom(SOCKET, buffer, 1, 0, (struct sockaddr*) &clientInfo, &len);
|
||||||
|
|
||||||
/* 2. Gestion erreur (erreur ou mauvais feedback != 0x10) */
|
/* 2. Gestion erreur (erreur ou mauvais feedback != 0x10) */
|
||||||
if( sent <= 0 || buffer[0] != TERMREQ_OFF ){
|
if( sent <= 0 || buffer[0] != TERMREQ_OFF ){
|
||||||
|
@ -284,7 +286,7 @@ void* manageViewTerm(void* THREADABLE_ARGS){
|
||||||
arg->activeUDPManagers[index] = 0;
|
arg->activeUDPManagers[index] = 0;
|
||||||
|
|
||||||
/* 2. On ferme la socket + libère la mémoire */
|
/* 2. On ferme la socket + libère la mémoire */
|
||||||
close(arg->socket);
|
close(SOCKET);
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
||||||
|
|
||||||
|
@ -331,10 +333,13 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
|
||||||
char* dataBuffer = malloc(1);
|
char* dataBuffer = malloc(1);
|
||||||
struct term_req request; // Requête
|
struct term_req request; // Requête
|
||||||
char flags;
|
char flags;
|
||||||
|
int SOCKET;
|
||||||
|
struct in_addr* ip = malloc(sizeof(struct in_addr));
|
||||||
|
|
||||||
|
|
||||||
/* 2. On récupère les arguments */
|
/* 2. On récupère les arguments */
|
||||||
struct handler_arg* arg = THREADABLE_ARGS;
|
struct handler_arg* arg = THREADABLE_ARGS;
|
||||||
|
memcpy(&SOCKET, &arg->socket, sizeof(int));
|
||||||
|
|
||||||
/* 3. On récupère le rang dans les "managers" */
|
/* 3. On récupère le rang dans les "managers" */
|
||||||
for( i = 0 ; i < MAX_UDP_THR ; i++ )
|
for( i = 0 ; i < MAX_UDP_THR ; i++ )
|
||||||
|
@ -344,11 +349,16 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
|
||||||
|
|
||||||
/* 4. Attente d'un client */
|
/* 4. Attente d'un client */
|
||||||
len = sizeof(struct sockaddr_in);
|
len = sizeof(struct sockaddr_in);
|
||||||
if( recvfrom(arg->socket, buffer, MAX_BUF_LEN*sizeof(char), 0, (struct sockaddr*) &clientInfo, &len) < 0 ){
|
if( recvfrom(SOCKET, buffer, MAX_BUF_LEN*sizeof(char), 0, (struct sockaddr*) &clientInfo, &len) < 0 ){
|
||||||
printf("{udp_cterm}{com}(%d) No terminal detected, exiting\n", index);
|
printf("{udp_cterm}{com}(%d) No terminal detected, exiting\n", index);
|
||||||
loop = 0;
|
loop = 0;
|
||||||
}else
|
}else{
|
||||||
printf("{udp_cterm}{com}(%d) Terminal connected\n", index);
|
ip->s_addr = clientInfo.sin_addr.s_addr;
|
||||||
|
printf("{udp_cterm}{com}(%d) Terminal connected from %s:%d\n", index, inet_ntoa(*ip), ntohs(clientInfo.sin_port));
|
||||||
|
}
|
||||||
|
|
||||||
|
free(ip);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
while( loop ){
|
while( loop ){
|
||||||
|
@ -360,14 +370,14 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
|
||||||
/* 1. On lit sur la socket */
|
/* 1. On lit sur la socket */
|
||||||
len = sizeof(struct sockaddr_in);
|
len = sizeof(struct sockaddr_in);
|
||||||
bzero(buffer, sizeof(char)*MAX_BUF_LEN);
|
bzero(buffer, sizeof(char)*MAX_BUF_LEN);
|
||||||
count = recvfrom(arg->socket, buffer, MAX_BUF_LEN, 0, (struct sockaddr*) &clientInfo, &len);
|
count = recvfrom(SOCKET, buffer, MAX_BUF_LEN, 0, (struct sockaddr*) &clientInfo, &len);
|
||||||
|
|
||||||
/* 2. Si erreur reception */
|
/* 2. Si erreur reception */
|
||||||
if( count <= 0 ) // because of timeout or error
|
if( count <= 0 ) // because of timeout or error
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if( count < TERMREQ_LEN ){
|
if( count < TERMREQ_LEN ){
|
||||||
send(arg->socket, "\0\0", sizeof(char)*2, 0);
|
send(SOCKET, "\0\0", sizeof(char)*2, 0);
|
||||||
if( DEBUGMOD&BUF ) printf("{udp_cterm}{com}(%d) Error receiving request\n", index);
|
if( DEBUGMOD&BUF ) printf("{udp_cterm}{com}(%d) Error receiving request\n", index);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -390,7 +400,7 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
|
||||||
update = ( request.flags&TERMREQ_ALT || request.flags&TERMREQ_CAP || request.flags&TERMREQ_SPD );
|
update = ( request.flags&TERMREQ_ALT || request.flags&TERMREQ_CAP || request.flags&TERMREQ_SPD );
|
||||||
fbk = request.flags&TERMREQ_FBK;
|
fbk = request.flags&TERMREQ_FBK;
|
||||||
if( !( update || fbk ) ){
|
if( !( update || fbk ) ){
|
||||||
send(arg->socket, "\x00\0", sizeof(char)*2, 0);
|
send(SOCKET, "\x00\0", sizeof(char)*2, 0);
|
||||||
if( request.flags != 0 )
|
if( request.flags != 0 )
|
||||||
printf("{udp_cterm}{com}(%d) Invalid flags\n", index);
|
printf("{udp_cterm}{com}(%d) Invalid flags\n", index);
|
||||||
continue;
|
continue;
|
||||||
|
@ -500,7 +510,7 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
|
||||||
=========================================================*/
|
=========================================================*/
|
||||||
printf("{udp_cterm}{com}(%d) Sending response { flags: %d; n: %d }\n", index, dataBuffer[0], dataBuffer[1]);
|
printf("{udp_cterm}{com}(%d) Sending response { flags: %d; n: %d }\n", index, dataBuffer[0], dataBuffer[1]);
|
||||||
len = sizeof(struct sockaddr_in);
|
len = sizeof(struct sockaddr_in);
|
||||||
if( sendto(arg->socket, dataBuffer, dataLen, 0, (struct sockaddr*) &clientInfo, len) < 0 )
|
if( sendto(SOCKET, dataBuffer, dataLen, 0, (struct sockaddr*) &clientInfo, len) < 0 )
|
||||||
printf("{udp_cterm}{com}(%d) Cannot answer to terminal\n", index);
|
printf("{udp_cterm}{com}(%d) Cannot answer to terminal\n", index);
|
||||||
|
|
||||||
|
|
||||||
|
@ -514,7 +524,7 @@ void* manageCtrlTerm(void* THREADABLE_ARGS){
|
||||||
arg->activeUDPManagers[index] = 0;
|
arg->activeUDPManagers[index] = 0;
|
||||||
|
|
||||||
/* 2. On ferme la socket */
|
/* 2. On ferme la socket */
|
||||||
close(arg->socket);
|
close(SOCKET);
|
||||||
free(dataBuffer);
|
free(dataBuffer);
|
||||||
|
|
||||||
/* 3. On arrête le THREAD */
|
/* 3. On arrête le THREAD */
|
||||||
|
|
|
@ -95,7 +95,7 @@ public class Plane {
|
||||||
case 4:
|
case 4:
|
||||||
if(this.isDead){
|
if(this.isDead){
|
||||||
return "\033[4;37;41m ATTENTION: avion hors ligne\t|\033[0m";
|
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";
|
return "\033[5;37;41m --Speed: "+this.speed+"\t\t\t|\033[0m";
|
||||||
}else{
|
}else{
|
||||||
return "\033[0m --Speed: "+this.speed+"\t\t\t|";
|
return "\033[0m --Speed: "+this.speed+"\t\t\t|";
|
||||||
|
|
Loading…
Reference in New Issue