Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Pinoxchio
apollo
提交
63da6bdf
A
apollo
项目概览
Pinoxchio
/
apollo
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
apollo
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
63da6bdf
编写于
11月 30, 2017
作者:
U
unacao
提交者:
siyangy
11月 30, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
safeguard json request via websocket (#1493)
上级
e5341d44
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
19 deletion
+52
-19
modules/dreamview/backend/map/map_service.cc
modules/dreamview/backend/map/map_service.cc
+7
-2
modules/dreamview/backend/simulation_world/simulation_world_updater.cc
...view/backend/simulation_world/simulation_world_updater.cc
+43
-17
modules/dreamview/backend/simulation_world/simulation_world_updater.h
...mview/backend/simulation_world/simulation_world_updater.h
+2
-0
未找到文件。
modules/dreamview/backend/map/map_service.cc
浏览文件 @
63da6bdf
...
...
@@ -72,10 +72,15 @@ void ExtractStringVectorFromJson(const nlohmann::json &json_object,
const
std
::
string
&
key
,
std
::
vector
<
std
::
string
>
*
result
)
{
auto
iter
=
json_object
.
find
(
key
);
if
(
iter
!=
json_object
.
end
())
{
if
(
iter
!=
json_object
.
end
()
&&
iter
->
is_array
()
)
{
result
->
reserve
(
iter
->
size
());
for
(
size_t
i
=
0
;
i
<
iter
->
size
();
++
i
)
{
result
->
push_back
((
*
iter
)[
i
]);
auto
value
=
(
*
iter
)[
i
];
if
(
value
.
is_string
())
{
result
->
push_back
(
value
);
}
else
{
AWARN
<<
"Expected 'string' type, but was "
<<
value
.
type_name
();
}
}
}
}
...
...
modules/dreamview/backend/simulation_world/simulation_world_updater.cc
浏览文件 @
63da6bdf
...
...
@@ -70,6 +70,12 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
return
;
}
if
(
!
radius
->
is_number
())
{
AERROR
<<
"Expect radius with type 'number', but was "
<<
radius
->
type_name
();
return
;
}
Json
response
=
sim_world_service_
.
GetMapElements
(
*
radius
);
response
[
"type"
]
=
"MapElements"
;
websocket_
->
SendData
(
conn
,
response
.
dump
());
...
...
@@ -107,7 +113,8 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
}
bool
requestPlanning
=
false
;
if
(
json
.
find
(
"planning"
)
!=
json
.
end
())
{
auto
planning
=
json
.
find
(
"planning"
);
if
(
planning
!=
json
.
end
()
&&
planning
->
is_boolean
())
{
requestPlanning
=
json
[
"planning"
];
}
...
...
@@ -170,30 +177,33 @@ SimulationWorldUpdater::SimulationWorldUpdater(WebSocketHandler *websocket,
bool
SimulationWorldUpdater
::
ConstructRoutingRequest
(
const
Json
&
json
,
RoutingRequest
*
routing_request
)
{
// Input validations
routing_request
->
clear_waypoint
();
// set start point
if
(
!
ContainsKey
(
json
,
"start"
))
{
AERROR
<<
"
Cannot prepare a routing request: input validation faile
d."
;
AERROR
<<
"
Failed to prepare a routing request: start point not foun
d."
;
return
false
;
}
// set start point
auto
start
=
json
[
"start"
];
if
(
!
ContainsKey
(
start
,
"x"
)
||
!
ContainsKey
(
start
,
"y"
))
{
AERROR
<<
"Failed to prepare a routing request: start point not found"
;
if
(
!
ValidateCoordinate
(
start
))
{
AERROR
<<
"Failed to prepare a routing request: invalid start point."
;
return
false
;
}
if
(
!
map_service_
->
ConstructLaneWayPoint
(
start
[
"x"
],
start
[
"y"
],
routing_request
->
add_waypoint
()))
{
AERROR
<<
"Failed to prepare a routing request:"
<<
" cannot locate start point on map."
;
return
false
;
}
routing_request
->
clear_waypoint
();
map_service_
->
ConstructLaneWayPoint
(
start
[
"x"
],
start
[
"y"
],
routing_request
->
add_waypoint
());
// set way point(s) if any
auto
iter
=
json
.
find
(
"waypoint"
);
if
(
iter
!=
json
.
end
())
{
if
(
iter
!=
json
.
end
()
&&
iter
->
is_array
()
)
{
auto
*
waypoint
=
routing_request
->
mutable_waypoint
();
for
(
size_t
i
=
0
;
i
<
iter
->
size
();
++
i
)
{
auto
&
point
=
(
*
iter
)[
i
];
if
(
!
ContainsKey
(
point
,
"x"
)
||
!
ContainsKey
(
point
,
"y"
))
{
AERROR
<<
"Failed to prepare a routing request:
waypoint not found
"
;
if
(
!
ValidateCoordinate
(
point
))
{
AERROR
<<
"Failed to prepare a routing request:
invalid waypoint.
"
;
return
false
;
}
...
...
@@ -205,18 +215,22 @@ bool SimulationWorldUpdater::ConstructRoutingRequest(
}
// set end point
auto
*
end_point
=
routing_request
->
add_waypoint
();
if
(
!
ContainsKey
(
json
,
"end"
))
{
AERROR
<<
"Failed to prepare a routing request: end point not found"
;
AERROR
<<
"Failed to prepare a routing request: end point not found
.
"
;
return
false
;
}
auto
end
=
json
[
"end"
];
if
(
!
ContainsKey
(
end
,
"x"
)
||
!
ContainsKey
(
end
,
"y"
))
{
AERROR
<<
"Failed to prepare a routing request: end point not found"
;
if
(
!
ValidateCoordinate
(
end
))
{
AERROR
<<
"Failed to prepare a routing request: invalid end point."
;
return
false
;
}
if
(
!
map_service_
->
ConstructLaneWayPoint
(
end
[
"x"
],
end
[
"y"
],
routing_request
->
add_waypoint
()))
{
AERROR
<<
"Failed to prepare a routing request:"
<<
" cannot locate end point on map."
;
return
false
;
}
map_service_
->
ConstructLaneWayPoint
(
end
[
"x"
],
end
[
"y"
],
end_point
);
AINFO
<<
"Constructed RoutingRequest to be sent:
\n
"
<<
routing_request
->
DebugString
();
...
...
@@ -224,6 +238,18 @@ bool SimulationWorldUpdater::ConstructRoutingRequest(
return
true
;
}
bool
SimulationWorldUpdater
::
ValidateCoordinate
(
const
nlohmann
::
json
&
json
)
{
if
(
!
ContainsKey
(
json
,
"x"
)
||
!
ContainsKey
(
json
,
"y"
))
{
AERROR
<<
"Failed to find x or y coordinate."
;
return
false
;
}
if
(
json
.
find
(
"x"
)
->
is_number
()
&&
json
.
find
(
"y"
)
->
is_number
())
{
return
true
;
}
AERROR
<<
"Both x and y coordinate should be a number."
;
return
false
;
}
void
SimulationWorldUpdater
::
Start
()
{
// start ROS timer, one-shot = false, auto-start = true
timer_
=
...
...
modules/dreamview/backend/simulation_world/simulation_world_updater.h
浏览文件 @
63da6bdf
...
...
@@ -89,6 +89,8 @@ class SimulationWorldUpdater {
const
nlohmann
::
json
&
json
,
apollo
::
routing
::
RoutingRequest
*
routing_request
);
bool
ValidateCoordinate
(
const
nlohmann
::
json
&
json
);
/**
* @brief Tries to load the points of interest from the file if it has
* not been.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录