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
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoph-Anton Schwierz
EmbeddedLinuxProject
Commits
3dc07858
Commit
3dc07858
authored
4 months ago
by
Chris
Browse files
Options
Downloads
Patches
Plain Diff
added FIFO for read_cpu_frequency
parent
62a6f361
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.c
+29
-3
29 additions, 3 deletions
main.c
with
29 additions
and
3 deletions
main.c
+
29
−
3
View file @
3dc07858
...
@@ -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
.
0
f
;
float
freq
=
atol
(
buffer
)
/
1000000
.
0
f
;
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
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