-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathweightroom.c
76 lines (56 loc) · 1.47 KB
/
weightroom.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/neutrino.h>
#include <sys/netmgr.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include "server.h"
#define MAX_WEIGHT 500
char* updateWeight(int* weight);
int main(int argc, char **argv){
int coid;
int server_ok;
//Connect to server
coid = name_open(SERVER_NAME, 0);
//Build the update struct
weightChange_t change;
change.type = WEIGHT_TYPE;
//Init temperature
srand(time(NULL));
int weight;
char* lift;
while(1){
//Check if someone has attempted to lift a weight that is above a certain threshold
lift = updateWeight(&weight);
if(!(lift == NULL)){
strcpy(change.lift, lift);
change.weight = weight;
printf("Someone attempted to lift a large weight: %d type of lift: %s\n", weight, lift);
MsgSend(coid, &change, sizeof(change), &server_ok, sizeof(server_ok));
}
}
return 0;
}
//Generator function not needed since few variables are being tracked
//Update function
//Randomly cause an emergency to occur
//This function is meant to simulate a person triggering an emergency
char* updateWeight(int* weight){
//Sleep for 10 seconds, arbitrary delay for someone to attempt a large lift
sleep(10);
int r = rand() % (600 - 200 + 1) + 200;
if(r >= MAX_WEIGHT){
*weight = r;
int i = (rand() % 3);
if(i == 0){
return "bench press";
} else if (i == 1){
return "deadlift";
} else if (i == 2){
return "squat rack";
}
}
return NULL;
}