Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
S
system_programming
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
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
hyunjun_cho
system_programming
Commits
7fa5bcaa
Commit
7fa5bcaa
authored
4 years ago
by
hyunjun_cho
Browse files
Options
Downloads
Patches
Plain Diff
application rename
parent
a1dff17e
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app1
+0
-0
0 additions, 0 deletions
app1
app1.c
+130
-0
130 additions, 0 deletions
app1.c
with
130 additions
and
0 deletions
app
→
app
1
+
0
−
0
View file @
7fa5bcaa
No preview for this file type
This diff is collapsed.
Click to expand it.
app1.c
0 → 100644
+
130
−
0
View file @
7fa5bcaa
#include
<fcntl.h>
#include
<unistd.h>
#include
<stdlib.h>
#include
<stdio.h>
#include
<string.h>
#include
<math.h>
#include
<errno.h>
#include
<time.h>
#include
<arpa/inet.h>
#include
<sys/socket.h>
#include
<sys/ioctl.h>
#include
<sys/types.h>
#include
<sys/sysmacros.h>
#define SMOKE_DEV_PATH "/dev/smoke_dev"
#define BUZZER_DEV_PATH "/dev/buzzer_dev"
#define HYDRO_DEV_PATH "/dev/hydro_dev"
#define IOCTL_HYDRO_MAGIC_NUMBER 'h'
#define INTERVAL 50000
#define BUFF_SIZE 50
typedef
struct
{
int
hydro_int
;
int
hydro_double
;
int
temp_int
;
int
temp_double
;
}
HYDRO
;
#define IOCTL_CMD_HYDRO _IOR(IOCTL_HYDRO_MAGIC_NUMBER, 0, HYDRO)
int
main
(
void
)
{
int
client_socket
;
struct
sockaddr_in
server_addr
;
char
buff
[
BUFF_SIZE
+
5
]
=
"*Humidity:"
;
char
buff2
[
BUFF_SIZE
+
5
]
=
"Temperature"
;
client_socket
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
);
if
(
client_socket
==
-
1
)
{
printf
(
"socket fail
\n
"
);
exit
(
1
);
}
memset
(
&
server_addr
,
0
,
sizeof
(
server_addr
));
server_addr
.
sin_family
=
AF_INET
;
server_addr
.
sin_port
=
htons
(
4029
);
server_addr
.
sin_addr
.
s_addr
=
inet_addr
(
"192.168.10.6"
);
if
(
connect
(
client_socket
,
(
struct
sockaddr
*
)
&
server_addr
,
sizeof
(
server_addr
))
==
-
1
)
{
printf
(
"connect error
\n
"
);
return
1
;
}
__pid_t
pid
;
int
smoke_dev
,
smoke_data
;
int
buzzer_dev
,
buzzer_data
=
400
;
int
hydro_dev
;
HYDRO
hydro_info
;
char
Temp
[
20
],
Hum
[
20
];
smoke_dev
=
open
(
SMOKE_DEV_PATH
,
O_RDONLY
);
buzzer_dev
=
open
(
BUZZER_DEV_PATH
,
O_RDWR
);
hydro_dev
=
open
(
HYDRO_DEV_PATH
,
O_RDONLY
);
if
(
smoke_dev
<
0
)
{
printf
(
"fail to open smoke detection sensor device
\n
"
);
return
1
;
}
if
(
buzzer_dev
<
0
)
{
printf
(
"fail to open buzzer sensor device
\n
"
);
return
1
;
}
if
(
hydro_dev
<
0
)
{
printf
(
"fail to open hydro sensor device
\n
"
);
return
1
;
}
int
count
=
0
;
pid
=
fork
();
if
(
pid
)
{
while
(
1
)
{
read
(
smoke_dev
,
&
smoke_data
,
sizeof
(
int
));
printf
(
"data : %d
\n
"
,
smoke_data
);
if
(
smoke_data
>
600
)
{
write
(
buzzer_dev
,
&
buzzer_data
,
sizeof
(
int
)
*
2
);
}
sleep
(
1
);
}
}
else
{
while
(
1
)
{
ioctl
(
hydro_dev
,
IOCTL_CMD_HYDRO
,
&
hydro_info
);
printf
(
"temperature is %d.%d%%, humidity is %d.%d%%
\n
"
,
hydro_info
.
temp_int
,
hydro_info
.
temp_double
,
hydro_info
.
hydro_int
,
hydro_info
.
hydro_double
);
if
(
hydro_info
.
temp_double
>
100
)
hydro_info
.
temp_double
/=
100
;
else
if
(
hydro_info
.
temp_double
>
10
)
hydro_info
.
temp_double
/=
10
;
if
(
hydro_info
.
hydro_double
>
100
)
hydro_info
.
hydro_double
/=
100
;
else
if
(
hydro_info
.
hydro_double
>
10
)
hydro_info
.
hydro_double
/=
10
;
sprintf
(
Temp
,
"%d.%dC"
,
hydro_info
.
temp_int
,
hydro_info
.
temp_double
);
sprintf
(
Hum
,
"%d.%d%%"
,
hydro_info
.
hydro_int
,
hydro_info
.
hydro_double
);
strcat
(
buff
,
Hum
);
strcat
(
buff2
,
Temp
);
printf
(
"%s %s
\n
"
,
Temp
,
Hum
);
write
(
client_socket
,
buff2
,
strlen
(
buff2
)
+
1
);
write
(
client_socket
,
buff
,
strlen
(
buff
)
+
1
);
strcpy
(
buff
,
"*Humidity:"
);
strcpy
(
buff2
,
"Temperature"
);
//buff = "**Humidity:", buff2 = "Temperature";
sleep
(
5
);
}
}
close
(
client_socket
);
close
(
smoke_dev
);
close
(
buzzer_dev
);
close
(
hydro_dev
);
return
0
;
}
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