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
e1dc9bc1
Commit
e1dc9bc1
authored
Mar 11, 2026
by
957dd
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了验证逻辑,空字符串不验证,验证失败会最多验证3次,防止失败
parent
39dea0c6
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
66 additions
and
16 deletions
+66
-16
main
build/main
+0
-0
car0102_control.c
drivers/devicecontrol/car0102_control.c
+2
-2
mqtt_verify.c
modules/mqtt/mqtt_verify.c
+64
-14
No files found.
build/main
View file @
e1dc9bc1
No preview for this file type
drivers/devicecontrol/car0102_control.c
View file @
e1dc9bc1
...
@@ -285,10 +285,10 @@ static void car0102_steering_angle_smooth_process() {
...
@@ -285,10 +285,10 @@ static void car0102_steering_angle_smooth_process() {
if
(
steering_mode
==
3
)
{
if
(
steering_mode
==
3
)
{
// 左转: 90 -> 130
// 左转: 90 -> 130
wanted_angle
=
90
+
(
input_angle
*
3
0
)
/
180
;
wanted_angle
=
90
+
(
input_angle
*
3
7
)
/
180
;
}
else
if
(
steering_mode
==
4
)
{
}
else
if
(
steering_mode
==
4
)
{
// 右转: 90 -> 50
// 右转: 90 -> 50
wanted_angle
=
90
-
(
input_angle
*
3
0
)
/
180
;
wanted_angle
=
90
-
(
input_angle
*
3
7
)
/
180
;
}
else
{
}
else
{
wanted_angle
=
90
;
wanted_angle
=
90
;
smooth_step
=
STEER_STEP_RETURN
;
// 回正阶段使用更大的步长
smooth_step
=
STEER_STEP_RETURN
;
// 回正阶段使用更大的步长
...
...
modules/mqtt/mqtt_verify.c
View file @
e1dc9bc1
...
@@ -25,6 +25,12 @@ char g_secret_key[1024];//存储上一次的topic
...
@@ -25,6 +25,12 @@ char g_secret_key[1024];//存储上一次的topic
bool
g_secret_key_index
=
TRUE
;
//用于判断是否对比topic
bool
g_secret_key_index
=
TRUE
;
//用于判断是否对比topic
/* topic 不同时发后端验证,失败可重试,超过 3 次不通过则判定该 topic 不通过 */
static
char
g_pending_verify_token
[
1024
];
static
char
g_last_seen_token
[
1024
];
/* 用于判断token是否变化(首次启动默认全0) */
static
int
g_verify_retry_count
=
0
;
#define VERIFY_RETRY_MAX 3
int
g_verify_index
=
0
;
//判断是否验证成功
int
g_verify_index
=
0
;
//判断是否验证成功
pthread_mutex_t
g_verify_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
//线程锁
pthread_mutex_t
g_verify_mutex
=
PTHREAD_MUTEX_INITIALIZER
;
//线程锁
...
@@ -97,19 +103,46 @@ int receive_jwt(cJSON *body) {
...
@@ -97,19 +103,46 @@ int receive_jwt(cJSON *body) {
token
=
json_token
->
valuestring
;
token
=
json_token
->
valuestring
;
token_time
=
json_token_time
->
valuestring
;
token_time
=
json_token_time
->
valuestring
;
if
(
g_secret_key_index
==
FALSE
)
{
/* 空字符串视为无效,不发给后端 */
if
(
strcmp
(
token
,
g_secret_key
)
!=
0
){
if
(
token
==
NULL
||
token
[
0
]
==
'\0'
||
token_time
==
NULL
||
token_time
[
0
]
==
'\0'
)
{
my_zlog_debug
(
"验证为空"
);
g_verify_index
=
1
;
return
1
;
}
/*
* token 变化触发验证策略:
* - 首次启动(g_last_seen_token 为空)只保存,不验证,确保下一次必定“有变化”再验证
* - 之后每次只要 token 和上一次接收到的不一样,就发起后端验证
*/
if
(
g_last_seen_token
[
0
]
==
'\0'
)
{
strncpy
(
g_last_seen_token
,
token
,
sizeof
(
g_last_seen_token
)
-
1
);
g_last_seen_token
[
sizeof
(
g_last_seen_token
)
-
1
]
=
'\0'
;
strncpy
(
g_pending_verify_token
,
token
,
sizeof
(
g_pending_verify_token
)
-
1
);
g_pending_verify_token
[
sizeof
(
g_pending_verify_token
)
-
1
]
=
'\0'
;
g_verify_retry_count
=
0
;
send_jwtser
(
token
);
send_jwtser
(
token
);
g_secret_key_index
=
TRUE
;
pthread_mutex_lock
(
&
g_verify_mutex
);
pthread_mutex_lock
(
&
g_verify_mutex
);
g_verify_count
=
0
;
g_verify_count
=
0
;
pthread_mutex_unlock
(
&
g_verify_mutex
);
pthread_mutex_unlock
(
&
g_verify_mutex
);
my_zlog_notice
(
"topic不同,验证完成"
);
my_zlog_notice
(
"首次token,发起验证"
);
}
}
else
if
(
strcmp
(
token
,
g_last_seen_token
)
!=
0
)
{
}
else
{
strncpy
(
g_last_seen_token
,
token
,
sizeof
(
g_last_seen_token
)
-
1
);
my_zlog_notice
(
"topic相同"
);
g_last_seen_token
[
sizeof
(
g_last_seen_token
)
-
1
]
=
'\0'
;
strcpy
(
g_secret_key
,
token
);
g_secret_key_index
=
FALSE
;
strncpy
(
g_pending_verify_token
,
token
,
sizeof
(
g_pending_verify_token
)
-
1
);
g_pending_verify_token
[
sizeof
(
g_pending_verify_token
)
-
1
]
=
'\0'
;
g_verify_retry_count
=
0
;
send_jwtser
(
token
);
pthread_mutex_lock
(
&
g_verify_mutex
);
g_verify_count
=
0
;
pthread_mutex_unlock
(
&
g_verify_mutex
);
my_zlog_notice
(
"token变化,发起验证"
);
}
else
{
my_zlog_notice
(
"token未变化"
);
}
}
...
@@ -170,13 +203,30 @@ int message2006_verify(cJSON *body){
...
@@ -170,13 +203,30 @@ int message2006_verify(cJSON *body){
if
(
strcmp
(
onlyid
,
g_only_id_middle
)
==
0
&&
strcmp
(
status
,
"1"
)
==
0
){
if
(
strcmp
(
onlyid
,
g_only_id_middle
)
==
0
&&
strcmp
(
status
,
"1"
)
==
0
){
my_zlog_debug
(
"获得验证正确"
);
my_zlog_debug
(
"获得验证正确"
);
g_service_verify
=
TRUE
;
g_service_verify
=
TRUE
;
}
else
{
g_verify_index
=
0
;
/* 后端通过后必须清除失败标志,否则正确 token 仍会提示验证不通过 */
my_zlog_debug
(
"获得验证c错误,禁止使用"
);
strcpy
(
g_secret_key
,
g_pending_verify_token
);
g_verify_index
=
1
;
g_secret_key_index
=
FALSE
;
my_zlog_debug
(
"g_verify_index= %d "
,
g_verify_index
);
g_verify_retry_count
=
0
;
}
else
{
/* 仅当 onlyid 匹配时视为本次验证的回复,否则可能是旧包 */
if
(
strcmp
(
onlyid
,
g_only_id_middle
)
==
0
)
{
g_verify_retry_count
++
;
if
(
g_verify_retry_count
<
VERIFY_RETRY_MAX
)
{
my_zlog_notice
(
"验证不通过,第%d次重试"
,
g_verify_retry_count
);
send_jwtser
(
g_pending_verify_token
);
}
else
{
my_zlog_warn
(
"topic验证超过%d次不通过,禁止使用"
,
VERIFY_RETRY_MAX
);
g_verify_index
=
1
;
g_service_verify
=
FALSE
;
g_service_verify
=
FALSE
;
return
2
;
return
2
;
}
}
}
else
{
my_zlog_debug
(
"获得验证错误,禁止使用"
);
g_verify_index
=
1
;
g_service_verify
=
FALSE
;
return
2
;
}
}
return
0
;
return
0
;
}
}
...
...
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