Commit bd8cdbef by gdj

增加获取设备osd接口getDeviceOsd

parent dff5999c
...@@ -346,4 +346,23 @@ public class DeviceController { ...@@ -346,4 +346,23 @@ public class DeviceController {
return HttpResultResponse.success(deviceInfoTotal); return HttpResultResponse.success(deviceInfoTotal);
} }
/**
* Get the real-time OSD data of a device from Redis cache.
* Returns different OSD structures depending on device type:
* - Dock (domain=3): OsdDock (contains modeCode: Idle/Debugging/Working etc.)
* - Drone (domain=0): OsdDockDrone or OsdRcDrone (contains modeCode, lat/lng, altitude, speed, battery etc.)
* - Remote Controller (domain=2): OsdRemoteControl (contains lat/lng, height etc.)
* @param workspaceId
* @param deviceSn
* @return OSD data object
*/
@GetMapping("/{workspace_id}/devices/{device_sn}/osd")
public HttpResultResponse getDeviceOsd(@PathVariable("workspace_id") String workspaceId,
@PathVariable("device_sn") String deviceSn) {
Optional<Object> osdOpt = deviceService.getDeviceOsd(workspaceId, deviceSn);
return osdOpt.isEmpty()
? HttpResultResponse.error("Device OSD data not found. The device may be offline, not reporting data, or not belong to this workspace.")
: HttpResultResponse.success(osdOpt.get());
}
} }
\ No newline at end of file
...@@ -294,4 +294,14 @@ public interface IDeviceService extends IService<DeviceEntity> { ...@@ -294,4 +294,14 @@ public interface IDeviceService extends IService<DeviceEntity> {
DeviceDetailCountDTO getDeviceInfoTotal(String workspaceId); DeviceDetailCountDTO getDeviceInfoTotal(String workspaceId);
/**
* Get the OSD real-time data of the device from Redis.
* Automatically determines the device type (Dock, Drone, RC) and returns the corresponding OSD data.
* Validates that the device belongs to the specified workspace.
* @param workspaceId
* @param deviceSn
* @return OSD data object, or empty if device not found or no OSD data
*/
Optional<Object> getDeviceOsd(String workspaceId, String deviceSn);
} }
\ No newline at end of file
...@@ -1042,6 +1042,39 @@ public class DeviceServiceImpl extends ServiceImpl<IDeviceMapper, DeviceEntity> ...@@ -1042,6 +1042,39 @@ public class DeviceServiceImpl extends ServiceImpl<IDeviceMapper, DeviceEntity>
} }
@Override @Override
public Optional<Object> getDeviceOsd(String workspaceId, String deviceSn) {
Optional<DeviceDTO> deviceOpt = getDeviceBySn(deviceSn);
if (deviceOpt.isEmpty()) {
return Optional.empty();
}
DeviceDTO device = deviceOpt.get();
// Validate that the device belongs to the specified workspace
if (!workspaceId.equals(device.getWorkspaceId())) {
log.warn("Device {} does not belong to workspace {}", deviceSn, workspaceId);
return Optional.empty();
}
DeviceDomainEnum domain = device.getDomain();
if (domain == null) {
return Optional.empty();
}
switch (domain) {
case DOCK:
return deviceRedisService.getDeviceOsd(deviceSn, OsdDock.class).map(osd -> osd);
case DRONE:
// Try DockDrone first, then RcDrone
Optional<OsdDockDrone> dockDrone = deviceRedisService.getDeviceOsd(deviceSn, OsdDockDrone.class);
if (dockDrone.isPresent()) {
return dockDrone.map(osd -> osd);
}
return deviceRedisService.getDeviceOsd(deviceSn, OsdRcDrone.class).map(osd -> osd);
case REMOTER_CONTROL:
return deviceRedisService.getDeviceOsd(deviceSn, OsdRemoteControl.class).map(osd -> osd);
default:
return Optional.empty();
}
}
@Override
public Boolean checkDockDrcMode(String dockSn) { public Boolean checkDockDrcMode(String dockSn) {
if (CUSTOM_DOCK_LIST.contains(dockSn) || dockSn.contains("12345")) { if (CUSTOM_DOCK_LIST.contains(dockSn) || dockSn.contains("12345")) {
......
...@@ -264,6 +264,7 @@ public class SDKDeviceService extends AbstractDeviceService { ...@@ -264,6 +264,7 @@ public class SDKDeviceService extends AbstractDeviceService {
} }
OsdRemoteControl data = request.getData(); OsdRemoteControl data = request.getData();
deviceRedisService.setDeviceOsd(from, data);
deviceService.pushOsdDataToPilot(device.getWorkspaceId(), from, deviceService.pushOsdDataToPilot(device.getWorkspaceId(), from,
new DeviceOsdHost() new DeviceOsdHost()
.setLatitude(data.getLatitude()) .setLatitude(data.getLatitude())
...@@ -297,6 +298,7 @@ public class SDKDeviceService extends AbstractDeviceService { ...@@ -297,6 +298,7 @@ public class SDKDeviceService extends AbstractDeviceService {
} }
OsdRcDrone data = request.getData(); OsdRcDrone data = request.getData();
deviceRedisService.setDeviceOsd(from, data);
deviceService.pushOsdDataToPilot(device.getWorkspaceId(), from, deviceService.pushOsdDataToPilot(device.getWorkspaceId(), from,
new DeviceOsdHost() new DeviceOsdHost()
.setLatitude(data.getLatitude()) .setLatitude(data.getLatitude())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment