Commit 11329db50ea3e084fc500e6a18b9751b39920f51
1 parent
e9db2061
Ansible terminé et démonstration fonctionnelle
Showing
7 changed files
with
46 additions
and
26 deletions
Show diff stats
Ansible/ansible.yml
@@ -12,17 +12,33 @@ | @@ -12,17 +12,33 @@ | ||
12 | 12 | ||
13 | - name: "Copie du fichier de lecture série" | 13 | - name: "Copie du fichier de lecture série" |
14 | copy: | 14 | copy: |
15 | - src: ~/pfe/serial | ||
16 | - dest: /home/pi/{{ servernames }}/serial | 15 | + src: ~/pfe/seriallistener |
16 | + dest: /home/pi/{{ servernames }}/seriallistener | ||
17 | + | ||
18 | + - name: "Droit d'execution pour serial_listener" | ||
19 | + shell: chmod +x /home/pi/{{ servernames }}/seriallistener | ||
17 | 20 | ||
18 | - name: "Copie du binaire pour le(s) capteur(s)" | 21 | - name: "Copie du binaire pour le(s) capteur(s)" |
19 | copy: | 22 | copy: |
20 | src: ~/pfe/files/{{ binary_dir }}/out.bin | 23 | src: ~/pfe/files/{{ binary_dir }}/out.bin |
21 | dest: /home/pi/{{ servernames }}/out.bin | 24 | dest: /home/pi/{{ servernames }}/out.bin |
22 | 25 | ||
26 | + - name: "Copie du ficher de correspondance" | ||
27 | + shell: cp /home/pi/config_raspberry.txt /home/pi/{{ servernames }}/ | ||
28 | + | ||
29 | + - name: "Récupération des périphériques à flasher" | ||
30 | + shell: grep -Ff /home/pi/{{ servernames }}/config_experimentation.txt /home/pi/config_raspberry.txt | cut -d= -f3 | ||
31 | + register: devices_to_flash | ||
32 | + | ||
33 | + - name: "Flashage des boards" | ||
34 | + shell: cp /home/pi/{{ servernames }}/out.bin /media/pi/{{ item }} | ||
35 | + with_items: "{{ devices_to_flash.stdout_lines }}" | ||
36 | + | ||
23 | - name: "Lancement du programme de lecture série" | 37 | - name: "Lancement du programme de lecture série" |
24 | - command: /home/pi/while | ||
25 | - async: 3000000 | 38 | + command: /home/pi/{{ servernames }}/seriallistener |
39 | + args: | ||
40 | + chdir: ./{{ servernames }} | ||
41 | + async: 3000000 | ||
26 | poll: 0 | 42 | poll: 0 |
27 | 43 | ||
28 | - name: "Exp en cours ..." | 44 | - name: "Exp en cours ..." |
@@ -30,7 +46,7 @@ | @@ -30,7 +46,7 @@ | ||
30 | seconds: "{{ exp_duration }}" | 46 | seconds: "{{ exp_duration }}" |
31 | 47 | ||
32 | - name: "Kill de l'application" | 48 | - name: "Kill de l'application" |
33 | - shell: pkill while | 49 | + shell: pkill -9 seriallistener |
34 | 50 | ||
35 | - name: "Récupération des noms des résultats" | 51 | - name: "Récupération des noms des résultats" |
36 | shell: (cd /home/pi/{{ servernames }}/res; find . -maxdepth 1 -type f) | cut -d'/' -f2 | 52 | shell: (cd /home/pi/{{ servernames }}/res; find . -maxdepth 1 -type f) | cut -d'/' -f2 |
@@ -45,3 +61,9 @@ | @@ -45,3 +61,9 @@ | ||
45 | 61 | ||
46 | - name: "Suppression du dossier sur le noeud" | 62 | - name: "Suppression du dossier sur le noeud" |
47 | shell: rm -rf /home/pi/{{ servernames }} | 63 | shell: rm -rf /home/pi/{{ servernames }} |
64 | + | ||
65 | + - name: "Suppression du fichier d'experimentation" | ||
66 | + file: | ||
67 | + path: "~/pfe/toflash/{{ servernames }}.yml.started" | ||
68 | + state: absent | ||
69 | + delegate_to: 127.0.0.1 |
Raspberry/listener deleted
No preview for this file type
Raspberry/listener.c
@@ -25,14 +25,10 @@ typedef struct{ | @@ -25,14 +25,10 @@ typedef struct{ | ||
25 | 25 | ||
26 | void sig_handler(int sig) | 26 | void sig_handler(int sig) |
27 | { | 27 | { |
28 | - if (sig == SIGINT){ | 28 | + if (sig == SIGTERM){ |
29 | printf("\nSignal SIGINT received\n"); | 29 | printf("\nSignal SIGINT received\n"); |
30 | sig_received = 1; | 30 | sig_received = 1; |
31 | } | 31 | } |
32 | - else if (sig == SIGKILL){ | ||
33 | - printf("\nSignal SIGKILL received\n"); | ||
34 | - sig_received = 1; | ||
35 | - } | ||
36 | } | 32 | } |
37 | 33 | ||
38 | void create_error_file(char *str, char *msg){ | 34 | void create_error_file(char *str, char *msg){ |
@@ -67,7 +63,7 @@ void save_data(int pt, char* sensor){ | @@ -67,7 +63,7 @@ void save_data(int pt, char* sensor){ | ||
67 | while(1){ | 63 | while(1){ |
68 | int r = read(pt ,line,1); | 64 | int r = read(pt ,line,1); |
69 | if(r>=0){ | 65 | if(r>=0){ |
70 | - printf("sensor : %s - c = %c (characters read : %d)\n\n", sensor, line[0], r); | 66 | + //printf("sensor : %s - c = %c (characters read : %d)\n\n", sensor, line[0], r); |
71 | r = fprintf(file, "%c",line[0]); | 67 | r = fprintf(file, "%c",line[0]); |
72 | } | 68 | } |
73 | fflush(file); | 69 | fflush(file); |
@@ -78,18 +74,18 @@ void save_data(int pt, char* sensor){ | @@ -78,18 +74,18 @@ void save_data(int pt, char* sensor){ | ||
78 | } | 74 | } |
79 | } | 75 | } |
80 | fclose(file); | 76 | fclose(file); |
81 | - printf("end save_data\n"); | 77 | + //printf("end save_data\n"); |
82 | } | 78 | } |
83 | 79 | ||
84 | void reset_serial(int pt){ | 80 | void reset_serial(int pt){ |
85 | tcsetattr(pt, TCSANOW, &old); | 81 | tcsetattr(pt, TCSANOW, &old); |
86 | close(pt); | 82 | close(pt); |
87 | - printf("end reset_serial\n"); | 83 | + //printf("end reset_serial\n"); |
88 | } | 84 | } |
89 | 85 | ||
90 | int set_serial(SensorAndPort* sensorAndPort){ | 86 | int set_serial(SensorAndPort* sensorAndPort){ |
91 | char *device = sensorAndPort->port; | 87 | char *device = sensorAndPort->port; |
92 | - printf("device : %s\n",device); | 88 | + //printf("device : %s\n",device); |
93 | 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) | 89 | 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) |
94 | if(pt == -1){ | 90 | if(pt == -1){ |
95 | create_error_file(sensorAndPort->sensor, "impossible de se connecter au port série, veuillez vérifier le microprocesseur et la raspberry"); | 91 | create_error_file(sensorAndPort->sensor, "impossible de se connecter au port série, veuillez vérifier le microprocesseur et la raspberry"); |
@@ -165,7 +161,7 @@ void get_ports_to_read(char list_sensors[MAX_SENSORS][30], char list_serial_port | @@ -165,7 +161,7 @@ void get_ports_to_read(char list_sensors[MAX_SENSORS][30], char list_serial_port | ||
165 | j++; | 161 | j++; |
166 | } | 162 | } |
167 | if(j==count_serial_port){ | 163 | if(j==count_serial_port){ |
168 | - printf("Il n'y a pas de capteurs avec ce nom : %s\n",list_sensors[i]); | 164 | + //printf("Il n'y a pas de capteurs avec ce nom : %s\n",list_sensors[i]); |
169 | create_error_file(list_sensors[i],"Il n'y a pas de capteurs avec ce nom"); | 165 | create_error_file(list_sensors[i],"Il n'y a pas de capteurs avec ce nom"); |
170 | } | 166 | } |
171 | j=0; | 167 | j=0; |
@@ -181,11 +177,11 @@ int main(int argc, char *argv[]){ | @@ -181,11 +177,11 @@ int main(int argc, char *argv[]){ | ||
181 | char * config_experimentation = "config_experimentation.txt"; | 177 | char * config_experimentation = "config_experimentation.txt"; |
182 | char * config_raspberry = "config_raspberry.txt"; | 178 | char * config_raspberry = "config_raspberry.txt"; |
183 | if(argc>1){ | 179 | if(argc>1){ |
184 | - printf("fichier contenant la liste des capteurs de l'experimentation : %s\n",argv[1]); | 180 | + //printf("fichier contenant la liste des capteurs de l'experimentation : %s\n",argv[1]); |
185 | char * config_experimentation = argv[1]; | 181 | char * config_experimentation = argv[1]; |
186 | } | 182 | } |
187 | if(argc>2){ | 183 | if(argc>2){ |
188 | - printf("fichier contenant la correspondance de tous les capteurs avec leur liaison série : %s\n",argv[2]); | 184 | + //printf("fichier contenant la correspondance de tous les capteurs avec leur liaison série : %s\n",argv[2]); |
189 | char * config_raspberry = argv[2]; | 185 | char * config_raspberry = argv[2]; |
190 | } | 186 | } |
191 | SensorAndPort sensorAndPort[MAX_SENSORS]; | 187 | SensorAndPort sensorAndPort[MAX_SENSORS]; |
@@ -200,8 +196,8 @@ int main(int argc, char *argv[]){ | @@ -200,8 +196,8 @@ int main(int argc, char *argv[]){ | ||
200 | count_serial_port = read_file_by_line(list_serial_port, config_raspberry); | 196 | count_serial_port = read_file_by_line(list_serial_port, config_raspberry); |
201 | get_ports_to_read(list_sensors,list_serial_port,count_sensors, count_serial_port, sensors_ports); | 197 | get_ports_to_read(list_sensors,list_serial_port,count_sensors, count_serial_port, sensors_ports); |
202 | 198 | ||
203 | - action.sa_handler=sig_handler; | ||
204 | - sigaction(SIGINT, &action, NULL); | 199 | + //action.sa_handler=sig_handler; |
200 | + //sigaction(SIGTERM, &action, NULL); | ||
205 | 201 | ||
206 | for(i=0;i<count_sensors;i++){ | 202 | for(i=0;i<count_sensors;i++){ |
207 | strcpy(sensorAndPort[i].sensor,list_sensors[i]); | 203 | strcpy(sensorAndPort[i].sensor,list_sensors[i]); |
@@ -216,4 +212,4 @@ int main(int argc, char *argv[]){ | @@ -216,4 +212,4 @@ int main(int argc, char *argv[]){ | ||
216 | 212 | ||
217 | //169.254.24.80 | 213 | //169.254.24.80 |
218 | 214 | ||
219 | -//169.254.25.26 | ||
220 | \ No newline at end of file | 215 | \ No newline at end of file |
216 | +//169.254.25.26 |
No preview for this file type
Serveur/main
No preview for this file type
Serveur/main.c
@@ -205,7 +205,7 @@ int process_exp(Experiment *experiment) { | @@ -205,7 +205,7 @@ int process_exp(Experiment *experiment) { | ||
205 | } | 205 | } |
206 | } | 206 | } |
207 | sprintf(cmd2, "mkdir ~/exp_%d", experiment->exp_id); | 207 | sprintf(cmd2, "mkdir ~/exp_%d", experiment->exp_id); |
208 | - sprintf(cmd1, "runuser -l %s -c \'echo \"%s\" | ssh pi@%s \"%s && cat > ~/exp_%d/sensors.txt\"", | 208 | + sprintf(cmd1, "runuser -l %s -c \'echo \"%s\" | ssh pi@%s \"%s && cat > ~/exp_%d/config_experimentation.txt\"", |
209 | USERNAME, | 209 | USERNAME, |
210 | sensors_list, | 210 | sensors_list, |
211 | experiment->nodes[i].ip, | 211 | experiment->nodes[i].ip, |
@@ -224,7 +224,7 @@ int process_exp(Experiment *experiment) { | @@ -224,7 +224,7 @@ int process_exp(Experiment *experiment) { | ||
224 | fclose(hosts_fp); | 224 | fclose(hosts_fp); |
225 | 225 | ||
226 | char ansible_command[512]; | 226 | char ansible_command[512]; |
227 | - sprintf(ansible_command, "runuser -l %s -c \'ansible-playbook /etc/ansible/roles/test.yml -i %s -e \"servernames=exp_%d exp_duration=%d binary_dir=%s\"", | 227 | + sprintf(ansible_command, "runuser -l %s -c \'ansible-playbook /home/antoine/pfe/ansible.yml -i %s -e \"servernames=exp_%d exp_duration=%d binary_dir=%s\"", |
228 | USERNAME, | 228 | USERNAME, |
229 | hosts_filename, | 229 | hosts_filename, |
230 | experiment->exp_id, | 230 | experiment->exp_id, |
@@ -275,8 +275,9 @@ void check_files() { | @@ -275,8 +275,9 @@ void check_files() { | ||
275 | 275 | ||
276 | if(dir != NULL) { | 276 | if(dir != NULL) { |
277 | while(dirent = readdir(dir)) { | 277 | while(dirent = readdir(dir)) { |
278 | - if(dirent->d_type == DT_REG) { | 278 | + if((dirent->d_type == DT_REG) && (strstr(dirent->d_name, ".started") == NULL)) { |
279 | char file_name[128]; | 279 | char file_name[128]; |
280 | + char new_file_name[128]; | ||
280 | strcpy(file_name, TOFLASH_PATH); | 281 | strcpy(file_name, TOFLASH_PATH); |
281 | strcat(file_name, dirent->d_name); | 282 | strcat(file_name, dirent->d_name); |
282 | Experiment *experiment = read_file(file_name); | 283 | Experiment *experiment = read_file(file_name); |
@@ -284,7 +285,9 @@ void check_files() { | @@ -284,7 +285,9 @@ void check_files() { | ||
284 | print_exp(experiment); | 285 | print_exp(experiment); |
285 | #endif | 286 | #endif |
286 | if(!process_exp(experiment)) { | 287 | if(!process_exp(experiment)) { |
287 | - remove(file_name); | 288 | + strcpy(new_file_name, file_name); |
289 | + strcat(new_file_name, ".started"); | ||
290 | + rename(file_name, new_file_name); | ||
288 | } | 291 | } |
289 | free_exp(experiment); | 292 | free_exp(experiment); |
290 | } | 293 | } |
@@ -320,4 +323,4 @@ int main(int argc, char **argv) { | @@ -320,4 +323,4 @@ int main(int argc, char **argv) { | ||
320 | sleep(10); | 323 | sleep(10); |
321 | } | 324 | } |
322 | return 0; | 325 | return 0; |
323 | -} | ||
324 | \ No newline at end of file | 326 | \ No newline at end of file |
327 | +} |
Serveur/serial deleted
@@ -1 +0,0 @@ | @@ -1 +0,0 @@ | ||
1 | -blabla |