Lab 6 – Temperature Sensor Network

In this lab, you’ll be designing a Temperature Sensor Network. You will be reading 3 temperature sensors, each at a rate of 1 sample/second. The data collected from these 3 sensors will be stored in 3 ring-buffers of size 10 each. Once every 5 seconds, you’ll be averaging the content of the 3 ring-buffers and storing the result in 3 additional ring-buffers of size 2. Once every 10 seconds, you’ll be averaging the content of the 3 lower-level ring-buffers and storing the results in 3 additional ring-buffers of size 1, than, you’ll compute the average of the 3 lowest-level buffers and store the result in a single ring-buffer of size 1.  Okay, by now you should be confused! Perhaps a diagram will help to clarify:

 

 

 

 

 

 

 

 

 

 

 

 

 


You’ll need to implement a total of 7 tasks, labeled a through g. Tasks a, b, and c will be running at 1 Hz and will read the corresponding temperature sensor and store the value in the next buffer location, in a circular manner. Tasks d, e, and f will run at .2 Hz and will, each time they are invoked, average the 10 samples of the corresponding first-level buffers and store the result in the next second-level buffer location, in a circular manner. Finally, task g will run at .1 Hz and will, each time it is invoked, average the 2 samples of the corresponding second-level buffers and store the results in the third-level buffer location. Than, task g will compute the average across the three third-level buffers and store the result into the single forth-level buffer. In addition, task g will print the result to the console.

To help get you started, some framework code is provided here main.c. Note that a structure, called temperature_t is defined that declares the buffers you’ll need. Also, start and stop routines (prog_start, prog_end) are provided to start/stop your system. Since there will be a total of 7 processes reading/writing the shared temperature_t structure, you must use semaphores for mutual exclusion.

Once you have completed your project, demo it to your TA for credit. In your report, write pseudo-code for designing the same system using a single task and a delay function, and discuss the advantage/disadvantage of the multi-task versus single-task versions.