Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
guipaiva authored Dec 18, 2019
1 parent 04e765b commit 064be9c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
44 changes: 22 additions & 22 deletions functions.c
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#include "functions.h"

int converte_x(int id){
int convert_x(int id){
int x;
if (id % 10 == 0)
id--;
x = 3*(id/10) +1;
return x;
}

int converte_y(int id){
int convert_y(int id){
int y;
if (id % 10 == 0){
y = 28;
Expand Down Expand Up @@ -206,9 +206,9 @@ void *print_matrix(void *args){
printf("\n");
}

printf("%sHora: %02d:%02d:%02d\n",WHT,hor,min,sec);
printf("%sTime: %02d:%02d:%02d\n",WHT,hor,min,sec);
if (yes)
printf("%sThread n. %d foi destruida\n",WHT,nodes[idx][idy].id);
printf("%sThread #%d has been destroyed\n",WHT,nodes[idx][idy].id);
yes = 0;
pthread_mutex_unlock(&mtx_prt);
sleep(1);
Expand All @@ -231,7 +231,7 @@ void *fire(void *args){
nodes[idx][idy].live = 0;
//pthread_cancel(sensor_threads[idx][idy]);
log_thr = fopen("threads.log", "a");
fprintf(log_thr, "Thread %d destruida em %02d:%02d:%02d\n", nodes[idx][idy].id,hor, min, sec);
fprintf(log_thr, "Thread #%d was destroyed at %02d:%02d:%02d\n", nodes[idx][idy].id,hor, min, sec);
fclose(log_thr);
}
else if (mat[x][y] == 'X'){}
Expand All @@ -246,8 +246,8 @@ void *sensor_node(void *args){
int idx, idy;
int x, y;
int sent;
x = converte_x(id);
y = converte_y(id);
x = convert_x(id);
y = convert_y(id);
idx = ((x+2)/3)-1;
idy = ((y+2)/3)-1;
while(1){
Expand Down Expand Up @@ -301,55 +301,55 @@ void *central(void *args){

if (nodes[i][j].U == 1){
nodes[i][j].U = 0;
log_fire = fopen("incendios.log", "a");
log_fire = fopen("fire.log", "a");
memcpy(msg, nodes[i][j].up, size);
fprintf(log_fire,"Central %02d:%02d:%02d\n",hor,min,sec);
fprintf(log_fire,"A Thread n. %d Identificou um incêndio em [%d][%d]",msg[0],msg[1],msg[2]);
fprintf(log_fire," às %02d:%02d:%02d\n",msg[3],msg[4],msg[5]);
fprintf(log_fire,"Thread #%d detected a fire at [%d][%d]",msg[0],msg[1],msg[2]);
fprintf(log_fire," at %02d:%02d:%02d\n\n",msg[3],msg[4],msg[5]);
fclose(log_fire);
clear_msg(msg);
firefighter(msg[1],msg[2]);
}
else if (nodes[i][j].D == 1){
nodes[i][j].D = 0;
log_fire = fopen("incendios.log", "a");
log_fire = fopen("fire.log", "a");
memcpy(msg, nodes[i][j].down, size);
fprintf(log_fire,"Central %02d:%02d:%02d\n",hor,min,sec);
fprintf(log_fire,"A Thread n. %d Identificou um incêndio em [%d][%d]",msg[0],msg[1],msg[2]);
fprintf(log_fire," às %02d:%02d:%02d\n",msg[3],msg[4],msg[5]);
fprintf(log_fire,"Thread #%d detected a fire at [%d][%d]",msg[0],msg[1],msg[2]);
fprintf(log_fire," at %02d:%02d:%02d\n\n",msg[3],msg[4],msg[5]);
fclose(log_fire);
clear_msg(msg);
firefighter(msg[1],msg[2]);
}
else if (nodes[i][j].L == 1){
nodes[i][j].L = 0;
log_fire = fopen("incendios.log", "a");
log_fire = fopen("fire.log", "a");
memcpy(msg, nodes[i][j].left, size);
fprintf(log_fire,"Central %02d:%02d:%02d\n",hor,min,sec);
fprintf(log_fire,"A Thread n. %d Identificou um incêndio em [%d][%d]",msg[0],msg[1],msg[2]);
fprintf(log_fire," às %02d:%02d:%02d\n",msg[3],msg[4],msg[5]);
fprintf(log_fire,"Thread #%d detected a fire at [%d][%d]",msg[0],msg[1],msg[2]);
fprintf(log_fire," at %02d:%02d:%02d\n\n",msg[3],msg[4],msg[5]);
fclose(log_fire);
clear_msg(msg);
firefighter(msg[1],msg[2]);
}
else if (nodes[i][j].R == 1){
nodes[i][j].R = 0;
log_fire = fopen("incendios.log", "a");
log_fire = fopen("fire.log", "a");
memcpy(msg, nodes[i][j].right, size);
fprintf(log_fire,"Central %02d:%02d:%02d\n",hor,min,sec);
fprintf(log_fire,"A Thread n. %d Identificou um incêndio em [%d][%d]",msg[0],msg[1],msg[2]);
fprintf(log_fire," às %02d:%02d:%02d\n",msg[3],msg[4],msg[5]);
fprintf(log_fire,"Thread #%d detected a fire at [%d][%d]",msg[0],msg[1],msg[2]);
fprintf(log_fire," at %02d:%02d:%02d\n\n",msg[3],msg[4],msg[5]);
fclose(log_fire);
clear_msg(msg);
firefighter(msg[1],msg[2]);
}
else if (nodes[i][j].C == 1){
nodes[i][j].C = 0;
log_fire = fopen("incendios.log", "a");
log_fire = fopen("fire.log", "a");
memcpy(msg, nodes[i][j].center, size);
fprintf(log_fire,"Central %02d:%02d:%02d\n",hor,min,sec);
fprintf(log_fire,"A Thread n. %d Identificou um incêndio em [%d][%d]",msg[0],msg[1],msg[2]);
fprintf(log_fire," às %02d:%02d:%02d\n",msg[3],msg[4],msg[5]);
fprintf(log_fire,"Thread #%d detected a fire at [%d][%d]",msg[0],msg[1],msg[2]);
fprintf(log_fire," at %02d:%02d:%02d\n\n",msg[3],msg[4],msg[5]);
fclose(log_fire);
clear_msg(msg);
firefighter(msg[1],msg[2]);
Expand Down
4 changes: 2 additions & 2 deletions functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ void send_msg(int x, int y);
void prop_msg(int x, int y);
void clear_msg(int msg[6]);
void firefighter(int x, int y);
int converte_x(int id);
int converte_y(int id);
int convert_x(int id);
int convert_y(int id);


#endif
2 changes: 1 addition & 1 deletion main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ int main(int argc, char const *argv[])
create_matrix(mat);

FILE *log_fire, *log_thr;
log_fire = fopen("incendios.log", "w");
log_fire = fopen("fire.log", "w");
fclose(log_fire);
log_thr = fopen("threads.log", "w");
fclose(log_thr);
Expand Down

0 comments on commit 064be9c

Please sign in to comment.