| | |
| | | import com.dji.sample.droneairport.utils.SM4Util; |
| | | import com.dji.sample.manage.dao.IDeviceMapper; |
| | | import com.dji.sample.manage.model.entity.DeviceEntity; |
| | | import com.dji.sample.manage.model.enums.DeviceModeCodeEnum; |
| | | import com.dji.sample.manage.model.enums.DockModeCodeEnum; |
| | | import com.dji.sample.manage.model.receiver.OsdDockReceiver; |
| | | import com.dji.sample.manage.model.receiver.OsdSubDeviceReceiver; |
| | | import com.dji.sample.manage.service.IDeviceRedisService; |
| | | import com.dji.sample.patches.dao.GetPatchesMapper; |
| | |
| | | import com.dji.sample.wayline.dao.IWaylineJobMapper; |
| | | import com.dji.sample.wayline.model.entity.WaylineFileEntity; |
| | | import com.dji.sample.wayline.model.entity.WaylineJobEntity; |
| | | import com.dji.sample.wayline.model.enums.WaylineJobStatusEnum; |
| | | import com.fasterxml.jackson.core.JsonProcessingException; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import org.bouncycastle.crypto.InvalidCipherTextException; |
| | |
| | | |
| | | } catch (Exception e) { |
| | | // 异常处理 |
| | | throw new IllegalArgumentException("Request failed: " + e.getMessage(), e); |
| | | throw new IllegalArgumentException("无人机机场注册失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | } catch (Exception e) { |
| | | // 异常处理 |
| | | throw new IllegalArgumentException("Request failed: " + e.getMessage(), e); |
| | | throw new IllegalArgumentException("无人机机场设备注册失败: " + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult getDroneState(String deviceId) throws Exception { |
| | | public String getDroneState(String deviceId) throws Exception { |
| | | DroneStateDto data = getAirportFromCache(deviceId); |
| | | String json = JSON.toJSONString(data); |
| | | String SM4Screct = SM4Util.encrypt("jsimjrby3wqb7dbq", json); |
| | | String SM2Screct = enSM2(SM4Screct, "23E57DA1E4AB865CCBC325B668762207DEF74345B782237808AE0BABDF26734D"); |
| | | return ResponseResult.success(SM2Screct); |
| | | return SM4Screct; |
| | | } |
| | | |
| | | @Override |
| | |
| | | List<Long> lists1 = new ArrayList<>(); |
| | | lists1.add(time); |
| | | String times = TimerUtil.convertTimestampToFormattedString(time); |
| | | param.setWaylineId(taskId); |
| | | param.setJobId(taskId); |
| | | timerUtil.sendPostWithParameters(waylineName, waylineFile.getWaylineId(), times, lists1, listOfLists, taskId+"~"+airport.getWorkspaceId(),airport.getDockSn()); |
| | | timerUtil.updatePatchesStatu(lotInfosForAirport); |
| | | } |
| | |
| | | |
| | | return param; |
| | | } |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | List<Long> lists1 = new ArrayList<>(); |
| | | lists1.add(time); |
| | | String times = TimerUtil.convertTimestampToFormattedString(time); |
| | | param.setWaylineId(taskId); |
| | | param.setJobId(taskId); |
| | | timerUtil.sendPostWithParameters(waylineName, waylineFile.getWaylineId(), times, lists1, listOfLists, airport.getWorkspaceId()+"~"+taskId,airport.getDockSn()); |
| | | timerUtil.updatePatchesStatu(lotInfosForAirport); |
| | | } |
| | |
| | | public void delTaskInfo(String taskId){ |
| | | taskInfoMapper.delete(new LambdaUpdateWrapper<TaskInfo>().eq(TaskInfo::getTaskId, taskId)); |
| | | } |
| | | |
| | | private String buildRequestBody(AddDeviceDto dto) { |
| | | try { |
| | | return objectMapper.writeValueAsString(dto); |
| | |
| | | TaskInfo taskInfo= taskInfoMapper.selectOne(new LambdaQueryWrapper<TaskInfo>().eq(TaskInfo::getTaskId, taskId)); |
| | | return taskInfo.getName(); |
| | | } |
| | | |
| | | public static String enSM2(String data, String pubKey) throws InvalidCipherTextException, IOException { |
| | | String encrypt = Utils.encrypt(data, pubKey); |
| | | encrypt = Utils.hexToBase64(encrypt); |
| | |
| | | String hex = Utils.convertBase64ToHex(Base64); |
| | | return Utils.decrypt(hex, priKey); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public static Map<String, String> createKey() throws NoSuchAlgorithmException { |
| | |
| | | return builder.build(); |
| | | } |
| | | |
| | | public String getDroneFromCache(String sn) { |
| | | public OsdSubDeviceReceiver getDroneFromCache(String sn) { |
| | | String key = "osd:" + sn; |
| | | return RedisOpsUtils.get(key).toString(); |
| | | return (OsdSubDeviceReceiver) RedisOpsUtils.get(key); |
| | | } |
| | | |
| | | public void delWaylineJob(String taskId) { |
| | | waylineJobMapper.delete(new LambdaQueryWrapper<WaylineJobEntity>().like(WaylineJobEntity::getJobId, taskId)); |
| | | } |
| | | |
| | | public DroneStateDto getAirportFromCache(String deviceId) { |
| | | String receiver = getDroneFromCache(deviceId); |
| | | double gimbalYaw =0.0; |
| | | double gimbalPitch=0.0; |
| | | com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(receiver); |
| | | double latitude = jsonObject.getDoubleValue("latitude"); |
| | | double longitude = jsonObject.getDoubleValue("longitude"); |
| | | int modeCode = jsonObject.getInteger("mode_code"); |
| | | double elevation = jsonObject.getDoubleValue("elevation"); |
| | | double height = jsonObject.getDoubleValue("height"); |
| | | com.alibaba.fastjson.JSONArray payloads = jsonObject.getJSONArray("payloads"); |
| | | if (payloads != null && payloads.size() > 1) { |
| | | com.alibaba.fastjson.JSONArray payloadArray = payloads.getJSONArray(1); |
| | | for (int i = 0; i < payloadArray.size(); i++) { |
| | | com.alibaba.fastjson.JSONObject payload = payloadArray.getJSONObject(i); |
| | | gimbalYaw = payload.getDoubleValue("gimbal_yaw"); |
| | | gimbalPitch = payload.getDoubleValue("gimbal_pitch"); |
| | | } |
| | | } |
| | | com.alibaba.fastjson.JSONObject battery = jsonObject.getJSONObject("battery"); |
| | | int batteryCapacityPercent = battery.getInteger("capacity_percent"); |
| | | Optional<OsdSubDeviceReceiver> deviceOsdOpt = redisService.getDeviceOsd(deviceId, OsdSubDeviceReceiver.class); |
| | | boolean result = deviceOsdOpt.isPresent(); |
| | | if (!result) { |
| | | String sn = deviceMapper.selectOne(new LambdaQueryWrapper<DeviceEntity>().eq(DeviceEntity::getChildSn, deviceId)).getDeviceSn(); |
| | | Optional<OsdDockReceiver> dockOsdOpt = redisService.getDeviceOsd(sn, OsdDockReceiver.class); |
| | | boolean results = dockOsdOpt.isPresent(); |
| | | if (!results){ |
| | | DroneStateDto.DroneStateDtoBuilder builder = DroneStateDto.builder(); |
| | | |
| | | builder.gimbalYal(gimbalYaw) |
| | | .gimbalPitch(gimbalPitch) |
| | | .batteryCapacityPercent(batteryCapacityPercent) |
| | | .height(height) |
| | | .latitude(latitude) |
| | | .longitude(longitude) |
| | | .modeCode(modeCode) |
| | | .elevation(elevation) |
| | | .gpsState(3); |
| | | |
| | | builder.gimbalYaw(0.0) |
| | | .gimbalPitch(0.0) |
| | | .batteryCapacityPercent(0) |
| | | .height(0) |
| | | .latitude(0) |
| | | .longitude(0) |
| | | .modeCode(1) |
| | | .elevation(0.0) |
| | | .gpsState(0) |
| | | .build(); |
| | | return builder.build(); |
| | | } |
| | | |
| | | OsdDockReceiver osdDockReceiver = objectMapper.convertValue(dockOsdOpt.get(), OsdDockReceiver.class); |
| | | int mode; |
| | | int sne = osdDockReceiver.getModeCode().getVal(); |
| | | if (sne==0){ |
| | | mode=1; |
| | | } |
| | | else { |
| | | mode=2; |
| | | } |
| | | DroneStateDto.DroneStateDtoBuilder builder = DroneStateDto.builder(); |
| | | builder.gimbalYaw(0.0) |
| | | .gimbalPitch(0.0) |
| | | .batteryCapacityPercent(osdDockReceiver.getDroneChargeState().getCapacityPercent()) |
| | | .height(osdDockReceiver.getHeight()) |
| | | .latitude(osdDockReceiver.getLatitude()) |
| | | .longitude(osdDockReceiver.getLongitude()) |
| | | .modeCode(mode) |
| | | .elevation(0.0) |
| | | .gpsState(2) |
| | | .build(); |
| | | return builder.build(); |
| | | } |
| | | OsdSubDeviceReceiver receiver = objectMapper.convertValue(deviceOsdOpt.get(), OsdSubDeviceReceiver.class); |
| | | DroneStateDto.DroneStateDtoBuilder builder = DroneStateDto.builder(); |
| | | builder.gimbalYaw(receiver.getPayloads().get(0).getGimbalYaw()) |
| | | .gimbalPitch(receiver.getPayloads().get(0).getGimbalPitch()) |
| | | .batteryCapacityPercent(receiver.getBattery().getCapacityPercent()) |
| | | .height(receiver.getHeight()) |
| | | .latitude(receiver.getLatitude()) |
| | | .longitude(receiver.getLongitude()) |
| | | .modeCode(2) |
| | | .elevation(receiver.getElevation()) |
| | | .gpsState(2) |
| | | .build(); |
| | | return builder.build(); |
| | | } |
| | | |
| | | public static AddTaskDto jsonToDto(JSONObject jsonObject) { |
| | | AddTaskDto dto = new AddTaskDto(); |
| | |
| | | // 执行更新操作 |
| | | taskInfoMapper.update(taskInfo, updateWrapper); |
| | | } |
| | | |
| | | public void updateJob(String jobid, String waylineId) { |
| | | LambdaUpdateWrapper<WaylineJobEntity> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | updateWrapper.eq(WaylineJobEntity::getJobId, jobid) |