Skip to content
Snippets Groups Projects
Commit 3dc07858 authored by Chris's avatar Chris
Browse files

added FIFO for read_cpu_frequency

parent 62a6f361
No related branches found
No related tags found
No related merge requests found
...@@ -26,7 +26,7 @@ void read_cpu_temp() ...@@ -26,7 +26,7 @@ void read_cpu_temp()
// write pipe // write pipe
const char *pOne = "/tmp/pipeOne"; const char *pOne = "/tmp/pipeOne";
int vOne = open(pOne, O_WRONLY); // todo: | O_NONBLOCK int vOne = open(pOne, O_WRONLY);
if (vOne == -1) if (vOne == -1)
{ {
perror("Failed to open pipe one in read_cpu_temp"); perror("Failed to open pipe one in read_cpu_temp");
...@@ -58,7 +58,20 @@ void read_cpu_frequency() ...@@ -58,7 +58,20 @@ void read_cpu_frequency()
if (fgets(buffer, sizeof(buffer), file) != NULL) if (fgets(buffer, sizeof(buffer), file) != NULL)
{ {
float freq = atol(buffer) / 1000000.0f; float freq = atol(buffer) / 1000000.0f;
char message[1024];
snprintf(message, sizeof(message), "%f", freq);
printf("CPU frequency: %f GHz\n", freq); printf("CPU frequency: %f GHz\n", freq);
//write pipe
const char *pTwo = "/tmp/pipeTwo";
int vTwo = open(pTwo, O_WRONLY);
if (vTwo == -1)
{
perror("Failed to open pipe two in read_cpu_frequency");
return;
}
write(vTwo, message, sizeof(message));
close(vTwo);
} }
else else
{ {
...@@ -72,14 +85,22 @@ int main(void) ...@@ -72,14 +85,22 @@ int main(void)
// create and open pipes // create and open pipes
const char *pOne = "/tmp/pipeOne"; const char *pOne = "/tmp/pipeOne";
mkfifo(pOne, 0666); mkfifo(pOne, 0666);
int vOne = open(pOne, O_RDONLY | O_NONBLOCK);
int vOne = open(pOne, O_RDONLY | O_NONBLOCK); // todo: | O_NONBLOCK
if (vOne == -1) if (vOne == -1)
{ {
perror("Failed to open pipe one in main"); perror("Failed to open pipe one in main");
return 1; return 1;
} }
const char *pTwo = "/tmp/pipeTwo";
mkfifo(pTwo, 0666);
int vTwo = open(pTwo, O_RDONLY | O_NONBLOCK);
if (vTwo == -1)
{
perror("Failed to open pipe two in main");
return 1;
}
read_cpu_temp(); read_cpu_temp();
read_cpu_frequency(); read_cpu_frequency();
...@@ -89,5 +110,10 @@ int main(void) ...@@ -89,5 +110,10 @@ int main(void)
printf("value one received: %s\n", mOne); printf("value one received: %s\n", mOne);
close(vOne); close(vOne);
char mTwo[1024] = {};
read(vTwo, mTwo, sizeof(mTwo));
printf("value two received: %s\n", mTwo);
close(vTwo);
return 0; return 0;
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment