The assignment refers to track A).
The HUB process receives a chosen number of temperatures from J sensors. For each sensor temperature, a child is created that takes care of the transmission to the hub. The hub waits for J connected processes and then the temperatures are sent to the server which takes care of forwarding them to the actuators already listening. Then, they calculate the average of the measures and the user is asked to unsubscribe the actuators.
First launch:
$ ./hub "J" (default J = 2)
$ ./server
subsequently the actuators are registered:
$ ./attuatori "name" "(i/d)"
Tgoal and the list of sensor names will be requested iteratively. e.g .:
$ ./attuatori a1 i
Tgoal = 23
Enter 0 to stop ...
Sensor name to subscribe: t1
Sensor name to subscribe: t2
Sensor name to subscribe: 0
$ ./attuatori a2 i
Tgoal = 18
Enter 0 to stop ...
Sensor name to subscribe: t1
Sensor name to subscribe: 0
The actuators will subscribe to the server and wait for the temperatures to be subscribed.
Successively it is required to run J processes (J terminals) sensors "name" "n° measures". e.g.:
$ ./sensors t1 3
$ ./sensors t2 4
Each process will send temperatures to the hub as required by the assignment. The hub will take care of the transmission to the server and the server will only forward the requested measures to the enrollment actuators.
The actuators will calculate the averages and decide accordingly whether to turn the heaters on or off.
The sensor processes end the execution by receiving the number of actuators that have subscribed to the measure. For terminate the actuators, it is required the subscription by the user.
So, one or more actuators are launched in unsubscribe mode. e.g .:
$ ./attuatori a3 d
Enter 0 to stop ...
Actuator name to unsubscribe: a1
Actuator name to unsubscribe: a2
Actuator name to unsubscribe: 0
Then, the server send an empty string to actuators and the reception will end.