diff --git a/PFE06/src/main/java/com/PFE/ServerManager/MainController.java b/PFE06/src/main/java/com/PFE/ServerManager/MainController.java index 1098e96..450e253 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/MainController.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/MainController.java @@ -121,6 +121,7 @@ public class MainController { modelAndView.addObject("succeed", succeed); System.out.println("all teams : " + teamRepository.findAll()); modelAndView.addObject("allTeams", teamRepository.findAll()); + modelAndView.addObject("allCustomers", customerRepository.findAll()); modelAndView.setViewName("registration"); return modelAndView; } @@ -130,26 +131,11 @@ public class MainController { return "denied"; } - @PostMapping(path="/addTeam") - public String addNewTeam(@RequestParam String teamName){ - - if(teamRepository.findByTeam(teamName) != null) { - return "redirect:/registration?message=Le groupe&succeed=-1"; - } - else { - Team t = new Team(); - t.setTeam(teamName); - t.setTeamId((int)(teamRepository.count()+1)); - teamRepository.save(t); - return "redirect:/registration?message=Le groupe&succeed=1"; - } - } - @PostMapping(path="/addUser") public String addNewUser(@RequestParam String email, @RequestParam String password, @RequestParam String role, @RequestParam String team) { if(customerRepository.findByEmail(email) != null) { - return "redirect:/registration?message=L'utilisateur&succeed=-1"; + return "redirect:/registration?message=L'utilisateur existe+d%C3%A9j%C3%A0&succeed=-1"; } else { Customer n = new Customer(); @@ -164,9 +150,43 @@ public class MainController { Team temp = teamRepository.findByTeam(team); temp.addCustomer(n); teamRepository.save(temp); - return "redirect:/registration?message=L'utilisateur&succeed=1"; + return "redirect:/registration?message=L'utilisateur a+%C3%A9t%C3%A9+ajout%C3%A9&succeed=1"; } + } + @PostMapping(path="/addTeam") + public String addNewTeam(@RequestParam String teamName){ + + if(teamRepository.findByTeam(teamName) != null) { + return "redirect:/registration?message=Le groupe existe+d%C3%A9j%C3%A0&succeed=-1"; + } + else { + Team t = new Team(); + t.setTeam(teamName); + t.setTeamId((int)(teamRepository.count()+1)); + teamRepository.save(t); + return "redirect:/registration?message=Le groupe a+%C3%A9t%C3%A9+ajout%C3%A9&succeed=1"; + } + } + + @PostMapping(path="/changeCustomerTeam") + public String addCustomerTeam(@RequestParam String teamName, @RequestParam String customerName){ + Team newTeam = teamRepository.findByTeam(teamName); + Customer customer = customerRepository.findByEmail(customerName); + Team oldTeam = teamRepository.findByCustomersContaining(customer); + if( newTeam == null || customer == null) { + return "redirect:/registration?message=le+groupe+ou+l%27utilisateur+n%27existe+plus&succeed=-1"; + } + else if(oldTeam == newTeam){ + return "redirect:/registration?message=l%27utilisateur+appartient+d%C3%A9j%C3%A0+%C3%A0+ce+groupe&succeed=-1"; + } + else { + newTeam.addCustomer(customer); + oldTeam.removeCustomer(customer); + teamRepository.save(newTeam); + teamRepository.save(oldTeam); + return "redirect:/registration?message=le+groupe+de+l%27utilisateur+a+bien+%C3%A9t%C3%A9+chang%C3%A9&succeed=1"; + } } @RequestMapping(value = "/file", method = RequestMethod.POST) diff --git a/PFE06/src/main/java/com/PFE/ServerManager/Team.java b/PFE06/src/main/java/com/PFE/ServerManager/Team.java index b9fc113..04fb29b 100644 --- a/PFE06/src/main/java/com/PFE/ServerManager/Team.java +++ b/PFE06/src/main/java/com/PFE/ServerManager/Team.java @@ -52,6 +52,11 @@ public class Team { } this.customers.add(customer); } + public void removeCustomer(Customer customer){ + if(customers != null){ + customers.remove(customer); + } + } public void setUpdates(Set updates) { this.updates = updates; diff --git a/PFE06/src/main/resources/templates/registration.html b/PFE06/src/main/resources/templates/registration.html index 5f2ea58..2e50357 100644 --- a/PFE06/src/main/resources/templates/registration.html +++ b/PFE06/src/main/resources/templates/registration.html @@ -41,17 +41,17 @@
-

Formulaire d'ajout d'un utilisateur

+

Ajouter un utilisateur

@@ -80,7 +80,7 @@
-

Formulaire d'ajout d'un groupe de travail

+

Ajouter un groupe de travail

diff --git a/Raspberry/config_experimentation.txt b/Raspberry/config_experimentation.txt index 07c3652..47f083c 100644 --- a/Raspberry/config_experimentation.txt +++ b/Raspberry/config_experimentation.txt @@ -1,3 +1,2 @@ temperature_1 -mouvement_2 -wrong_file \ No newline at end of file +mouvement_2 \ No newline at end of file diff --git a/Raspberry/data b/Raspberry/data deleted file mode 100644 index 95dca7f..0000000 Binary files a/Raspberry/data and /dev/null differ diff --git a/Raspberry/data.c b/Raspberry/data.c deleted file mode 100644 index a01c254..0000000 --- a/Raspberry/data.c +++ /dev/null @@ -1,85 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -int pt; -struct termios tty, old; /* Create the structure */ - -void reset_tty(){ - tcsetattr(pt, TCSANOW, &old); - close(pt); -} - -int main(){ - int r=-1; - char * device = "/dev/ttyS3"; - pt = open(device, O_RDWR | O_NOCTTY | O_SYNC); - if(pt == -1){ - perror("open"); - exit(-1); - } - printf("open : %d\n",pt); - ioctl(pt, I_SRDOPT, RMSGD); - tcgetattr(pt, &old); - atexit(reset_tty); - - tcgetattr(pt, &tty); // Get the current attributes of the Serial port - - //cfmakeraw(&tty); - tty.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON | IXOFF); - printf("iflag = %x\n",tty.c_iflag); - tty.c_oflag &= ~(OPOST); - printf("oflag = %x\n",tty.c_oflag); - tty.c_cflag |= (CS8); - tty.c_cflag &= ~(CSIZE|PARENB); - printf("cflag = %x\n",tty.c_cflag); - tty.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); - printf("lflag = %x\n",tty.c_lflag); - - tty.c_cc[VMIN] = 7; - tty.c_cc[VTIME] = 0; - cfsetispeed(&tty,B9600); // Setting the Baud rate - cfsetospeed(&tty,B9600); - - /*Peut-être inutile si on est en liaison série et pas en USB : le TCSAFLUSH devrait suffir*/ - sleep(1); - - if(tcflush(pt, TCIFLUSH)==-1){ - perror("tcflush"); - exit(-1); - } - - if(tcsetattr(pt, TCSANOW, &tty)==-1){ - perror("tcsetattr"); - } - - int i = 0; - char end[20]; - - if(cfgetispeed(&tty)!=B9600) - { - perror("cfgetispeed"); - exit(-1); - } - - int count = 0; - char line[20]; - memset(line,0,sizeof(line)); - - while(count<14){ - r = read(pt ,line,1); - printf("c = %c (characters read : %d)\n",line[0],r); - //printf("l = %c\n",line[0]); - count++; - memset(line,0,sizeof(line)); - printf("\n"); - } - - //close(pt); - return 0; -} \ No newline at end of file diff --git a/Raspberry/data.cpp b/Raspberry/data.cpp deleted file mode 100644 index bd4d97f..0000000 --- a/Raspberry/data.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include -using namespace std; - -int main() -{ - cout << "Hello, World!"; - return 0; -} \ No newline at end of file diff --git a/Raspberry/listener b/Raspberry/listener index deb7b19..33ceb9f 100644 Binary files a/Raspberry/listener and b/Raspberry/listener differ diff --git a/Raspberry/listener.c b/Raspberry/listener.c index 2358f4c..2914e9b 100644 --- a/Raspberry/listener.c +++ b/Raspberry/listener.c @@ -55,7 +55,7 @@ void save_data(int pt, char* sensor){ strcat(base, sensor); strcat(base, ".txt"); file = fopen(base,"w"); - printf("base = %s\n",base); + //printf("base = %s\n",base); if(file==NULL){ perror("fopen"); exit(-1); @@ -66,8 +66,10 @@ void save_data(int pt, char* sensor){ memset(line,0,sizeof(line)); while(1){ int r = read(pt ,line,1); - printf("c = %c (characters read : %d)\n\n", line[0], r); - r = fprintf(file, "%c",line[0]); + if(r>=0){ + printf("sensor : %s - c = %c (characters read : %d)\n\n", sensor, line[0], r); + r = fprintf(file, "%c",line[0]); + } fflush(file); memset(line,0,sizeof(line)); count++; @@ -85,32 +87,35 @@ void reset_serial(int pt){ printf("end reset_serial\n"); } -void * set_serial(void * sensorAndPort2){ - char *device = ((SensorAndPort *)sensorAndPort2)->port; +int set_serial(SensorAndPort* sensorAndPort){ + char *device = sensorAndPort->port; printf("device : %s\n",device); - //char * device = (char *)deviceV; int pt = open(device, O_RDWR | O_NOCTTY | O_SYNC); // retourne une erreur si le terminal n'est connecté à rien (pas de STM32 ni de Arduino dans notre cas) if(pt == -1){ - create_error_file(((SensorAndPort *)sensorAndPort2)->sensor, "impossible de se connecter au port série, veuillez vérifier le microprocesseur et la raspberry"); + create_error_file(sensorAndPort->sensor, "impossible de se connecter au port série, veuillez vérifier le microprocesseur et la raspberry"); perror("in set_serial(...) - open"); pthread_exit(NULL); } - ioctl(pt, I_SRDOPT, RMSGD); - //fcntl(pt, F_SETFL, 0); + //ioctl(pt, I_SRDOPT, RMSGD); tcgetattr(pt, &old); - tcgetattr(pt, &tty); // Get the current attributes of the Serial port - // cfmakeraw(&tty); - tty.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON | IXOFF); - tty.c_oflag &= ~(OPOST); - tty.c_cflag |= (CS8); - tty.c_cflag &= ~(CSIZE|PARENB); - tty.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); - tty.c_cc[VMIN] = 1; - tty.c_cc[VTIME] = 0; + tcgetattr(pt, &tty); + //////////////////////////////////////////////////////////////////////////////////////// + // Sur les Raspberry le code du read() est bien bloquant comme prévu mais par sur linux Ubuntun. + // Donc sur les Raspberry, il est nécessaire de mettre un VTIME et de mettre VMIN = 0 + // car le timer commence lorsque le premier caractère est détécté : + // Si aucun caractère n'arrive le timer ne commence jamais et le read bloque à l'infini + //////////////////////////////////////////////////////////////////////////////////////// cfsetispeed(&tty,B9600); cfsetospeed(&tty,B9600); - sleep(1); + tty.c_cc[VMIN] = 1; + tty.c_cc[VTIME] = 10; + + tty.c_cflag |= CLOCAL; + tty.c_cflag |= CREAD; + cfmakeraw(&tty); + + sleep(1); // nécessaire pour que le flush soit fait if(tcflush(pt, TCIFLUSH)==-1){ perror("in set_serial(...) - tcflush"); pthread_exit(NULL); @@ -124,8 +129,12 @@ void * set_serial(void * sensorAndPort2){ perror("in set_serial(...) - cfgetispeed"); pthread_exit(NULL); } + return pt; +} - save_data(pt, ((SensorAndPort *)sensorAndPort2)->sensor); +void * start(void * sensorAndPort){ + int pt = set_serial((SensorAndPort *) sensorAndPort); + save_data(pt, ((SensorAndPort *)sensorAndPort)->sensor); reset_serial(pt); pthread_exit(NULL); } @@ -168,17 +177,27 @@ void get_ports_to_read(char list_sensors[MAX_SENSORS][30], char list_serial_port } -int main(){ +int main(int argc, char *argv[]){ + char * config_experimentation = "config_experimentation.txt"; + char * config_raspberry = "config_raspberry.txt"; + if(argc>1){ + printf("fichier contenant la liste des capteurs de l'experimentation : %s\n",argv[1]); + char * config_experimentation = argv[1]; + } + if(argc>2){ + printf("fichier contenant la correspondance de tous les capteurs avec leur liaison série : %s\n",argv[2]); + char * config_raspberry = argv[2]; + } SensorAndPort sensorAndPort[MAX_SENSORS]; - + char device[MAX_SENSORS][12]; pthread_t threads[MAX_SENSORS]; char list_sensors[MAX_SENSORS][30], list_serial_port[MAX_SENSORS][30], sensors_ports[MAX_SENSORS][30]; int i=0, count_sensors=0, count_serial_port=0; - count_sensors = read_file_by_line(list_sensors, "config_experimentation.txt"); + count_sensors = read_file_by_line(list_sensors, config_experimentation); printf("numbers of sensors = %d\n",count_sensors); - count_serial_port = read_file_by_line(list_serial_port, "config_raspberry.txt"); + count_serial_port = read_file_by_line(list_serial_port, config_raspberry); get_ports_to_read(list_sensors,list_serial_port,count_sensors, count_serial_port, sensors_ports); action.sa_handler=sig_handler; @@ -187,10 +206,14 @@ int main(){ for(i=0;i