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
5eda44dc
Commit
5eda44dc
authored
Jul 23, 2025
by
学习的菜鸟
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
加入了wifi修改
parent
812f44eb
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
289 additions
and
100 deletions
+289
-100
device_wifi_change.c
app/device_change/device_wifi_change.c
+3
-2
device_fileopen.c
app/device_identity/device_fileopen.c
+0
-1
device_identity.c
app/device_identity/device_identity.c
+1
-1
main.c
app/main/main.c
+25
-7
main.h
app/main/main.h
+14
-0
pthread_open.c
app/main/pthread_open.c
+4
-4
Makefile
build/Makefile
+18
-18
main
build/main
+0
-0
device_init.c
drivers/gpio/device_init.c
+8
-6
device_init.h
drivers/gpio/device_init.h
+1
-1
gpio_init.c
drivers/gpio/gpio_init.c
+6
-4
gpio_init.h
drivers/gpio/gpio_init.h
+2
-2
softiic.c
drivers/gpio/softiic.c
+2
-2
softiic.h
drivers/gpio/softiic.h
+1
-1
INA226.c
drivers/sensors/INA226.c
+22
-4
INA226.h
drivers/sensors/INA226.h
+5
-7
audioplay.c
drivers/sensors/audioplay.c
+107
-0
audioplay.h
drivers/sensors/audioplay.h
+10
-0
warn.c
drivers/sensors/warn.c
+5
-4
warn.h
drivers/sensors/warn.h
+3
-3
devcontrol_common.h
include/devcontrol_common.h
+0
-1
http_request.c
modules/http/http_request.c
+22
-4
http_request.h
modules/http/http_request.h
+2
-1
mqtt_infor_handle.c
modules/mqtt/mqtt_infor_handle.c
+28
-27
No files found.
app/device_change/device_wifi_change.c
View file @
5eda44dc
#include "
device_wifi_change
.h"
#include "
audioplay
.h"
#include "device_identity.h"
#include "device_identity.h"
#include "mqtt_init.h"
#include "mqtt_init.h"
#include "common.h"
#include "common.h"
#include "delay.h"
#include "delay.h"
#include "device_wifi_change.h"
char
current_ssid
[
SSID_MAX_LEN
]
=
{
0
};
//用于存现在已连接WiFi
char
current_ssid
[
SSID_MAX_LEN
]
=
{
0
};
//用于存现在已连接WiFi
char
wifi_Last_ssid
[
SSID_MAX_LEN
]
=
{
0
}
;
char
wifi_Last_ssid
[
SSID_MAX_LEN
]
=
{
0
}
;
...
@@ -443,7 +444,7 @@ int wifi_change_sendmqtt_init(){
...
@@ -443,7 +444,7 @@ int wifi_change_sendmqtt_init(){
}
else
{
}
else
{
if
(
change_wifi_connect
(
default_SSID
,
default_password
)
==
0
)
delete_wifi_conf
();
if
(
change_wifi_connect
(
default_SSID
,
default_password
)
==
0
)
delete_wifi_conf
();
my_zlog_debug
(
"WiFi无网切回"
);
my_zlog_debug
(
"WiFi无网切回"
);
delay_s
(
10
);
;
delay_s
(
10
);
}
}
}
}
...
...
app/device_identity/device_fileopen.c
View file @
5eda44dc
...
@@ -45,7 +45,6 @@ char *device_inspect() {
...
@@ -45,7 +45,6 @@ char *device_inspect() {
/*设备读取文件初始化*/
/*设备读取文件初始化*/
int
device_id_file_init
()
{
int
device_id_file_init
()
{
g_device_id
=
device_inspect
();
g_device_id
=
device_inspect
();
my_zlog_debug
(
"读取到文件内容222: %s"
,
g_device_id
);
return
0
;
return
0
;
}
}
char
*
device_id_function
(){
char
*
device_id_function
(){
...
...
app/device_identity/device_identity.c
View file @
5eda44dc
...
@@ -159,7 +159,7 @@ int device_mqtt_topic_init() {
...
@@ -159,7 +159,7 @@ int device_mqtt_topic_init() {
free
(
sub_str
);
free
(
sub_str
);
delay_s
(
2
0
);
delay_s
(
1
0
);
if
(
g_device_name_exists
==
0
)
{
if
(
g_device_name_exists
==
0
)
{
sprintf
(
g_app2dev_topic
,
"app2dev/%s"
,
readbuf
);
sprintf
(
g_app2dev_topic
,
"app2dev/%s"
,
readbuf
);
sprintf
(
g_dev2app_topic
,
"dev2app/%s"
,
readbuf
);
sprintf
(
g_dev2app_topic
,
"dev2app/%s"
,
readbuf
);
...
...
app/main/main.c
View file @
5eda44dc
#include "main.h"
#include "main.h"
int
main
(){
int
main
(){
if
(
mylog_init
()
!=
0
){
if
(
mylog_init
()
!=
0
){
my_zlog_error
(
"日志初始化失败,错误代码:%d"
,
mylog_init
());
my_zlog_error
(
"日志初始化失败,错误代码:%d"
,
mylog_init
());
return
-
1
;
return
-
1
;
}
}
if
(
wiringPiSetup
()
==
-
1
)
{
if
(
wiringPiSetup
()
==
-
1
)
{
my_zlog_fatal
(
"WiringPi setup failed!"
);
my_zlog_fatal
(
"WiringPi setup failed!"
);
return
-
2
;
return
-
2
;
}
}
if
(
wifi_change_sendmqtt_init
()
!=
0
){
my_zlog_error
(
"WIFI是否更改检查相关,不会到这一步,有问题会直接重启,可能会导致重启,不会因此造成程序停止"
);
}
if
(
device_id_file_init
()
!=
0
){
if
(
device_id_file_init
()
!=
0
){
my_zlog_error
(
"设备id读取失败"
);
my_zlog_error
(
"设备id读取失败"
);
return
-
3
;
return
-
3
;
}
}
if
(
device_mqtt_topic_init
()
!=
0
){
if
(
device_mqtt_topic_init
()
!=
0
){
my_zlog_error
(
"mqtt的topic读取
失败"
);
my_zlog_error
(
"设备id判断
失败"
);
return
-
4
;
return
-
4
;
}
}
int
thread_rc
=
thread_start_init
(
thread_exit_time
,
thread_mqtt_beat
,
thread_open_browser
,
thread_mqtt_reconnect
,
thread_time_calculation
,
thread_play_mp3
);
if
(
request_date
()
!=
0
){
my_zlog_error
(
"请求数据失败"
);
return
-
5
;
}
if
(
softiic_init
()
!=
0
){
my_zlog_error
(
"软件iic初始化失败"
);
return
-
6
;
}
if
(
ina225_init
()
!=
0
){
my_zlog_warn
(
"此版本电压没有使用INA226"
);
}
int
thread_rc
=
thread_start_init
(
thread_exit_time
,
thread_mqtt_beat
,
thread_open_browser
,
thread_mqtt_reconnect
,
thread_time_calculation
,
thread_play_mp3
);
thread_end_close
();
thread_end_close
();
my_log_close
();
//关闭日志
my_log_close
();
//关闭日志
...
...
app/main/main.h
View file @
5eda44dc
...
@@ -5,6 +5,10 @@
...
@@ -5,6 +5,10 @@
#include "device_fileopen.h"
#include "device_fileopen.h"
#include "device_identity.h"
#include "device_identity.h"
#include "pthread_open.h"
#include "pthread_open.h"
#include "http_request.h"
#include "device_wifi_change.h"
#include "softiic.h"
#include "INA226.h"
/*设备id读取初始化*/
/*设备id读取初始化*/
int
device_id_file_init
();
int
device_id_file_init
();
...
@@ -15,18 +19,28 @@ int mylog_init();
...
@@ -15,18 +19,28 @@ int mylog_init();
/*wiringPi初始化函数*/
/*wiringPi初始化函数*/
int
wiringPiSetup
();
int
wiringPiSetup
();
int
softiic_init
();
/*mqtt的topic初始化*/
/*mqtt的topic初始化*/
int
device_mqtt_topic_init
();
int
device_mqtt_topic_init
();
int
ina225_init
();
/*wifi改变初始化,放在main开头,必须要等mqtt直播就绪才行*/
int
wifi_change_sendmqtt_init
();
/*线程初始化函数*/
/*线程初始化函数*/
int
thread_start_init
(
ThreadFunc
thread_exit_time
,
ThreadFunc
thread_mqtt_beat
,
int
thread_start_init
(
ThreadFunc
thread_exit_time
,
ThreadFunc
thread_mqtt_beat
,
ThreadFunc
thread_open_browser
,
ThreadFunc
thread_mqtt_reconnect
,
ThreadFunc
thread_open_browser
,
ThreadFunc
thread_mqtt_reconnect
,
ThreadFunc
thread_time_calculation
,
ThreadFunc
thread_play_mp3
);
ThreadFunc
thread_time_calculation
,
ThreadFunc
thread_play_mp3
);
/*像服务器请求*/
int
request_date
();
/*线程关闭函数*/
/*线程关闭函数*/
void
thread_end_close
()
;
void
thread_end_close
()
;
/*关闭log日志记录*/
/*关闭log日志记录*/
void
my_log_close
();
void
my_log_close
();
#endif
#endif
app/main/pthread_open.c
View file @
5eda44dc
...
@@ -5,8 +5,10 @@
...
@@ -5,8 +5,10 @@
#include "mqtt_infor_handle.h"
#include "mqtt_infor_handle.h"
#include "browser_open.h"
#include "browser_open.h"
#include "mqtt_verify.h"
#include "mqtt_verify.h"
#include "device_wifi_change.h"
//
#include "device_wifi_change.h"
#include "browser_open.h"
#include "browser_open.h"
#include "device_init.h"
#include "audioplay.h"
pthread_t
g_thread
[
6
];
// 全局线程句柄数组(或传参)
pthread_t
g_thread
[
6
];
// 全局线程句柄数组(或传参)
...
@@ -55,10 +57,8 @@ void *thread_exit_time(void *arg) {
...
@@ -55,10 +57,8 @@ void *thread_exit_time(void *arg) {
void
*
thread_mqtt_beat
(
void
*
arg
)
{
void
*
thread_mqtt_beat
(
void
*
arg
)
{
my_zlog_info
(
"thread_mqtt_beat start"
);
my_zlog_info
(
"thread_mqtt_beat start"
);
wifi_change_sendmqtt_init
();
delay_s
(
5
);
delay_s
(
5
);
g_webrtc_index
=
1
;
g_webrtc_index
=
1
;
int
device_type
=
0
;
while
(
1
)
{
while
(
1
)
{
if
(
device_type
==
202
)
delay_ms
(
45
);
if
(
device_type
==
202
)
delay_ms
(
45
);
if
(
device_type
!=
202
)
delay_ms
(
100
);
if
(
device_type
!=
202
)
delay_ms
(
100
);
...
@@ -134,7 +134,7 @@ void *thread_time_calculation(void *arg) {
...
@@ -134,7 +134,7 @@ void *thread_time_calculation(void *arg) {
//专门处理MP3播放
//专门处理MP3播放
void
*
thread_play_mp3
(
void
*
arg
)
{
void
*
thread_play_mp3
(
void
*
arg
)
{
//
audioplay_cycle();
audioplay_cycle
();
return
NULL
;
return
NULL
;
}
}
...
...
build/Makefile
View file @
5eda44dc
...
@@ -822,29 +822,29 @@ drivers/sensors/temperature.c.s:
...
@@ -822,29 +822,29 @@ drivers/sensors/temperature.c.s:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/temperature.c.s
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/temperature.c.s
.PHONY
:
drivers/sensors/temperature.c.s
.PHONY
:
drivers/sensors/temperature.c.s
drivers/sensors/war
m.o
:
drivers/sensors/warm
.c.o
drivers/sensors/war
n.o
:
drivers/sensors/warn
.c.o
.PHONY
:
drivers/sensors/war
m
.o
.PHONY
:
drivers/sensors/war
n
.o
# target to build an object file
# target to build an object file
drivers/sensors/war
m
.c.o
:
drivers/sensors/war
n
.c.o
:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/war
m
.c.o
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/war
n
.c.o
.PHONY
:
drivers/sensors/war
m
.c.o
.PHONY
:
drivers/sensors/war
n
.c.o
drivers/sensors/war
m.i
:
drivers/sensors/warm
.c.i
drivers/sensors/war
n.i
:
drivers/sensors/warn
.c.i
.PHONY
:
drivers/sensors/war
m
.i
.PHONY
:
drivers/sensors/war
n
.i
# target to preprocess a source file
# target to preprocess a source file
drivers/sensors/war
m
.c.i
:
drivers/sensors/war
n
.c.i
:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/war
m
.c.i
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/war
n
.c.i
.PHONY
:
drivers/sensors/war
m
.c.i
.PHONY
:
drivers/sensors/war
n
.c.i
drivers/sensors/war
m.s
:
drivers/sensors/warm
.c.s
drivers/sensors/war
n.s
:
drivers/sensors/warn
.c.s
.PHONY
:
drivers/sensors/war
m
.s
.PHONY
:
drivers/sensors/war
n
.s
# target to generate assembly for a file
# target to generate assembly for a file
drivers/sensors/war
m
.c.s
:
drivers/sensors/war
n
.c.s
:
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/war
m
.c.s
$(MAKE)
$(MAKESILENT)
-f
CMakeFiles/main.dir/build.make CMakeFiles/main.dir/drivers/sensors/war
n
.c.s
.PHONY
:
drivers/sensors/war
m
.c.s
.PHONY
:
drivers/sensors/war
n
.c.s
modules/browser/browser_open.o
:
modules/browser/browser_open.c.o
modules/browser/browser_open.o
:
modules/browser/browser_open.c.o
.PHONY
:
modules/browser/browser_open.o
.PHONY
:
modules/browser/browser_open.o
...
@@ -1651,9 +1651,9 @@ help:
...
@@ -1651,9 +1651,9 @@ help:
@
echo
"... drivers/sensors/temperature.o"
@
echo
"... drivers/sensors/temperature.o"
@
echo
"... drivers/sensors/temperature.i"
@
echo
"... drivers/sensors/temperature.i"
@
echo
"... drivers/sensors/temperature.s"
@
echo
"... drivers/sensors/temperature.s"
@
echo
"... drivers/sensors/war
m
.o"
@
echo
"... drivers/sensors/war
n
.o"
@
echo
"... drivers/sensors/war
m
.i"
@
echo
"... drivers/sensors/war
n
.i"
@
echo
"... drivers/sensors/war
m
.s"
@
echo
"... drivers/sensors/war
n
.s"
@
echo
"... modules/browser/browser_open.o"
@
echo
"... modules/browser/browser_open.o"
@
echo
"... modules/browser/browser_open.i"
@
echo
"... modules/browser/browser_open.i"
@
echo
"... modules/browser/browser_open.s"
@
echo
"... modules/browser/browser_open.s"
...
...
build/main
View file @
5eda44dc
No preview for this file type
drivers/gpio/device_init.c
View file @
5eda44dc
...
@@ -5,13 +5,15 @@
...
@@ -5,13 +5,15 @@
int
abnormal_pin_pwm_stop
=
0
;
int
abnormal_pin_pwm_stop
=
0
;
int
device_type
=
0
;
const
deviceconfig_t
device_configs
[]
=
{
const
deviceconfig_t
device_configs
[]
=
{
// car0101配置
// car0101配置
{
{
.
device_id
=
101
,
.
device_id
=
101
,
.
device_name
=
"car0101"
,
.
device_name
=
"car0101"
,
.
gpio_pins
=
{
5
,
6
,
7
,
10
,
16
,
20
,
22
,
23
,
24
,
25
,
26
,
27
,
-
1
},
.
gpio_pins
=
{
5
,
6
,
7
,
10
,
16
,
20
,
22
,
23
,
24
,
25
,
26
,
-
1
},
.
gpio_pwms
=
{
-
1
},
.
gpio_pwms
=
{
27
,
-
1
},
.
device_pwm_init
=
physics_pwm_init
,
.
device_pwm_init
=
physics_pwm_init
,
.
device_control_stop
=
car0101_middle_pwm
,
.
device_control_stop
=
car0101_middle_pwm
,
.
emergency_code
=
101
.
emergency_code
=
101
...
@@ -66,7 +68,7 @@ const deviceconfig_t device_configs[] = {
...
@@ -66,7 +68,7 @@ const deviceconfig_t device_configs[] = {
{
.
device_id
=
-
1
}
{
.
device_id
=
-
1
}
};
};
bool
get_array_length
(
int
*
arr
)
{
bool
get_array_length
(
const
int
*
arr
)
{
if
(
arr
[
0
]
!=
-
1
)
{
// 遇到-1停止计数
if
(
arr
[
0
]
!=
-
1
)
{
// 遇到-1停止计数
return
TRUE
;
return
TRUE
;
}
}
...
@@ -94,9 +96,8 @@ void device_init(int device_id) {
...
@@ -94,9 +96,8 @@ void device_init(int device_id) {
if
(
get_array_length
(
config
->
gpio_pins
)
==
TRUE
)
init_gpiopwm
(
config
->
gpio_pwms
);
// GPIOsoft_pwm初始化
if
(
get_array_length
(
config
->
gpio_pins
)
==
TRUE
)
init_gpiopwm
(
config
->
gpio_pwms
);
// GPIOsoft_pwm初始化
config
->
device_pwm_init
();
// PWM初始化
config
->
device_pwm_init
();
// PWM初始化
config
->
device_control_stop
();
// 速度控制初始化
config
->
device_control_stop
();
// 速度控制初始化
device_type
=
config
->
emergency_code
;
// 设置异常停止代码
abnormal_pin_pwm_stop
=
config
->
emergency_code
;
printf
(
"%s initialized successfully!
\n
"
,
config
->
device_name
);
printf
(
"%s initialized successfully!
\n
"
,
config
->
device_name
);
}
}
\ No newline at end of file
drivers/gpio/device_init.h
View file @
5eda44dc
#ifndef DEVICE_INIT_H__
#ifndef DEVICE_INIT_H__
#define DEVICE_INIT_H__
#define DEVICE_INIT_H__
extern
int
abnormal_pin_pwm_stop
;
extern
int
device_type
;
typedef
struct
{
typedef
struct
{
int
device_id
;
// 设备ID (101, 102等)
int
device_id
;
// 设备ID (101, 102等)
...
...
drivers/gpio/gpio_init.c
View file @
5eda44dc
#include "common.h"
#include "common.h"
#include "gpio_init.h"
#include "gpio_init.h"
#include "http_request.h"
#include "http_request.h"
#include "device_init.h"
#include "devcontrol_common.h"
#define MIN_DUTY 0 // 最小占空比
#define MIN_DUTY 0 // 最小占空比
#define MAX_DUTY 100 // 最大占空比
#define MAX_DUTY 100 // 最大占空比
...
@@ -13,7 +15,7 @@ int g_gpiowpi[40]; //能使用高低引脚和其他引脚
...
@@ -13,7 +15,7 @@ int g_gpiowpi[40]; //能使用高低引脚和其他引脚
int
g_gpiocount
=
0
;
int
g_gpiocount
=
0
;
int
g_gpio_softpwmcount
=
0
;
int
g_gpio_softpwmcount
=
0
;
void
init_gpiowpi
(
int
*
values_pin
)
{
void
init_gpiowpi
(
const
int
*
values_pin
)
{
while
(
values_pin
[
g_gpiocount
]
!=
-
1
)
{
while
(
values_pin
[
g_gpiocount
]
!=
-
1
)
{
g_gpiocount
++
;
g_gpiocount
++
;
}
}
...
@@ -27,7 +29,7 @@ void init_gpiowpi(int *values_pin) {
...
@@ -27,7 +29,7 @@ void init_gpiowpi(int *values_pin) {
}
}
}
}
void
init_gpiopwm
(
int
*
values_pwm
)
{
void
init_gpiopwm
(
const
int
*
values_pwm
)
{
while
(
values_pwm
[
g_gpio_softpwmcount
]
!=
-
1
)
{
while
(
values_pwm
[
g_gpio_softpwmcount
]
!=
-
1
)
{
g_gpio_softpwmcount
++
;
g_gpio_softpwmcount
++
;
}
}
...
@@ -68,8 +70,8 @@ void pwm_value(int pin,int value) { //软件陪我们控制调速
...
@@ -68,8 +70,8 @@ void pwm_value(int pin,int value) { //软件陪我们控制调速
softPwmWrite
(
pin
,
shot_speed
);
softPwmWrite
(
pin
,
shot_speed
);
my_zlog_debug
(
"pin:%d,%d"
,
pin
,
shot_speed
);
my_zlog_debug
(
"pin:%d,%d"
,
pin
,
shot_speed
);
}
else
{
}
else
{
//if(AppExit_pin_pwm ==
202)softPwmWrite(pin, 30);
if
(
device_type
==
DEVICE_TANK0
202
)
softPwmWrite
(
pin
,
30
);
//if(AppExit_pin_pwm !=
202 )softPwmWrite(pin, shot_speed);
if
(
device_type
!=
DEVICE_TANK0
202
)
softPwmWrite
(
pin
,
shot_speed
);
}
}
...
...
drivers/gpio/gpio_init.h
View file @
5eda44dc
...
@@ -11,8 +11,8 @@
...
@@ -11,8 +11,8 @@
#define PWM_PIN_SPEED 21
#define PWM_PIN_SPEED 21
#define PWM_PIN_CHANGE 2
#define PWM_PIN_CHANGE 2
void
init_gpiowpi
(
int
*
values_pin
);
//gpio引脚初始化
void
init_gpiowpi
(
const
int
*
values_pin
);
//gpio引脚初始化
void
init_gpiopwm
(
int
*
values_pwm
);
void
init_gpiopwm
(
const
int
*
values_pwm
);
void
pin_value
(
int
pin
,
int
value
);
//控制引脚高低
void
pin_value
(
int
pin
,
int
value
);
//控制引脚高低
...
...
drivers/gpio/softiic.c
View file @
5eda44dc
...
@@ -11,12 +11,12 @@ void i2c_delay() {
...
@@ -11,12 +11,12 @@ void i2c_delay() {
}
}
// 初始化 I2C 引脚
// 初始化 I2C 引脚
bool
SOFT
iic_init
()
{
int
soft
iic_init
()
{
pinMode
(
sda_pin
,
OUTPUT
);
pinMode
(
sda_pin
,
OUTPUT
);
pinMode
(
scl_pin
,
OUTPUT
);
pinMode
(
scl_pin
,
OUTPUT
);
digitalWrite
(
sda_pin
,
HIGH
);
digitalWrite
(
sda_pin
,
HIGH
);
digitalWrite
(
scl_pin
,
HIGH
);
digitalWrite
(
scl_pin
,
HIGH
);
return
true
;
return
0
;
}
}
// I2C 起始信号
// I2C 起始信号
...
...
drivers/gpio/softiic.h
View file @
5eda44dc
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
extern
int
sda_pin
;
// GPIO0
extern
int
sda_pin
;
// GPIO0
extern
int
scl_pin
;
// GPIO1
extern
int
scl_pin
;
// GPIO1
bool
SOFT
iic_init
();
int
soft
iic_init
();
// I2C 起始信号
// I2C 起始信号
void
i2c_start
();
void
i2c_start
();
...
...
drivers/sensors/INA226.c
View file @
5eda44dc
...
@@ -4,8 +4,9 @@
...
@@ -4,8 +4,9 @@
float
currentLSB
;
float
currentLSB
;
// 配置 INA226
// 配置 INA226
bool
INA
226_configure
()
{
bool
ina
226_configure
()
{
uint16_t
config
=
0x4127
;
// 默认配置:16次平均,1.1ms 转换时间,连续模式
uint16_t
config
=
0x4127
;
// 默认配置:16次平均,1.1ms 转换时间,连续模式
i2c_start
();
i2c_start
();
i2c_write_byte
(
INA226_ADDRESS
<<
1
);
i2c_write_byte
(
INA226_ADDRESS
<<
1
);
...
@@ -17,7 +18,7 @@ bool INA226_configure() {
...
@@ -17,7 +18,7 @@ bool INA226_configure() {
}
}
// 校准 INA226
// 校准 INA226
bool
INA
226_calibrate
(
float
rShuntValue
,
float
iMaxExpected
)
{
bool
ina
226_calibrate
(
float
rShuntValue
,
float
iMaxExpected
)
{
currentLSB
=
iMaxExpected
/
32767
.
0
;
// 电流 LSB
currentLSB
=
iMaxExpected
/
32767
.
0
;
// 电流 LSB
uint16_t
calibrationValue
=
(
uint16_t
)(
0
.
00512
/
(
currentLSB
*
rShuntValue
));
uint16_t
calibrationValue
=
(
uint16_t
)(
0
.
00512
/
(
currentLSB
*
rShuntValue
));
...
@@ -31,7 +32,7 @@ bool INA226_calibrate(float rShuntValue, float iMaxExpected) {
...
@@ -31,7 +32,7 @@ bool INA226_calibrate(float rShuntValue, float iMaxExpected) {
}
}
// 读取总线电压
// 读取总线电压
float
INA226_readBusVoltage
()
{
float
ina226_readbusvoltage
()
{
i2c_start
();
i2c_start
();
i2c_write_byte
(
INA226_ADDRESS
<<
1
);
i2c_write_byte
(
INA226_ADDRESS
<<
1
);
i2c_write_byte
(
INA226_REG_BUSVOLTAGE
);
i2c_write_byte
(
INA226_REG_BUSVOLTAGE
);
...
@@ -45,7 +46,7 @@ float INA226_readBusVoltage() {
...
@@ -45,7 +46,7 @@ float INA226_readBusVoltage() {
}
}
// 读取电流
// 读取电流
float
INA226_readC
urrent
()
{
float
ina226_readc
urrent
()
{
i2c_start
();
i2c_start
();
i2c_write_byte
(
INA226_ADDRESS
<<
1
);
i2c_write_byte
(
INA226_ADDRESS
<<
1
);
i2c_write_byte
(
INA226_REG_CURRENT
);
i2c_write_byte
(
INA226_REG_CURRENT
);
...
@@ -57,3 +58,20 @@ float INA226_readCurrent() {
...
@@ -57,3 +58,20 @@ float INA226_readCurrent() {
int16_t
value
=
(
high
<<
8
)
|
low
;
int16_t
value
=
(
high
<<
8
)
|
low
;
return
-
value
*
currentLSB
;
return
-
value
*
currentLSB
;
}
}
int
ina225_init
(){
// 配置 INA226
if
(
!
ina226_configure
())
{
my_zlog_warn
(
"INA226初始化失败"
);
return
-
1
;
}
// 校准 INA226
float
rshuntvalue
=
0
.
01
;
// 分流电阻值(单位:欧姆)
float
imaxexpected
=
5
;
// 最大预期电流(单位:安培)
if
(
!
ina226_calibrate
(
rshuntvalue
,
imaxexpected
)){
my_zlog_warn
(
"INA226校准失败"
);
return
-
2
;
}
return
0
;
}
drivers/sensors/INA226.h
View file @
5eda44dc
...
@@ -10,16 +10,13 @@
...
@@ -10,16 +10,13 @@
#define INA226_REG_CURRENT (0x04)
#define INA226_REG_CURRENT (0x04)
#define INA226_REG_CALIBRATION (0x05)
#define INA226_REG_CALIBRATION (0x05)
// 配置 INA226
/*初始化ina226,包括配置 INA226和校准 INA226*/
bool
INA226_configure
();
int
ina225_init
();
// 校准 INA226
bool
INA226_calibrate
(
float
rShuntValue
,
float
iMaxExpected
);
// 读取总线电压
// 读取总线电压
float
INA226_readBusV
oltage
();
float
ina226_readbusv
oltage
();
// 读取电流
// 读取电流
float
INA226_readC
urrent
();
float
ina226_readc
urrent
();
#endif // INA226_H
#endif // INA226_H
\ No newline at end of file
drivers/sensors/audioplay.c
0 → 100644
View file @
5eda44dc
#include "common.h"
#include "audioplay.h"
#include "device_identity.h"
#include "mqtt_init.h"
int
audio_status
=
7
;
char
urlbuf
[
512
];
char
keybuf
[
256
];
double
audio_volume
=
0
.
8
;
//接收音频播放
void
audioplay_mqtt_receive
(
cJSON
*
json
)
{
// 解析"audioLink"字段(修正了原始JSON中的拼写错误)
cJSON
*
audio_link
=
cJSON_GetObjectItemCaseSensitive
(
json
,
"audioLink"
);
if
(
cJSON_IsString
(
audio_link
)
&&
(
audio_link
->
valuestring
!=
NULL
))
{
my_zlog_debug
(
"音频链接: %s"
,
audio_link
->
valuestring
);
char
*
url
=
audio_link
->
valuestring
;
snprintf
(
urlbuf
,
sizeof
(
urlbuf
),
"%s"
,
url
);
}
else
{
my_zlog_warn
(
"错误:无法解析音频链接字段"
);
}
// 解析"key"字段
cJSON
*
key_char
=
cJSON_GetObjectItemCaseSensitive
(
json
,
"key"
);
if
(
cJSON_IsString
(
key_char
)
&&
(
key_char
->
valuestring
!=
NULL
))
{
my_zlog_debug
(
"音频链接: %s"
,
key_char
->
valuestring
);
char
*
key
=
key_char
->
valuestring
;
snprintf
(
keybuf
,
sizeof
(
keybuf
),
"%s"
,
key
);
}
else
{
my_zlog_warn
(
"错误:无法解析音频链接"
);
audio_status
=
5
;
}
// 解析"status"字段
cJSON
*
audio_status_val
=
cJSON_GetObjectItemCaseSensitive
(
json
,
"status"
);
if
(
cJSON_IsNumber
(
audio_status_val
))
{
my_zlog_debug
(
"标志: %d"
,
audio_status_val
->
valueint
);
audio_status
=
audio_status_val
->
valueint
;
}
else
{
my_zlog_warn
(
"错误:无法解析标志字段"
);
}
// 解析"volume"字段
cJSON
*
volume
=
cJSON_GetObjectItemCaseSensitive
(
json
,
"volume"
);
if
(
cJSON_IsNumber
(
volume
))
{
my_zlog_debug
(
"声量大小: %1f"
,
volume
->
valuedouble
);
audio_volume
=
volume
->
valuedouble
+
0
.
0
;
}
else
{
my_zlog_warn
(
"错误:无法解析声量字段"
);
}
}
//发送音频播放是否完毕
void
audioplay_send_mqtt
()
{
cJSON
*
root
=
cJSON_CreateObject
();
cJSON
*
body
=
cJSON_CreateObject
();
cJSON
*
head
=
cJSON_CreateObject
();
// 添加各个字段到 JSON 对象
cJSON_AddStringToObject
(
body
,
"type"
,
"audio"
);
cJSON_AddStringToObject
(
body
,
"audioLink"
,
urlbuf
);
cJSON_AddStringToObject
(
body
,
"key"
,
keybuf
);
cJSON_AddNumberToObject
(
body
,
"status"
,
audio_status
);
cJSON_AddNumberToObject
(
body
,
"volume"
,
audio_volume
);
cJSON_AddNumberToObject
(
head
,
"message_type"
,
3001
);
cJSON_AddItemToObject
(
root
,
"body"
,
body
);
cJSON_AddItemToObject
(
root
,
"head"
,
head
);
// 将 JSON 对象转换为字符串
char
*
json_string
=
cJSON_PrintUnformatted
(
root
);
my_zlog_debug
(
"%s"
,
json_string
);
mosquitto_publish
(
mosq
,
NULL
,
mqtt_topic_pure_number
(),
strlen
(
json_string
),
json_string
,
0
,
false
);
// 释放 JSON 对象内存
cJSON_Delete
(
root
);
}
//音频播放
void
audioplay_cycle
(){
char
command
[
512
];
int
ret
;
while
(
1
){
if
(
audio_status
==
0
){
char
*
urlmoddle
=
urlbuf
;
snprintf
(
command
,
sizeof
(
command
),
"sudo ffplay -nodisp -autoexit -loglevel quiet -af
\"
volume=%1f
\"
\"
%s
\"
"
,
audio_volume
,
urlmoddle
);
my_zlog_debug
(
"播放地址: %s
\n
"
,
urlbuf
);
ret
=
system
(
command
);
if
(
ret
==
-
1
)
{
my_zlog_error
(
"播放失败"
);
audio_status
=
2
;
}
if
(
WIFEXITED
(
ret
)
&&
WEXITSTATUS
(
ret
)
==
0
)
{
my_zlog_debug
(
"播放已成功完成 : %s "
,
urlbuf
);
audio_status
=
1
;
}
else
{
my_zlog_warn
(
"播放失败或中断: %s "
,
urlbuf
);
audio_status
=
2
;
}
audioplay_send_mqtt
();
}
}
}
\ No newline at end of file
drivers/sensors/audioplay.h
0 → 100644
View file @
5eda44dc
#ifndef AUDIOPLAY_H
#define AUDIOPLAY_H
#include <cjson/cJSON.h>
// extern int audio_status;
void
audioplay_mqtt_receive
(
cJSON
*
body
);
//接收音频mqtt播放函数
void
audioplay_cycle
();
//音频播放线程中函数
#endif
\ No newline at end of file
drivers/sensors/war
m
.c
→
drivers/sensors/war
n
.c
View file @
5eda44dc
#include "common.h"
#include "common.h"
#include "war
m
.h"
#include "war
n
.h"
#include "http_request.h"
#include "http_request.h"
#include "mylog.h"
#include "mylog.h"
#include "gpio_init.h"
#include "gpio_init.h"
...
@@ -57,14 +57,14 @@ int alarm_control_close(float voltage) {//关闭警报
...
@@ -57,14 +57,14 @@ int alarm_control_close(float voltage) {//关闭警报
}
}
int
alarm_control
(
float
voltage
)
{
int
alarm_control
(
float
voltage
)
{
#if WAR
M
_MODE == 1
#if WAR
N
_MODE == 1
my_zlog_info
(
"Mode 1: 执行代码A"
);
my_zlog_info
(
"Mode 1: 执行代码A"
);
return
alarm_control_open
(
voltage
);
return
alarm_control_open
(
voltage
);
#elif WAR
M
_MODE == 2
#elif WAR
N
_MODE == 2
my_zlog_info
(
"Mode 2: 执行代码B"
);
my_zlog_info
(
"Mode 2: 执行代码B"
);
return
alarm_control_close
(
voltage
);
return
alarm_control_close
(
voltage
);
#else
#else
my_zlog_error
(
"未知的 WAR
M_MODE: %d"
,
WARM
_MODE
);
my_zlog_error
(
"未知的 WAR
N_MODE: %d"
,
WARN
_MODE
);
return
-
1
;
return
-
1
;
#endif
#endif
}
}
\ No newline at end of file
drivers/sensors/war
m
.h
→
drivers/sensors/war
n
.h
View file @
5eda44dc
#ifndef WAR
M
_H__
#ifndef WAR
N
_H__
#define WAR
M
_H__
#define WAR
N
_H__
/*当mode为1时候打开警报,为2时候关闭警告*/
/*当mode为1时候打开警报,为2时候关闭警告*/
#define WAR
M
_MODE 1
#define WAR
N
_MODE 1
int
alarm_control
(
float
voltage
);
int
alarm_control
(
float
voltage
);
...
...
include/devcontrol_common.h
View file @
5eda44dc
...
@@ -3,7 +3,6 @@
...
@@ -3,7 +3,6 @@
#include "car0101_control.h"
#include "car0101_control.h"
#define DEVICE_CAR0101 101
#define DEVICE_CAR0101 101
#define DEVICE_CAR0102 102
#define DEVICE_CAR0102 102
#define DEVICE_CAR0103 103
#define DEVICE_CAR0103 103
...
...
modules/http/http_request.c
View file @
5eda44dc
...
@@ -12,7 +12,7 @@ int g_errCodeValue;
...
@@ -12,7 +12,7 @@ int g_errCodeValue;
bool
g_enable_buzzer_value
=
0
;
bool
g_enable_buzzer_value
=
0
;
double
g_warn_voltage_value
=
10
.
7
;
double
g_warn_voltage_value
=
10
.
7
;
double
g_err_voltage_value
=
9
.
7
;
double
g_err_voltage_value
=
9
.
7
;
double
g_shot_speed_value
=
0
.
7
;
double
g_shot_speed_value
=
0
.
5
;
// 回调函数,用于处理接收到的数据
// 回调函数,用于处理接收到的数据
static
size_t
WriteMemoryCallback
(
void
*
contents
,
size_t
size
,
size_t
nmemb
,
void
*
userp
)
{
static
size_t
WriteMemoryCallback
(
void
*
contents
,
size_t
size
,
size_t
nmemb
,
void
*
userp
)
{
...
@@ -109,11 +109,12 @@ char *wirte_json() {
...
@@ -109,11 +109,12 @@ char *wirte_json() {
char
*
payload
=
cJSON_PrintUnformatted
(
body
);
char
*
payload
=
cJSON_PrintUnformatted
(
body
);
my_zlog_debug
(
"%s"
,
payload
);
my_zlog_debug
(
"%s"
,
payload
);
cJSON_Delete
(
body
);
// 释放 cJSON 对象
cJSON_Delete
(
body
);
return
payload
;
return
payload
;
}
}
int
request_date
()
{
//请求数据
int
request_date
_open
()
{
//请求数据
CURL
*
curl
;
CURL
*
curl
;
CURLcode
res
;
CURLcode
res
;
...
@@ -164,7 +165,23 @@ int request_date() {//请求数据
...
@@ -164,7 +165,23 @@ int request_date() {//请求数据
free
(
chunk
.
memory
);
free
(
chunk
.
memory
);
curl_slist_free_all
(
headers
);
curl_slist_free_all
(
headers
);
curl_easy_cleanup
(
curl
);
curl_easy_cleanup
(
curl
);
curl_global_cleanup
();
curl_global_cleanup
();
return
0
;
return
0
;
}
int
request_date
()
{
#if HTTP_REQUEST_INDEX == 1
// 当MODE为1时的代码
my_zlog_info
(
"HTTP Mode 1: 执行代码A"
);
return
request_date_open
();
#elif HTTP_REQUEST_INDEX == 2
// 当MODE为2时的代码
my_zlog_info
(
"HTTP Mode 2: 执行代码B"
);
return
0
;
#else
my_zlog_error
(
"未知的 WARM_MODE: %d"
,
HTTP_REQUEST_INDEX
);
return
-
1
;
#endif
}
}
\ No newline at end of file
modules/http/http_request.h
View file @
5eda44dc
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
#include"common.h"// 用于存储HTTP响应数据的结构体
#include"common.h"// 用于存储HTTP响应数据的结构体
#define HTTP_REQUEST_INDEX 1
/*2为关闭请求,1为打开*/
#define HTTP_REQUEST_INDEX 2
struct
MemoryStruct
{
struct
MemoryStruct
{
char
*
memory
;
char
*
memory
;
...
...
modules/mqtt/mqtt_infor_handle.c
View file @
5eda44dc
...
@@ -9,10 +9,14 @@
...
@@ -9,10 +9,14 @@
#include "common.h"
#include "common.h"
#include "INA226.h"
#include "INA226.h"
#include "ads1115.h"
#include "ads1115.h"
#include "war
m
.h"
#include "war
n
.h"
#include "device_fileopen.h"
#include "device_fileopen.h"
#include "devcontrol_common.h"
#include "devcontrol_common.h"
#include "device_wifi_change.h"
#include "audioplay.h"
#include "gpio_init.h"
#include "gpio_init.h"
#include "device_init.h"
bool
g_verified_mode
=
TRUE
;
//控制是否需要验证
bool
g_verified_mode
=
TRUE
;
//控制是否需要验证
...
@@ -26,13 +30,13 @@ unsigned char g_valt[4];//存放mqtt接收的tpye,mode等
...
@@ -26,13 +30,13 @@ unsigned char g_valt[4];//存放mqtt接收的tpye,mode等
//心跳发送格式*5/2
//心跳发送格式*5/2
void
heartbeat_send
()
{
void
heartbeat_send
()
{
float
voltage
=
0
;
//INA226_readBusV
oltage();
float
voltage
=
ina226_readbusv
oltage
();
float
current
=
0
;
//INA226_readC
urrent();
float
current
=
ina226_readc
urrent
();
my_zlog_debug
(
"%.2f
\n
"
,
voltage
);
my_zlog_debug
(
"%.2f"
,
voltage
);
if
(
voltage
<=
0
.
5
){
if
(
voltage
<=
0
.
5
){
voltage
=
ads1115_read_channel
(
0
)
*
5
/
2
;
voltage
=
ads1115_read_channel
(
0
)
*
5
/
2
;
current
=
ads1115_read_channel
(
1
)
*
5
/
2
;
current
=
ads1115_read_channel
(
1
)
*
5
/
2
;
my_zlog_debug
(
"%.2f
\n
"
,
voltage
);
my_zlog_debug
(
"%.2f"
,
voltage
);
current
=
(
current
-
voltage
)
*
100
;
current
=
(
current
-
voltage
)
*
100
;
}
}
char
voltage_str
[
20
];
// 足够存储转换后的字符串的缓冲区
char
voltage_str
[
20
];
// 足够存储转换后的字符串的缓冲区
...
@@ -78,8 +82,7 @@ void heartbeat_send() {
...
@@ -78,8 +82,7 @@ void heartbeat_send() {
//mqtt设备行走驱动函数
//mqtt设备行走驱动函数
void
device_driver
(){
void
device_driver
(){
int
device_type
=
0
;
if
(
device_type
==
DEVICE_CAR0101
)
car0101_control_change
(
g_valt
)
;
if
(
device_type
==
101
)
car0101_control_change
(
g_valt
)
;
// if(AppExit_pin_pwm == 102) car0102_speed_change(valt) ;
// if(AppExit_pin_pwm == 102) car0102_speed_change(valt) ;
// if(AppExit_pin_pwm == 103 ) car0103_change(valt) ;
// if(AppExit_pin_pwm == 103 ) car0103_change(valt) ;
// if(AppExit_pin_pwm == 104 ) car0104_change(valt) ;
// if(AppExit_pin_pwm == 104 ) car0104_change(valt) ;
...
@@ -90,22 +93,20 @@ void device_driver(){
...
@@ -90,22 +93,20 @@ void device_driver(){
//角度发送
//角度发送
void
angle_mqtt_send
()
{
void
angle_mqtt_send
()
{
// float angle_shot=ads1115_read_channel(2);
float
angle_shot
=
ads1115_read_channel
(
2
);
// if(angle_shot>0){
if
(
angle_shot
>
0
){
// angle_shot=angle_shot*360/5;
angle_shot
=
angle_shot
*
360
/
5
;
// //my_zlog_debug("%.2f",angle_shot);
cJSON
*
root
=
cJSON_CreateObject
();
// topic_middle_value();
char
TOPIC_send_angle
[
26
];
// cJSON *root = cJSON_CreateObject();
double
rounded_angle
=
round
(
angle_shot
*
100
)
/
100
;
// char TOPIC_send_angle[26];
sprintf
(
TOPIC_send_angle
,
"dev_rtinfo/%s"
,
mqtt_topic_pure_number
());
// double rounded_angle = round(angle_shot * 100) / 100;
cJSON_AddStringToObject
(
root
,
"type"
,
"tank_angle"
);
// sprintf(TOPIC_send_angle,"dev_rtinfo/%s",TOPIC3);
cJSON_AddNumberToObject
(
root
,
"angle"
,
rounded_angle
);
// cJSON_AddStringToObject(root, "type","tank_angle");
char
*
payload
=
cJSON_PrintUnformatted
(
root
);
// cJSON_AddNumberToObject(root, "angle",rounded_angle);
my_zlog_debug
(
"%s"
,
payload
);
// char *payload = cJSON_PrintUnformatted(root);
mosquitto_publish
(
mosq
,
NULL
,
TOPIC_send_angle
,
strlen
(
payload
),
payload
,
0
,
false
);
// my_zlog_debug("%s",payload);
cJSON_Delete
(
root
);
// 释放 cJSON 对象
// mosquitto_publish(mosq, NULL, TOPIC_send_angle, strlen(payload), payload, 0, false);
}
// cJSON_Delete(root); // 释放 cJSON 对象
// }
}
}
...
@@ -116,7 +117,7 @@ void mqtt_wirte(){
...
@@ -116,7 +117,7 @@ void mqtt_wirte(){
heartbeat_send
();
heartbeat_send
();
g_heartbeat_count
=
0
;
g_heartbeat_count
=
0
;
}
}
// if( AppExit_pin_pwm
== 202) angle_mqtt_send();
if
(
device_type
==
202
)
angle_mqtt_send
();
}
}
...
@@ -269,7 +270,7 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
...
@@ -269,7 +270,7 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
my_zlog_debug
(
"进入引脚控制"
);
my_zlog_debug
(
"进入引脚控制"
);
break
;
break
;
case
2001
:
case
2001
:
//
audioplay_mqtt_receive(body);
audioplay_mqtt_receive
(
body
);
my_zlog_debug
(
"进入音频播放"
);
my_zlog_debug
(
"进入音频播放"
);
break
;
break
;
case
2002
:
case
2002
:
...
@@ -277,11 +278,11 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
...
@@ -277,11 +278,11 @@ int device_message_receive(cJSON *json){//接收到的控制设备的mqtt消息
my_zlog_debug
(
"进入修改设备号"
);
my_zlog_debug
(
"进入修改设备号"
);
break
;
break
;
case
2003
:
case
2003
:
//
scan_wifi_json();
scan_wifi_json
();
my_zlog_debug
(
"进入查询WiFi"
);
my_zlog_debug
(
"进入查询WiFi"
);
break
;
break
;
case
2004
:
case
2004
:
//
wifi_change_recmqtt(body);
wifi_change_recmqtt
(
body
);
my_zlog_debug
(
"进入修改WiFi"
);
my_zlog_debug
(
"进入修改WiFi"
);
break
;
break
;
case
2006
:
case
2006
:
...
...
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