Compare commits

...

9 Commits
prod ... master

Author SHA1 Message Date
xdrm-brackets 2d176987ea last fix std99 2017-05-19 09:45:15 +02:00
SeekDaSky d11649e9b9 Merge remote-tracking branch 'origin/master' 2017-05-19 09:35:53 +02:00
SeekDaSky 710a5def49 fix 2017-05-19 09:35:50 +02:00
xdrm-brackets 87509e8efe Fixed Makefile-s 2017-05-19 08:50:44 +02:00
xdrm-brackets 4636c79334 fixed socket reference conflicts in vTerm+cTerm as in plane 2017-05-19 08:49:05 +02:00
SeekDaSky c8da1b3ba6 ControlTerm - final 2017-05-18 20:43:32 +02:00
SeekDaSky 821808a420 fix compilation 2017-05-18 20:24:39 +02:00
xdrm-brackets f5232693d3 Merge branch 'source' 2017-05-18 00:14:37 +02:00
xdrm-brackets 1246fbbdc5 Removed c-emul 2017-05-18 00:14:33 +02:00
12 changed files with 71 additions and 551 deletions

View File

@ -1,524 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h> // close
#include <netinet/in.h>
#include <netdb.h> // getaddrinfo, getnameinfo
#include <arpa/inet.h>
#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;
}

Binary file not shown.

View File

@ -167,7 +167,11 @@ 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");
s.nextLine(); s.nextLine();
@ -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());

View File

@ -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|";

View File

@ -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;

View File

@ -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 >/dev/null 2>&1 && rm ./lib/network/**/*.o || return 0; @rm ./lib/network/**/*.o;
@find ./boot >/dev/null 2>&1 && rm ./boot || return 0; @rm ./boot;

View File

@ -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;
}

View File

@ -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 >/dev/null 2>&1 && rm lib/network/*.o || return 0; @rm lib/network/*.o;
@find lib/network/**/*.o >/dev/null 2>&1 && rm lib/network/**/*.o || return 0; @rm lib/network/**/*.o;
@find lib/local/*.o >/dev/null 2>&1 && rm lib/local/*.o || return 0; @rm lib/local/*.o;
@find boot >/dev/null 2>&1 && rm boot || return 0; @rm boot;

View File

@ -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);
@ -452,4 +453,4 @@ void* MCAST_PUBLISH(void* THREADABLE_ARGS){
close(SOCKET); close(SOCKET);
return NULL; return NULL;
} }

View File

@ -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 */

View File

@ -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|";

Binary file not shown.