Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeoFlyApi
Overview
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
GeoFly
GeoFlyApi
Commits
625ee59d
Commit
625ee59d
authored
May 21, 2025
by
真的三个金鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
UOM 上报频率
parent
700ffe35
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
35 deletions
+114
-35
sample/src/main/java/com/dji/sample/manage/service/impl/SDKDeviceService.java
+114
-35
No files found.
sample/src/main/java/com/dji/sample/manage/service/impl/SDKDeviceService.java
View file @
625ee59d
...
...
@@ -35,10 +35,10 @@ import org.springframework.util.StringUtils;
import
java.math.RoundingMode
;
import
java.time.LocalDateTime
;
import
java.util.
Date
;
import
java.util.
List
;
import
java.util.
Object
s
;
import
java.util.
Optional
;
import
java.util.
*
;
import
java.util.
concurrent.ConcurrentHashMap
;
import
java.util.
concurrent.Executor
s
;
import
java.util.
concurrent.ScheduledExecutorService
;
import
java.util.stream.Collectors
;
/**
...
...
@@ -68,6 +68,9 @@ public class SDKDeviceService extends AbstractDeviceService {
@Autowired
private
UOMRecordService
uomRecordService
;
private
static
final
ScheduledExecutorService
recordExecutor
=
Executors
.
newScheduledThreadPool
(
4
);
private
static
final
Map
<
String
,
Long
>
lastRecordTimeMap
=
new
ConcurrentHashMap
<>();
private
static
final
long
MIN_RECORD_INTERVAL
=
2000
;
// 2秒间隔
@Override
public
TopicStatusResponse
<
MqttReply
>
updateTopoOnline
(
TopicStatusRequest
<
UpdateTopo
>
request
,
MessageHeaders
headers
)
{
UpdateTopoSubDevice
updateTopoSubDevice
=
request
.
getData
().
getSubDevices
().
get
(
0
);
...
...
@@ -188,37 +191,38 @@ public class SDKDeviceService extends AbstractDeviceService {
DeviceDTO
device
=
deviceOpt
.
get
();
deviceRedisService
.
setDeviceOnline
(
device
);
deviceRedisService
.
setDeviceOsd
(
from
,
request
.
getData
());
new
Thread
(()
->
{
UOMDroneFlightRecordDTO
uomDroneFlightRecordDTO
=
new
UOMDroneFlightRecordDTO
();
uomDroneFlightRecordDTO
.
setOrderID
(
device
.
getDeviceSn
()+
"-"
+
DateUtil
.
format
(
new
Date
(),
"yyyyMMdd"
)+
"-"
+
RandomUtil
.
randomString
(
8
));
uomDroneFlightRecordDTO
.
setSn
(
device
.
getDeviceSn
());
uomDroneFlightRecordDTO
.
setFlightStatus
(
"Land"
);
uomDroneFlightRecordDTO
.
setManufacturerID
(
"914403007954257495"
);
uomDroneFlightRecordDTO
.
setUasID
(
"UAS-DEFAULT"
);
uomDroneFlightRecordDTO
.
setTimeStamp
(
DateUtil
.
format
(
DateUtil
.
date
(
request
.
getTimestamp
()),
"yyyyMMddHHmmss"
));
uomDroneFlightRecordDTO
.
setUasModel
(
device
.
getType
().
name
());
uomDroneFlightRecordDTO
.
setCoordinate
(
1
);
uomDroneFlightRecordDTO
.
setLongitude
((
long
)
(
NumberUtil
.
round
(
request
.
getData
().
getLongitude
(),
7
,
RoundingMode
.
DOWN
).
doubleValue
()
*
10000000
));
uomDroneFlightRecordDTO
.
setLatitude
((
long
)
(
NumberUtil
.
round
(
request
.
getData
().
getLatitude
(),
7
,
RoundingMode
.
DOWN
).
doubleValue
()
*
10000000
));
uomDroneFlightRecordDTO
.
setHeightType
(
1
);
uomDroneFlightRecordDTO
.
setHeight
((
int
)
(
NumberUtil
.
round
(
request
.
getData
().
getElevation
(),
1
,
RoundingMode
.
DOWN
).
doubleValue
()
*
10
));
uomDroneFlightRecordDTO
.
setAltitude
((
int
)
(
request
.
getData
().
getHeight
().
doubleValue
()
*
10
));
uomDroneFlightRecordDTO
.
setVS
((
int
)
(
NumberUtil
.
round
(
request
.
getData
().
getVerticalSpeed
(),
1
,
RoundingMode
.
DOWN
).
doubleValue
()
*
10
));
uomDroneFlightRecordDTO
.
setGS
((
int
)
(
NumberUtil
.
round
(
request
.
getData
().
getHorizontalSpeed
(),
1
,
RoundingMode
.
DOWN
).
doubleValue
()
*
10
));
uomDroneFlightRecordDTO
.
setCourse
(-
999
);
log
.
info
(
"UOM Record start: =================+++++++++++++++++"
);
log
.
info
(
"UOM Record DTO: "
+
JSONUtil
.
toJsonStr
(
uomDroneFlightRecordDTO
));
try
{
String
body
=
uomRecordService
.
sendRecord
(
uomDroneFlightRecordDTO
);
log
.
info
(
"UOM Record: "
+
body
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
log
.
error
(
"UOM Record Error: "
+
e
.
getMessage
());
log
.
error
(
"UOM Record Error: "
+
e
.
getMessage
());
}
log
.
info
(
"UOM Record end: =================+++++++++++++++++"
);
}).
start
();
// 3. 带频率控制的记录上报
submitRecordWithRateLimit
(
device
,
request
);
// new Thread(() -> {
// UOMDroneFlightRecordDTO uomDroneFlightRecordDTO = new UOMDroneFlightRecordDTO();
// uomDroneFlightRecordDTO.setOrderID(device.getDeviceSn()+"-"+ DateUtil.format(new Date(), "yyyyMMdd")+"-"+ RandomUtil.randomString(8));
// uomDroneFlightRecordDTO.setSn(device.getDeviceSn());
// uomDroneFlightRecordDTO.setFlightStatus("Land");
// uomDroneFlightRecordDTO.setManufacturerID("914403007954257495");
// uomDroneFlightRecordDTO.setUasID("UAS-DEFAULT");
// uomDroneFlightRecordDTO.setTimeStamp(DateUtil.format(DateUtil.date(request.getTimestamp()),"yyyyMMddHHmmss"));
// uomDroneFlightRecordDTO.setUasModel(device.getType().name());
// uomDroneFlightRecordDTO.setCoordinate(1);
// uomDroneFlightRecordDTO.setLongitude((long) (NumberUtil.round(request.getData().getLongitude(),7, RoundingMode.DOWN).doubleValue() * 10000000));
// uomDroneFlightRecordDTO.setLatitude((long) (NumberUtil.round(request.getData().getLatitude(),7, RoundingMode.DOWN).doubleValue() * 10000000));
// uomDroneFlightRecordDTO.setHeightType(1);
// uomDroneFlightRecordDTO.setHeight((int) (NumberUtil.round(request.getData().getElevation(),1, RoundingMode.DOWN).doubleValue() * 10));
// uomDroneFlightRecordDTO.setAltitude((int) (request.getData().getHeight().doubleValue() * 10));
// uomDroneFlightRecordDTO.setVS((int) (NumberUtil.round(request.getData().getVerticalSpeed(),1, RoundingMode.DOWN).doubleValue() * 10));
// uomDroneFlightRecordDTO.setGS((int) (NumberUtil.round(request.getData().getHorizontalSpeed(),1, RoundingMode.DOWN).doubleValue() * 10));
// uomDroneFlightRecordDTO.setCourse(-999);
// log.info("UOM Record start: =================+++++++++++++++++");
// log.info("UOM Record DTO: " + JSONUtil.toJsonStr(uomDroneFlightRecordDTO));
// try {
// String body = uomRecordService.sendRecord(uomDroneFlightRecordDTO);
// log.info("UOM Record: " + body);
// } catch (Exception e) {
// e.printStackTrace();
// log.error("UOM Record Error: " + e.getMessage());
// log.error("UOM Record Error: " + e.getMessage());
// }
// log.info("UOM Record end: =================+++++++++++++++++");
// }).start();
deviceService
.
pushOsdDataToWeb
(
device
.
getWorkspaceId
(),
BizCodeEnum
.
DEVICE_OSD
,
from
,
request
.
getData
());
}
...
...
@@ -538,4 +542,79 @@ public class SDKDeviceService extends AbstractDeviceService {
deviceRedisService
.
setDeviceOsd
(
dockSn
,
oldDock
);
}
}
private
void
submitRecordWithRateLimit
(
DeviceDTO
device
,
TopicOsdRequest
<
OsdDockDrone
>
request
)
{
String
sn
=
device
.
getDeviceSn
();
long
currentTime
=
System
.
currentTimeMillis
();
// 检查时间间隔
if
(
lastRecordTimeMap
.
containsKey
(
sn
))
{
long
lastTime
=
lastRecordTimeMap
.
get
(
sn
);
if
(
currentTime
-
lastTime
<
MIN_RECORD_INTERVAL
)
{
log
.
debug
(
"Skip record for SN {} due to rate limit"
,
sn
);
return
;
}
}
// 更新时间戳并提交任务
lastRecordTimeMap
.
put
(
sn
,
currentTime
);
recordExecutor
.
submit
(()
->
processFlightRecord
(
device
,
request
));
}
private
void
processFlightRecord
(
DeviceDTO
device
,
TopicOsdRequest
<
OsdDockDrone
>
request
)
{
// 1. 构建DTO(提取为独立方法)
UOMDroneFlightRecordDTO
recordDto
=
buildFlightRecordDto
(
device
,
request
);
// 2. 记录日志(优化日志格式)
log
.
info
(
"UOM Record start ================= [SN: {}]"
,
device
.
getDeviceSn
());
log
.
debug
(
"UOM Record DTO: {}"
,
JSONUtil
.
toJsonStr
(
recordDto
));
// 3. 发送记录(带异常处理)
try
{
String
response
=
uomRecordService
.
sendRecord
(
recordDto
);
log
.
info
(
"UOM Record success, response: {}"
,
response
);
}
catch
(
Exception
e
)
{
log
.
error
(
"UOM Record failed for SN {}: {}"
,
device
.
getDeviceSn
(),
e
.
getMessage
());
log
.
debug
(
"Stack trace: "
,
e
);
}
finally
{
log
.
info
(
"UOM Record end =================== [SN: {}]"
,
device
.
getDeviceSn
());
}
}
private
UOMDroneFlightRecordDTO
buildFlightRecordDto
(
DeviceDTO
device
,
TopicOsdRequest
<
OsdDockDrone
>
request
)
{
UOMDroneFlightRecordDTO
dto
=
new
UOMDroneFlightRecordDTO
();
// 公共字段设置
dto
.
setOrderID
(
String
.
format
(
"%s-%s-%s"
,
device
.
getDeviceSn
(),
DateUtil
.
format
(
new
Date
(),
"yyyyMMdd"
),
RandomUtil
.
randomString
(
8
)));
dto
.
setSn
(
device
.
getDeviceSn
());
dto
.
setFlightStatus
(
"Land"
);
dto
.
setManufacturerID
(
"914403007954257495"
);
dto
.
setUasID
(
"UAS-DEFAULT"
);
dto
.
setTimeStamp
(
DateUtil
.
format
(
DateUtil
.
date
(
request
.
getTimestamp
()),
"yyyyMMddHHmmss"
));
dto
.
setUasModel
(
device
.
getType
().
name
());
// 坐标相关计算
OsdDockDrone
data
=
request
.
getData
();
dto
.
setCoordinate
(
1
);
dto
.
setLongitude
(
convertCoordinate
(
data
.
getLongitude
().
doubleValue
()));
dto
.
setLatitude
(
convertCoordinate
(
data
.
getLatitude
().
doubleValue
()));
dto
.
setHeightType
(
1
);
dto
.
setHeight
(
convertToInt
(
data
.
getElevation
().
doubleValue
(),
1
));
dto
.
setAltitude
(
convertToInt
(
data
.
getHeight
().
doubleValue
(),
0
));
dto
.
setVS
(
convertToInt
(
data
.
getVerticalSpeed
().
doubleValue
(),
1
));
dto
.
setGS
(
convertToInt
(
data
.
getHorizontalSpeed
().
doubleValue
(),
1
));
dto
.
setCourse
(-
999
);
return
dto
;
}
// 辅助方法
private
long
convertCoordinate
(
Double
value
)
{
return
(
long
)
(
NumberUtil
.
round
(
value
,
7
,
RoundingMode
.
DOWN
).
doubleValue
()
*
10000000
);
}
private
int
convertToInt
(
Double
value
,
int
decimalPlaces
)
{
return
(
int
)
(
NumberUtil
.
round
(
value
,
decimalPlaces
,
RoundingMode
.
DOWN
).
doubleValue
()
*
10
);
}
}
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