Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
car-controlserver
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wenzhongjian
car-controlserver
Commits
9db62149
Commit
9db62149
authored
Feb 11, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
78c45f77
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
34 additions
and
34 deletions
+34
-34
gpio.h
lib/gpio.h
+8
-1
main
main
+0
-0
gpio.c
src/gpio.c
+5
-2
gpio.o
src/gpio.o
+0
-0
opensh.c
src/opensh.c
+14
-16
opensh.o
src/opensh.o
+0
-0
main.c
usr/main.c
+7
-15
main.o
usr/main.o
+0
-0
No files found.
lib/gpio.h
View file @
9db62149
#ifndef __GPIO_H__
#ifndef __GPIO_H__
#define __GPIO_H__
#define __GPIO_H__
// 定义 PWM 引脚的 WiringPi 编号
#define PWM_PIN 1
// 定义 PWM 频率为 50Hz
#define PWM_FREQ 50
// 定义占空比范围,这里设置为 0 到 1000
#define MIN_DUTY 0
#define MAX_DUTY 1000
#endif
#endif
\ No newline at end of file
main
View file @
9db62149
No preview for this file type
src/gpio.c
View file @
9db62149
#include "wiringPi.h"
#include <wiringPi.h>
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
src/gpio.o
View file @
9db62149
No preview for this file type
src/opensh.c
View file @
9db62149
...
@@ -35,35 +35,33 @@ int opencamsh()
...
@@ -35,35 +35,33 @@ int opencamsh()
}
}
void
refresh_cam
()
//使用xdottol进行模拟刷新页面
{
void
refresh_cam
()
{
//刷新页面
//system(SHELLFILECLOSE);
setenv
(
"XAUTHORITY"
,
"/home/orangepi/.Xauthority"
,
1
);
//加入授权
setenv
(
"XAUTHORITY"
,
"/home/orangepi/.Xauthority"
,
1
);
const
char
*
search_command
=
"xdotool search --class
\"
chromium-browser
\"
"
;
//获取窗口id
const
char
*
search_command
=
"xdotool search --name
\"
Mozilla chromium-browser
\"
"
;
FILE
*
fp
=
popen
(
search_command
,
"r"
);
FILE
*
fp
=
popen
(
search_command
,
"r"
);
if
(
!
fp
)
{
if
(
!
fp
)
{
perror
(
"Failed to execute search command"
);
perror
(
"Failed to execute search command"
);
return
;
return
;
}
}
char
window_id
[
32
];
char
window_id
[
32
];
while
(
fgets
(
window_id
,
sizeof
(
window_id
),
fp
)
!=
NULL
)
{
while
(
fgets
(
window_id
,
sizeof
(
window_id
),
fp
)
!=
NULL
)
{
// 去掉换行符
window_id
[
strcspn
(
window_id
,
"
\n
"
)]
=
'\0'
;
window_id
[
strcspn
(
window_id
,
"
\n
"
)]
=
'\0'
;
// 使用 xdotool 激活窗口并发送 Ctrl+r 快捷键进行刷新
char
activate_command
[
128
];
char
activate_command
[
128
];
snprintf
(
activate_command
,
sizeof
(
activate_command
),
"xdotool windowactivate --sync %s key Ctrl+r"
,
window_id
);
snprintf
(
activate_command
,
sizeof
(
activate_command
),
"xdotool windowactivate --sync %s key Ctrl+r"
,
window_id
);
pid_t
pid
=
fork
();
printf
(
"Executing: %s
\n
"
,
activate_command
);
if
(
pid
==
0
)
{
if
(
system
(
activate_command
)
!=
0
)
{
// 子进程执行命令
fprintf
(
stderr
,
"Failed to refresh window with ID: %s
\n
"
,
window_id
);
execl
(
"/bin/sh"
,
"sh"
,
"-c"
,
activate_command
,
(
char
*
)
NULL
);
perror
(
"Failed to execute command"
);
exit
(
EXIT_FAILURE
);
}
else
if
(
pid
>
0
)
{
// 父进程不等待子进程结束,继续执行
printf
(
"Executing in child process: %s
\n
"
,
activate_command
);
}
else
{
}
else
{
p
rintf
(
"Refreshed window with ID: %s
\n
"
,
window_id
);
p
error
(
"Failed to fork"
);
}
}
}
}
// 关闭文件指针
pclose
(
fp
);
pclose
(
fp
);
printf
(
"recam
\n
"
);
printf
(
"recam
\n
"
);
}
}
...
...
src/opensh.o
View file @
9db62149
No preview for this file type
usr/main.c
View file @
9db62149
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
#include <netinet/in.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <ifaddrs.h>
#include <wiringPi.h>
#include "gpio.h"
#include "gps.h"
#include "gps.h"
#include "main.h"
#include "main.h"
#include "ip.h"
#include "ip.h"
...
@@ -24,7 +26,7 @@
...
@@ -24,7 +26,7 @@
char
buffer
[
30
];
// 用于存储文件内容
char
buffer
[
30
];
// 用于存储文件内容
pthread_mutex_t
topic3_mutex
;
void
*
serial_usart1
(
void
*
arg
)
void
*
serial_usart1
(
void
*
arg
)
{
{
...
@@ -65,9 +67,7 @@ void *Mqttbeat(void *arg)
...
@@ -65,9 +67,7 @@ void *Mqttbeat(void *arg)
printf
(
"Mqttbeat start
\n
"
);
printf
(
"Mqttbeat start
\n
"
);
Delay_Ms
(
30
,
0
);
Delay_Ms
(
30
,
0
);
refresh_cam
();
refresh_cam
();
Delay_Ms
(
5
,
0
);
Delay_Ms
(
10
,
0
);
refresh_cam
();
Delay_Ms
(
20
,
0
);
refresh_cam
();
refresh_cam
();
Delay_Ms
(
10
,
0
);
Delay_Ms
(
10
,
0
);
...
@@ -75,9 +75,7 @@ void *Mqttbeat(void *arg)
...
@@ -75,9 +75,7 @@ void *Mqttbeat(void *arg)
{
{
ipaddr
();
//获取ip
ipaddr
();
//获取ip
Delay_Ms
(
3
,
0
);
Delay_Ms
(
3
,
0
);
pthread_mutex_lock
(
&
topic3_mutex
);
mqtt_wirte
();
//心跳,3s一个
mqtt_wirte
();
//心跳,3s一个
pthread_mutex_unlock
(
&
topic3_mutex
);
}
}
...
@@ -88,9 +86,7 @@ void *Mqttbeat(void *arg)
...
@@ -88,9 +86,7 @@ void *Mqttbeat(void *arg)
void
*
opensh
(
void
*
arg
)
void
*
opensh
(
void
*
arg
)
{
{
Delay_Ms
(
10
,
0
);
Delay_Ms
(
10
,
0
);
pthread_mutex_lock
(
&
topic3_mutex
);
printf
(
"open cam
\n
"
);
printf
(
"open cam
\n
"
);
pthread_mutex_unlock
(
&
topic3_mutex
);
opencamsh
();
//10s后打开火狐游览器并且进入网址
opencamsh
();
//10s后打开火狐游览器并且进入网址
return
NULL
;
return
NULL
;
...
@@ -108,10 +104,8 @@ void *serial_usart2(void *arg)
...
@@ -108,10 +104,8 @@ void *serial_usart2(void *arg)
void
*
Mqtt_onnect
(
void
*
arg
)
void
*
Mqtt_onnect
(
void
*
arg
)
{
{
Delay_Ms
(
5
,
0
);
Delay_Ms
(
5
,
0
);
pthread_mutex_lock
(
&
topic3_mutex
);
mqtt_init
();
//mqtt初始化
mqtt_init
();
//mqtt初始化
mqtt_create
(
mosq
);
//创建mqtt客户端
mqtt_create
(
mosq
);
//创建mqtt客户端
pthread_mutex_unlock
(
&
topic3_mutex
);
while
(
1
)
while
(
1
)
{
{
mqtt_create
(
mosq
);
mqtt_create
(
mosq
);
...
@@ -156,9 +150,9 @@ char *device_inspect()
...
@@ -156,9 +150,9 @@ char *device_inspect()
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
pthread_mutex_init
(
&
topic3_mutex
,
NULL
)
!=
0
)
{
if
(
wiringPiSetup
()
==
-
1
)
{
fprintf
(
stderr
,
"Mutex initialization failed
\n
"
);
printf
(
"WiringPi setup failed!
\n
"
);
return
EXIT_FAILURE
;
return
1
;
}
}
Delay_Ms
(
10
,
0
);
Delay_Ms
(
10
,
0
);
...
@@ -172,12 +166,10 @@ int main(int argc, char *argv[]) {
...
@@ -172,12 +166,10 @@ int main(int argc, char *argv[]) {
//TOPIC3=device_inspect();//读取文件内容
//TOPIC3=device_inspect();//读取文件内容
//sprintf(TOPIC3,"%s",buffer);
//sprintf(TOPIC3,"%s",buffer);
//strcpy(TOPIC3,device_inspect());
//strcpy(TOPIC3,device_inspect());
pthread_mutex_lock
(
&
topic3_mutex
);
sprintf
(
TOPIC2
,
"dev2app/%s"
,
readbuf
);
sprintf
(
TOPIC2
,
"dev2app/%s"
,
readbuf
);
sprintf
(
TOPIC
,
"app2dev/%s"
,
readbuf
);
sprintf
(
TOPIC
,
"app2dev/%s"
,
readbuf
);
sprintf
(
TOPIC3
,
"%s"
,
readbuf
);
sprintf
(
TOPIC3
,
"%s"
,
readbuf
);
printf
(
"1:%s,2:%s,3:%s
\n
"
,
TOPIC
,
TOPIC2
,
TOPIC3
);
printf
(
"1:%s,2:%s,3:%s
\n
"
,
TOPIC
,
TOPIC2
,
TOPIC3
);
pthread_mutex_unlock
(
&
topic3_mutex
);
system
(
"pkill chromium-browser"
);
system
(
"pkill chromium-browser"
);
gStart
=
time
(
NULL
);
//开始时间戳
gStart
=
time
(
NULL
);
//开始时间戳
...
...
usr/main.o
View file @
9db62149
No preview for this file type
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment