The main purpose of this exercise is to program a very simple diagnostic system. It reads the values of the induction motor current, and detects the overload (for now, detects exceeding some value of current), and gives RMS. It also provides self-diagnostics which makes sure that data is read correctly.
Skills:
Grading: points are given in square brackets.
./a.out data1.dat
read_data.c
to count number of values read from fileread_data.c
) write a program which reads the data in and stops after reading the value exceeding some given x [2] (where x is a value given as a parameter [2]). The program should write out the value as well as the number of values read so far (index
) on the standard error output [2] (use fprintf(stderr,…)
).float array[3]={71,72,73}; int i=0,k=0; for(i=0;i<30;i++) { k=i%3; printf("%f \n",array[k]); }
In this example, while i
changes from 0 to 30, k
changes only from 0 to 2. Remember that in c language the first index in array is 0 and the last is n-1
while n
is the size of array.
./a.out ac_current.dat > rms_value.dat
Note if the output file doesn't exist, it will be created, if it exists it will be overwritten.
To plot data from a file, you can write the following command:
echo 'plot "ac_current.dat" with lines; pause mouse' | gnuplot
A watchdog is a process which makes sure that other processes work properly. It is often used to make sure that data from sensors is read.
Enhance your program to accommodate a watchdog in the following way.
Introduce a shared memory data containing information about how many measurements have been read in, it will be needed to set up a watchdog.
Program the watchdog. It will check if data is read at least 1000 times a second.
fprintf(stderr,…)
).usleep()
or sleep()
in the child process while reading some given index) [2].