Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EmbeddedLinuxProject
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoph-Anton Schwierz
EmbeddedLinuxProject
Commits
297bcc5a
Commit
297bcc5a
authored
6 months ago
by
Chris
Browse files
Options
Downloads
Patches
Plain Diff
added FIFO for read_cpu_temp
parent
8688dd31
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.c
+35
-2
35 additions, 2 deletions
main.c
with
35 additions
and
2 deletions
main.c
+
35
−
2
View file @
297bcc5a
#include
<stdio.h>
#include
<stdlib.h>
#include
<sys/stat.h>
//for pipes
#include
<fcntl.h>
#include
<unistd.h>
void
read_cpu_temp
()
{
FILE
*
file
;
...
...
@@ -14,7 +18,20 @@ void read_cpu_temp() {
if
(
fgets
(
buffer
,
sizeof
(
buffer
),
file
)
!=
NULL
)
{
long
temp
=
atol
(
buffer
)
/
1000
;
printf
(
"CPU temperature: %ld C
\n
"
,
temp
);
char
message
[
1024
];
snprintf
(
message
,
sizeof
(
message
),
"%ld"
,
temp
);
printf
(
"CPU temperature: %ld C
\n
"
,
temp
);
//todo: print message instead of temp?
//write pipe
const
char
*
pOne
=
"/tmp/pipeOne"
;
int
vOne
=
open
(
pOne
,
O_WRONLY
);
//todo: | O_NONBLOCK
if
(
vOne
==
-
1
){
perror
(
"Failed to open pipe one in read_cpu_temp"
);
return
;
}
write
(
vOne
,
message
,
sizeof
(
message
));
close
(
vOne
);
}
else
{
printf
(
"Error reading file
\n
"
);
}
...
...
@@ -27,7 +44,7 @@ void read_cpu_frequency() {
char
*
freq_path
=
"/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_cur_freq"
;
file
=
fopen
(
freq_path
,
"r"
);
if
(
file
==
NULL
)
{
if
(
file
==
NULL
)
{
b
printf
(
"Error opening file
\n
"
);
return
;
}
...
...
@@ -42,7 +59,23 @@ void read_cpu_frequency() {
}
int
main
(
void
)
{
//create pipes
const
char
*
pOne
=
"/tmp/pipeOne"
;
mkfifo
(
pOne
,
0666
);
read_cpu_temp
();
read_cpu_frequency
();
//read pipes
int
vOne
=
open
(
pOne
,
O_RDONLY
);
//todo: | O_NONBLOCK
if
(
vOne
==
-
1
)
{
perror
(
"Failed to open pipe one in main"
);
return
1
;
}
char
mOne
[
1024
]
=
{};
//for now only sending char with the pipe
read
(
vOne
,
mOne
,
sizeof
(
mOne
));
printf
(
"value one received: %s
\n
"
,
mOne
);
close
(
vOne
);
return
0
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment