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
0ae069ac
Commit
0ae069ac
authored
Apr 10, 2025
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化了bug,减少了内存泄漏
parent
dd1ee7c8
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
119 additions
and
41 deletions
+119
-41
judg.c
device_judg/judg/judg.c
+22
-6
judg.h
device_judg/judg/judg.h
+2
-1
fileopen.h
include/fileopen.h
+12
-0
thread_main.h
include/thread_main.h
+0
-4
fileopen.c
src/fileopen.c
+51
-0
mqtt.c
src/mqtt.c
+20
-5
opensh.c
src/opensh.c
+3
-0
request.c
src/request.c
+4
-0
thread_main.c
src/thread_main.c
+0
-25
warm.c
system/sensor/warm.c
+3
-0
main.h
usr/main.h
+2
-0
No files found.
device_judg/judg/judg.c
View file @
0ae069ac
...
...
@@ -9,9 +9,23 @@
#include "tank.h"
#include "ship.h"
#include "pao.h"
#include "fileopen.h"
char
TOPIC_middle
[
23
];
char
TOPIC2_middle
[
23
];
char
TOPIC3_middle
[
15
];
void
topic_middle_value
()
{
TOPIC
=
TOPIC_middle
;
TOPIC2
=
TOPIC2_middle
;
TOPIC3
=
TOPIC3_middle
;
}
int
Device_File_Init
()
{
const
char
*
readbuf
=
device_inspect
();
//将第3个和第4个字符提取出来
char
*
sub_str
=
malloc
(
5
);
sub_str
[
0
]
=
readbuf
[
2
];
...
...
@@ -39,12 +53,14 @@ int Device_File_Init() {
free
(
sub_str
);
}
Delay_Ms
(
20
,
0
);
TOPIC
=
malloc
(
24
);
TOPIC2
=
malloc
(
24
);
TOPIC3
=
malloc
(
16
);
sprintf
(
TOPIC2
,
"dev2app/%s"
,
readbuf
);
sprintf
(
TOPIC
,
"app2dev/%s"
,
readbuf
);
sprintf
(
TOPIC3
,
"%s"
,
readbuf
);
sprintf
(
TOPIC2_middle
,
"dev2app/%s"
,
readbuf
);
sprintf
(
TOPIC_middle
,
"app2dev/%s"
,
readbuf
);
sprintf
(
TOPIC3_middle
,
"%s"
,
readbuf
);
topic_middle_value
();
//指针传值声明
printf
(
"1:%s,2:%s,3:%s
\n
"
,
TOPIC
,
TOPIC2
,
TOPIC3
);
return
0
;
}
device_judg/judg/judg.h
View file @
0ae069ac
#ifndef __JUDG_H__
#define __JUDG_H__
int
Device_File_Init
();
int
Device_File_Init
();
//指针传值声明
#endif
\ No newline at end of file
include/fileopen.h
0 → 100644
View file @
0ae069ac
#ifndef __FILEOPEN_H__
#define __FILEOPEN_H__
#define filename "/home/orangepi/car/master/Deviceld.txt"//设备名存放文件
#define file_version "/home/orangepi/car/master/version.conf"
char
*
device_inspect
()
;
//打开设备号文件
char
*
program_version
()
;
//打开版本文件
#endif
\ No newline at end of file
include/thread_main.h
View file @
0ae069ac
#ifndef __THREAD_MAIN_H__
#define __THREAD_MAIN_H__
#define filename "/home/orangepi/car/master/Deviceld.txt"
int
thread_start
(
void
*
AppExit
(
void
*
arg
),
void
*
Mqttbeat
(
void
*
arg
),
void
*
opensh
(
void
*
arg
),
void
*
Mqtt_onnect
(
void
*
arg
))
;
void
*
AppExit
(
void
*
arg
)
;
void
*
Mqttbeat
(
void
*
arg
)
;
void
*
opensh
(
void
*
arg
)
;
void
*
Mqtt_onnect
(
void
*
arg
)
;
char
*
device_inspect
()
;
void
thread_end
()
;
#endif
\ No newline at end of file
src/fileopen.c
0 → 100644
View file @
0ae069ac
#include "fileopen.h"
#include "common.h"
#include "delay.h"
char
buffer_device
[
30
];
// 用于存储文件内容
char
buffer_version
[
30
];
// 用于存储版本号内容
char
*
device_inspect
()
{
//读出文件函数
FILE
*
file
;
while
(
1
)
{
file
=
fopen
(
filename
,
"r"
);
// 以只读模式打开文件
if
(
file
==
NULL
)
{
printf
(
"文件 %s 打开失败,等待中...
\n
"
,
filename
);
}
else
{
// 尝试读取文件内容
if
(
fgets
(
buffer_device
,
sizeof
(
buffer_device
),
file
)
!=
NULL
)
{
// 如果文件内容不为空
fclose
(
file
);
printf
(
"读取到文件内容: %s
\n
"
,
buffer_device
);
return
buffer_device
;
}
else
{
printf
(
"文件为空,等待中...
\n
"
);
}
fclose
(
file
);
}
Delay_Ms
(
1
,
0
);
// 等待1秒后再次检查
}
}
char
*
program_version
()
{
//打开版本文件
FILE
*
file
;
file
=
fopen
(
file_version
,
"r"
);
// 以只读模式打开文件
if
(
file
==
NULL
)
{
printf
(
"文件无"
);
}
else
{
// 尝试读取文件内容
if
(
fgets
(
buffer_version
,
sizeof
(
buffer_version
),
file
)
!=
NULL
)
{
// 如果文件内容不为空
fclose
(
file
);
printf
(
"读取到文件内容: %s
\n
"
,
buffer_version
);
return
buffer_version
;
}
else
{
printf
(
"文件为空,等待中...
\n
"
);
}
fclose
(
file
);
}
}
\ No newline at end of file
src/mqtt.c
View file @
0ae069ac
...
...
@@ -7,12 +7,16 @@
#include "heat.h"
#include "mqtt.h"
#include "warm.h"
#include "fileopen.h"
#include "judg.h"
struct
mosquitto
*
mosq
;
char
*
TOPIC
;
char
*
TOPIC2
;
char
*
TOPIC3
;
char
*
TOPIC
=
NULL
;
char
*
TOPIC2
=
NULL
;
char
*
TOPIC3
=
NULL
;
char
*
version_num
;
//版本号指针
int
gPwmCount
=
0
;
// 计数
int
gmessage_type
=
10086
;
...
...
@@ -53,7 +57,7 @@ int mqtt_init() {
void
on_connect
(
struct
mosquitto
*
mosq
,
void
*
obj
,
int
rc
)
{
//回调函数
if
(
rc
==
0
)
{
printf
(
"Connected to broker
\n
"
);
topic_middle_value
();
mosquitto_subscribe
(
mosq
,
NULL
,
TOPIC
,
0
);
}
else
{
...
...
@@ -61,7 +65,7 @@ void on_connect(struct mosquitto *mosq, void *obj, int rc) {//回调函数
}
}
void
mqtt_wirte
(){
//心跳格式
void
mqtt_wirte
(){
//心跳格式
,每5s一次心跳
float
voltage
=
INA226_readBusVoltage
(
sda_pin
,
scl_pin
);
float
current
=
INA226_readCurrent
(
sda_pin
,
scl_pin
);
...
...
@@ -73,10 +77,16 @@ void mqtt_wirte(){//心跳格式
if
(
AppExit_pin_pwm
/
100
!=
2
)
alarm_control
(
voltage
);
//判断电压警报
/*读取程序版本号*/
version_num
=
malloc
(
16
);
version_num
=
program_version
();
heat_tem
();
//获取CPU温度
message
=
1
;
topic_middle_value
();
cJSON
*
root
=
cJSON_CreateObject
();
cJSON
*
body
=
cJSON_CreateObject
();
cJSON
*
head
=
cJSON_CreateObject
();
...
...
@@ -88,6 +98,7 @@ void mqtt_wirte(){//心跳格式
cJSON_AddStringToObject
(
body
,
"Tem:"
,
temperature
);
//发送温度
cJSON_AddStringToObject
(
body
,
"N"
,
glat
);
//gps
cJSON_AddStringToObject
(
body
,
"E"
,
glon
);
//gps
cJSON_AddStringToObject
(
body
,
"version"
,
version_num
);
//gps
cJSON_AddNumberToObject
(
head
,
"message_type"
,
message
);
...
...
@@ -98,6 +109,10 @@ void mqtt_wirte(){//心跳格式
printf
(
"%s
\n
"
,
payload
);
mosquitto_publish
(
mosq
,
NULL
,
TOPIC2
,
strlen
(
payload
),
payload
,
0
,
false
);
mosquitto_publish
(
mosq
,
NULL
,
TOPIC3
,
strlen
(
payload
),
payload
,
0
,
false
);
cJSON_Delete
(
root
);
// 释放 cJSON 对象
return
;
}
void
message_3
(
cJSON
*
body
,
cJSON
*
pwm_ctrl
){
//message_type为3,控制pwm
...
...
src/opensh.c
View file @
0ae069ac
#include "common.h"
#include "mqtt.h"
#include "opensh.h"
#include "judg.h"
char
gwebcam
[
254
];
//存放启动火狐网站命令
...
...
@@ -8,6 +9,8 @@ int opencamsh(){
const
char
*
url
=
"https://jywy.yd-ss.com?dev="
;
char
urls
[
50
];
topic_middle_value
();
sprintf
(
urls
,
"%s%s"
,
url
,
TOPIC3
);
//setenv("DISPLAY", ":0", 1);//设置环境变量https://jywy.yd-ss.com?dev=controcar0004 --new-window sudo
...
...
src/request.c
View file @
0ae069ac
...
...
@@ -2,6 +2,8 @@
#include <cjson/cJSON.h>
#include "request.h"
#include "mqtt.h"
#include "judg.h"
const
char
*
post
=
"http://47.119.190.60/api/v1/device/config"
;
int
errCodeValue
;
...
...
@@ -82,6 +84,8 @@ int analysis_request_json(char *payload_str) {
char
*
wirte_json
()
{
cJSON
*
body
=
cJSON_CreateObject
();
topic_middle_value
();
cJSON_AddStringToObject
(
body
,
"device_id"
,
TOPIC3
);
// 发送设备id
char
*
payload
=
cJSON_PrintUnformatted
(
body
);
...
...
src/thread_main.c
View file @
0ae069ac
...
...
@@ -10,7 +10,6 @@
#include "common.h"
#include "thread_main.h"
char
buffer
[
30
];
// 用于存储文件内容
pthread_t
thread
[
4
];
//开启线程
int
thread_start
(
void
*
AppExit
(
void
*
arg
),
void
*
Mqttbeat
(
void
*
arg
),
void
*
opensh
(
void
*
arg
),
void
*
Mqtt_onnect
(
void
*
arg
)){
...
...
@@ -89,30 +88,6 @@ void *Mqtt_onnect(void *arg) {//mqtt异常处理,断开自动重连,简单
return
NULL
;
}
char
*
device_inspect
()
{
//读出文件函数
FILE
*
file
;
while
(
1
)
{
file
=
fopen
(
filename
,
"r"
);
// 以只读模式打开文件
if
(
file
==
NULL
)
{
printf
(
"文件 %s 打开失败,等待中...
\n
"
,
filename
);
}
else
{
// 尝试读取文件内容
if
(
fgets
(
buffer
,
sizeof
(
buffer
),
file
)
!=
NULL
)
{
// 如果文件内容不为空
fclose
(
file
);
printf
(
"读取到文件内容: %s
\n
"
,
buffer
);
return
buffer
;
}
else
{
printf
(
"文件为空,等待中...
\n
"
);
}
fclose
(
file
);
}
Delay_Ms
(
1
,
0
);
// 等待1秒后再次检查
}
}
// 等待线程结束
void
thread_end
()
{
...
...
system/sensor/warm.c
View file @
0ae069ac
...
...
@@ -7,7 +7,10 @@
int
alarm_highest
(
int
index
)
{
//最高警报,最低电压报警
if
(
index
==
1
)
{
pin_value
(
20
,
1
);
//紫灯
if
(
enable_buzzer_value
)
{
pin_value
(
22
,
1
);
//蜂鸣器
}
}
else
if
(
index
==
0
)
{
pin_value
(
20
,
0
);
//紫灯
pin_value
(
22
,
0
);
//蜂鸣器
...
...
usr/main.h
View file @
0ae069ac
...
...
@@ -14,5 +14,6 @@
#include "thread_main.h"
#include "judg.h"
#include "request.h"
#include "fileopen.h"
#endif
\ No newline at end of file
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