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
82c5d97f
Commit
82c5d97f
authored
5 months ago
by
fdai7354
Browse files
Options
Downloads
Patches
Plain Diff
Write to the Character Device
parent
eea6a9d5
No related branches found
No related tags found
1 merge request
!1
Kernel module
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.c
+27
-0
27 additions, 0 deletions
main.c
with
27 additions
and
0 deletions
main.c
+
27
−
0
View file @
82c5d97f
...
@@ -9,6 +9,8 @@
...
@@ -9,6 +9,8 @@
static
const
char
*
PIPE_ONE
=
"/tmp/pipeOne"
;
static
const
char
*
PIPE_ONE
=
"/tmp/pipeOne"
;
static
const
char
*
PIPE_TWO
=
"/tmp/pipeTwo"
;
static
const
char
*
PIPE_TWO
=
"/tmp/pipeTwo"
;
static
const
char
*
CHAR_DEV
=
"/dev/packet_receiver"
;
int
main
(
void
)
int
main
(
void
)
{
{
// mkfifo() nur ausführen, wenn die Pipes noch nicht existieren,
// mkfifo() nur ausführen, wenn die Pipes noch nicht existieren,
...
@@ -36,6 +38,16 @@ int main(void)
...
@@ -36,6 +38,16 @@ int main(void)
return
1
;
return
1
;
}
}
// Open the char device for writing
int
fdCharDev
=
open
(
CHAR_DEV
,
O_WRONLY
);
if
(
fdCharDev
==
-
1
)
{
perror
(
"open /dev/packet_receiver"
);
close
(
fdOne
);
close
(
fdTwo
);
return
1
;
}
printf
(
"Opened %s for writing.
\n
"
,
CHAR_DEV
);
// Dauerhafte Lese-Schleife
// Dauerhafte Lese-Schleife
while
(
1
)
{
while
(
1
)
{
char
bufOne
[
128
]
=
{
0
};
char
bufOne
[
128
]
=
{
0
};
...
@@ -91,6 +103,21 @@ int main(void)
...
@@ -91,6 +103,21 @@ int main(void)
break
;
break
;
}
}
// ========= Write to char device =========
// Build a packet string. Adapt SENDER / IDs / values to your needs.
// Example: "SENDER=1 VID1=10 VAL1=<temp> VID2=11 VAL2=<freq>"
char
transmitBuf
[
256
]
=
{
0
};
snprintf
(
transmitBuf
,
sizeof
(
transmitBuf
),
"SENDER=1 VID1=10 VAL1=%s VID2=11 VAL2=%s"
,
bufOne
,
bufTwo
);
ssize_t
written
=
write
(
fdCharDev
,
transmitBuf
,
strlen
(
transmitBuf
));
if
(
written
<
0
)
{
perror
(
"write /dev/packet_receiver"
);
}
else
{
printf
(
"Wrote packet to %s: %s
\n
"
,
CHAR_DEV
,
transmitBuf
);
}
// Kurze Pause, damit CPU-Last nicht durch
// Kurze Pause, damit CPU-Last nicht durch
// Dauerschleife hochgetrieben wird
// Dauerschleife hochgetrieben wird
usleep
(
200000
);
// 200 ms
usleep
(
200000
);
// 200 ms
...
...
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