diff --git a/app/src/main/java/com/aros/apron/activity/ConnectionActivity.kt b/app/src/main/java/com/aros/apron/activity/ConnectionActivity.kt index 61372738..b08f8452 100644 --- a/app/src/main/java/com/aros/apron/activity/ConnectionActivity.kt +++ b/app/src/main/java/com/aros/apron/activity/ConnectionActivity.kt @@ -90,7 +90,8 @@ open class ConnectionActivity : BaseActivity() { } if (TextUtils.isEmpty(PreferenceUtils.getInstance().mqttServerUri)){ PreferenceUtils.getInstance().mqttServerUri = - "tcp://192.168.20.90:2883" + // "tcp://192.168.20.90:2883" + "tcp://broker.emqx.io" } if (TextUtils.isEmpty(PreferenceUtils.getInstance().mqttUserName)){ diff --git a/app/src/main/java/com/aros/apron/activity/MainActivity.kt b/app/src/main/java/com/aros/apron/activity/MainActivity.kt index 69acdb06..61aa5cf0 100644 --- a/app/src/main/java/com/aros/apron/activity/MainActivity.kt +++ b/app/src/main/java/com/aros/apron/activity/MainActivity.kt @@ -47,8 +47,10 @@ import com.aros.apron.tools.MqttManager import com.aros.apron.tools.PreferenceUtils import com.dji.wpmzsdk.manager.WPMZManager import com.google.gson.Gson +import dji.sdk.keyvalue.key.CameraKey import dji.sdk.keyvalue.key.DJIKey import dji.sdk.keyvalue.key.FlightControllerKey +import dji.sdk.keyvalue.key.GimbalKey import dji.sdk.keyvalue.key.KeyTools import dji.sdk.keyvalue.value.common.CameraLensType import dji.sdk.keyvalue.value.common.ComponentIndexType @@ -578,9 +580,12 @@ open class MainActivity : BaseActivity() { val isFlightControllerConnect = KeyManager.getInstance().getValue(DJIKey.create(FlightControllerKey.KeyConnection)) -// val isCameraConnect = -// KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey.KeyConnection, ComponentIndexType.PORT_1)) - // LogUtil.log(TAG,isCameraConnect.toString()) + val isCameraConnect = + KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey.KeyConnection, ComponentIndexType.PORT_1)) + val isGimbal =KeyManager.getInstance().getValue(KeyTools.createKey(GimbalKey.KeyConnection, ComponentIndexType.PORT_1)) + LogUtil.log(TAG,isCameraConnect.toString()) + + //全装在初始化 if ((isFlightControllerConnect == null || !isFlightControllerConnect)) { handler.postDelayed({ initDJIManager() @@ -588,29 +593,34 @@ open class MainActivity : BaseActivity() { } else { initTimes++ LogUtil.log(TAG, "初始化$initTimes") - MissionV3Manager.getInstance().initMissionManager() - FlightManager.getInstance().initFlightInfo() - BatteryManager.getInstance().initBatteryInfo() - StickManager.getInstance().initStickInfo() - GimbalManager.getInstance().initGimbalInfo() - AlternateLandingManager.getInstance().initAlterLandingInfo() - OSDManager.getInstance().initOsd() - FlightTaskProgressManager.getInstance().initFlightTaskProgress() - MediaManager.getInstance().init() - StreamManager.getInstance().initStreamManager() - - //负载 - PayloadWidgetManager.getInstance().initPayloadInfo() - //初始化上报 - LTEManager.getInstance().initLTEInfo() - WirelessLinkManager.getInstance().initWirelessLink() - CameraManager.getInstance().initCameraInfo() - - LEDsSettingsManager.getInstance().initLEDsInfo() - LogUtil.log(TAG,"自定义推流方式:"+PreferenceUtils.getInstance().customStreamType) Handler().postDelayed(Runnable { + + + MissionV3Manager.getInstance().initMissionManager() + FlightManager.getInstance().initFlightInfo() + BatteryManager.getInstance().initBatteryInfo() + StickManager.getInstance().initStickInfo() + AlternateLandingManager.getInstance().initAlterLandingInfo() + OSDManager.getInstance().initOsd() + FlightTaskProgressManager.getInstance().initFlightTaskProgress() + MediaManager.getInstance().init() + StreamManager.getInstance().initStreamManager() + + GimbalManager.getInstance().initGimbalInfo() + //负载 + PayloadWidgetManager.getInstance().initPayloadInfo() + //初始化上报 + LTEManager.getInstance().initLTEInfo() + WirelessLinkManager.getInstance().initWirelessLink() + CameraManager.getInstance().initCameraInfo() + + LEDsSettingsManager.getInstance().initLEDsInfo() + + + + if (PreferenceUtils.getInstance().customStreamType==1){ StreamManager.getInstance() .startLiveWithRTSP() diff --git a/app/src/main/java/com/aros/apron/app/ApronApp.kt b/app/src/main/java/com/aros/apron/app/ApronApp.kt index d59dd644..0d682234 100644 --- a/app/src/main/java/com/aros/apron/app/ApronApp.kt +++ b/app/src/main/java/com/aros/apron/app/ApronApp.kt @@ -8,9 +8,12 @@ import com.aros.apron.tools.LogUtil import com.aros.apron.xclog.CrashHandler import com.aros.apron.xclog.XcFileLog import com.aros.apron.xclog.XcLogConfig +import com.dji.wpmzsdk.manager.WPMZManager import com.orhanobut.logger.AndroidLogAdapter import com.orhanobut.logger.Logger import com.orhanobut.logger.PrettyFormatStrategy +import dji.v5.common.utils.GeoidManager +import dji.v5.utils.common.ContextUtil import org.opencv.android.OpenCVLoader @@ -57,13 +60,9 @@ open class ApronApp : Application() { return true } }) - - - XcFileLog.init(XcLogConfig()) //打印崩溃日志 CrashHandler.getInstance().init() - // 初始化 OpenCV if (OpenCVLoader.initLocal()) { LogUtil.log("qwq","opencv" + diff --git a/app/src/main/java/com/aros/apron/base/BaseManager.java b/app/src/main/java/com/aros/apron/base/BaseManager.java index f93d8674..dd40b0a1 100644 --- a/app/src/main/java/com/aros/apron/base/BaseManager.java +++ b/app/src/main/java/com/aros/apron/base/BaseManager.java @@ -5,11 +5,13 @@ import static com.aros.apron.tools.Utils.getIDJIErrorMsg; import android.os.Handler; import android.os.Looper; import android.text.TextUtils; +import android.util.Log; import androidx.annotation.NonNull; import com.aros.apron.constant.AMSConfig; import com.aros.apron.constant.Constant; +import com.aros.apron.entity.CameraPhotoTakeProgress; import com.aros.apron.entity.CurrentWayline; import com.aros.apron.entity.FlightTaskProgress; import com.aros.apron.entity.MediaUpLoad; @@ -17,6 +19,7 @@ import com.aros.apron.entity.MessageDown; import com.aros.apron.entity.MessageEvent; import com.aros.apron.entity.MessageReply; import com.aros.apron.entity.Movement; +import com.aros.apron.entity.TakeoffToPointProgress; import com.aros.apron.entity.TaskFailEvent; import com.aros.apron.entity.WirelessLink; import com.aros.apron.tools.LogUtil; @@ -27,6 +30,7 @@ import com.google.gson.Gson; import org.eclipse.paho.android.service.MqttAndroidClient; import org.eclipse.paho.client.mqttv3.MqttMessage; +import java.util.Locale; import java.util.UUID; import dji.v5.common.callback.CommonCallbacks; @@ -131,7 +135,7 @@ public abstract class BaseManager { * 发送常规event事件 */ public void sendEvent2Server(String msg,int level) { - LogUtil.log(TAG,"发送常规事件:"+"run_log -"+msg); + //LogUtil.log(TAG,"发送常规事件:"+"run_log -"+msg); try { if (MqttManager.getInstance().mqttAndroidClient.isConnected()) { MessageEvent messageEvent = new MessageEvent(); @@ -164,7 +168,7 @@ public abstract class BaseManager { * 发送媒体文件上传事件 */ public void sendMediaUpload2Server(String fileName,int uploaded_file_count,int expected_file_count) { - LogUtil.log(TAG,"发送媒体上传完成事件:"+fileName); + //LogUtil.log(TAG,"发送媒体上传完成事件:"+fileName); try { if (MqttManager.getInstance().mqttAndroidClient.isConnected()) { MediaUpLoad mediaUpLoad = new MediaUpLoad(); @@ -204,17 +208,23 @@ public abstract class BaseManager { final FlightTaskProgress.Data.Output.Ext ext = new FlightTaskProgress.Data.Output.Ext(); ext.setCurrent_waypoint_index(Movement.getInstance().getTask_current_waypoint_index()); ext.setFlight_id(PreferenceUtils.getInstance().getFlightId()); + //媒体文件数量 ext.setMedia_count(Movement.getInstance().getTask_media_count()); ext.setTrack_id(Movement.getInstance().getTrack_id()); ext.setWayline_id(Movement.getInstance().getTask_wayline_id()); ext.setWayline_mission_state(Movement.getInstance().getTask_wayline_mission_state()); final FlightTaskProgress.Data.Output.Progress progress = new FlightTaskProgress.Data.Output.Progress(); +// LogUtil.log(TAG,"CurrentWayline"+CurrentWayline.getInstance().getWaypoints()+"size"+CurrentWayline.getInstance().getWaypoints().size() +// +"getTask_wayline_mission_state"+Movement.getInstance().getTask_wayline_mission_state()); if (CurrentWayline.getInstance().getWaypoints() != null && CurrentWayline.getInstance().getWaypoints().size() > 0 && Movement.getInstance().getTask_wayline_mission_state() == 6) { + //这个没执行到 progress.setPercent((100 * (Movement.getInstance().getCurrentWaypointIndex() + 1) / CurrentWayline.getInstance().getWaypoints().size())); + + } progress.setCurrent_step(Movement.getInstance().getTask_current_step()); @@ -264,6 +274,7 @@ public abstract class BaseManager { breakPoint.setLatitude(breakPointInfo.getLocation().getLatitude()); breakPoint.setLongitude(breakPointInfo.getLocation().getLongitude()); + breakPoint.setProgress(Movement.getInstance().getTask_progress()); breakPoint.setState(Movement.getInstance().getState()); breakPoint.setWayline_id(Movement.getInstance().getTask_wayline_id()); @@ -353,9 +364,8 @@ public abstract class BaseManager { MqttMessage mqttMessage = new MqttMessage(new Gson().toJson(flightTaskProgress).getBytes("UTF-8")); mqttMessage.setQos(0); MqttManager.getInstance().mqttAndroidClient.publish(AMSConfig.UP_UAV_EVENT, mqttMessage); - LogUtil.log(TAG, "发送任务进度事件(正常状态):" + new Gson().toJson(flightTaskProgress)); + //LogUtil.log(TAG, "发送任务进度事件(正常状态):" + new Gson().toJson(flightTaskProgress)); } - } else { LogUtil.log(TAG, "发送任务进度event失败:mqtt 未连接"); } @@ -380,6 +390,7 @@ public abstract class BaseManager { Movement.getInstance().setHeight(breakPointInfo.getLocation().getAltitude()); Movement.getInstance().setTask_latitude(breakPointInfo.getLocation().getLatitude()); Movement.getInstance().setTask_longitude(breakPointInfo.getLocation().getLongitude()); + Movement.getInstance().setTask_progress(breakPointInfo.getSegmentProgress()); Movement.getInstance().setTask_state(0); Movement.getInstance().setTask_wayline_id(breakPointInfo.getWaylineID()); @@ -434,6 +445,109 @@ public abstract class BaseManager { LogUtil.log(TAG, "发送sdr异常:" + e.toString()); } } + /** + * 上报一键起飞任务进度 + */ + public void sendTakeoffToPointProgress2Server() { + try { + if (MqttManager.getInstance().mqttAndroidClient.isConnected()) { + + // 构建 data 数据 + TakeoffToPointProgress.Data data = new TakeoffToPointProgress.Data(); + data.setFlightId(PreferenceUtils.getInstance().getFlightId()); + data.setTrackId(PreferenceUtils.getInstance().getFlightId()); + data.setStatus(Movement.getInstance().getTakeoff_status()); + data.setResult(Movement.getInstance().getTakeoff_result()); + data.setWayPointIndex(Movement.getInstance().getCurrentWaypointIndex()); + data.setRemainingDistance(Movement.getInstance().getTakeoff_remaining_distance()); + data.setRemainingTime(Movement.getInstance().getTakeoff_remaining_time()); + data.setPlannedPathPoints(Movement.getInstance().getTakeoff_planned_path_points()); + + // 构建事件对象 + TakeoffToPointProgress progress = new TakeoffToPointProgress(); + progress.setBid(UUID.randomUUID().toString()); + progress.setTid(UUID.randomUUID().toString()); + progress.setTimestamp(System.currentTimeMillis()); + progress.setMethod("takeoff_to_point_progress"); + progress.setNeedReply(1); + progress.setData(data); + + // 发送 + MqttMessage mqttMessage = new MqttMessage(new Gson().toJson(progress).getBytes("UTF-8")); + mqttMessage.setQos(0); + MqttManager.getInstance().mqttAndroidClient.publish(AMSConfig.UP_UAV_EVENT, mqttMessage); + + LogUtil.log(TAG, "发送一键起飞进度事件:" + new Gson().toJson(progress)); + + } else { + LogUtil.log(TAG, "发送一键起飞进度event失败:mqtt 未连接"); + } + } catch (Exception e) { + e.printStackTrace(); + LogUtil.log(TAG, "发送一键起飞进度event异常:" + e.toString()); + } + } + + /** + * 上报拍照进度(camera_photo_take_progress) + * 目前仅支持:全景拍照模式 + * 数据先存 Movement,再组装发送 + */ + public void sendCameraPhotoTakeProgress2Server() { + try { + if (MqttManager.getInstance().mqttAndroidClient.isConnected()) { + + // 构建 output.progress + CameraPhotoTakeProgress.Data.Output.Progress progress = + new CameraPhotoTakeProgress.Data.Output.Progress(); + progress.setCurrent_step(Movement.getInstance().getPhoto_current_step()); + progress.setPercent(Movement.getInstance().getPhoto_percent()); + + // 构建 output.ext + CameraPhotoTakeProgress.Data.Output.Ext ext = + new CameraPhotoTakeProgress.Data.Output.Ext(); + ext.setCamera_mode(3); + + // 构建 output + CameraPhotoTakeProgress.Data.Output output = + new CameraPhotoTakeProgress.Data.Output(); + output.setStatus(Movement.getInstance().getPhoto_status()); + output.setProgress(progress); + output.setExt(ext); + + // 构建 data + CameraPhotoTakeProgress.Data data = new CameraPhotoTakeProgress.Data(); + data.setResult(Movement.getInstance().getPhoto_result()); + data.setOutput(output); + + // 构建完整消息 + CameraPhotoTakeProgress photoProgress = new CameraPhotoTakeProgress(); + photoProgress.setBid(UUID.randomUUID().toString()); + photoProgress.setTid(UUID.randomUUID().toString()); + photoProgress.setTimestamp(System.currentTimeMillis()); + photoProgress.setMethod("camera_photo_take_progress"); + photoProgress.setData(data); + + // 发送 + MqttMessage mqttMessage = new MqttMessage( + new Gson().toJson(photoProgress).getBytes("UTF-8") + ); + mqttMessage.setQos(0); + MqttManager.getInstance().mqttAndroidClient.publish( + AMSConfig.UP_UAV_EVENT, + mqttMessage + ); + LogUtil.log(TAG, "发送拍照进度事件:" + new Gson().toJson(photoProgress)); + } else { + LogUtil.log(TAG, "发送拍照进度失败:mqtt 未连接"); + } + } catch (Exception e) { + e.printStackTrace(); + LogUtil.log(TAG, "发送拍照进度异常:" + e.toString()); + } + } + + public boolean getGimbalAndCameraEnabled() { diff --git a/app/src/main/java/com/aros/apron/callback/MqttCallBack.java b/app/src/main/java/com/aros/apron/callback/MqttCallBack.java index e16cd9bd..98d03191 100644 --- a/app/src/main/java/com/aros/apron/callback/MqttCallBack.java +++ b/app/src/main/java/com/aros/apron/callback/MqttCallBack.java @@ -6,6 +6,7 @@ import android.os.Looper; import android.util.Log; import com.aros.apron.app.ApronApp; +import com.aros.apron.base.BaseManager; import com.aros.apron.constant.AMSConfig; import com.aros.apron.constant.Constant; import com.aros.apron.entity.ApronExecutionStatus; @@ -31,19 +32,18 @@ import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; import org.eclipse.paho.client.mqttv3.MqttCallbackExtended; import org.eclipse.paho.client.mqttv3.MqttMessage; -public class MqttCallBack implements MqttCallbackExtended { +public class MqttCallBack extends BaseManager implements MqttCallbackExtended { private String TAG = "MqttCallBack"; @Override public void connectionLost(Throwable cause) { - LogUtil.log(TAG, "MQtt connectionLost:" + cause.toString()); + LogUtil.log(TAG, "MQtt connectionLost:"+cause.toString()); //短线也要清空这个 clearVirtualStickHeartbeat(); } - //断线重连 public void reConnect() throws Exception { if (null != MqttManager.getInstance().mqttAndroidClient) { @@ -52,6 +52,7 @@ public class MqttCallBack implements MqttCallbackExtended { } + // 心跳检测 private volatile long lastDrControlTime = 0; private final Handler vsHandler = new Handler(Looper.getMainLooper()); @@ -59,9 +60,7 @@ public class MqttCallBack implements MqttCallbackExtended { private static final long TIMEOUT_MS = 500; // 500ms 无数据触发 - /** - * 每次收到控制指令都调 - */ + /** 每次收到控制指令都调 */ private void resetVirtualStickHeartbeat() { lastDrControlTime = System.currentTimeMillis(); @@ -80,9 +79,7 @@ public class MqttCallBack implements MqttCallbackExtended { vsHandler.postDelayed(vsTimeoutCheck, TIMEOUT_MS); } - /** - * 清理虚拟摇杆心跳(断网/退出/销毁时调) - */ + /** 清理虚拟摇杆心跳(断网/退出/销毁时调) */ private void clearVirtualStickHeartbeat() { if (vsTimeoutCheck != null) { vsHandler.removeCallbacks(vsTimeoutCheck); @@ -92,17 +89,24 @@ public class MqttCallBack implements MqttCallbackExtended { } + + + + + @Override public void messageArrived(String topic, MqttMessage mqttMessage) { String jsonString = null; -// Log.e(TAG, "入口打印:" +mqttMessage.toString()); + //Log.e(TAG, "入口打印:" +mqttMessage.toString()); try { + jsonString = new String(mqttMessage.getPayload(), "UTF-8"); } catch (Exception e) { LogUtil.log(TAG, "解析异常"); throw new RuntimeException(e); } MessageDown message = new Gson().fromJson(jsonString, MessageDown.class); + //LogUtil.log(TAG,message.getMethod()); switch (message.getMethod()) { case Constant.PILOT_ON: // LogUtil.log(TAG, "收到:遥控器是否开机" + jsonString); @@ -140,7 +144,7 @@ public class MqttCallBack implements MqttCallbackExtended { LogUtil.log(TAG, "收到:航线" + jsonString); //设置modecode Movement.getInstance().setMode_code(1); - OSDManager.getInstance().pushFlightAttitude(); + sendFlightTaskProgress2Server(); //设置标志为 Movement.getInstance().setFlightmode(1); MissionV3Manager.getInstance().taskExecute(message); @@ -158,6 +162,7 @@ public class MqttCallBack implements MqttCallbackExtended { LogUtil.log(TAG, "收到:返航" + jsonString); //自动返航 (如果调用方法失败了 这个设置就有一个问题但是为了方便看懂我就放这里了没放成功的回调里面) Movement.getInstance().setMode_code(9); + sendFlightTaskProgress2Server(); FlightManager.getInstance().startGoHome(message); break; case Constant.RETURN_HOME_CANCEL: @@ -184,7 +189,7 @@ public class MqttCallBack implements MqttCallbackExtended { LogUtil.log(TAG, "收到:一键起飞" + jsonString); //设置modecode Movement.getInstance().setMode_code(1); - OSDManager.getInstance().pushFlightAttitude(); + sendFlightTaskProgress2Server(); //设置标志为 Movement.getInstance().setFlightmode(2); TakeOffToPointManager.getInstance().taskExecute(message); @@ -212,7 +217,7 @@ public class MqttCallBack implements MqttCallbackExtended { LogUtil.log(TAG, "收到:进入指令飞行控制模式" + jsonString); StickManager.getInstance().setVirtualStickModeEnabled(message); break; - //退出控制权时,要自动触发续飞航线 + //退出控制权时,要自动触发续飞航线 case Constant.DRC_MODE_EXIT: LogUtil.log(TAG, "收到:退出指令飞行控制模式" + jsonString); //清理这个时间戳循环 @@ -260,10 +265,6 @@ public class MqttCallBack implements MqttCallbackExtended { LogUtil.log(TAG, "收到:负载控制—变焦" + jsonString); CameraManager.getInstance().setCameraZoomRatios(message); break; - case Constant.CAMERA_FRAME_ZOOM: - LogUtil.log(TAG, "收到:框选变焦" + jsonString); - CameraManager.getInstance().camera_frame_zoom(message); - break; case Constant.GIMBAL_RESET: LogUtil.log(TAG, "收到:负载控制—重置云台" + jsonString); GimbalManager.getInstance().gimbalReset(message); @@ -316,6 +317,11 @@ public class MqttCallBack implements MqttCallbackExtended { case Constant.POI_CIRCLE_SPEED_SET: LogUtil.log(TAG, "收到:飞行控制—POI 环绕速度设置" + jsonString); break; + case Constant.CAMERA_FRAME_ZOOM: + LogUtil.log(TAG, "收到:框选变焦" + jsonString); + CameraManager.getInstance().camera_frame_zoom(message); + break; + // //获取控制权 // case 60007: // LogUtil.log(TAG, "收到:获取控制权" + jsonString); @@ -667,23 +673,21 @@ public class MqttCallBack implements MqttCallbackExtended { public void deliveryComplete(IMqttDeliveryToken token) { } - - String[] topics = new String[]{ + String[] topics = new String[] { AMSConfig.getInstance().DOWN_UAV_EVENT_REPLY, AMSConfig.getInstance().DOWN_UAV_SERVICES, }; - int[] qos = new int[]{ + int[] qos = new int[] { 1, 1 }; - @Override public void connectComplete(boolean reconnect, String serverURI) { try { // if (reconnect) {//重新订阅 - LogUtil.log(TAG, "MQtt ConnectComplete:" + serverURI); - MqttManager.getInstance().mqttAndroidClient.subscribe(topics, qos);//订阅主题:注册 + LogUtil.log(TAG, "MQtt ConnectComplete:" + serverURI); + MqttManager.getInstance().mqttAndroidClient.subscribe(topics, qos);//订阅主题:注册 // MqttManager.getInstance().mqttAndroidClient.subscribe(AMSConfig.DOWN_UAV_EVENT_REPLY, 1);//订阅主题:注册 - // publish(topic,"注册",0); + // publish(topic,"注册",0); // } } catch (Exception e) { LogUtil.log(TAG, "MQtt ConnectException:" + e.toString()); diff --git a/app/src/main/java/com/aros/apron/constant/Constant.java b/app/src/main/java/com/aros/apron/constant/Constant.java index 063f0ec1..cf0dafe6 100644 --- a/app/src/main/java/com/aros/apron/constant/Constant.java +++ b/app/src/main/java/com/aros/apron/constant/Constant.java @@ -277,13 +277,14 @@ public class Constant { * 遥控器上报sdr和4g状态 */ public static final String WIRELESS_LINK="wireless_link"; + /** * 框选变焦 */ public static final String CAMERA_FRAME_ZOOM="camera_frame_zoom"; - - - + /** + * 急停 + */ diff --git a/app/src/main/java/com/aros/apron/entity/FlightMission.java b/app/src/main/java/com/aros/apron/entity/FlightMission.java index 3e08123f..31bb0789 100644 --- a/app/src/main/java/com/aros/apron/entity/FlightMission.java +++ b/app/src/main/java/com/aros/apron/entity/FlightMission.java @@ -88,6 +88,10 @@ public class FlightMission { this.speed = speed; } + + + + public Float getTakeOffSecurityHeight() { return takeOffSecurityHeight; } diff --git a/app/src/main/java/com/aros/apron/entity/MessageDown.java b/app/src/main/java/com/aros/apron/entity/MessageDown.java index 8af3b483..d06b90d9 100644 --- a/app/src/main/java/com/aros/apron/entity/MessageDown.java +++ b/app/src/main/java/com/aros/apron/entity/MessageDown.java @@ -68,7 +68,7 @@ public class MessageDown { private int out_of_control_action; private boolean takeoffToPointTask; private BreakPoint break_point; - private int camera_mode; + private int camera_mode=0;//初始化为拍照 private String h; private String seq; private String w; @@ -90,13 +90,13 @@ public class MessageDown { private int focus_mode; private int focus_value; - private int commander_flight_height; + private double commander_flight_height; private int commander_mode_lost_action; private String max_speed; private int rc_lost_action; private int rth_altitude; private String security_takeoff_height; - private int target_height; + private double target_height; private double target_latitude; private double target_longitude; private String fly_to_id; @@ -110,6 +110,7 @@ public class MessageDown { private float width; + public float getWidth() { return width; } @@ -187,7 +188,7 @@ public class MessageDown { this.longitude = longitude; } } - public int getCommander_flight_height() { + public double getCommander_flight_height() { return commander_flight_height; } @@ -227,7 +228,7 @@ public class MessageDown { this.security_takeoff_height = security_takeoff_height; } - public int getTarget_height() { + public double getTarget_height() { return target_height; } diff --git a/app/src/main/java/com/aros/apron/entity/MissionDataBean.java b/app/src/main/java/com/aros/apron/entity/MissionDataBean.java new file mode 100644 index 00000000..3ac46190 --- /dev/null +++ b/app/src/main/java/com/aros/apron/entity/MissionDataBean.java @@ -0,0 +1,135 @@ +package com.aros.apron.entity; + + +/** + * 服务端下发的整条 JSON 对应实体 + */ +public class MissionDataBean { + + /** 备降点 */ + private LatLngAlt alternate_land_point; + + /** 指挥官飞行高度 */ + private int commander_flight_height; + + /** 指挥官模式丢失动作 */ + private int commander_mode_lost_action; + + /** 航线唯一编号 */ + private String flight_id; + + /** 最大飞行速度 (m/s) */ + private int max_speed; + + /** 遥控丢失动作 */ + private int rc_lost_action; + + /** 返航高度 (m) */ + private int rth_altitude; + + /** 安全起飞高度 (m) */ + private double security_takeoff_height; + + /** 目标高度 (m) */ + private double target_height; + + /** 目标纬度 (°) */ + private double target_latitude; + + /** 目标经度 (°) */ + private double target_longitude; + + /* ---------------- getter / setter ---------------- */ + public LatLngAlt getAlternateLandPoint() { + return alternate_land_point; + } + public void setAlternateLandPoint(LatLngAlt alternate_land_point) { + this.alternate_land_point = alternate_land_point; + } + public int getCommanderFlightHeight() { + return commander_flight_height; + } + public void setCommanderFlightHeight(int commander_flight_height) { + this.commander_flight_height = commander_flight_height; + } + public int getCommanderModeLostAction() { + return commander_mode_lost_action; + } + public void setCommanderModeLostAction(int commander_mode_lost_action) { + this.commander_mode_lost_action = commander_mode_lost_action; + } + public String getFlightId() { + return flight_id; + } + public void setFlightId(String flight_id) { + this.flight_id = flight_id; + } + public int getMaxSpeed() { + return max_speed; + } + public void setMaxSpeed(int max_speed) { + this.max_speed = max_speed; + } + public int getRcLostAction() { + return rc_lost_action; + } + public void setRcLostAction(int rc_lost_action) { + this.rc_lost_action = rc_lost_action; + } + public int getRthAltitude() { + return rth_altitude; + } + public void setRthAltitude(int rth_altitude) { + this.rth_altitude = rth_altitude; + } + public double getSecurityTakeoffHeight() { + return security_takeoff_height; + } + public void setSecurityTakeoffHeight(int security_takeoff_height) { + this.security_takeoff_height = security_takeoff_height; + } + public double getTargetHeight() { + return target_height; + } + public void setTargetHeight(double target_height) { + this.target_height = target_height; + } + public double getTargetLatitude() { + return target_latitude; + } + public void setTargetLatitude(double target_latitude) { + this.target_latitude = target_latitude; + } + public double getTargetLongitude() { + return target_longitude; + } + public void setTargetLongitude(double target_longitude) { + this.target_longitude = target_longitude; + } + + /* ---------------- 内部嵌套类:备降点 ---------------- */ + public static class LatLngAlt { + private double latitude; + private double longitude; + private double safe_land_height; + + public double getLatitude() { + return latitude; + } + public void setLatitude(double latitude) { + this.latitude = latitude; + } + public double getLongitude() { + return longitude; + } + public void setLongitude(double longitude) { + this.longitude = longitude; + } + public double getSafeLandHeight() { + return safe_land_height; + } + public void setSafeLandHeight(int safe_land_height) { + this.safe_land_height = safe_land_height; + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/aros/apron/entity/Movement.java b/app/src/main/java/com/aros/apron/entity/Movement.java index 4ea907a3..e96f4133 100644 --- a/app/src/main/java/com/aros/apron/entity/Movement.java +++ b/app/src/main/java/com/aros/apron/entity/Movement.java @@ -113,6 +113,8 @@ public class Movement { private boolean virtualcontrollget=false;//是否已经获得过控制权 + private int GPSSatelliteCount; //卫星个数 + //适配上云格式参数,拿到后再进行组装 private double measure_target_altitude; @@ -274,6 +276,124 @@ public class Movement { private String sdr_freq_band; private String freq_band_4g; + + // ========== 一键起飞相关字段 ========== + private boolean takeofftopointmission; + private String takeoff_status; // task_ready/wayline_progress/wayline_ok/wayline_failed/wayline_cancel/task_finish + private int takeoff_result; // 0成功,非0错误 + private float takeoff_remaining_distance; // 剩余距离(米) + private float takeoff_remaining_time; // 剩余时间(秒) + private double speed; //全局速度 + private List takeoff_planned_path_points; // 规划轨迹点 + + // ========== 上报拍照进度 ==========(全景) + private String photo_status; // in_progress/ok/fail + private int photo_current_step; // 3000/3002/3005 + private int photo_percent; // 0-100 + private int photo_result; // 0成功,非0错误 + + + + + public int getGPSSatelliteCount() { + return GPSSatelliteCount; + } + + public void setGPSSatelliteCount(int GPSSatelliteCount) { + this.GPSSatelliteCount = GPSSatelliteCount; + } + + public double getSpeed() { + return speed; + } + public void setSpeed(double speed) { + this.speed = speed; + } + + public boolean isTakeofftopointmission() { + return takeofftopointmission; + } + + public void setTakeofftopointmission(boolean takeofftopointmission) { + this.takeofftopointmission = takeofftopointmission; + } + + public int getPhoto_current_step() { + return photo_current_step; + } + + public void setPhoto_current_step(int photo_current_step) { + this.photo_current_step = photo_current_step; + } + + public int getPhoto_result() { + return photo_result; + } + + public void setPhoto_result(int photo_result) { + this.photo_result = photo_result; + } + + public String getPhoto_status() { + return photo_status; + } + + public void setPhoto_status(String photo_status) { + this.photo_status = photo_status; + } + + + public int getPhoto_percent() { + return photo_percent; + } + + public void setPhoto_percent(int photo_percent) { + this.photo_percent = photo_percent; + } + + + public String getTakeoff_status() { + return takeoff_status; + } + + public void setTakeoff_status(String takeoff_status) { + this.takeoff_status = takeoff_status; + } + + public int getTakeoff_result() { + return takeoff_result; + } + + public void setTakeoff_result(int takeoff_result) { + this.takeoff_result = takeoff_result; + } + + + + public float getTakeoff_remaining_distance() { + return takeoff_remaining_distance; + } + + public void setTakeoff_remaining_distance(float takeoff_remaining_distance) { + this.takeoff_remaining_distance = takeoff_remaining_distance; + } + + public float getTakeoff_remaining_time() { + return takeoff_remaining_time; + } + + public void setTakeoff_remaining_time(float takeoff_remaining_time) { + this.takeoff_remaining_time = takeoff_remaining_time; + } + + public List getTakeoff_planned_path_points() { + return takeoff_planned_path_points; + } + + public void setTakeoff_planned_path_points(List takeoff_planned_path_points) { + this.takeoff_planned_path_points = takeoff_planned_path_points; + } + public boolean isVirtualcontrollget() { return virtualcontrollget; } diff --git a/app/src/main/java/com/aros/apron/entity/Osd.java b/app/src/main/java/com/aros/apron/entity/Osd.java index ef72aa4f..8869817d 100644 --- a/app/src/main/java/com/aros/apron/entity/Osd.java +++ b/app/src/main/java/com/aros/apron/entity/Osd.java @@ -77,7 +77,7 @@ public class Osd { public static class Data { @SerializedName("53-0-0") - private Data._$5300 _$5300; + private _$5300 _$5300; private int activation_time; private double attitude_head; private double attitude_pitch; diff --git a/app/src/main/java/com/aros/apron/manager/CameraManager.java b/app/src/main/java/com/aros/apron/manager/CameraManager.java index 4378d4bd..8ca68f2b 100644 --- a/app/src/main/java/com/aros/apron/manager/CameraManager.java +++ b/app/src/main/java/com/aros/apron/manager/CameraManager.java @@ -4,6 +4,8 @@ import static com.aros.apron.tools.Utils.getIDJIErrorMsg; import static dji.sdk.keyvalue.key.KeyTools.createKey; import android.os.Handler; +import android.os.Looper; +import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -28,14 +30,20 @@ import dji.sdk.keyvalue.value.camera.CameraStorageInfo; import dji.sdk.keyvalue.value.camera.CameraStorageInfos; import dji.sdk.keyvalue.value.camera.CameraStorageLocation; import dji.sdk.keyvalue.value.camera.CameraThermalPalette; +import dji.sdk.keyvalue.value.camera.CameraType; import dji.sdk.keyvalue.value.camera.CameraVideoStreamSourceType; import dji.sdk.keyvalue.value.camera.LaserMeasureInformation; +import dji.sdk.keyvalue.value.camera.PanoramaExitStatus; +import dji.sdk.keyvalue.value.camera.PhotoPanoStichingState; import dji.sdk.keyvalue.value.camera.PhotoState; import dji.sdk.keyvalue.value.camera.RecordingState; import dji.sdk.keyvalue.value.camera.TapZoomMode; +import dji.sdk.keyvalue.value.camera.ThermalDigitalZoomFactor; import dji.sdk.keyvalue.value.camera.ThermalDisplayMode; import dji.sdk.keyvalue.value.camera.ThermalGainMode; import dji.sdk.keyvalue.value.camera.ThermalTemperatureMeasureMode; +import dji.sdk.keyvalue.value.camera.VideoRecordingStatus; +import dji.sdk.keyvalue.value.camera.VisionPhotoPanoramaMissionState; import dji.sdk.keyvalue.value.camera.ZoomTargetPointInfo; import dji.sdk.keyvalue.value.common.CameraLensType; import dji.sdk.keyvalue.value.common.ComponentIndexType; @@ -47,780 +55,1024 @@ import dji.v5.common.error.IDJIError; import dji.v5.manager.KeyManager; public class CameraManager extends BaseManager { + private Handler panoHandler = new Handler(Looper.getMainLooper()); + private Runnable panoRunnable; + private boolean isPanoRunning = false; + private static final long INTERVAL = 1000; // 1秒 + private void startReport() { + if (isPanoRunning) return; // 已开启则忽略 + + isPanoRunning = true; + + panoRunnable = new Runnable() { + @Override + public void run() { + if (!isPanoRunning) return; + + sendCameraPhotoTakeProgress2Server(); // 你的方法 + + panoHandler.postDelayed(this, INTERVAL); // 1秒后循环 + } + }; + + panoHandler.post(panoRunnable); // 立即执行 + } + + private void stopReport() { + if (!isPanoRunning) return; + + isPanoRunning = false; + panoHandler.removeCallbacks(panoRunnable); + + sendCameraPhotoTakeProgress2Server(); // 最后报一次 + } + + private CameraManager() { - } +} - private static class CameraHolder { - private static final CameraManager INSTANCE = new CameraManager(); - } +private static class CameraHolder { + private static final CameraManager INSTANCE = new CameraManager(); +} - public static CameraManager getInstance() { - return CameraHolder.INSTANCE; - } +public static CameraManager getInstance() { + return CameraHolder.INSTANCE; +} - public void initCameraInfo() { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey.KeyConnection, ComponentIndexType.PORT_1)); - if (isConnect != null && isConnect) { - //全局画面中测量的最高温度 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalGlobalMinTemperature, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { - if (t1 != null) { - Movement.getInstance().setThermal_global_temperature_min(t1); +public void initCameraInfo() { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey.KeyConnection, ComponentIndexType.PORT_1)); + if (isConnect != null && isConnect) { + //全局画面中测量的最高温度 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalGlobalMinTemperature, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { + if (t1 != null) { + Movement.getInstance().setThermal_global_temperature_min(t1); + } + } + }); + + //全景任务状态 + KeyManager.getInstance().listen(createKey(CameraKey.KeyVisionPhotoPanoramaMissionState, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable VisionPhotoPanoramaMissionState visionPhotoPanoramaMissionState, @Nullable VisionPhotoPanoramaMissionState t1) { + if (t1 != null) { + if (t1 == VisionPhotoPanoramaMissionState.IDLE) { + Movement.getInstance().setPhoto_current_step(3000); + } else if (t1 == VisionPhotoPanoramaMissionState.RELEASE) { +// Movement.getInstance().setPhoto_result(0); +// Movement.getInstance().setPhoto_status("ok"); +// Movement.getInstance().setCameraMode(3); +// stopReport(); + } else if (t1 == VisionPhotoPanoramaMissionState.RUNNING) { + Movement.getInstance().setPhoto_status("in_progress"); + Movement.getInstance().setPhoto_current_step(3002); + } else if (t1 == VisionPhotoPanoramaMissionState.UNKNOWN) { +// Movement.getInstance().setPhoto_result(1); +// Movement.getInstance().setPhoto_current_step(3000); +// Movement.getInstance().setPhoto_status("fail"); + } else if (t1 == VisionPhotoPanoramaMissionState.PROCESSING) { + Movement.getInstance().setPhoto_current_step(3005); + } else if (t1 == VisionPhotoPanoramaMissionState.FORBIDDEN) { + Movement.getInstance().setPhoto_result(1); + Movement.getInstance().setPhoto_current_step(3000); + Movement.getInstance().setPhoto_status("fail"); } } - }); - //激光测距信息 - KeyManager.getInstance().listen(createKey(CameraKey.KeyLaserMeasureInformation, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable LaserMeasureInformation laserMeasureInformation, @Nullable LaserMeasureInformation t1) { - if (t1 != null) { - if (t1.getLocation3D() != null) { - Movement.getInstance().setMeasure_target_altitude(t1.getLocation3D().getAltitude()); - Movement.getInstance().setMeasure_target_latitude(t1.getLocation3D().getLatitude()); - Movement.getInstance().setMeasure_target_longitude(t1.getLocation3D().getLongitude()); - Movement.getInstance().setMeasure_target_distance(t1.getDistance().intValue()); - Movement.getInstance().setMeasure_target_error_state(t1.getLaserMeasureState().value()); - Movement.getInstance().setPayload_index("53-0-0"); - } + } + }); + //全景退出 + KeyManager.getInstance().listen(createKey(CameraKey.KeyPanoramaExitStatus, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable PanoramaExitStatus panoramaExitStatus, @Nullable PanoramaExitStatus t1) { + if(t1!=null){ + LogUtil.log(TAG,t1.toString()); + if(t1==PanoramaExitStatus.SUCCESSFUL){ + Movement.getInstance().setPhoto_current_step(3000); + Movement.getInstance().setPhoto_result(0); + Movement.getInstance().setPhoto_status("ok"); + Movement.getInstance().setCameraMode(3); + Movement.getInstance().setMode_code(3); + stopReport(); } } - }); + } + }); - //调色盘样式。{"0":"白热","1":"黑热","2":"描红","3":"医疗","5":"彩虹 1","6":"铁红","8":"北极","11":"熔岩","12":"热铁","13":"彩虹 2"} - KeyManager.getInstance().listen(createKey(CameraKey.KeyThermalPalette, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraThermalPalette cameraThermalPalette, @Nullable CameraThermalPalette t1) { - if (t1 != null) { - Movement.getInstance().setThermal_current_palette_style(t1.value()); + KeyManager.getInstance().listen(createKey(CameraKey.KeyPanoramaProgressInPercent, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if (t1 != null) { + Movement.getInstance().setPhoto_percent(t1); + if(t1==100){ + Movement.getInstance().setPhoto_current_step(3000); + Movement.getInstance().setPhoto_result(0); + Movement.getInstance().setPhoto_status("ok"); + Movement.getInstance().setCameraMode(3); + Movement.getInstance().setMode_code(3); + stopReport(); } } - }); - - //增益模式。{"0":"自动","1":"低增益, 测温范围0°C-500°C","2":"高增益, 测温范围-20°C-150°C"} - KeyManager.getInstance().listen(createKey(CameraKey.KeyThermalGainMode, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable ThermalGainMode thermalGainMode, @Nullable ThermalGainMode t1) { - if (t1 != null) { - Movement.getInstance().setThermal_gain_mode(t1.value()); + } + }); + //是否正在拍全景 + KeyManager.getInstance().listen(createKey(CameraKey.KeyIsShootingPhotoPanorama, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Boolean aBoolean, @Nullable Boolean t1) { + if (t1 != null) { + if (t1 == true) { + startReport(); + } else { + stopReport(); } } - }); + } + }); - //全局画面中测量的最高温度 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalGlobalMaxTemperature, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { - if (t1 != null) { - Movement.getInstance().setThermal_global_temperature_max(t1); + //激光测距信息 + KeyManager.getInstance().listen(createKey(CameraKey.KeyLaserMeasureInformation, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable LaserMeasureInformation laserMeasureInformation, @Nullable LaserMeasureInformation t1) { + if (t1 != null) { + if (t1.getLocation3D() != null) { + Movement.getInstance().setMeasure_target_altitude(t1.getLocation3D().getAltitude()); + Movement.getInstance().setMeasure_target_latitude(t1.getLocation3D().getLatitude()); + Movement.getInstance().setMeasure_target_longitude(t1.getLocation3D().getLongitude()); + Movement.getInstance().setMeasure_target_distance(t1.getDistance().intValue()); + Movement.getInstance().setMeasure_target_error_state(t1.getLaserMeasureState().value()); + Movement.getInstance().setPayload_index("53-0-0"); } } - }); + } + }); - //等温线最高值。较低和中等等温线阈值之间的温度值将以调色板中的128-175色显示。 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalIsothermUpperValue, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { - if (t1 != null) { - Movement.getInstance().setThermal_isotherm_upper_limit(t1); - } + //调色盘样式。{"0":"白热","1":"黑热","2":"描红","3":"医疗","5":"彩虹 1","6":"铁红","8":"北极","11":"熔岩","12":"热铁","13":"彩虹 2"} + KeyManager.getInstance().listen(createKey(CameraKey.KeyThermalPalette, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraThermalPalette cameraThermalPalette, @Nullable CameraThermalPalette t1) { + if (t1 != null) { + Movement.getInstance().setThermal_current_palette_style(t1.value()); } - }); + } + }); - //等温线最低值。较低和中等等温线阈值之间的温度值将以调色板中的128-175色显示。 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalIsothermLowerValue, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { - if (t1 != null) { - Movement.getInstance().setThermal_isotherm_lower_limit(t1); - } + //增益模式。{"0":"自动","1":"低增益, 测温范围0°C-500°C","2":"高增益, 测温范围-20°C-150°C"} + KeyManager.getInstance().listen(createKey(CameraKey.KeyThermalGainMode, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable ThermalGainMode thermalGainMode, @Nullable ThermalGainMode t1) { + if (t1 != null) { + Movement.getInstance().setThermal_gain_mode(t1.value()); } - }); + } + }); - //是否开启等温线 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalIsothermEnabled, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Boolean aBoolean, @Nullable Boolean t1) { - if (t1 != null) { - Movement.getInstance().setThermal_isotherm_state(t1 ? 1 : 0); - } + //全局画面中测量的最高温度 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalGlobalMaxTemperature, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { + if (t1 != null) { + Movement.getInstance().setThermal_global_temperature_max(t1); } - }); + } + }); - //相机模式 - KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. - KeyCameraMode, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraMode oldValue, @Nullable CameraMode newValue) { - if (newValue != null) { - Movement.getInstance().setCamera_mode(newValue.value()); - LogUtil.log(TAG, "相机模式:" + newValue + "old" + oldValue); - } + //等温线最高值。较低和中等等温线阈值之间的温度值将以调色板中的128-175色显示。 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalIsothermUpperValue, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if (t1 != null) { + Movement.getInstance().setThermal_isotherm_upper_limit(t1); } - }); + } + }); - //当前测温模式 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalTemperatureMeasureMode, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable ThermalTemperatureMeasureMode thermalTemperatureMeasureMode, @Nullable ThermalTemperatureMeasureMode t1) { - if (t1 != null && thermalTemperatureMeasureMode != null) { - Movement.getInstance().setIr_metering_mode(thermalTemperatureMeasureMode.value()); - } + //等温线最低值。较低和中等等温线阈值之间的温度值将以调色板中的128-175色显示。 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalIsothermLowerValue, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if (t1 != null) { + Movement.getInstance().setThermal_isotherm_lower_limit(t1); } - }); + } + }); - //当前测温的点的位置 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalSpotMetersurePoint, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable DoublePoint2D doublePoint2D, @Nullable DoublePoint2D t1) { - if (t1 != null) { - Movement.getInstance().setX(t1.getX()); - Movement.getInstance().setX(t1.getY()); - } + //是否开启等温线 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalIsothermEnabled, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Boolean aBoolean, @Nullable Boolean t1) { + if (t1 != null) { + Movement.getInstance().setThermal_isotherm_state(t1 ? 1 : 0); } - }); + } + }); - //当前测温的点的温度 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalSpotMetersureTemperature, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { - if (t1 != null) { - Movement.getInstance().setTemperature(t1.intValue()); - } + //相机模式 + KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. + KeyCameraMode, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraMode oldValue, @Nullable CameraMode newValue) { + if (newValue != null) { + //Movement.getInstance().setCamera_mode(newValue.value()); + // LogUtil.log(TAG, "相机模式:" + newValue + "old" + oldValue); } - }); + } + }); - //当前红外变焦倍率 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalZoomRatios, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { - if (t1 != null) { - Movement.getInstance().setIr_zoom_factor(t1.intValue()); - } + //当前测温模式 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalTemperatureMeasureMode, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable ThermalTemperatureMeasureMode thermalTemperatureMeasureMode, @Nullable ThermalTemperatureMeasureMode t1) { + if (t1 != null && thermalTemperatureMeasureMode != null) { + Movement.getInstance().setIr_metering_mode(thermalTemperatureMeasureMode.value()); } - }); + } + }); - //拍照状态 - KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.KeyPhotoState, - ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable PhotoState photoState, @Nullable PhotoState t1) { - if (t1 != null) { - Movement.getInstance().setPhoto_state(t1.value()); - } + //当前测温的点的位置 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalSpotMetersurePoint, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable DoublePoint2D doublePoint2D, @Nullable DoublePoint2D t1) { + if (t1 != null) { + Movement.getInstance().setX(t1.getX()); + Movement.getInstance().setX(t1.getY()); } - }); + } + }); - - //视频录制时长 - KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. - KeyRecordingTime, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer oldValue, @Nullable Integer newValue) { - if (newValue != null) { - Movement.getInstance().setRecord_time(newValue); - } + //当前测温的点的温度 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalSpotMetersureTemperature, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { + if (t1 != null) { + Movement.getInstance().setTemperature(t1.intValue()); } - }); + } + }); - - //视频录制状态 - KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. - KeyRecordingState, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable RecordingState recordingState, @Nullable RecordingState t1) { - if (t1 != null) { - Movement.getInstance().setRecording_state(t1.value() == 0 ? 0 : 1); - } + //当前红外变焦倍率 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalZoomRatios, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { + if (t1 != null) { + Movement.getInstance().setIr_zoom_factor(t1.intValue()); } - }); + } + }); - //剩余照片数 - KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. - KeySDCardAvailablePhotoCount, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { - if (t1 != null) { - LogUtil.log(TAG, "剩余拍照数setRemain_photo_num" + t1 + "old" + integer); + //拍照状态 + KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.KeyPhotoState, + ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable PhotoState photoState, @Nullable PhotoState t1) { + if (t1 != null) { + Movement.getInstance().setPhoto_state(t1.value()); + } + } + }); + + //视频录制时长 + KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. + KeyRecordingTime, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer oldValue, @Nullable Integer newValue) { + if (newValue != null) { + Movement.getInstance().setRecord_time(newValue); + } + } + }); + //视频录制状态 + KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. + KeyRecordingState, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable RecordingState recordingState, @Nullable RecordingState t1) { + if (t1 != null) { + Movement.getInstance().setRecording_state(t1.value() == 0 ? 0 : 1); + } + } + }); + + //剩余照片数 + KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. + KeySDCardAvailablePhotoCount, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if (t1 != null) { + //LogUtil.log(TAG, "剩余拍照数setRemain_photo_num" + t1 + "old" + integer); + if (t1 != 0) { Movement.getInstance().setRemain_photo_num(t1); } + } - }); - - //剩余录像时间 - KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. - KeySSDAvailableRecordingTimeInSeconds, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { - if (t1 != null) { - // - LogUtil.log(TAG, "剩余录像时间KeySSDAvailableRecordingTimeInSeconds" + t1 + "old" + integer); - Movement.getInstance().setRemain_record_duration(t1); - + } + }); + //剩余录像时间 + KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. + KeyIsRecording, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Boolean aBoolean, @Nullable Boolean t1) { + if(t1!=null){ + if(t1==true){ + Integer recordingTime = KeyManager.getInstance().getValue( + KeyTools.createKey(CameraKey.KeySSDAvailableRecordingTimeInSeconds, ComponentIndexType.PORT_1) + ); + LogUtil.log(TAG,"录像时间"+recordingTime); } } - }); - - //视频录制时长 - KeyManager.getInstance().listen(KeyTools.createKey(CameraKey. - KeySSDAvailableRecordingTimeInSeconds, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { - if (t1 != null) { - Movement.getInstance().setRemain_record_duration(t1); - + } + }); + //视频录制时长 + KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.KeyRecordingTime, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if (t1 != null) { + Movement.getInstance().setRecord_time(t1); + } + } + }); + //是否在录像 + KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.KeyVideoRecordingStatus, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable VideoRecordingStatus videoRecordingStatus, @Nullable VideoRecordingStatus t1) { + if (t1 != null) { + Boolean recording = t1.getIsRecording(); + if (recording != null && recording) { + Movement.getInstance().setRecording_state(1); // 正在录 + } else { + Movement.getInstance().setRecording_state(0); // 未录或未知 } } - }); - - //分屏是否使能 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalDisplayMode, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable ThermalDisplayMode thermalDisplayMode, @Nullable ThermalDisplayMode t1) { - if (t1 != null) { - Movement.getInstance().setScreen_split_enable(t1.value() == 2 ? true : false); - } + } + }); + //分屏是否使能 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalDisplayMode, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_THERMAL), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable ThermalDisplayMode thermalDisplayMode, @Nullable ThermalDisplayMode t1) { + if (t1 != null) { + Movement.getInstance().setScreen_split_enable(t1.value() == 2 ? true : false); } - }); + } + }); - //广角镜头曝光模式 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyExposureMode, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_WIDE), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraExposureMode cameraExposureMode, @Nullable CameraExposureMode t1) { - if (t1 != null) { - LogUtil.log(TAG, "监听曝光模式:" + t1.name()); - Movement.getInstance().setWide_exposure_mode(t1.value()); - } + //广角镜头曝光模式 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyExposureMode, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_WIDE), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraExposureMode cameraExposureMode, @Nullable CameraExposureMode t1) { + if (t1 != null) { + //LogUtil.log(TAG, "监听曝光模式:" + t1.name()); + Movement.getInstance().setWide_exposure_mode(t1.value()); } - }); + } + }); - //广角镜头曝光值 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyExposureCompensation, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_WIDE), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraExposureCompensation cameraExposureCompensation, @Nullable CameraExposureCompensation t1) { - if (cameraExposureCompensation != null) { - Movement.getInstance().setWide_exposure_value(cameraExposureCompensation.value()); - } + //广角镜头曝光值 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyExposureCompensation, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_WIDE), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraExposureCompensation cameraExposureCompensation, @Nullable CameraExposureCompensation t1) { + if (cameraExposureCompensation != null) { + Movement.getInstance().setWide_exposure_value(cameraExposureCompensation.value()); } - }); + } + }); - //广角镜头感光度 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyISO, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_WIDE), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraISO cameraISO, @Nullable CameraISO t1) { - if (t1 != null) { - Movement.getInstance().setWide_iso(t1.value()); - } + //广角镜头感光度 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyISO, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_WIDE), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraISO cameraISO, @Nullable CameraISO t1) { + if (t1 != null) { + Movement.getInstance().setWide_iso(t1.value()); } - }); + } + }); - //广角镜头快门速度 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyShutterSpeed, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_WIDE), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraShutterSpeed cameraShutterSpeed, @Nullable CameraShutterSpeed t1) { - if (t1 != null) { - Movement.getInstance().setWide_shutter_speed(t1.value()); - } + //广角镜头快门速度 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyShutterSpeed, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_WIDE), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraShutterSpeed cameraShutterSpeed, @Nullable CameraShutterSpeed t1) { + if (t1 != null) { + Movement.getInstance().setWide_shutter_speed(t1.value()); } - }); + } + }); - //变焦镜头标定的最远对焦值 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusRingMaxValue, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { - if (t1 != null) { - Movement.getInstance().setZoom_calibrate_farthest_focus_value(t1); - } + //变焦镜头标定的最远对焦值 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusRingMaxValue, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if (t1 != null) { + Movement.getInstance().setZoom_calibrate_farthest_focus_value(t1); } - }); + } + }); - //变焦镜头标定的最近对焦值 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusRingMinValue, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { - if (t1 != null) { - Movement.getInstance().setZoom_calibrate_farthest_focus_value(t1); - } + //变焦镜头标定的最近对焦值 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusRingMinValue, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if (t1 != null) { + Movement.getInstance().setZoom_calibrate_farthest_focus_value(t1); } - }); + } + }); - //变焦镜头曝光模式 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyExposureMode, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraExposureMode cameraExposureMode, @Nullable CameraExposureMode t1) { - if (t1 != null) { - Movement.getInstance().setZoom_exposure_mode(t1.value()); - } + //变焦镜头曝光模式 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyExposureMode, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraExposureMode cameraExposureMode, @Nullable CameraExposureMode t1) { + if (t1 != null) { + Movement.getInstance().setZoom_exposure_mode(t1.value()); } - }); + } + }); - //变焦镜头感光度 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyExposureCompensation, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraExposureCompensation cameraExposureCompensation, @Nullable CameraExposureCompensation t1) { - if (t1 != null) { - Movement.getInstance().setZoom_exposure_value(t1.value()); - } + //变焦镜头感光度 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyExposureCompensation, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraExposureCompensation cameraExposureCompensation, @Nullable CameraExposureCompensation t1) { + if (t1 != null) { + Movement.getInstance().setZoom_exposure_value(t1.value()); } - }); + } + }); - //变焦镜头感光度 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyExposureCompensation, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraExposureCompensation cameraExposureCompensation, @Nullable CameraExposureCompensation t1) { - if (t1 != null) { - Movement.getInstance().setZoom_exposure_value(t1.value()); - } + //变焦镜头感光度 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyExposureCompensation, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraExposureCompensation cameraExposureCompensation, @Nullable CameraExposureCompensation t1) { + if (t1 != null) { + Movement.getInstance().setZoom_exposure_value(t1.value()); } - }); - - //变焦倍数 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatios, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { - if (t1 != null) { - Movement.getInstance().setZoom_factor(t1); - } + } + }); + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyThermalZoomRatios, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { + if (t1 != null) { + Movement.getInstance().setZoom_factor(t1); } - }); - - //变焦镜头对焦模式 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusMode, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraFocusMode cameraFocusMode, @Nullable CameraFocusMode t1) { - if (t1 != null) { - Movement.getInstance().setZoom_focus_mode(t1.value()); - } + } + }); + //变焦倍数 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatios, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Double aDouble, @Nullable Double t1) { + if (t1 != null) { + Movement.getInstance().setZoom_factor(t1); } - }); + } + }); - //变焦镜头对焦状态 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusState, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraFocusState cameraFocusState, @Nullable CameraFocusState t1) { - if (t1 != null) { - Movement.getInstance().setZoom_focus_state(t1.value()); - } + //变焦镜头对焦模式 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusMode, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraFocusMode cameraFocusMode, @Nullable CameraFocusMode t1) { + if (t1 != null) { + Movement.getInstance().setZoom_focus_mode(t1.value()); } - }); + } + }); - //变焦镜头对焦值 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusRingValue, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { - if (t1 != null) { - Movement.getInstance().setZoom_focus_value(t1); - } + //变焦镜头对焦状态 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusState, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraFocusState cameraFocusState, @Nullable CameraFocusState t1) { + if (t1 != null) { + Movement.getInstance().setZoom_focus_state(t1.value()); } - }); + } + }); - //变焦镜头感光度 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyISO, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraISO cameraISO, @Nullable CameraISO t1) { - if (t1 != null) { - Movement.getInstance().setZoom_iso(t1.value()); - } + //变焦镜头对焦值 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusRingValue, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if (t1 != null) { + Movement.getInstance().setZoom_focus_value(t1); } - }); + } + }); - //变焦镜头最大对焦值 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusRingMaxValue, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { - if (t1 != null) { - Movement.getInstance().setZoom_max_focus_value(t1); - } + //变焦镜头感光度 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyISO, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraISO cameraISO, @Nullable CameraISO t1) { + if (t1 != null) { + Movement.getInstance().setZoom_iso(t1.value()); } - }); + } + }); - //变焦镜头最小对焦值 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusRingMinValue, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { - if (t1 != null) { - Movement.getInstance().setZoom_min_focus_value(t1); - } + //变焦镜头最大对焦值 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusRingMaxValue, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if (t1 != null) { + Movement.getInstance().setZoom_max_focus_value(t1); } - }); + } + }); - //变焦镜头快门速度 - KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyShutterSpeed, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraShutterSpeed cameraShutterSpeed, @Nullable CameraShutterSpeed t1) { - if (t1 != null) { - Movement.getInstance().setZoom_shutter_speed(t1.value()); - } + //变焦镜头最小对焦值 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyCameraFocusRingMinValue, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if (t1 != null) { + Movement.getInstance().setZoom_min_focus_value(t1); } - }); + } + }); - //SD卡容量 - KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.KeyCameraStorageInfos, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { - @Override - public void onValueChange(@Nullable CameraStorageInfos cameraStorageInfos, @Nullable CameraStorageInfos t1) { - if (t1 != null) { - CameraStorageInfo cameraStorageInfoByLocation = t1.getCameraStorageInfoByLocation(CameraStorageLocation.SDCARD); - if (cameraStorageInfoByLocation != null) { + //变焦镜头快门速度 + KeyManager.getInstance().listen(KeyTools.createCameraKey(CameraKey.KeyShutterSpeed, + ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraShutterSpeed cameraShutterSpeed, @Nullable CameraShutterSpeed t1) { + if (t1 != null) { + Movement.getInstance().setZoom_shutter_speed(t1.value()); + } + } + }); + + //SD卡容量 + KeyManager.getInstance().listen(KeyTools.createKey(CameraKey.KeyCameraStorageInfos, ComponentIndexType.PORT_1), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable CameraStorageInfos cameraStorageInfos, @Nullable CameraStorageInfos t1) { + if (t1 != null) { + CameraStorageInfo cameraStorageInfoByLocation = t1.getCameraStorageInfoByLocation(CameraStorageLocation.SDCARD); + if (cameraStorageInfoByLocation != null) { // //剩余可以拍照张数 // int pitcurenum = cameraStorageInfoByLocation.getAvailablePhotoCount(); // Movement.getInstance().setRemain_photo_num(pitcurenum); // LogUtil.log(TAG, "//剩余可以拍照张数" + pitcurenum); - Movement.getInstance().setTotal(cameraStorageInfoByLocation.getStorageCapacity() * 1024); - Movement.getInstance().setUsed((cameraStorageInfoByLocation.getStorageCapacity() * 1024) - - (cameraStorageInfoByLocation.getStorageLeftCapacity())); - } - + Movement.getInstance().setTotal(cameraStorageInfoByLocation.getStorageCapacity() * 1024); + Movement.getInstance().setUsed((cameraStorageInfoByLocation.getStorageCapacity() * 1024) + - (cameraStorageInfoByLocation.getStorageLeftCapacity())); } - } - }); - } - } - - //切换相机拍照录像模式 - public void setCameraMode(MessageDown message) { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. - KeyConnection, ComponentIndexType.PORT_1)); - if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { - if (message != null) { - int cameraMode = message.getData().getCamera_mode(); - ProductType productType = KeyManager.getInstance().getValue(KeyTools.createKey(ProductKey.KeyProductType)); - if (productType != null) { - int cameraModevalue = 0; - if (cameraMode == 1) { - cameraModevalue = 1; - } else if (cameraMode == 2) { - cameraModevalue = 11; - } else if (cameraMode == 3) { - cameraModevalue = 12; - } - //设置相机模式 - Movement.getInstance().setCamera_mode(cameraMode); - KeyManager.getInstance().setValue(KeyTools.createKey(CameraKey.KeyCameraMode, ComponentIndexType.PORT_1), - - CameraMode.find(cameraModevalue), - new CommonCallbacks.CompletionCallback() { - @Override - public void onSuccess() { - sendMsg2Server(message); - } - - @Override - public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server(message, "相机模式切换失败:" + getIDJIErrorMsg(error)); - } - }); - - } else { - sendFailMsg2Server(message, "切换失败:当前状态相机禁止操作"); } } - } else { - sendFailMsg2Server(message, "当前状态相机禁止操作"); - } + }); } - - //框选变焦 - public void camera_frame_zoom(MessageDown message) { - //这个locked参数没有处理 - - //使用aim转过去 - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey( - CameraKey.KeyConnection, ComponentIndexType.PORT_1)); - - if (isConnect == null || !isConnect || !getGimbalAndCameraEnabled()) { - LogUtil.log(TAG, "指点对焦失败:相机未连接或禁止操作"); - return; - } - - CameraLensType type = parseLensType1(message.getData().getCamera_type()); - if (type == null) { - sendFailMsg2Server(message, "不支持的相机类型"); - return; - } - - KeyManager.getInstance().setValue( - KeyTools.createCameraKey(CameraKey.KeyTapZoomEnable, - ComponentIndexType.PORT_1, type), - true, - new CommonCallbacks.CompletionCallback() { - @Override - public void onSuccess() { - LogUtil.log(TAG, "设置使能指点成功"); - //使用aim 加变焦 - camera_frame_zoom_and_bianjiao(message, type); +} - } +//切换相机拍照录像模式 +public void setCameraMode(MessageDown message) { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. + KeyConnection, ComponentIndexType.PORT_1)); + if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { + if (message != null) { - @Override - public void onFailure(@NonNull IDJIError error) { - LogUtil.log(TAG, "设置使能指点失败:" + new Gson().toJson(error)); - sendFailMsg2Server(message, "设置使能指点失败:" + getIDJIErrorMsg(error)); - } - }); - } + int cameraMode = message.getData().getCamera_mode(); + // 新增:如果当前已经是该模式,直接返回成功 + if (cameraMode == Movement.getInstance().getCamera_mode()) { + LogUtil.log(TAG, "相机模式已是" + cameraMode + ",无需切换"); + sendMsg2Server(message); + return; + } - private CameraLensType parseLensType1(String cameraType) { - if (cameraType == null) return null; - if ("ir".equals(cameraType)) { - return CameraLensType.CAMERA_LENS_THERMAL; - } else if ("wide".equals(cameraType)) { - return CameraLensType.CAMERA_LENS_ZOOM; - } else if ("zoom".equals(cameraType)) { - return CameraLensType.CAMERA_LENS_ZOOM; - } - return null; - } - - - private void camera_frame_zoom_and_bianjiao(MessageDown message, CameraLensType type) { - ZoomTargetPointInfo info = new ZoomTargetPointInfo(); - info.setX(Double.valueOf(message.getData().getX())); - info.setY(Double.valueOf(message.getData().getY())); - info.setTapZoomModeEnable(true); - - double width = message.getData().getWidth(); - double height = message.getData().getHeight(); - - double zoomRatio = calculateZoomRatio(width, height); - - //没有对lock判断 - info.setMode(TapZoomMode.GIMBAL_FOLLOW); // 或 TAP_ZOOM模式,看需求 - - KeyManager.getInstance().performAction( - KeyTools.createCameraKey(CameraKey.KeyTapZoomAtTarget, - ComponentIndexType.PORT_1, type), - info, - new CommonCallbacks.CompletionCallbackWithParam() { - @Override - public void onSuccess(EmptyMsg emptyMsg) { - //开始变焦 - KeyManager.getInstance().setValue(KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatios, - ComponentIndexType.PORT_1, type), - Double.valueOf(zoomRatio), new CommonCallbacks.CompletionCallback() { - @Override - public void onSuccess() { - sendMsg2Server(message); - } - - @Override - public void onFailure(@NonNull IDJIError idjiError) { - sendFailMsg2Server(message, "变焦失败:" + getIDJIErrorMsg(idjiError)); - } - }); - } - @Override - public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server(message, "aim操作失败:" + getIDJIErrorMsg(error)); - } - }); - } - //设置变焦倍率 - public static double calculateZoomRatio(double width, double height) { - // 防呆:如果传入 0 或负数,返回 1 倍(不 zoom) - if (width <= 0 || height <= 0) { - return 1.0; - } - - // 取宽高中的大值(保证框能装下) - double maxDimension = Math.max(width, height); - - // 反比计算:框越小,zoom 越大 - // 例:max=1.0(全画面)→ zoom=1.0 - // max=0.5(半屏) → zoom=2.0 - // max=0.005(很小) → zoom=200.0 - double zoom = 1.0 / maxDimension; - - // 限制在你的相机范围内 1x ~ 200x - return Math.max(1.0, Math.min(200.0, zoom)); - - } - //开始拍照 - public void startShootPhoto(MessageDown message) { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. - KeyConnection, ComponentIndexType.PORT_1)); - if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { - KeyManager.getInstance().performAction(KeyTools.createKey(CameraKey.KeyStartShootPhoto, - ComponentIndexType.PORT_1), - new CommonCallbacks.CompletionCallbackWithParam() { - @Override - public void onSuccess(EmptyMsg emptyMsg) { - sendMsg2Server(message); - } - - @Override - public void onFailure(@NonNull IDJIError error) { - LogUtil.log(TAG, "拍照失败:" + new Gson().toJson(error)); - sendFailMsg2Server(message, "拍照失败:" + getIDJIErrorMsg(error)); - } - }); - } else { - sendFailMsg2Server(message, "当前状态相机禁止操作"); - } - } - - - //结束拍照 - public void stopShootPhoto(MessageDown message) { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. - KeyConnection, ComponentIndexType.PORT_1)); - if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { - KeyManager.getInstance().performAction(KeyTools.createKey(CameraKey.KeyStopShootPhoto, - ComponentIndexType.PORT_1), new CommonCallbacks.CompletionCallbackWithParam() { - @Override - public void onSuccess(EmptyMsg emptyMsg) { - sendMsg2Server(message); + ProductType productType = KeyManager.getInstance().getValue(KeyTools.createKey(ProductKey.KeyProductType)); + if (productType != null) { + int cameraModevalue = 0; + if (cameraMode == 1) { + cameraModevalue = 1; + } else if (cameraMode == 2) { + cameraModevalue = 11; + } else if (cameraMode == 3) { + cameraModevalue = 12; } - @Override - public void onFailure(@NonNull IDJIError error) { - LogUtil.log(TAG, "停止拍照失败:" + new Gson().toJson(error)); - sendFailMsg2Server(message, "停止拍照失败:" + getIDJIErrorMsg(error)); - } - }); - } else { - sendFailMsg2Server(message, "当前状态相机禁止操作"); - } - } - - //开始录像 - public void startRecordVideo(MessageDown message) { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. - KeyConnection, ComponentIndexType.PORT_1)); - if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { - KeyManager.getInstance().performAction(KeyTools.createKey(CameraKey.KeyStartRecord, - ComponentIndexType.PORT_1), new CommonCallbacks.CompletionCallbackWithParam() { - @Override - public void onSuccess(EmptyMsg emptyMsg) { - sendMsg2Server(message); - } - - @Override - public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server(message, "开始录像失败:" + getIDJIErrorMsg(error)); - } - }); - } else { - sendFailMsg2Server(message, "当前状态相机禁止操作"); - } - } - - //停止录像 - public void stopRecordVideo(MessageDown message) { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. - KeyConnection, ComponentIndexType.PORT_1)); - if (isConnect != null && isConnect) { - KeyManager.getInstance().performAction(KeyTools.createKey(CameraKey.KeyStopRecord, - ComponentIndexType.PORT_1), new CommonCallbacks.CompletionCallbackWithParam() { - @Override - public void onSuccess(EmptyMsg emptyMsg) { - LogUtil.log(TAG, "停止录像成功"); - } - - @Override - public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server(message, "停止录像失败:" + getIDJIErrorMsg(error)); - } - }); - } else { - sendFailMsg2Server(message, "当前状态相机禁止操作"); - } - } - - - //设置变焦倍率 - public void setCameraZoomRatios(MessageDown message) { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. - KeyConnection, ComponentIndexType.PORT_1)); - if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { - if (message != null) { - int type = 1; - switch (message.getData().getCamera_type()) { - case "ir": - type = 3; - break; - case "normal": - type = 0; - break; - case "wide": - type = 1; - break; - case "zoom": - type = 2; - break; - } - KeyManager.getInstance().setValue(KeyTools.createKey(CameraKey.KeyCameraVideoStreamSource, - ComponentIndexType.PORT_1) - , CameraVideoStreamSourceType.find(type), + KeyManager.getInstance().setValue(KeyTools.createKey(CameraKey.KeyCameraMode, ComponentIndexType.PORT_1), + CameraMode.find(cameraModevalue), new CommonCallbacks.CompletionCallback() { @Override public void onSuccess() { - new Handler().postDelayed(new Runnable() { - @Override - public void run() { - int cameraZoomRatios = message.getData().getZoom_factor(); - KeyManager.getInstance().setValue(KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatios, - ComponentIndexType.PORT_1, CameraLensType.CAMERA_LENS_ZOOM), - Double.valueOf(cameraZoomRatios), new CommonCallbacks.CompletionCallback() { - @Override - public void onSuccess() { - Movement.getInstance().setZoom_factor(cameraZoomRatios); - sendMsg2Server(message); - } - - @Override - public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server(message, "设置变焦倍率失败:" + getIDJIErrorMsg(error)); - } - }); - } - }, 200); + //设置相机模式 + Movement.getInstance().setCamera_mode(cameraMode); + LogUtil.log(TAG, "切换成功" + Movement.getInstance().getCamera_mode()); + OSDManager.getInstance().pushFlightAttitude(); + sendMsg2Server(message); } @Override public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server(message, "切换相机视频流失败:" + getIDJIErrorMsg(error)); + sendFailMsg2Server(message, "相机模式切换失败:" + getIDJIErrorMsg(error)); } }); + } else { - sendFailMsg2Server(message, "当前状态相机禁止操作"); + sendFailMsg2Server(message, "切换失败:当前状态相机禁止操作"); } } + } else { + sendFailMsg2Server(message, "当前状态相机禁止操作"); } +} + +//框选变焦 +public void camera_frame_zoom(MessageDown message) { + //这个locked参数没有处理 + + //使用aim转过去 + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey( + CameraKey.KeyConnection, ComponentIndexType.PORT_1)); + + if (isConnect == null || !isConnect || !getGimbalAndCameraEnabled()) { + LogUtil.log(TAG, "指点对焦失败:相机未连接或禁止操作"); + return; + } + + CameraLensType type = parseLensType1(message.getData().getCamera_type()); + if (type == null) { + sendFailMsg2Server(message, "不支持的相机类型"); + return; + } + + KeyManager.getInstance().setValue( + KeyTools.createCameraKey(CameraKey.KeyTapZoomEnable, + ComponentIndexType.PORT_1, type), + true, + new CommonCallbacks.CompletionCallback() { + @Override + public void onSuccess() { + LogUtil.log(TAG, "设置使能指点成功"); + //使用aim 加变焦 + camera_frame_zoom_and_bianjiao(message, type); + + + } + + @Override + public void onFailure(@NonNull IDJIError error) { + LogUtil.log(TAG, "设置使能指点失败:" + new Gson().toJson(error)); + sendFailMsg2Server(message, "设置使能指点失败:" + getIDJIErrorMsg(error)); + } + }); +} + +private CameraLensType parseLensType1(String cameraType) { + if (cameraType == null) return null; + if ("ir".equals(cameraType)) { + return CameraLensType.CAMERA_LENS_THERMAL; + } else if ("wide".equals(cameraType)) { + return CameraLensType.CAMERA_LENS_ZOOM; + } else if ("zoom".equals(cameraType)) { + return CameraLensType.CAMERA_LENS_ZOOM; + } + return null; +} + + +private void camera_frame_zoom_and_bianjiao(MessageDown message, CameraLensType type) { + ZoomTargetPointInfo info = new ZoomTargetPointInfo(); + info.setX(Double.valueOf(message.getData().getX())); + info.setY(Double.valueOf(message.getData().getY())); + info.setTapZoomModeEnable(true); + + double width = message.getData().getWidth(); + double height = message.getData().getHeight(); + + double zoomRatio = calculateZoomRatio(width, height); + + //没有对lock判断 + info.setMode(TapZoomMode.GIMBAL_FOLLOW); // 或 TAP_ZOOM模式,看需求 + + KeyManager.getInstance().performAction( + KeyTools.createCameraKey(CameraKey.KeyTapZoomAtTarget, + ComponentIndexType.PORT_1, type), + info, + new CommonCallbacks.CompletionCallbackWithParam() { + @Override + public void onSuccess(EmptyMsg emptyMsg) { + //开始变焦 + KeyManager.getInstance().setValue(KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatios, + ComponentIndexType.PORT_1, type), + Double.valueOf(zoomRatio), new CommonCallbacks.CompletionCallback() { + @Override + public void onSuccess() { + LogUtil.log(TAG, "变焦成功"); + sendMsg2Server(message); + } + + @Override + public void onFailure(@NonNull IDJIError idjiError) { + sendFailMsg2Server(message, "变焦失败:" + getIDJIErrorMsg(idjiError)); + } + }); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + sendFailMsg2Server(message, "aim操作失败:" + getIDJIErrorMsg(error)); + } + }); +} + +//设置变焦倍率 +public static double calculateZoomRatio(double width, double height) { + // 防呆:如果传入 0 或负数,返回 1 倍(不 zoom) + if (width <= 0 || height <= 0) { + return 1.0; + } + + // 取宽高中的大值(保证框能装下) + double maxDimension = Math.max(width, height); + + // 反比计算:框越小,zoom 越大 + // 例:max=1.0(全画面)→ zoom=1.0 + // max=0.5(半屏) → zoom=2.0 + // max=0.005(很小) → zoom=200.0 + double zoom = 1.0 / maxDimension; + + // 限制在你的相机范围内 1x ~ 200x + return Math.max(1.0, Math.min(200.0, zoom)); + +} + +//开始拍照 +public void startShootPhoto(MessageDown message) { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. + KeyConnection, ComponentIndexType.PORT_1)); + if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { + KeyManager.getInstance().performAction(KeyTools.createKey(CameraKey.KeyStartShootPhoto, + ComponentIndexType.PORT_1), + new CommonCallbacks.CompletionCallbackWithParam() { + @Override + public void onSuccess(EmptyMsg emptyMsg) { + LogUtil.log(TAG,"拍照成功"); + sendMsg2Server(message); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + LogUtil.log(TAG, "拍照失败:" + new Gson().toJson(error)); + sendFailMsg2Server(message, "拍照失败:" + getIDJIErrorMsg(error)); + } + }); + } else { + sendFailMsg2Server(message, "当前状态相机禁止操作"); + } +} + + +//结束拍照 +public void stopShootPhoto(MessageDown message) { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. + KeyConnection, ComponentIndexType.PORT_1)); + if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { + KeyManager.getInstance().performAction(KeyTools.createKey(CameraKey.KeyStopShootPhoto, + ComponentIndexType.PORT_1), new CommonCallbacks.CompletionCallbackWithParam() { + @Override + public void onSuccess(EmptyMsg emptyMsg) { + sendMsg2Server(message); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + LogUtil.log(TAG, "停止拍照失败:" + new Gson().toJson(error)); + sendFailMsg2Server(message, "停止拍照失败:" + getIDJIErrorMsg(error)); + } + }); + } else { + sendFailMsg2Server(message, "当前状态相机禁止操作"); + } +} + + +//开始录像 +public void startRecordVideo(MessageDown message) { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. + KeyConnection, ComponentIndexType.PORT_1)); + if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { + KeyManager.getInstance().performAction(KeyTools.createKey(CameraKey.KeyStartRecord, + ComponentIndexType.PORT_1), new CommonCallbacks.CompletionCallbackWithParam() { + @Override + public void onSuccess(EmptyMsg emptyMsg) { + sendMsg2Server(message); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + sendFailMsg2Server(message, "开始录像失败:" + getIDJIErrorMsg(error)); + } + }); + } else { + sendFailMsg2Server(message, "当前状态相机禁止操作"); + } +} + +//停止录像 +public void stopRecordVideo(MessageDown message) { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. + KeyConnection, ComponentIndexType.PORT_1)); + if (isConnect != null && isConnect) { + KeyManager.getInstance().performAction(KeyTools.createKey(CameraKey.KeyStopRecord, + ComponentIndexType.PORT_1), new CommonCallbacks.CompletionCallbackWithParam() { + @Override + public void onSuccess(EmptyMsg emptyMsg) { + LogUtil.log(TAG, "停止录像成功"); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + sendFailMsg2Server(message, "停止录像失败:" + getIDJIErrorMsg(error)); + } + }); + } else { + sendFailMsg2Server(message, "当前状态相机禁止操作"); + } +} + + +// 设置变焦倍率 +public void setCameraZoomRatios(MessageDown message) { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. + KeyConnection, ComponentIndexType.PORT_1)); + if (isConnect == null || !isConnect || !getGimbalAndCameraEnabled()) { + sendFailMsg2Server(message, "当前状态相机禁止操作"); + return; + } + + if (message == null) return; + + String cameraType = message.getData().getCamera_type(); + double zoomFactor = message.getData().getZoom_factor(); + + // 检查是否有红外(H30T) + CameraType cameraTypeEnum = KeyManager.getInstance().getValue( + KeyTools.createKey(CameraKey.KeyCameraType, ComponentIndexType.PORT_1)); + boolean hasThermal = (cameraTypeEnum == CameraType.ZENMUSE_H30T); + + // 1. 映射视频流类型和镜头类型 + CameraVideoStreamSourceType streamSource; + CameraLensType lensType; + double minZoom, maxZoom; + final boolean isWide; + final boolean isIr; + + switch (cameraType) { + case "ir": + if (!hasThermal) { + sendFailMsg2Server(message, "当前负载无红外功能,仅H30T支持"); + return; + } + streamSource = CameraVideoStreamSourceType.INFRARED_CAMERA; + lensType = CameraLensType.CAMERA_LENS_THERMAL; + minZoom = 2; + maxZoom = 20; // 红外 2-20倍 + isWide = false; + isIr = true; + break; + case "wide": + streamSource = CameraVideoStreamSourceType.WIDE_CAMERA; + lensType = CameraLensType.CAMERA_LENS_WIDE; + minZoom = 1; + maxZoom = 1; + isWide = true; + isIr = false; + break; + case "zoom": + streamSource = CameraVideoStreamSourceType.ZOOM_CAMERA; + lensType = CameraLensType.CAMERA_LENS_ZOOM; + minZoom = 2; + maxZoom = 200; + isWide = false; + isIr = false; + break; + default: + streamSource = CameraVideoStreamSourceType.DEFAULT_CAMERA; + lensType = CameraLensType.CAMERA_LENS_ZOOM; + minZoom = 2; + maxZoom = 200; + isWide = false; + isIr = false; + break; + } + + // 2. 切换视频流 + final double finalMinZoom = minZoom; + final double finalMaxZoom = maxZoom; + + KeyManager.getInstance().setValue( + KeyTools.createKey(CameraKey.KeyCameraVideoStreamSource, ComponentIndexType.PORT_1), + streamSource, + new CommonCallbacks.CompletionCallback() { + @Override + public void onSuccess() { + // 广角不设置变焦 + if (isWide) { + LogUtil.log(TAG, "广角切换成功,无需设置变焦"); + Movement.getInstance().setZoom_factor(1); + sendMsg2Server(message); + return; + } + + // 强制截断变焦范围 + final double validZoom = Math.max(finalMinZoom, Math.min(finalMaxZoom, zoomFactor)); + + new Handler(Looper.getMainLooper()).postDelayed(() -> { + if (isIr) { + KeyManager.getInstance().setValue( + KeyTools.createCameraKey(CameraKey.KeyThermalZoomRatios, + ComponentIndexType.PORT_1, lensType), + validZoom, + new CommonCallbacks.CompletionCallback() { + @Override + public void onSuccess() { + LogUtil.log(TAG, "红外变焦成功: " + validZoom); + Movement.getInstance().setZoom_factor((int) validZoom); + sendMsg2Server(message); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + sendFailMsg2Server(message, "红外变焦失败:" + getIDJIErrorMsg(error)); + } + } + ); + } else { + // 可见光变焦 + KeyManager.getInstance().setValue( + KeyTools.createCameraKey(CameraKey.KeyCameraZoomRatios, + ComponentIndexType.PORT_1, lensType), + validZoom, + new CommonCallbacks.CompletionCallback() { + @Override + public void onSuccess() { + LogUtil.log(TAG, "变焦成功: " + cameraType + "=" + validZoom); + Movement.getInstance().setZoom_factor((int) validZoom); + sendMsg2Server(message); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + sendFailMsg2Server(message, "设置变焦倍率失败:" + getIDJIErrorMsg(error)); + } + } + ); + } + }, 200); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + sendFailMsg2Server(message, "切换相机视频流失败:" + getIDJIErrorMsg(error)); + } + } + ); +} + +// private void setstepThermalZoomRatios(){ +// KeyManager.getInstance().setValue( +// KeyTools.createKey(CameraKey.KeyThermalDigitalZoomFactor, ComponentIndexType.PORT_1), +// ThermalDigitalZoomFactor.FACTOR_X2, +// new CommonCallbacks.CompletionCallback() { +// @Override +// public void onSuccess() { +// // +// LogUtil.log(TAG,"设置红外步长为2x"); +// } // +// @Override +// public void onFailure(@NonNull IDJIError idjiError) { +// LogUtil.log(TAG,"设置红外步长为1x失败"+idjiError); +// +// } +// } +// ); +// } + // //设置红外变焦倍率(支持1x、2x、4x、8x变焦倍率) // public void setThermalZoomRatios(MQMessage message) { // Boolean isConnect =KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. @@ -848,42 +1100,42 @@ public class CameraManager extends BaseManager { // } // } - //切换广角变焦红外 - public void setCameraVideoStreamSource(MessageDown message) { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. - KeyConnection, ComponentIndexType.PORT_1)); - if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { - if (message != null) { - int type = 1; - switch (message.getData().getVideo_type()) { - case "ir": - type = 3; - break; - case "normal": - type = 0; - break; - case "wide": - type = 1; - break; - case "zoom": - type = 2; - break; - } +//切换广角变焦红外 +public void setCameraVideoStreamSource(MessageDown message) { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. + KeyConnection, ComponentIndexType.PORT_1)); + if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { + if (message != null) { + int type = 1; + switch (message.getData().getVideo_type()) { + case "ir": + type = 3; + break; + case "normal": + type = 0; + break; + case "wide": + type = 1; + break; + case "zoom": + type = 2; + break; + } - KeyManager.getInstance().setValue(KeyTools.createKey(CameraKey.KeyCameraVideoStreamSource, - ComponentIndexType.PORT_1) - , CameraVideoStreamSourceType.find(type), - new CommonCallbacks.CompletionCallback() { - @Override - public void onSuccess() { - sendMsg2Server(message); - } + KeyManager.getInstance().setValue(KeyTools.createKey(CameraKey.KeyCameraVideoStreamSource, + ComponentIndexType.PORT_1) + , CameraVideoStreamSourceType.find(type), + new CommonCallbacks.CompletionCallback() { + @Override + public void onSuccess() { + sendMsg2Server(message); + } - @Override - public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server(message, "切换相机视频流失败:" + getIDJIErrorMsg(error)); - } - }); + @Override + public void onFailure(@NonNull IDJIError error) { + sendFailMsg2Server(message, "切换相机视频流失败:" + getIDJIErrorMsg(error)); + } + }); // if (type == 3) { // KeyManager.getInstance().setValue(KeyTools.createCameraKey(CameraKey.KeyThermalDisplayMode, // ComponentIndexType.PORT_1, @@ -901,13 +1153,13 @@ public class CameraManager extends BaseManager { // } // }); // } - } - } else { - sendFailMsg2Server(message, "当前状态相机禁止操作"); } - + } else { + sendFailMsg2Server(message, "当前状态相机禁止操作"); } +} + // //设置红外镜头的显示模式 // public void setThermalDisplayMode(MQMessage message) { // Boolean isConnect =KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. @@ -961,7 +1213,7 @@ public class CameraManager extends BaseManager { // // - /// /设置对焦模式 +/// /设置对焦模式 //public void setCameraFocusMode(MQMessage message) { // Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. // KeyConnection,ComponentIndexType.PORT_1)); @@ -989,35 +1241,35 @@ public class CameraManager extends BaseManager { // } //} // - //格式化SD卡 - public void formatStorage(MessageDown message) { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. - KeyConnection, ComponentIndexType.PORT_1)); - if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { - KeyManager.getInstance().performAction(KeyTools.createKey(CameraKey.KeyFormatStorage, ComponentIndexType.PORT_1), CameraStorageLocation.SDCARD, new CommonCallbacks.CompletionCallbackWithParam() { - @Override - public void onSuccess(EmptyMsg emptyMsg) { - if (message != null) { - sendMsg2Server(message); - } - LogUtil.log(TAG, "sd卡已格式化"); +//格式化SD卡 +public void formatStorage(MessageDown message) { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. + KeyConnection, ComponentIndexType.PORT_1)); + if (isConnect != null && isConnect && getGimbalAndCameraEnabled()) { + KeyManager.getInstance().performAction(KeyTools.createKey(CameraKey.KeyFormatStorage, ComponentIndexType.PORT_1), CameraStorageLocation.SDCARD, new CommonCallbacks.CompletionCallbackWithParam() { + @Override + public void onSuccess(EmptyMsg emptyMsg) { + if (message != null) { + sendMsg2Server(message); } - - @Override - public void onFailure(@NonNull IDJIError error) { - if (message != null) { - sendFailMsg2Server(message, "SD卡格式化失败:" + getIDJIErrorMsg(error)); - } - LogUtil.log(TAG, "sd卡格式化失败:" + new Gson().toJson(error)); - } - }); - } else { - if (message != null) { - sendFailMsg2Server(message, "当前状态相机禁止操作"); + LogUtil.log(TAG, "sd卡已格式化"); } - LogUtil.log(TAG, "当前状态相机禁止操作"); + @Override + public void onFailure(@NonNull IDJIError error) { + if (message != null) { + sendFailMsg2Server(message, "SD卡格式化失败:" + getIDJIErrorMsg(error)); + } + LogUtil.log(TAG, "sd卡格式化失败:" + new Gson().toJson(error)); + } + }); + } else { + if (message != null) { + sendFailMsg2Server(message, "当前状态相机禁止操作"); } + LogUtil.log(TAG, "当前状态相机禁止操作"); + + } // // } //// @@ -1095,105 +1347,105 @@ public class CameraManager extends BaseManager { // } //} // +} + +//指点对焦 +public void tapZoomAtTarget(MessageDown message) { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey( + CameraKey.KeyConnection, ComponentIndexType.PORT_1)); + // + LogUtil.log(TAG, "双击回中" + message.toString()); + if (isConnect == null || !isConnect || !getGimbalAndCameraEnabled()) { + LogUtil.log(TAG, "指点对焦失败:相机未连接或禁止操作"); + return; } - //指点对焦 - public void tapZoomAtTarget(MessageDown message) { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey( - CameraKey.KeyConnection, ComponentIndexType.PORT_1)); - // - LogUtil.log(TAG, "双击回中" + message.toString()); - if (isConnect == null || !isConnect || !getGimbalAndCameraEnabled()) { - LogUtil.log(TAG, "指点对焦失败:相机未连接或禁止操作"); - return; - } - - CameraLensType type = parseLensType(message.getData().getCamera_type()); - if (type == null) { - sendFailMsg2Server(message, "不支持的相机类型"); - return; - } - - KeyManager.getInstance().setValue( - KeyTools.createCameraKey(CameraKey.KeyTapZoomEnable, - ComponentIndexType.PORT_1, type), - true, - new CommonCallbacks.CompletionCallback() { - @Override - public void onSuccess() { - LogUtil.log(TAG, "设置使能指点成功"); - performTapZoom(message, type); - } - - @Override - public void onFailure(@NonNull IDJIError error) { - LogUtil.log(TAG, "设置使能指点失败:" + new Gson().toJson(error)); - sendFailMsg2Server(message, "设置使能指点失败:" + getIDJIErrorMsg(error)); - } - }); + CameraLensType type = parseLensType(message.getData().getCamera_type()); + if (type == null) { + sendFailMsg2Server(message, "不支持的相机类型"); + return; } - private void performTapZoom(MessageDown message, CameraLensType type) { - ZoomTargetPointInfo info = new ZoomTargetPointInfo(); - info.setX(Double.valueOf(message.getData().getX())); - info.setY(Double.valueOf(message.getData().getY())); - info.setTapZoomModeEnable(true); - //没有对lock判断 - info.setMode(TapZoomMode.GIMBAL_FOLLOW); // 或 TAP_ZOOM模式,看需求 - - KeyManager.getInstance().performAction( - KeyTools.createCameraKey(CameraKey.KeyTapZoomAtTarget, - ComponentIndexType.PORT_1, type), - info, - new CommonCallbacks.CompletionCallbackWithParam() { - @Override - public void onSuccess(EmptyMsg emptyMsg) { - sendMsg2Server(message); - } - - @Override - public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server(message, "指点变焦失败:" + getIDJIErrorMsg(error)); - } - }); - } - - private CameraLensType parseLensType(String cameraType) { - if (cameraType == null) return null; - if ("ir".equals(cameraType)) { - return CameraLensType.CAMERA_LENS_THERMAL; - } else if ("wide".equals(cameraType)) { - return CameraLensType.CAMERA_LENS_WIDE; - } else if ("zoom".equals(cameraType)) { - return CameraLensType.CAMERA_LENS_ZOOM; - } - return null; - } - - - //切换为广角镜头,降低曝光率 - public void resumeLensToWideISOManual() { - Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. - KeyConnection, ComponentIndexType.PORT_1)); - if (isConnect != null && isConnect) { - //切换成广角镜头 - KeyManager.getInstance().setValue(KeyTools.createKey(CameraKey.KeyCameraVideoStreamSource, - ComponentIndexType.PORT_1), CameraVideoStreamSourceType.WIDE_CAMERA, new CommonCallbacks.CompletionCallback() { + KeyManager.getInstance().setValue( + KeyTools.createCameraKey(CameraKey.KeyTapZoomEnable, + ComponentIndexType.PORT_1, type), + true, + new CommonCallbacks.CompletionCallback() { @Override public void onSuccess() { - LogUtil.log(TAG, "返航时将镜头切为广角"); + LogUtil.log(TAG, "设置使能指点成功"); + performTapZoom(message, type); } @Override public void onFailure(@NonNull IDJIError error) { - LogUtil.log(TAG, "返航切换广角失败:" + new Gson().toJson(error)); + LogUtil.log(TAG, "设置使能指点失败:" + new Gson().toJson(error)); + sendFailMsg2Server(message, "设置使能指点失败:" + getIDJIErrorMsg(error)); } }); +} - } else { - LogUtil.log(TAG, "降落切换广角失败:当前状态相机禁止操作"); - } +private void performTapZoom(MessageDown message, CameraLensType type) { + ZoomTargetPointInfo info = new ZoomTargetPointInfo(); + info.setX(Double.valueOf(message.getData().getX())); + info.setY(Double.valueOf(message.getData().getY())); + info.setTapZoomModeEnable(true); + //没有对lock判断 + info.setMode(TapZoomMode.GIMBAL_FOLLOW); // 或 TAP_ZOOM模式,看需求 + + KeyManager.getInstance().performAction( + KeyTools.createCameraKey(CameraKey.KeyTapZoomAtTarget, + ComponentIndexType.PORT_1, type), + info, + new CommonCallbacks.CompletionCallbackWithParam() { + @Override + public void onSuccess(EmptyMsg emptyMsg) { + sendMsg2Server(message); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + sendFailMsg2Server(message, "指点变焦失败:" + getIDJIErrorMsg(error)); + } + }); +} + +private CameraLensType parseLensType(String cameraType) { + if (cameraType == null) return null; + if ("ir".equals(cameraType)) { + return CameraLensType.CAMERA_LENS_THERMAL; + } else if ("wide".equals(cameraType)) { + return CameraLensType.CAMERA_LENS_WIDE; + } else if ("zoom".equals(cameraType)) { + return CameraLensType.CAMERA_LENS_ZOOM; } + return null; +} + + +//切换为广角镜头,降低曝光率 +public void resumeLensToWideISOManual() { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(CameraKey. + KeyConnection, ComponentIndexType.PORT_1)); + if (isConnect != null && isConnect) { + //切换成广角镜头 + KeyManager.getInstance().setValue(KeyTools.createKey(CameraKey.KeyCameraVideoStreamSource, + ComponentIndexType.PORT_1), CameraVideoStreamSourceType.WIDE_CAMERA, new CommonCallbacks.CompletionCallback() { + @Override + public void onSuccess() { + LogUtil.log(TAG, "返航时将镜头切为广角"); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + LogUtil.log(TAG, "返航切换广角失败:" + new Gson().toJson(error)); + } + }); + + } else { + LogUtil.log(TAG, "降落切换广角失败:当前状态相机禁止操作"); + } +} // //设置自定义文件后缀 // public void setCustomExpandNameSetting() { diff --git a/app/src/main/java/com/aros/apron/manager/FlightManager.java b/app/src/main/java/com/aros/apron/manager/FlightManager.java index 1683f811..f9bac9c3 100644 --- a/app/src/main/java/com/aros/apron/manager/FlightManager.java +++ b/app/src/main/java/com/aros/apron/manager/FlightManager.java @@ -7,8 +7,10 @@ import android.os.Handler; import android.os.Looper; import android.text.TextUtils; import android.util.Log; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; + import com.aros.apron.base.BaseManager; import com.aros.apron.constant.AMSConfig; import com.aros.apron.entity.ApronExecutionStatus; @@ -22,8 +24,11 @@ import com.aros.apron.tools.LogUtil; import com.aros.apron.tools.MqttManager; import com.aros.apron.tools.PreferenceUtils; import com.google.gson.Gson; + import org.greenrobot.eventbus.EventBus; + import java.util.List; + import dji.sdk.keyvalue.key.AirLinkKey; import dji.sdk.keyvalue.key.FlightControllerKey; import dji.sdk.keyvalue.key.KeyTools; @@ -93,7 +98,7 @@ public class FlightManager extends BaseManager { if (newValue != null) { if (!newValue) { - LogUtil.log(TAG,"遥控器断开连接"); + LogUtil.log(TAG, "遥控器断开连接"); // 飞机未连接时设置未连接状态 Movement.getInstance().setMode_code(14); OSDManager.getInstance().pushFlightAttitude(); @@ -101,10 +106,9 @@ public class FlightManager extends BaseManager { Movement.getInstance().setMissionFinish(true); - }else{ + } else { - - LogUtil.log(TAG,"setMode_code1(0)"); + LogUtil.log(TAG, "setMode_code1(0)"); //连上就待机 Movement.getInstance().setMissionFinish(false); Movement.getInstance().setMode_code(0); @@ -114,14 +118,13 @@ public class FlightManager extends BaseManager { } }); //重新复制一下如果一直断开这个回调会不执行 - if(isConnect){ - LogUtil.log(TAG,"setMode_code2(0)"); + if (isConnect) { + LogUtil.log(TAG, "setMode_code2(0)"); Movement.getInstance().setMode_code(0); - }else{ + } else { Movement.getInstance().setMode_code(14); } - if (isConnect != null && isConnect) { if (!TextUtils.isEmpty(PreferenceUtils.getInstance().getAlternatePointLon()) @@ -131,10 +134,12 @@ public class FlightManager extends BaseManager { } iDeviceStatusManager = dji.v5.manager.diagnostic.DeviceStatusManager.getInstance(); + LogUtil.log(TAG,"iDeviceStatusManager"+"设置成功"); iDeviceStatusManager.addDJIDeviceStatusChangeListener(new DJIDeviceStatusChangeListener() { @Override public void onDeviceStatusUpdate(DJIDeviceStatus from, DJIDeviceStatus to) { if (to != null && !TextUtils.isEmpty(to.description())) { + LogUtil.log(TAG,"setPlaneMessage"+to.description()); Movement.getInstance().setPlaneMessage(to.description()); pushFlightAttitude(); } @@ -147,11 +152,11 @@ public class FlightManager extends BaseManager { @Override public void onUpdate(@NonNull PerceptionInfo information) { if (information != null) { - if (information.getDownwardObstacleAvoidanceWorking()!=null){ + if (information.getDownwardObstacleAvoidanceWorking() != null) { Movement.getInstance().setDownside(information.getDownwardObstacleAvoidanceWorking() ? 1 : 0); } Movement.getInstance().setHorizon(information.isHorizontalObstacleAvoidanceEnabled() ? 1 : 0); - if (information.getUpwardObstacleAvoidanceWorking()!=null){ + if (information.getUpwardObstacleAvoidanceWorking() != null) { Movement.getInstance().setUpside(information.getUpwardObstacleAvoidanceWorking() ? 1 : 0); } pushFlightAttitude(); @@ -187,13 +192,13 @@ public class FlightManager extends BaseManager { ApronExecutionStatus.getInstance().setAircraftWaitShutDown(false); //起飞了这个状态就看这里 - if(Movement.getInstance().getFlightmode()==1){ + if (Movement.getInstance().getFlightmode() == 1) { Movement.getInstance().setMode_code(5); - }else if(Movement.getInstance().getFlightmode()==2){ + } else if (Movement.getInstance().getFlightmode() == 2) { Movement.getInstance().setMode_code(17); } - }else{ - LogUtil.log(TAG,"setMode_code3(0)"); + } else { + LogUtil.log(TAG, "setMode_code3(0)"); Movement.getInstance().setMode_code(0); OSDManager.getInstance().pushFlightAttitude(); @@ -204,7 +209,6 @@ public class FlightManager extends BaseManager { pushFlightAttitude(); - } } }); @@ -214,7 +218,7 @@ public class FlightManager extends BaseManager { public void onValueChange(@Nullable Boolean oldValue, @Nullable Boolean newValue) { if (newValue != null) { - if(newValue==false){ + if (newValue == false) { //电机不转待机 Movement.getInstance().setMode_code(0); OSDManager.getInstance().pushFlightAttitude(); @@ -227,7 +231,6 @@ public class FlightManager extends BaseManager { } }); - //挡位 KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyRemoteControllerFlightMode), this, new CommonCallbacks.KeyListener() { @Override @@ -238,7 +241,6 @@ public class FlightManager extends BaseManager { } } }); - KeyManager.getInstance().listen(KeyTools.createKey(ProductKey.KeyProductType), this, new CommonCallbacks.KeyListener() { @Override public void onValueChange(@Nullable ProductType productType, @Nullable ProductType t1) { @@ -248,7 +250,6 @@ public class FlightManager extends BaseManager { } } }); - //飞机SN号 KeyManager.getInstance().listen(createKey(FlightControllerKey.KeySerialNumber), this, new CommonCallbacks.KeyListener() { @Override @@ -259,7 +260,6 @@ public class FlightManager extends BaseManager { } } }); - //RID状态 KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyRidWorkingStatusPush), this, new CommonCallbacks.KeyListener() { @Override @@ -271,7 +271,6 @@ public class FlightManager extends BaseManager { } } }); - //rtk起飞高度(计算海拔高度使用) KeyManager.getInstance().listen(createKey(RtkMobileStationKey.KeyRTKTakeoffAltitudeInfo), this, new CommonCallbacks.KeyListener() { @Override @@ -305,10 +304,20 @@ public class FlightManager extends BaseManager { Movement.getInstance().setLatitude(newValue.getLatitude()); Movement.getInstance().setLongitude(newValue.getLongitude()); pushFlightAttitude(); + + + } } }); + KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyAircraftVelocity), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Velocity3D velocity3D, @Nullable Velocity3D t1) { + + } + }); + //水平&垂直速度 KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyAircraftVelocity), this, new CommonCallbacks.KeyListener() { @Override @@ -338,6 +347,17 @@ public class FlightManager extends BaseManager { } }); + KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyGPSSatelliteCount), this, new CommonCallbacks.KeyListener() { + @Override + public void onValueChange(@Nullable Integer integer, @Nullable Integer t1) { + if(t1!=null){ + Movement.getInstance().setGPSSatelliteCount(t1); + } + } + }); + + + KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyGPSSignalLevel), this, new CommonCallbacks.KeyListener() { @Override public void onValueChange(@Nullable GPSSignalLevel gpsSignalLevel, @Nullable GPSSignalLevel t1) { @@ -385,7 +405,7 @@ public class FlightManager extends BaseManager { KeyManager.getInstance().listen(createKey(FlightControllerKey.KeyWindDirection), this, new CommonCallbacks.KeyListener() { @Override public void onValueChange(@Nullable WindDirection windDirection, @Nullable WindDirection t1) { - if (t1!=null){ + if (t1 != null) { Movement.getInstance().setWind_direction(t1.value()); pushFlightAttitude(); } @@ -429,45 +449,45 @@ public class FlightManager extends BaseManager { Movement.getInstance().setPlaneMode(newValue.name()); pushFlightAttitude(); - switch (newValue){ - case TAKE_OFF_READY: - //Movement.getInstance().setMode_code(2); - break; - case VIRTUAL_STICK: - //Movement.getInstance().setMode_code(3); - break; - case AUTO_TAKE_OFF: - //我觉得可能会重复设置 - //Movement.getInstance().setMode_code(4); - break; - case WAYPOINT: - //Movement.getInstance().setMode_code(5); - break; - case PANO: - Movement.getInstance().setMode_code(6); - break; - case FOLLOW_ME: - Movement.getInstance().setMode_code(7); - break; - case AUTO_AVOIDANCE: - Movement.getInstance().setMode_code(8); - break; - case GO_HOME: - Movement.getInstance().setMode_code(9); - break; - case AUTO_LANDING: - Movement.getInstance().setMode_code(10); - //重置这个飞行状态 - Movement.getInstance().setFlightmode(0); - break; - case FORCE_LANDING: - Movement.getInstance().setMode_code(11); - break; - case POI: - Movement.getInstance().setMode_code(20); - break; + switch (newValue) { + case TAKE_OFF_READY: + //Movement.getInstance().setMode_code(2); + break; + case VIRTUAL_STICK: + //Movement.getInstance().setMode_code(3); + break; + case AUTO_TAKE_OFF: + //我觉得可能会重复设置 + //Movement.getInstance().setMode_code(4); + break; + case WAYPOINT: + //Movement.getInstance().setMode_code(5); + break; + case PANO: + Movement.getInstance().setMode_code(6); + break; + case FOLLOW_ME: + Movement.getInstance().setMode_code(7); + break; + case AUTO_AVOIDANCE: + Movement.getInstance().setMode_code(8); + break; + case GO_HOME: + Movement.getInstance().setMode_code(9); + break; + case AUTO_LANDING: + Movement.getInstance().setMode_code(10); + //重置这个飞行状态 + Movement.getInstance().setFlightmode(0); + break; + case FORCE_LANDING: + Movement.getInstance().setMode_code(11); + break; + case POI: + Movement.getInstance().setMode_code(20); + break; - } + } } } }); @@ -732,7 +752,7 @@ public class FlightManager extends BaseManager { //开舱门 openCabinDoor(); //降落时将云台朝下 - //gimbalDownwards(); + gimbalDownwards(); //返航时将云台归中,曝光ISO降低 //gimbalAndCameraReset(); //开始视觉识别降落 @@ -744,8 +764,9 @@ public class FlightManager extends BaseManager { //(决定飞机触发电量低的返航) public boolean isTriggerRoomBattrryLanding; + private void batteryLowLanding() { - if (isTriggerRoomBattrryLanding){ + if (isTriggerRoomBattrryLanding) { return; } int forcedBattery = Integer.valueOf(PreferenceUtils.getInstance().getForcedBattery()); @@ -754,23 +775,23 @@ public class FlightManager extends BaseManager { String missionState = Movement.getInstance().getWaypointMissionExecuteState(); boolean isMissionExecuting = (!TextUtils.isEmpty(missionState) && (missionState.equals("EXECUTING") || missionState.equals("ENTER_WAYLINE")) - ||(!TextUtils.isEmpty(Movement.getInstance().getPlaneMode()) - &&Movement.getInstance().getPlaneMode().equals("WAYPOINT"))); + || (!TextUtils.isEmpty(Movement.getInstance().getPlaneMode()) + && Movement.getInstance().getPlaneMode().equals("WAYPOINT"))); // 获取飞行状态和航线状态 - boolean isFlyingAndBatteryOk = isFlying &&value!=null&&value< forcedBattery&&isMissionExecuting; - boolean isAlterLandStatus=(PreferenceUtils.getInstance().getNeedTriggerAlterArucoLand()||PreferenceUtils.getInstance().getTriggerToAlternatePoint()); + boolean isFlyingAndBatteryOk = isFlying && value != null && value < forcedBattery && isMissionExecuting; + boolean isAlterLandStatus = (PreferenceUtils.getInstance().getNeedTriggerAlterArucoLand() || PreferenceUtils.getInstance().getTriggerToAlternatePoint()); - if (isFlyingAndBatteryOk&& !isTriggerRoomBattrryLanding&&!isAlterLandStatus) { + if (isFlyingAndBatteryOk && !isTriggerRoomBattrryLanding && !isAlterLandStatus) { isTriggerRoomBattrryLanding = true; KeyManager.getInstance().performAction(createKey(FlightControllerKey.KeyStartGoHome), new CommonCallbacks.CompletionCallbackWithParam() { @Override public void onSuccess(EmptyMsg emptyMsg) { - sendEvent2Server("电量低于阈值,强制返航",2); + sendEvent2Server("电量低于阈值,强制返航", 2); } @Override public void onFailure(@NonNull IDJIError error) { - sendEvent2Server("电量低于阈值,返航失败",2); + sendEvent2Server("电量低于阈值,返航失败", 2); } }); @@ -820,16 +841,15 @@ public class FlightManager extends BaseManager { //降落时将云台朝下 private void gimbalDownwards() { if (goHomeExecutionState == GoHomeState.LANDING.value() - && Movement.getInstance().getElevation() > 11 - && !isGimbalDownwards) { - DroneHelper.getInstance().setGimbalPitchDegree(); - //将镜头设置为自动对焦 - DroneHelper.getInstance().setCameraFocusMode(); - isGimbalDownwards = true; + && Movement.getInstance().getElevation() > 11) { +// DroneHelper.getInstance().setGimbalPitchDegree(); +// //将镜头设置为自动对焦 +// DroneHelper.getInstance().setCameraFocusMode(); +// isGimbalDownwards = true; PerceptionManager.getInstance().setPerceptionEnable(false); - if (Movement.getInstance().getIsRecording()==1){ - CameraManager.getInstance().stopRecordVideo(null); - } +// if (Movement.getInstance().getIsRecording() == 1) { +// CameraManager.getInstance().stopRecordVideo(null); +// } } } @@ -860,9 +880,7 @@ public class FlightManager extends BaseManager { } - - - private static final double FLYING_HEIGHT_THRESHOLD_MAX = 5; + private static final double FLYING_HEIGHT_THRESHOLD_MAX = 5.5; private static final double FLYING_HEIGHT_THRESHOLD_MAX_ALTERNATE = 10; private static final double FLYING_HEIGHT_THRESHOLD_MIN = -2; private static final double FLYING_HEIGHT_THRESHOLD_MIN_ALTERNATE = 2.0; @@ -907,17 +925,17 @@ public class FlightManager extends BaseManager { PreferenceUtils.getInstance().setNeedTriggerAlterArucoLand(true); PreferenceUtils.getInstance().setNeedTriggerApronArucoLand(false); LogUtil.log(TAG, "开始识别备降点二维码,椭球高度:" + Movement.getInstance().getElevation() + "米" + "--超声波高度:" + Movement.getInstance().getUltrasonicHeight() + "分米"); - sendEvent2Server("开始备降点视觉降落",1); + sendEvent2Server("开始备降点视觉降落", 1); } else { LogUtil.log(TAG, "识别ApronTag:" + PreferenceUtils.getInstance().getNeedTriggerApronArucoLand()); EventBus.getDefault().post(FLAG_START_DETECT_ARUCO_APRON); PreferenceUtils.getInstance().setNeedTriggerAlterArucoLand(false); PreferenceUtils.getInstance().setNeedTriggerApronArucoLand(true); LogUtil.log(TAG, "开始识别机库二维码,椭球高度:" + Movement.getInstance().getElevation() + "米" + "--超声波高度:" + Movement.getInstance().getUltrasonicHeight() + "分米"); - sendEvent2Server("开始视觉降落",1); + sendEvent2Server("开始视觉降落", 1); } isSendDetect = true; - PerceptionManager.getInstance().setPerceptionEnable(false); + //PerceptionManager.getInstance().setPerceptionEnable(false); } @@ -966,8 +984,8 @@ public class FlightManager extends BaseManager { return !isTriggerLanding && (isFlying || isMotorsOn) && AlternateArucoDetect.getInstance().isCanLanding(); } else { return !isTriggerLanding && (isFlying || isMotorsOn) && ( - ApronArucoDetect.getInstance().isCanLanding()|| (ApronArucoDetect.getInstance().isStartFastStick() - && ApronArucoDetect.getInstance().getCheckThrowingErrorsTimes() > 100)); + ApronArucoDetect.getInstance().isCanLanding() || (ApronArucoDetect.getInstance().isStartFastStick() + && ApronArucoDetect.getInstance().getCheckThrowingErrorsTimes() > 100)); } } @@ -996,7 +1014,7 @@ public class FlightManager extends BaseManager { if (!PreferenceUtils.getInstance().getNeedTriggerAlterArucoLand()) { // 发送无人机入库消息到服务器********************待修改************************ ApronExecutionStatus.getInstance().setAircraftWaitShutDown(false); - DockStorageManager.getInstance().sendDockStorageMsg2Server( ); + DockStorageManager.getInstance().sendDockStorageMsg2Server(); } // 上传媒体文件 SystemManager.getInstance().upLoadMedia(MqttManager.getInstance().mqttAndroidClient); @@ -1015,7 +1033,7 @@ public class FlightManager extends BaseManager { Movement.getInstance().setMissionFinish1(true); Movement.getInstance().setTask_current_step(25); - sendOpenCabinDoorMsg=false; + sendOpenCabinDoorMsg = false; } } @@ -1035,15 +1053,16 @@ public class FlightManager extends BaseManager { KeyManager.getInstance().performAction(createKey(FlightControllerKey.KeyStartGoHome), new CommonCallbacks.CompletionCallbackWithParam() { @Override public void onSuccess(EmptyMsg emptyMsg) { - sendMsg2Server( message); + sendMsg2Server(message); } + @Override public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server( message, "返航执行失败:" + getIDJIErrorMsg(error)); + sendFailMsg2Server(message, "返航执行失败:" + getIDJIErrorMsg(error)); } }); } else { - sendFailMsg2Server( message, "返航执行失败:飞控未连接"); + sendFailMsg2Server(message, "返航执行失败:飞控未连接"); } } @@ -1058,22 +1077,21 @@ public class FlightManager extends BaseManager { public void onSuccess(EmptyMsg emptyMsg) { //只有在取消返航时才能显示取消返航失败 Movement.getInstance().setMode_code(3); - sendMsg2Server( message); + sendMsg2Server(message); } @Override public void onFailure(@NonNull IDJIError error) { - LogUtil.log(TAG,"取消返航执行失败"+error); - sendFailMsg2Server( message, "取消返航执行失败:" + getIDJIErrorMsg(error)); + LogUtil.log(TAG, "取消返航执行失败" + error); + sendFailMsg2Server(message, "取消返航执行失败:" + getIDJIErrorMsg(error)); } }); } else { - sendFailMsg2Server( message, "飞控未连接"); + sendFailMsg2Server(message, "飞控未连接"); } } - private void resetAircrftLandingStatus() { // 避免在下次起飞时触发视觉识别 PreferenceUtils.getInstance().setNeedTriggerApronArucoLand(false); @@ -1133,21 +1151,21 @@ public class FlightManager extends BaseManager { KeyManager.getInstance().performAction(createKey(FlightControllerKey.KeyStartAutoLanding), new CommonCallbacks.CompletionCallbackWithParam() { @Override public void onSuccess(EmptyMsg emptyMsg) { - if (message!=null){ - sendMsg2Server( message); + if (message != null) { + sendMsg2Server(message); } } @Override public void onFailure(@NonNull IDJIError error) { LogUtil.log(TAG, "降落失败:" + new Gson().toJson(error)); - if (message!=null){ - sendFailMsg2Server( message, "降落失败:" + getIDJIErrorMsg(error)); + if (message != null) { + sendFailMsg2Server(message, "降落失败:" + getIDJIErrorMsg(error)); } } }); } else { - sendFailMsg2Server( message, "飞控未连接"); + sendFailMsg2Server(message, "飞控未连接"); } } @@ -1155,6 +1173,7 @@ public class FlightManager extends BaseManager { * 紧急悬停 */ public void emergencyHover(MessageDown message) { + FlightMode flightMode = KeyManager.getInstance().getValue(createKey(FlightControllerKey.KeyFlightMode)); if (flightMode != null) { switch (flightMode) { @@ -1163,14 +1182,13 @@ public class FlightManager extends BaseManager { @Override public void onSuccess(EmptyMsg emptyMsg) { LogUtil.log(TAG, "紧急悬停,取消返航成功"); - sendMsg2Server( message); + sendMsg2Server(message); resetAircrftLandingStatus(); - } @Override public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server( message, "紧急悬停,取消返航失败:" + getIDJIErrorMsg(error)); + sendFailMsg2Server(message, "紧急悬停,取消返航失败:" + getIDJIErrorMsg(error)); } }); break; @@ -1181,14 +1199,14 @@ public class FlightManager extends BaseManager { @Override public void onSuccess() { LogUtil.log(TAG, "紧急悬停,终止任务成功"); - sendMsg2Server( message); + sendMsg2Server(message); resetAircrftLandingStatus(); } @Override public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server( message, "紧急悬停,终止任务失败:" + getIDJIErrorMsg(error)); + sendFailMsg2Server(message, "紧急悬停,终止任务失败:" + getIDJIErrorMsg(error)); } }); break; @@ -1196,7 +1214,7 @@ public class FlightManager extends BaseManager { KeyManager.getInstance().performAction(createKey(FlightControllerKey.KeyStopAutoLanding), new CommonCallbacks.CompletionCallbackWithParam() { @Override public void onSuccess(EmptyMsg emptyMsg) { - sendMsg2Server( message); + sendMsg2Server(message); resetAircrftLandingStatus(); } @@ -1204,7 +1222,7 @@ public class FlightManager extends BaseManager { @Override public void onFailure(@NonNull IDJIError error) { LogUtil.log(TAG, "紧急悬停,取消降落失败:" + new Gson().toJson(error)); - sendFailMsg2Server( message, "紧急悬停,取消降落失败:" + getIDJIErrorMsg(error)); + sendFailMsg2Server(message, "紧急悬停,取消降落失败:" + getIDJIErrorMsg(error)); } }); break; @@ -1213,19 +1231,52 @@ public class FlightManager extends BaseManager { @Override public void onSuccess() { LogUtil.log(TAG, "紧急悬停,控制权释放成功"); - sendMsg2Server( message); + sendMsg2Server(message); resetAircrftLandingStatus(); } @Override public void onFailure(@NonNull IDJIError error) { - sendFailMsg2Server( message, "紧急悬停,控制权失败:" + getIDJIErrorMsg(error)); + sendFailMsg2Server(message, "紧急悬停,控制权失败:" + getIDJIErrorMsg(error)); } }); break; } } + if (Movement.getInstance().isOpendrc() == true) { + //直接关闭虚拟摇杆 + VirtualStickManager.getInstance().disableVirtualStick(new CommonCallbacks.CompletionCallback() { + @Override + public void onSuccess() { + LogUtil.log(TAG, "紧急悬停,控制权释放成功"); + sendMsg2Server(message); + resetAircrftLandingStatus(); + Movement.getInstance().setOpendrc(false); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + sendFailMsg2Server(message, "紧急悬停,控制权失败:" + getIDJIErrorMsg(error)); + } + }); + } + VirtualStickManager.getInstance().setVirtualStickAdvancedModeEnabled(true); + VirtualStickManager.getInstance().enableVirtualStick(new CommonCallbacks.CompletionCallback() { + @Override + public void onSuccess() { + LogUtil.log(TAG, "紧急悬停获得控制权成功"); + sendMsg2Server(message); + resetAircrftLandingStatus(); + Movement.getInstance().setOpendrc(true); + Movement.getInstance().setMode_code(3); + OSDManager.getInstance().pushFlightAttitude(); + } + + @Override + public void onFailure(@NonNull IDJIError error) { + sendFailMsg2Server(message, "紧急悬停获得控制权失败" + getIDJIErrorMsg(error)); + } + }); + } - - } diff --git a/app/src/main/java/com/aros/apron/manager/FlightTaskProgressManager.java b/app/src/main/java/com/aros/apron/manager/FlightTaskProgressManager.java index c02f4f3a..4dd22180 100644 --- a/app/src/main/java/com/aros/apron/manager/FlightTaskProgressManager.java +++ b/app/src/main/java/com/aros/apron/manager/FlightTaskProgressManager.java @@ -38,20 +38,15 @@ public class FlightTaskProgressManager extends BaseManager { // sendFlightTaskProgress2Server(); // // } - //只要一个满足就上报 if (Movement.getInstance().isPlaneWing() || Movement.getInstance().isMotorsOn()) { sendFlightTaskProgress2Server(); } - - if (Movement.getInstance().isMissionFinish1()) { sendFlightTaskProgress2Server(); handler.removeCallbacks(this); return; } - - // 始终基于“实际执行时间”来调度 handler.postDelayed(this, INTERVAL); } diff --git a/app/src/main/java/com/aros/apron/manager/FlyToPointManager.java b/app/src/main/java/com/aros/apron/manager/FlyToPointManager.java index ca872595..6d34e364 100644 --- a/app/src/main/java/com/aros/apron/manager/FlyToPointManager.java +++ b/app/src/main/java/com/aros/apron/manager/FlyToPointManager.java @@ -149,7 +149,7 @@ public class FlyToPointManager extends BaseManager { KeyConnection)); if (isConnect != null && isConnect) { - WaypointMissionManager.getInstance().pushKMZFileToAircraft(Environment.getExternalStorageDirectory().getPath() + "/" + "FlyTo.kmz", new CommonCallbacks.CompletionCallbackWithProgress() { + WaypointMissionManager.getInstance().pushKMZFileToAircraft(getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + "/" + "FlyTo.kmz", new CommonCallbacks.CompletionCallbackWithProgress() { @Override public void onProgressUpdate(Double progress) { sendEvent2Server("指点航线上传进度:" + progress, 1); @@ -176,7 +176,7 @@ public class FlyToPointManager extends BaseManager { sendFailMsg2Server(message,"指点航线上传失败:"+ Utils.getIDJIErrorMsg(error)); //待机 Movement.getInstance().setMode_code(0); - OSDManager.getInstance().pushFlightAttitude(); + sendFlightTaskProgress2Server(); } }); } @@ -204,6 +204,7 @@ public class FlyToPointManager extends BaseManager { //指令飞行( 指点前置不需要起飞准备这些因为没有指点起飞的航线) Movement.getInstance().setMode_code(17); + sendFlightTaskProgress2Server(); } @Override @@ -211,10 +212,11 @@ public class FlyToPointManager extends BaseManager { sendFailMsg2Server(message,"指点航线执行失败:" + new Gson().toJson(error)); //待机 Movement.getInstance().setMode_code(0); - OSDManager.getInstance().pushFlightAttitude(); + sendFlightTaskProgress2Server(); + } }; - WaypointMissionManager.getInstance().startMission("ToPoint", callback); + WaypointMissionManager.getInstance().startMission("FlyTo", callback); } else { sendEvent2Server("指点任务开始失败,设备未连接", 2); } @@ -225,7 +227,7 @@ public class FlyToPointManager extends BaseManager { KeyConnection)); if (isConnect != null && isConnect) { IWaypointMissionManager missionManager = WaypointMissionManager.getInstance(); - missionManager.stopMission("ToPoint", new CommonCallbacks.CompletionCallback() { + missionManager.stopMission("FlyTo", new CommonCallbacks.CompletionCallback() { @Override public void onSuccess() { sendMsg2Server(message); diff --git a/app/src/main/java/com/aros/apron/manager/GimbalManager.java b/app/src/main/java/com/aros/apron/manager/GimbalManager.java index 6ecc55c3..8402fd32 100644 --- a/app/src/main/java/com/aros/apron/manager/GimbalManager.java +++ b/app/src/main/java/com/aros/apron/manager/GimbalManager.java @@ -260,6 +260,7 @@ public class GimbalManager extends BaseManager { public void gimbalLookAt(MessageDown message) { Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(GimbalKey. KeyConnection, ComponentIndexType.PORT_1)); + // LogUtil.log(TAG,"isConnect"+isConnect); if (isConnect != null && isConnect) { LookAtInfo lookAtInfo = new LookAtInfo(); lookAtInfo.setMode(message.getData().isLocked() ? @@ -272,11 +273,13 @@ public class GimbalManager extends BaseManager { KeyManager.getInstance().performAction(KeyTools.createKey(FlightControllerKey.KeyLookAt), lookAtInfo, new CommonCallbacks.CompletionCallbackWithParam() { @Override public void onSuccess(EmptyMsg emptyMsg) { + LogUtil.log(TAG,"看向目标点成功"); sendMsg2Server(message); } @Override public void onFailure(@NonNull IDJIError error) { + LogUtil.log(TAG,"看向目标点失败"); sendFailMsg2Server(message, "看向目标点失败:" + getIDJIErrorMsg(error)); } } diff --git a/app/src/main/java/com/aros/apron/manager/MediaManager.java b/app/src/main/java/com/aros/apron/manager/MediaManager.java index 11baf5e0..d9ee1849 100644 --- a/app/src/main/java/com/aros/apron/manager/MediaManager.java +++ b/app/src/main/java/com/aros/apron/manager/MediaManager.java @@ -19,6 +19,7 @@ import com.amazonaws.services.s3.model.ProgressListener; import com.amazonaws.services.s3.model.PutObjectRequest; import com.aros.apron.base.BaseManager; import com.aros.apron.entity.ApronExecutionStatus; +import com.aros.apron.entity.Movement; import com.aros.apron.tools.LogUtil; import com.aros.apron.tools.PreferenceUtils; import com.autonavi.base.amap.mapcore.FileUtil; @@ -140,6 +141,9 @@ public class MediaManager extends BaseManager { if (mState == MediaFileListState.UP_TO_DATE) { mediaFiles = MediaDataCenter.getInstance().getMediaManager().getMediaFileListData().getData(); + //倒是看会不会上传 + Movement.getInstance().setTask_media_count(mediaFiles.size()); + if (mediaFiles != null&&mediaFiles.size()>0) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { pullOriginalMediaFileFromCamera(); diff --git a/app/src/main/java/com/aros/apron/manager/MissionV3Manager.java b/app/src/main/java/com/aros/apron/manager/MissionV3Manager.java index 1f21e5a1..fcfc901e 100644 --- a/app/src/main/java/com/aros/apron/manager/MissionV3Manager.java +++ b/app/src/main/java/com/aros/apron/manager/MissionV3Manager.java @@ -324,42 +324,6 @@ public class MissionV3Manager extends BaseManager { //4.信号收敛(等待GPS搜星) if (statusOk) { verifyGpsAndMissionState(message); - - -// String planeMessage = Movement.getInstance().getPlaneMessage(); -// int quality = Movement.getInstance().getQuality(); -// -// boolean isPlaneMessageValid = !TextUtils.isEmpty(planeMessage) && !planeMessage.equals("无法起飞"); -// boolean isGpsQualityValid = (quality == 4 || quality == 5 || quality == 10); -// -// -// -// int tryCount = 99; -// while(--tryCount > 0){ -// //下方航线 -// if(isPlaneMessageValid && isGpsQualityValid){ -// //下发航线 -// downLoadKMZFile(message); -// //等待航线状态为: -// int awaitTime =30; -// while(--awaitTime>0){ -// int modeCode= Movement.getInstance().getMode_code(); -// if( modeCode == 4){ -// break; -// }else { -// sleep(1s) -// } -// } -// if(awaitTime>0){ -// breeak; -// } -// } -// -// -// -// } - - } }); } @@ -432,14 +396,18 @@ public class MissionV3Manager extends BaseManager { int missionStateCode = Movement.getInstance().getMissionStateCode(); String planeMessage = Movement.getInstance().getPlaneMessage(); int quality = Movement.getInstance().getQuality(); + int GPSSatelliteCount=Movement.getInstance().getGPSSatelliteCount(); boolean isMissionStateValid = (missionStateCode == 2 || missionStateCode == 0 || missionStateCode == 7); boolean isPlaneMessageValid = !TextUtils.isEmpty(planeMessage) && !planeMessage.equals("无法起飞"); boolean isGpsQualityValid = (quality == 4 || quality == 5 || quality == 10); + boolean GPSSatelliteCountValid=GPSSatelliteCount>15; LogUtil.log(TAG,"isMissionStateValid"+isMissionStateValid+"isPlaneMessageValid"+isPlaneMessageValid+"isGpsQualityValid"+isGpsQualityValid); // if (isMissionStateValid && isPlaneMessageValid && isGpsQualityValid) { - if (isPlaneMessageValid && isGpsQualityValid) { + + //sendEvent2Server("卫星数量"+GPSSatelliteCount,1); + if (isGpsQualityValid||GPSSatelliteCountValid) { //5.下载航线 downLoadKMZFile(message); verifyGpsAndMissionStateSuccess = true; @@ -601,7 +569,7 @@ public class MissionV3Manager extends BaseManager { //自主起飞 Movement.getInstance().setMode_code(4); - OSDManager.getInstance().pushFlightAttitude(); + sendFlightTaskProgress2Server(); Movement.getInstance().setTask_current_step(22); startMission(message); @@ -630,7 +598,7 @@ public class MissionV3Manager extends BaseManager { } else { //待机 Movement.getInstance().setMode_code(0); - OSDManager.getInstance().pushFlightAttitude(); + sendFlightTaskProgress2Server(); sendEvent2Server("航线第" + pushKMZFileTimes + "次上传失败,直接关机", 2); TaskFailManager.getInstance().sendTaskFailMsg2Server(-1); @@ -702,7 +670,7 @@ public class MissionV3Manager extends BaseManager { //待机 Movement.getInstance().setMode_code(0); - OSDManager.getInstance().pushFlightAttitude(); + sendFlightTaskProgress2Server(); sendEvent2Server("航线第" + startMissionFailTimes + "次开始失败,直接关机:" + "---" + new Gson().toJson(error) + "--" + Movement.getInstance().getQuality(), 2); TaskFailManager.getInstance().sendTaskFailMsg2Server(-1); diff --git a/app/src/main/java/com/aros/apron/manager/OSDManager.java b/app/src/main/java/com/aros/apron/manager/OSDManager.java index 180c30ec..57137057 100644 --- a/app/src/main/java/com/aros/apron/manager/OSDManager.java +++ b/app/src/main/java/com/aros/apron/manager/OSDManager.java @@ -68,10 +68,14 @@ public class OSDManager extends BaseManager { } lastExecuteTime = now; Boolean isConnect = KeyManager.getInstance().getValue(createKey(FlightControllerKey.KeyConnection)); - if (isConnect != null && isConnect && !Movement.getInstance().isMissionFinish()) { - pushFlightAttitude(); - }else{ - LogUtil.log(TAG,"osd stop:flight controller is null"); + if (!Movement.getInstance().isMissionFinish()) { + if (isConnect != null && isConnect) { + pushFlightAttitude(); + } else { + LogUtil.log(TAG, "osd stop:flight controller is null"); + } + } else { + LogUtil.log(TAG, "osd stop:flight controller is null"); } // 始终基于“实际执行时间”来调度 handler.postDelayed(this, INTERVAL); @@ -96,8 +100,6 @@ public class OSDManager extends BaseManager { public void pushFlightAttitude() { try { - - if (batteries != null && batteries.size() > 0) { batteries.clear(); } diff --git a/app/src/main/java/com/aros/apron/manager/PerceptionManager.java b/app/src/main/java/com/aros/apron/manager/PerceptionManager.java index 031f58b4..68a899a6 100644 --- a/app/src/main/java/com/aros/apron/manager/PerceptionManager.java +++ b/app/src/main/java/com/aros/apron/manager/PerceptionManager.java @@ -39,6 +39,7 @@ public class PerceptionManager extends BaseManager { private boolean closePerceptionSuccess; public void setPerceptionEnable(boolean perceptionEnable) { + if (PreferenceUtils.getInstance().getCloseObsEnable() && perceptionEnable) { LogUtil.log(TAG, "全局避障关闭,不开启避障"); return; @@ -53,7 +54,7 @@ public class PerceptionManager extends BaseManager { LogUtil.log(TAG, "避障开启"); } else { closePerceptionSuccess = true; - LogUtil.log(TAG, "避障关闭"); + //LogUtil.log(TAG, "避障关闭"); } } diff --git a/app/src/main/java/com/aros/apron/manager/PlayLoadManager.java b/app/src/main/java/com/aros/apron/manager/PlayLoadManager.java new file mode 100644 index 00000000..111109a9 --- /dev/null +++ b/app/src/main/java/com/aros/apron/manager/PlayLoadManager.java @@ -0,0 +1,78 @@ +package com.aros.apron.manager; + +import androidx.annotation.NonNull; + +import com.aros.apron.entity.PayloadInfo; +import com.aros.apron.tools.LogUtil; + +import java.util.Map; + +import dji.sdk.keyvalue.key.FlightControllerKey; +import dji.sdk.keyvalue.key.KeyTools; +import dji.v5.common.callback.CommonCallbacks; +import dji.v5.common.error.IDJIError; +import dji.v5.manager.KeyManager; +import dji.v5.manager.aircraft.payload.PayloadCenter; +import dji.v5.manager.aircraft.payload.PayloadIndexType; +import dji.v5.manager.aircraft.payload.data.PayloadWidgetInfo; +import dji.v5.manager.aircraft.payload.listener.PayloadBasicInfoListener; +import dji.v5.manager.aircraft.payload.listener.PayloadDataListener; +import dji.v5.manager.aircraft.payload.listener.PayloadWidgetInfoListener; +import dji.v5.manager.interfaces.IPayloadManager; + +public class PlayLoadManager { + + private String TAG = this.getClass().getSimpleName(); + + private PlayLoadManager() { + } + + public static PlayLoadManager getInstance() { + return PlayLoadManagerHolder.INSTANCE; + } + + private static class PlayLoadManagerHolder { + private static final PlayLoadManager INSTANCE = new PlayLoadManager(); + } + + public void init() { + Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(FlightControllerKey.KeyConnection)); + if (isConnect != null && isConnect) { + Map payloadManager = PayloadCenter.getInstance().getPayloadManager(); + if (payloadManager != null) { + IPayloadManager iPayloadManager = payloadManager.get(PayloadIndexType.PORT_1); + if (iPayloadManager != null) { + + + iPayloadManager.addPayloadWidgetInfoListener(new PayloadWidgetInfoListener() { + @Override + public void onPayloadWidgetInfoUpdate(PayloadWidgetInfo info) { + LogUtil.log(TAG,"负载信息"+info.toString()); + } + }); + + iPayloadManager.pullWidgetInfoFromPayload(new CommonCallbacks.CompletionCallback() { + @Override + public void onSuccess() { + LogUtil.log(TAG,"拉取成功"); + } + + @Override + public void onFailure(@NonNull IDJIError idjiError) { + LogUtil.log(TAG,"拉取成功"); + } + }); + + + + + } else { + LogUtil.log(TAG, "监听EXTERNAL PSDK数据失败:设备未连接"); + } + + + } + } + + } +} diff --git a/app/src/main/java/com/aros/apron/manager/StickManager.java b/app/src/main/java/com/aros/apron/manager/StickManager.java index c3aa7ce4..620ab6d6 100644 --- a/app/src/main/java/com/aros/apron/manager/StickManager.java +++ b/app/src/main/java/com/aros/apron/manager/StickManager.java @@ -4,6 +4,7 @@ import static com.aros.apron.tools.Utils.getIDJIErrorMsg; import static dji.sdk.keyvalue.key.KeyTools.createKey; import android.os.Handler; +import android.os.Looper; import android.text.TextUtils; import androidx.annotation.NonNull; @@ -58,6 +59,8 @@ public class StickManager extends BaseManager { public void onSuccess() { LogUtil.log(TAG, "控制权获取成功"); VirtualStickManager.getInstance().setVirtualStickAdvancedModeEnabled(true); + + } @Override public void onFailure(@NonNull IDJIError error) { @@ -83,15 +86,19 @@ public class StickManager extends BaseManager { } - //获得拟摇杆控制权 + //取消虚拟摇杆控制权 public void enableVirtualStick(MessageDown message) { + //吐过开启了drc或者使用过摇杆 + if(Movement.getInstance().isOpendrc()==false){ VirtualStickManager.getInstance().setVirtualStickAdvancedModeEnabled(true); VirtualStickManager.getInstance().enableVirtualStick(new CommonCallbacks.CompletionCallback() { @Override public void onSuccess() { + Movement.getInstance().setOpendrc(true); if (message != null) { sendMsg2Server(message); } + LogUtil.log(TAG, "控制权获取成功"); VirtualStickManager.getInstance().setVirtualStickAdvancedModeEnabled(true); //获得过控制权 @@ -106,6 +113,8 @@ public class StickManager extends BaseManager { } } }); + + } } //取消虚拟摇杆控制权 @@ -115,7 +124,6 @@ public class StickManager extends BaseManager { public void onSuccess() { if (message != null) { sendMsg2Server(message); - if(Movement.getInstance().getFlightmode()==1){ Movement.getInstance().setMode_code(5); }else if(Movement.getInstance().getFlightmode()==2){ @@ -138,15 +146,17 @@ public class StickManager extends BaseManager { }); } - - //飞行控制权抢夺 public void setVirtualStickModeEnabled(MessageDown message) { + //Movement.getInstance().setMode_code(3); //设置标志为 - Movement.getInstance().setOpendrc(true); - StickManager.getInstance().enableVirtualStick(message); - sendMsg2Server(message); + new Handler(Looper.getMainLooper()).postDelayed(() -> { + // 这里放你要延迟执行的代码 + StickManager.getInstance().enableVirtualStick(message); + }, 2000); + + //sendMsg2Server(message); ////// Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(FlightControllerKey.KeyConnection)); ////// if (isConnect != null && isConnect) { @@ -238,7 +248,6 @@ public class StickManager extends BaseManager { LogUtil.log(TAG,"飞机未起飞:禁止手控"); return; } - VirtualStickFlightControlParam param = new VirtualStickFlightControlParam(); param.setRollPitchControlMode(RollPitchControlMode.VELOCITY);// param.setYawControlMode(YawControlMode.ANGULAR_VELOCITY); @@ -260,7 +269,6 @@ public class StickManager extends BaseManager { param.setVerticalThrottle(Double.valueOf(message.getData().getH()));//上下(速度模式-4m/s-4m/s) } - //手动飞行 Movement.getInstance().setMode_code(16); VirtualStickManager.getInstance().sendVirtualStickAdvancedParam(param); diff --git a/app/src/main/java/com/aros/apron/manager/TakeOffToPointManager.java b/app/src/main/java/com/aros/apron/manager/TakeOffToPointManager.java index fc2563ed..9ebe1e15 100644 --- a/app/src/main/java/com/aros/apron/manager/TakeOffToPointManager.java +++ b/app/src/main/java/com/aros/apron/manager/TakeOffToPointManager.java @@ -7,6 +7,7 @@ import android.os.Environment; import android.os.Handler; import android.os.Looper; import android.text.TextUtils; +import android.util.Log; import androidx.annotation.NonNull; @@ -17,10 +18,12 @@ import com.aros.apron.entity.ApronExecutionStatus; import com.aros.apron.entity.CurrentWayline; import com.aros.apron.entity.FlightMission; import com.aros.apron.entity.MessageDown; +import com.aros.apron.entity.MissionDataBean; import com.aros.apron.entity.MissionPoint; import com.aros.apron.entity.Movement; import com.aros.apron.tools.DomParserKML; import com.aros.apron.tools.DomParserWPML; +import com.aros.apron.tools.Generakmztools; import com.aros.apron.tools.LogUtil; import com.aros.apron.tools.PreferenceUtils; import com.aros.apron.tools.RestartAPPTool; @@ -39,6 +42,8 @@ import dji.sdk.keyvalue.key.KeyTools; import dji.sdk.keyvalue.value.flightcontroller.RemoteControllerFlightMode; import dji.sdk.wpmz.value.mission.Wayline; import dji.sdk.wpmz.value.mission.WaylineExecuteWaypoint; +import dji.sdk.wpmz.value.mission.WaylineMissionConfig; +import dji.sdk.wpmz.value.mission.WaylineMissionConfigParseInfo; import dji.sdk.wpmz.value.mission.WaylineWaylinesParseInfo; import dji.v5.common.callback.CommonCallbacks; import dji.v5.common.error.IDJIError; @@ -67,6 +72,7 @@ public class TakeOffToPointManager extends BaseManager { //收到一键起飞航线 public void taskExecute(MessageDown message) { + PreferenceUtils.getInstance().setMissionType(1); PreferenceUtils.getInstance().setFlightId(message.getData().getFlight_id()); PreferenceUtils.getInstance().setAlternatePointLon(message.getData().getAlternate_land_point().getLongitude() + ""); @@ -75,7 +81,7 @@ public class TakeOffToPointManager extends BaseManager { message.getData().getAlternate_land_point().getSafe_land_height() + ""); Movement.getInstance().setTask_current_step(5); - + LogUtil.log(TAG,"生成"); //1.检查图传是否连接 checkVtxWithDelay(() -> { //避免重复执行 @@ -88,8 +94,10 @@ public class TakeOffToPointManager extends BaseManager { boolean statusOk = verifyAircraftStatus(message); //4.信号收敛(等待GPS搜星) if (statusOk) { + LogUtil.log(TAG,"verifyGpsAndMissionState(message)执行了"); verifyGpsAndMissionState(message); } + }); } @@ -120,12 +128,12 @@ public class TakeOffToPointManager extends BaseManager { TaskFailManager.getInstance().sendTaskFailMsg2Server(-1); return false; } - //6.检查航线参数 - if (message.getData().getFile() == null) { - sendEvent2Server("航线参数异常",2); - TaskFailManager.getInstance().sendTaskFailMsg2Server(-1); - return false; - } +// //6.检查航线参数 +// if (message.getData().getFile() == null) { +// sendEvent2Server("航线参数异常",2); +// TaskFailManager.getInstance().sendTaskFailMsg2Server(-1); +// return false; +// } //7.检查电池电量 Integer value = KeyManager.getInstance().getValue(createKey(FlightControllerKey. KeyBatteryPowerPercent, 0)); @@ -171,6 +179,7 @@ public class TakeOffToPointManager extends BaseManager { // if (isMissionStateValid && isPlaneMessageValid && isGpsQualityValid) { if (isPlaneMessageValid && isGpsQualityValid) { //5.生成航线 + LogUtil.log(TAG,"执行toGenerateKMZFile"); toGenerateKMZFile(message); verifyGpsAndMissionStateSuccess = true; } else { @@ -217,68 +226,14 @@ public class TakeOffToPointManager extends BaseManager { */ public void toGenerateKMZFile(MessageDown message) { Movement.getInstance().setTask_current_step(16); - // 创建第一个 MissionPoint 对象 - MissionPoint missionPoint = new MissionPoint(); - missionPoint.setLat(String.valueOf(Movement.getInstance().getLatitude())); - missionPoint.setLng(String.valueOf(Movement.getInstance().getLongitude())); - missionPoint.setSpeed(Double.parseDouble(message.getData().getMax_speed())); - missionPoint.setExecuteHeight(message.getData().getTarget_height() - 1); - - // 创建第二个 MissionPoint 对象 - MissionPoint missionPoint1 = new MissionPoint(); - missionPoint1.setLat(message.getData().getTarget_latitude() + ""); - missionPoint1.setLng(message.getData().getTarget_longitude() + ""); - missionPoint1.setSpeed(Double.parseDouble(message.getData().getMax_speed())); - missionPoint1.setExecuteHeight(message.getData().getTarget_height()); - - // 创建一个 MissionPoint 列表 - List missionPoints = new ArrayList<>(); - missionPoints.add(missionPoint); - missionPoints.add(missionPoint1); - - // 创建 FlightMission 对象并设置其属性 - FlightMission flightMission = new FlightMission(); - flightMission.setPoints(missionPoints); - flightMission.setMissionId(2); - flightMission.setFinishAction("noAction"); - flightMission.setTakeOffSecurityHeight( - Float.parseFloat(message.getData().getSecurity_takeoff_height())); - flightMission.setSpeed(Double.parseDouble(message.getData().getMax_speed())); - - LogUtil.log(TAG, "当前高度:" + Movement.getInstance().getElevation() - + "-一键起飞安全起飞高度:" + message.getData().getSecurity_takeoff_height()); - - sendEvent2Server("开始生成一键起飞航线", 1); - - // 生成xml文件 - File file1 = new File( - getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + File.separator + "wpmz"); - if (!file1.exists()) { - if (file1.mkdirs()) { - sendEvent2Server("一键起飞航线文件生成成功", 1); - } else { - sendEvent2Server("一键起飞航线文件生成失败", 2); - } + MissionDataBean data = new Gson().fromJson(new Gson().toJson(message.getData()), MissionDataBean.class); + Boolean generateKmz=Generakmztools.getInstance().generateKmz(data); + LogUtil.log(TAG,"生成的boole"+generateKmz); + if(generateKmz==true){ + pushKMZFileToAircraft(message); + }else{ + sendEvent2Server("航线生成失败", 1); } - DomParserKML domParserKML = new DomParserKML(getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + File.separator + "wpmz", - "/template.kml"); - domParserKML.createKml(flightMission); - - DomParserWPML domParserWPML = new DomParserWPML(getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + File.separator + "wpmz", - "/waylines.wpml"); - domParserWPML.createWpml(flightMission); - - File kmzFile = new File(getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS) + File.separator + "ToPoint.kmz"); - kmzFile.getParentFile().mkdirs(); - - try { - ZipUtil.zip(getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + "/wpmz", - getExternalStoragePublicDirectory("KMZ").getAbsolutePath() + File.separator + "ToPoint.kmz"); - } catch (IOException e) { - sendEvent2Server("一键起飞任务生成异常", 2); - throw new RuntimeException(e); - } - pushKMZFileToAircraft(message); } private int pushKMZFileTimes = 0; @@ -298,22 +253,23 @@ public class TakeOffToPointManager extends BaseManager { * 6.上传指点航线 * @param message */ - private void pushKMZFileToAircraft(MessageDown message) { + public void pushKMZFileToAircraft(MessageDown message) { Boolean isConnect = KeyManager.getInstance().getValue(KeyTools.createKey(FlightControllerKey. KeyConnection)); if (isConnect != null && isConnect) { - - KMZInfo kmzInfo = WPMZManager.getInstance().getKMZInfo( - Environment.getExternalStorageDirectory().getPath() + "/" + "ToPoint.kmz"); + String kmzAbsPath = "/storage/self/primary/DJIDemo/cache/kmz/takeofftopoint.kmz"; + KMZInfo kmzInfo = WPMZManager.getInstance().getKMZInfo(kmzAbsPath); if (kmzInfo != null) { // Utils.printJson(TAG,"航点详情:"+new Gson().toJson(kmzInfo)); WaylineWaylinesParseInfo waylineWaylinesParseInfo = kmzInfo.getWaylineWaylinesParseInfo(); + WaylineMissionConfig configParseInfo= kmzInfo.getWaylineMissionConfigParseInfo().getConfig(); if (waylineWaylinesParseInfo != null) { List waylines = waylineWaylinesParseInfo.getWaylines(); - if (waylines != null && waylines.size() > 0) { + if (waylines != null && waylines.size() >0) { List waypoints = waylines.get(0).getWaypoints(); if (waypoints != null && waypoints.size() > 0) { //将航点列表保存在本地 + Movement.getInstance().setSpeed(configParseInfo.getGlobalTransitionalSpeed()); CurrentWayline.getInstance().setWaypoints(waypoints); LogUtil.log(TAG, "该航线有" + waypoints.size() + "个航点"); } else { @@ -332,18 +288,20 @@ public class TakeOffToPointManager extends BaseManager { } - WaypointMissionManager.getInstance().pushKMZFileToAircraft(Environment.getExternalStorageDirectory().getPath() + "/" + "aros.kmz", new CommonCallbacks.CompletionCallbackWithProgress() { + WaypointMissionManager.getInstance().pushKMZFileToAircraft(kmzAbsPath, new CommonCallbacks.CompletionCallbackWithProgress() { @Override public void onProgressUpdate(Double progress) { sendEvent2Server("航线上传进度:" + progress, 1); Movement.getInstance().setTask_current_step(17); + + } @Override public void onSuccess() { //起飞准备完毕 Movement.getInstance().setMode_code(2); - + sendFlightTaskProgress2Server(); sendEvent2Server("航线上传成功,准备执行任务", 1); isPushKMZSuccess = true; mainHandler.postDelayed(new Runnable() { @@ -352,9 +310,10 @@ public class TakeOffToPointManager extends BaseManager { /** * 7.开始任务 */ + //自主起飞 Movement.getInstance().setMode_code(4); - OSDManager.getInstance().pushFlightAttitude(); + sendFlightTaskProgress2Server(); Movement.getInstance().setTask_current_step(22); startMission(message); pushKMZFileTimes = 0; @@ -382,7 +341,7 @@ public class TakeOffToPointManager extends BaseManager { sendEvent2Server("航线第" + pushKMZFileTimes + "次上传失败,直接关机",2); //待机 Movement.getInstance().setMode_code(0); - OSDManager.getInstance().pushFlightAttitude(); + sendFlightTaskProgress2Server(); TaskFailManager.getInstance().sendTaskFailMsg2Server(-1); } @@ -422,17 +381,7 @@ public class TakeOffToPointManager extends BaseManager { sendEvent2Server("任务开始执行", 1); Movement.getInstance().setTask_current_step(23); sendFlightTaskProgress2Server(); -// Movement.getInstance().setMode_code(5); -// -// //自动起飞 -// Movement.getInstance().setMode_code(4); -// //延迟2s -// new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(() -> { -// Movement.getInstance().setMode_code(17); -// }, 2000); - } - @Override public void onFailure(@NonNull IDJIError error) { LogUtil.log(TAG, "航线执行失败:" + new Gson().toJson(error)); @@ -452,7 +401,7 @@ public class TakeOffToPointManager extends BaseManager { if (!Movement.getInstance().isPlaneWing()) { //待机 Movement.getInstance().setMode_code(0); - OSDManager.getInstance().pushFlightAttitude(); + sendFlightTaskProgress2Server(); sendEvent2Server("航线第" + startMissionFailTimes + "次开始失败,直接关机:" + "---" + new Gson().toJson(error) + "--" + Movement.getInstance().getQuality(),2); TaskFailManager.getInstance().sendTaskFailMsg2Server(-1); @@ -464,8 +413,7 @@ public class TakeOffToPointManager extends BaseManager { } } }; - - WaypointMissionManager.getInstance().startMission("ToPoint", callback); + WaypointMissionManager.getInstance().startMission("takeofftopoint", callback); } else { sendEvent2Server("任务开始失败,设备未连接", 2); } diff --git a/app/src/main/java/com/aros/apron/tools/ApronArucoDetect.java b/app/src/main/java/com/aros/apron/tools/ApronArucoDetect.java index ad85a282..daea2711 100644 --- a/app/src/main/java/com/aros/apron/tools/ApronArucoDetect.java +++ b/app/src/main/java/com/aros/apron/tools/ApronArucoDetect.java @@ -68,10 +68,10 @@ public class ApronArucoDetect { // 【关键修改1】M400下视镜头右后方补偿量(像素,正值向右补偿) // 如果还往左偏就调大,往右偏就调小,建议范围 30-80 - private static final double LENS_OFFSET_X = 35.0; + private static final double LENS_OFFSET_X = 15.0; private static final double LENS_OFFSET_Y = 20.0; // 【关键修改2】放宽居中判定阈值(原40,补偿后改为60更合理) - private static final int CENTER_ERR_MAX = 35; // 居中误差(px) + private static final int CENTER_ERR_MAX = 40; // 居中误差(px) public PIDControl pidControlX = null; public PIDControl pidControlY = null; @@ -121,11 +121,13 @@ public class ApronArucoDetect { } private static final float SLOW_LAND_SPEED = -0.3f; // 远场慢降 - private static final int PIXEL_TRIGGER = 350; // 近场像素阈值 + private static final float SLOW_SUPER_SPEED = -0.1f; // 超近慢降 + + private static final int PIXEL_TRIGGER = 400; // 近场像素阈值 public void init() { - pidControlX = new PIDControl(0.8f, 0.002f, 0.09f, 0.05f, 2.0f, 0.05f); - pidControlY = new PIDControl(0.8f, 0.002f, 0.09f, 0.05f, 2.0f, 0.05f); + pidControlX = new PIDControl(0.6f, 0.015f, 0.12f, 0.05f, 2.0f, 0.05f); + pidControlY = new PIDControl(0.6f, 0.015f, 0.12f, 0.05f, 2.0f, 0.05f); pidControlX.reset(); pidControlY.reset(); @@ -198,7 +200,7 @@ public class ApronArucoDetect { arucoNotFoundTag = false; int[] idArray = ids.toArray(); int ultrasonicHeight = Movement.getInstance().getUltrasonicHeight(); - //double flyingHeight = Movement.getInstance().getFlyingHeight(); + // double flyingHeight = Movement.getInstance().getElevation(); // 如果只有一个而且是6 if (idArray.length == 1 && idArray[0] == 6) { @@ -226,7 +228,7 @@ public class ApronArucoDetect { /* 近场 + 对准 + 像素够 → 立即速降 */ if (!startFastStick && pixelWidth >= PIXEL_TRIGGER && -// flyingHeight <= 0.4 && +// flyingHeight <= 1 && ultrasonicHeight <= 4 && errX < CENTER_ERR_MAX && errY < CENTER_ERR_MAX) { @@ -251,10 +253,8 @@ public class ApronArucoDetect { endTime = System.currentTimeMillis(); long lostDuration = endTime - startTime; //1s到8s内 - if (lostDuration > 1000 && lostDuration <= 8000) { - + if (lostDuration > 700 && lostDuration <= 8000) { if (Movement.getInstance().getUltrasonicHeight()<=30) { - DroneHelper.getInstance().moveVxVyYawrateHeight(0f, 0f, 0f, 0.3f); if (dropTimes > Integer.parseInt(AMSConfig.getInstance().getAlternateLandingTimes())) { LogUtil.log(TAG, "超过复降限制,去备降点"); @@ -398,24 +398,34 @@ public class ApronArucoDetect { double cy = (pts[0].y + pts[1].y + pts[2].y + pts[3].y) / 4.0; Point screenCenter = new Point(imageWidth / 2.0, imageHeight / 2.0); - // 【关键修改4】PID控制也加上相同的偏移补偿(注意这里不加abs,保留符号给PID判断方向) double errX = (cx - screenCenter.x) + LENS_OFFSET_X; // 向右补偿 - double errY = (cy - screenCenter.y) - LENS_OFFSET_Y; // Y方向不变 + double errY = (cy - screenCenter.y) - LENS_OFFSET_Y; // Y方向不变 /* 3. PID 微调水平 */ - pidControlX.setInputFilterAll((float) (errX / 800.0)); - pidControlY.setInputFilterAll((float) (-errY / 800)); + pidControlX.setInputFilterAll((float) (errX / 700.0)); + pidControlY.setInputFilterAll((float) (-errY/ 700.0)); float vx = (float) Math.max(-0.25, Math.min(0.25, pidControlX.get_pid())); float vy = (float) Math.max(-0.25, Math.min(0.25, pidControlY.get_pid())); /* 4. 远场慢降:像素 < 1500 且 > 2 m */ double pixelWidth = Math.sqrt(Math.pow(pts[1].x - pts[0].x, 2) + Math.pow(pts[1].y - pts[0].y, 2)); + // double flyingHeight = Movement.getInstance().getElevation(); - float vz = (pixelWidth < PIXEL_TRIGGER && -// Movement.getInstance().getFlyingHeight() > 0.4f && - Movement.getInstance().getUltrasonicHeight() > 4) ? - SLOW_LAND_SPEED : 0.0f; + int currentHeight = Movement.getInstance().getUltrasonicHeight(); + + float vz; + if (currentHeight <= 4) { + vz = 0.0f; // 近场悬停,等速降 + } else if (currentHeight <= 6) { + vz = SLOW_SUPER_SPEED; // -0.1f,过渡层 + } else { + vz = SLOW_LAND_SPEED; // -0.3f,远场慢降 + } +// if (flyingHeight <= 0.2) { +// vz = 0.0f; +// LogUtil.log(TAG, "相对高度" + flyingHeight + "强制悬停"); +// } /* 5. 输出 */ DroneHelper.getInstance().moveVxVyYawrateHeight(vx, vy, 0f, vz); diff --git a/app/src/main/java/com/aros/apron/tools/ArucoViewModel.kt b/app/src/main/java/com/aros/apron/tools/ArucoViewModel.kt index 7395a1d2..08b9527c 100644 --- a/app/src/main/java/com/aros/apron/tools/ArucoViewModel.kt +++ b/app/src/main/java/com/aros/apron/tools/ArucoViewModel.kt @@ -1,4 +1,4 @@ -//package com.shd.nest.viewmodel +package com.aros.apron.tools//package com.shd.nest.viewmodel // //import android.annotation.SuppressLint //import android.graphics.Bitmap diff --git a/app/src/main/java/com/aros/apron/tools/BluetoothAccessibilityService.kt b/app/src/main/java/com/aros/apron/tools/BluetoothAccessibilityService.kt index 81e6cfc2..f00c3649 100644 --- a/app/src/main/java/com/aros/apron/tools/BluetoothAccessibilityService.kt +++ b/app/src/main/java/com/aros/apron/tools/BluetoothAccessibilityService.kt @@ -1,4 +1,4 @@ - +package com.aros.apron.tools import android.accessibilityservice.AccessibilityService import android.annotation.SuppressLint import android.app.Notification diff --git a/app/src/main/java/com/aros/apron/tools/Generakmztools.java b/app/src/main/java/com/aros/apron/tools/Generakmztools.java new file mode 100644 index 00000000..088c7c2f --- /dev/null +++ b/app/src/main/java/com/aros/apron/tools/Generakmztools.java @@ -0,0 +1,199 @@ +package com.aros.apron.tools; + +import android.util.Log; + +import com.aros.apron.base.BaseManager; +import com.aros.apron.entity.MissionDataBean; +import com.aros.apron.entity.Movement; +import com.aros.apron.manager.TakeOffToPointManager; +import com.dji.wpmzsdk.common.data.Template; +import com.dji.wpmzsdk.manager.WPMZManager; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; + +import dji.sdk.keyvalue.key.FlightControllerKey; +import dji.sdk.keyvalue.key.KeyTools; +import dji.sdk.keyvalue.value.common.LocationCoordinate3D; +import dji.sdk.wpmz.value.mission.*; +import dji.v5.manager.KeyManager; + +/** + * 单航点起飞→目标点→返航 + * 纯 Java、无 Builder、无 WaypointHeadingParam + */ +public class Generakmztools extends BaseManager { + private Generakmztools() {} + private static class Holder { private static final Generakmztools INSTANCE = new Generakmztools(); } + public static Generakmztools getInstance() { return Holder.INSTANCE; } + + public Boolean generateKmz(MissionDataBean data) { + sendEvent2Server("开始生成一键起飞航线", 1); + LocationCoordinate3D lat = KeyManager.getInstance().getValue(KeyTools.createKey(FlightControllerKey. + KeyAircraftLocation3D)); + + if (lat == null) { + LogUtil.log("qwq", "当前位置为空,无法生成航线"); + sendEvent2Server("生成失败:未获取到飞机当前位置", 1); + return false; + } + if (lat.getLatitude() == null || lat.getLongitude() == null|| lat.getAltitude() == null) { + LogUtil.log("qwq", "当前位置坐标无效"); + sendEvent2Server("生成失败:位置坐标无效", 1); + return false; + } + + File root = new File("/storage/self/primary/DJIDemo/cache/kmz"); + if (!root.exists()) root.mkdirs(); + File kmz = new File(root, "takeofftopoint.kmz"); + + /* 1. 基本信息 */ + WaylineMission mission = new WaylineMission(); + mission.setAuthor("aros"); + double now = System.currentTimeMillis(); + mission.setCreateTime(now); + mission.setUpdateTime(now); + + /* 2. 全局策略 */ + WaylineMissionConfig config = new WaylineMissionConfig(); + //飞向目标点的模式 + config.setFlyToWaylineMode(WaylineFlyToWaylineMode.SAFELY); + //航线结束后的动作 + config.setFinishAction(WaylineFinishedAction.NO_ACTION); + if(data.getCommanderModeLostAction()==0){ + //继续 + config.setExitOnRCLostBehavior(WaylineExitOnRCLostBehavior.GO_ON); + }else if(data.getCommanderModeLostAction()==1){ + //失控退出航线 + config.setExitOnRCLostBehavior(WaylineExitOnRCLostBehavior.EXCUTE_RC_LOST_ACTION); + } + //失控退出航线的动作 + if(data.getRcLostAction()==0){ + //悬停 + config.setExitOnRCLostType(WaylineExitOnRCLostAction.HOVER); + } else if (data.getRcLostAction()==1) { + //精确着陆 + config.setExitOnRCLostType(WaylineExitOnRCLostAction.LANDING); + } else if (data.getRcLostAction()==2) { + //返航 + config.setExitOnRCLostType(WaylineExitOnRCLostAction.GO_BACK); + } + //全局过度速度 + config.setGlobalTransitionalSpeed((double)data.getMaxSpeed()); + //全局返航高度 + config.setGlobalRTHHeight((double)data.getRthAltitude()); + config.setIsGlobalRTHHeightSet(true); + //安全起飞高度 + config.setSecurityTakeOffHeight((double)data.getSecurityTakeoffHeight()); + config.setIsSecurityTakeOffHeightSet(true); + + + + //为400准备的 + WaylineDroneInfo droneInfo = new WaylineDroneInfo(); + droneInfo.setDroneType(WaylineDroneType.PM440); + config.setDroneInfo(droneInfo); + + + //这个航点列表 + WaylineWaypoint wp1 = new WaylineWaypoint(); + WaylineWaypoint wp = new WaylineWaypoint(); + + //初始点 + wp1.setWaypointIndex(0); + wp1.setLocation(new WaylineLocationCoordinate2D(lat.getLatitude(), lat.getLongitude())); + //wp1.setHeight((double)data.getCommanderFlightHeight()); + wp1.setHeight(data.getTargetHeight()- Movement.getInstance().getHeight()); + // wp1.setUseGlobalFlightHeight(true); + //椭球高 + wp1.setEllipsoidHeight(data.getTargetHeight()- Movement.getInstance().getHeight()); + wp1.setUseStraightLine(true); + wp1.setUseGlobalTurnParam(true); + wp1.setUseGlobalYawParam(true); + wp1.setUseGlobalGimbalHeadingParam(true); + wp1.setUseGlobalAutoFlightSpeed(true); + wp1.setIsRisky(false); + + + + //基础设置 + wp.setWaypointIndex(1); + wp.setLocation(new WaylineLocationCoordinate2D(data.getTargetLatitude(), data.getTargetLongitude())); + //wp.setHeight((double)data.getCommanderFlightHeight()); + wp.setHeight(data.getTargetHeight()- Movement.getInstance().getHeight()); + // wp.setUseGlobalFlightHeight(true); + //椭球高 + wp.setEllipsoidHeight(data.getTargetHeight()- Movement.getInstance().getHeight()); + wp.setUseStraightLine(true); + wp.setUseGlobalTurnParam(true); + wp.setUseGlobalYawParam(true); + wp.setUseGlobalGimbalHeadingParam(true); + wp.setUseGlobalAutoFlightSpeed(true); + wp.setIsRisky(false); + + + List wpList = new ArrayList<>(); + wpList.add(wp1); + wpList.add(wp); + + /* 4. */ + WaylineTemplateWaypointInfo waypointInfo = new WaylineTemplateWaypointInfo(); + + waypointInfo.setGlobalFlightHeight(data.getTargetHeight()); + waypointInfo.setIsGlobalFlightHeightSet(true); + + WaylineWaypointYawParam waypointYawParam=new WaylineWaypointYawParam(); + waypointYawParam.setYawMode(WaylineWaypointYawMode.FOLLOW_WAYLINE); + waypointInfo.setGlobalYawParam(waypointYawParam); + waypointInfo.setIsTemplateGlobalYawParamSet(true); + + WaylineWaypointGimbalHeadingParam waypointGimbalHeadingParam=new WaylineWaypointGimbalHeadingParam(); + waypointGimbalHeadingParam.setHeadingMode(WaylineWaypointGimbalHeadingMode.FOLLOW_WAYLINE); + waypointGimbalHeadingParam.setYawAngle(0.0); + waypointGimbalHeadingParam.setPitchAngle(0.0); + waypointInfo.setGlobalGimbalHeadingParam(waypointGimbalHeadingParam); + + waypointInfo.setGlobalTurnMode(WaylineWaypointTurnMode.COORDINATE_TURN); + waypointInfo.setIsTemplateGlobalTurnModeSet(true); + waypointInfo.setWaypoints(wpList); + + waypointInfo.setUseStraightLine(true); + + + + /* 5. */ + WaylineCoordinateParam coordParam = new WaylineCoordinateParam(); + coordParam.setCoordinateMode(WaylineCoordinateMode.WGS84); + coordParam.setAltitudeMode(WaylineAltitudeMode.RELATIVE_TO_START_POINT); + coordParam.setPositioningType(WaylinePositioningType.GPS); + + /* 6. */ + Template template = new Template(); + template.setTemplateId(0); + template.setCoordinateParam(coordParam); + template.setTransitionalSpeed((double)data.getMaxSpeed()); + template.setWaypointInfo(waypointInfo); + template.setUseGlobalTransitionalSpeed(true); + template.setAutoFlightSpeed((double)data.getMaxSpeed()); + + //不写就报错 + template.setPayloadParam(new ArrayList<>()); + /* 7. 生成文件 */ + WPMZManager.getInstance().generateKMZFile(kmz.getAbsolutePath(), mission, config, template); + //验证这个kmz + + WaylineCheckErrorMsg result= WPMZManager.getInstance().checkValidation(kmz.getAbsolutePath()); + LogUtil.log("qwq",result.toString()); + if (result.getValue().isEmpty()) { + LogUtil.log("qwq", "KMZ 校验通过"); + sendEvent2Server("一键起飞航线文件生成成功", 1); + return true; + } else { + // 其他错误码照旧报错 + LogUtil.log("qwq", "校验失败,错误码:" + result.getValue()); + sendEvent2Server("一键起飞航线文件生成失败错误码:"+result.getValue(), 1); + return false; + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/aros/apron/tools/OpenCVHelper.java b/app/src/main/java/com/aros/apron/tools/OpenCVHelper.java deleted file mode 100644 index ec4c6c62..00000000 --- a/app/src/main/java/com/aros/apron/tools/OpenCVHelper.java +++ /dev/null @@ -1,292 +0,0 @@ -//package com.aros.apron.tools; -// -//import static org.opencv.core.Core.BORDER_DEFAULT; -//import static org.opencv.core.Core.extractChannel; -// -//import android.content.Context; -//import android.util.Log; -// -//import org.opencv.aruco.Aruco; -//import org.opencv.aruco.Dictionary; -//import org.opencv.core.Core; -//import org.opencv.core.CvType; -//import org.opencv.core.Mat; -//import org.opencv.core.MatOfDouble; -//import org.opencv.core.MatOfPoint3f; -//import org.opencv.core.MatOfRect; -//import org.opencv.core.Point; -//import org.opencv.core.Rect; -//import org.opencv.core.Scalar; -//import org.opencv.core.Size; -//import org.opencv.imgproc.Imgproc; -//import org.opencv.objdetect.CascadeClassifier; -// -//import java.util.ArrayList; -//import java.util.List; -// -//import dji.v5.manager.aircraft.virtualstick.VirtualStickManager; -// -//public class OpenCVHelper { -// private static final Scalar FACE_RECT_COLOR = new Scalar(0, 255, 0, 255); -// private Context context; -// private MatOfPoint3f objPoints; -// private Mat intrinsic; -// private MatOfDouble distortion; -// private Mat logoImg; -// private MatOfPoint3f objectPoints; -// -// public OpenCVHelper(Context context) { -// this.context = context; -// } -// -// public Mat defaultImageProcessing(Mat input) { -// Imgproc.putText(input, "Default", new Point(150, 40), 1, 4, new Scalar(255, 255, 255), 2, 8, false); -// return input; -// } -// -// public Mat convertToGray(Mat input) { -// Mat output = new Mat(); -// Imgproc.cvtColor(input, output, Imgproc.COLOR_RGBA2GRAY); -// return output; -// } -// -// public Mat detectEdgesUsingCanny(Mat input) { -// Mat output = new Mat(); -// Imgproc.Canny(input, output, 80, 100); -// return output; -// } -// -// public Mat detectEdgesUsingLaplacian(Mat input) { -// Mat grayImg = new Mat(); -// Mat intermediateMat = new Mat(); -// Mat output = new Mat(); -// Imgproc.cvtColor(input, grayImg, Imgproc.COLOR_RGBA2GRAY); -// Imgproc.GaussianBlur(grayImg, grayImg, new Size(3, 3), 0, 0); -// Imgproc.Laplacian(grayImg, intermediateMat, CvType.CV_8U, 3, 1, 0, BORDER_DEFAULT); -// Core.convertScaleAbs(intermediateMat, intermediateMat, 10, 0); -// Imgproc.cvtColor(intermediateMat, output, Imgproc.COLOR_GRAY2RGBA, 4); -// grayImg.release(); -// intermediateMat.release(); -// return output; -// } -// -// public Mat blurImage(Mat input) { -// Mat grayMat = new Mat(); -// Mat output = new Mat(); -// Imgproc.cvtColor(input, grayMat, Imgproc.COLOR_RGBA2GRAY); -// Imgproc.GaussianBlur(grayMat, output, new Size(35, 35), 0, 0); -// grayMat.release(); -// return output; -// } -// -// public Mat detectFaces(Mat input, CascadeClassifier faceDetector) { -// Mat grayImgMat = new Mat(); -// MatOfRect faces = new MatOfRect(); -// Mat output; -// Imgproc.cvtColor(input, grayImgMat, Imgproc.COLOR_RGBA2GRAY); -// if (faceDetector != null) { -// faceDetector.detectMultiScale(grayImgMat, faces, 1.1, 2, 2, new Size(60, 60), new Size()); -// } -// output = input; -// Rect[] facesArray = faces.toArray(); -// for (Rect rect : facesArray) { -// Imgproc.rectangle(output, rect.tl(), rect.br(), FACE_RECT_COLOR, 3); -// } -// return output; -// } -// -// public Mat detectArucoTags(Mat input, Dictionary dictionary) { -// -// Mat grayImgMat = new Mat(); -// Mat intermediateImgMat = new Mat(); -// Mat output = new Mat(); -// Imgproc.cvtColor(input, grayImgMat, Imgproc.COLOR_RGBA2GRAY); -// Imgproc.cvtColor(input, intermediateImgMat, Imgproc.COLOR_RGBA2RGB); -// Mat ids = new Mat(); -// List corners = new ArrayList<>(); -// Aruco.detectMarkers(grayImgMat, dictionary, corners, ids); -// if (ids.depth() > 0) { -//// Log.e("检测到TAG", "----1111------"); -// Aruco.drawDetectedMarkers(intermediateImgMat, corners, ids, new Scalar(255, 0, 255)); -// moveOnArucoDetected(ids, corners, intermediateImgMat.width(), intermediateImgMat.height()); -// } -// Imgproc.cvtColor(intermediateImgMat, output, Imgproc.COLOR_RGB2BGR); -// Imgproc.cvtColor(output, output, Imgproc.COLOR_BGR2RGBA, 4); -// grayImgMat.release(); -// intermediateImgMat.release(); -// return output; -// } -// -// private void moveOnArucoDetected(Mat ids, -// List corners, -// int imageWidth, -// int imageHeight) { -// ////执行逻辑来决定将无人机移动到哪里 -// ////计算标记中心 -// Scalar markerCenter = new Scalar(0, 0); -// for (Mat corner : corners) { -// markerCenter = Core.mean(corner); -// } -//// Log.e("markerCenter:", markerCenter.toString()); -//// Log.e("imageWidth" + imageWidth, "imageHeight" + imageHeight); -// //使所需的标签位于图像框的中心 -// //计算相对于图像中心的图像矢量 -// Scalar imageVector = new Scalar(markerCenter.val[0] - imageWidth / 2f, markerCenter.val[1] - imageHeight / 2f); -// //将矢量从图像坐标转换为无人机导航坐标 -// Scalar motionVector = convertImageVectorToMotionVector(imageVector); -// //如果没有检测到标签,则无需移动 -// if (ids.size().empty()) { -// motionVector = new Scalar(0, 0); -//// Log.e("未检测到TAG","----1111------"); -// } -// if (imageVector.val[0] < 100 && imageVector.val[0] > -100 && imageVector.val[1] < 100 && imageVector.val[1] > -100) { -// VirtualStickManager.getInstance().getLeftStick().setVerticalPosition(-30); -// } else { -// if (imageVector.val[0] < 0) { -// VirtualStickManager.getInstance().getRightStick().setHorizontalPosition(-10); -// } -// if (imageVector.val[0] > 0) { -// VirtualStickManager.getInstance().getRightStick().setHorizontalPosition(10); -// } -// if (imageVector.val[1] < 0) { -// VirtualStickManager.getInstance().getRightStick().setVerticalPosition(-10); -// } -// if (imageVector.val[1] > 0) { -// VirtualStickManager.getInstance().getRightStick().setVerticalPosition(10); -// } -// } -// } -// -//// public void doDroneMoveUsingImage(Mat input, DroneHelper droneHelper) { -//// /* -//// * Remember this function is called every time -//// * a frame is available. So don't do long loop here. -//// */ -//// Imgproc.cvtColor(input, input, Imgproc.COLOR_BGR2YUV); -//// extractChannel(input, input, 0); -//// FlightControlData controlData = -//// new FlightControlData(0.1f, 0.0f, 0.0f, 0.0f); //pitch, roll, yaw, verticalThrottle -//// droneHelper.sendMovementCommand(controlData); -//// } -// -// public Mat doAROnImage(Mat input, Dictionary dictionary, DroneHelper droneHelper) { -// //TODO: -// // Since this is the bonus part, only high-level instructions will be provided -// // One way you can do this is to: -// // 1. Identify the Aruco tags with corner pixel location -// // Hint:Aruco.detectMarkers(...) -// // 2. For each corner in 3D space, define their 3D locations -// // The 3D locations you defined here will determine the origin of your coordinate frame -// // 3. Given the 3D locations you defined, their 2D pixel location in the image, and camera parameters -// // You can calculate the 6 DOF of the camera relative to the tag coordinate frame -// // Hint: Calib3d.solvePnP(...) -// // 4. To put artificial object in the image, you need to create 3D points first and project them into 2D image -// // With the projected image points, you can draw lines or polygon -// // Hint: Calib3d.projectPoints(...); -// // 5. To put dji image on a certain location, -// // you need find the homography between the projected 4 corners and the 4 corners of the logo image -// // Hint: Calib3d.findHomography(...); -// // 6. Once the homography is found, warp the image with perspective -// // Hint: Imgproc.warpPerspective(...); -// // 7. Now you have the warped logo image in the right location, just overlay them on top of the camera image -// Mat output = new Mat(); -// Mat grayMat = convertToGray(input); -// -// //TODO: Do your magic!!! -// // Hint how to overlay warped logo onto the original camera image -// /* -// Imgproc.cvtColor(logoWarped, grayMat, Imgproc.COLOR_BGR2GRAY); -// Imgproc.threshold(grayMat, grayMat, 0, 255, Imgproc.THRESH_BINARY); -// bitwise_not(grayMat, grayInv); -// input.copyTo(src1Final, grayInv); -// logoWarped.copyTo(src2Final, grayMat); -// Core.add(src1Final, src2Final, output); -// */ -// //end magic -// -// if (output.empty()) { -// output = grayMat; -// } -// -// return output; -// } -// -// public void startDetectAruco(DroneHelper droneHelper) { -//// droneHelper.enterVirtualStickMode(); -// -// droneHelper.setVerticalModeToVelocity(); -// -//// droneHelper.setGimbalPitchDegree(-90.0f); -// } -// -// public void startDroneMove(DroneHelper droneHelper) { -//// droneHelper.enterVirtualStickMode(); -// droneHelper.setVerticalModeToVelocity(); -// } -// -//// public void startDoAR(DroneHelper droneHelper) { -//// droneHelper.enterVirtualStickMode(); -//// droneHelper.setVerticalModeToAbsoluteHeight(); -//// Bitmap bMap = BitmapFactory.decodeResource(context.getResources(), R.drawable.dji_logo); -//// logoImg = new Mat(); -//// Utils.bitmapToMat(bMap, logoImg); -//// -//// //Camera calibration code -//// intrinsic = new Mat(3, 3, CvType.CV_32F); -//// intrinsic.put(0, -//// 0, -//// 1.2702029303551683e+03, -//// 0., -//// 7.0369652952332717e+02, -//// 0., -//// 1.2682183239938338e+03, -//// 3.1342369745005681e+02, -//// 0., -//// 0., -//// 1.); -//// -//// distortion = new MatOfDouble(3.2177759275048554e-02, -//// 1.1688831035623757e+00, -//// -1.6742357543049650e-02, -//// 1.4173384809091350e-02, -//// -6.1914718831876847e+00); -//// -//// // Please measure the marker size in Meter and enter it here -//// double markerSizeMeters = 0.13; -//// double halfMarkerSize = markerSizeMeters * 0.5; -//// -//// // Self-defined tag location in 3D, this is used in step 2 in doAR -//// objPoints = new MatOfPoint3f(); -//// List point3List = new ArrayList<>(); -//// point3List.add(new Point3(-halfMarkerSize, -halfMarkerSize, 0)); -//// point3List.add(new Point3(-halfMarkerSize, halfMarkerSize, 0)); -//// point3List.add(new Point3(halfMarkerSize, halfMarkerSize, 0)); -//// point3List.add(new Point3(halfMarkerSize, -halfMarkerSize, 0)); -//// objPoints.fromList(point3List); -//// -//// // AR object points in 3D, this is used in step 4 in doAR -//// objectPoints = new MatOfPoint3f(); -//// -//// List point3DList = new ArrayList<>(); -//// point3DList.add(new Point3(-halfMarkerSize, -halfMarkerSize, 0)); -//// point3DList.add(new Point3(-halfMarkerSize, halfMarkerSize, 0)); -//// point3DList.add(new Point3(halfMarkerSize, halfMarkerSize, 0)); -//// point3DList.add(new Point3(halfMarkerSize, -halfMarkerSize, 0)); -//// point3DList.add(new Point3(-halfMarkerSize, -halfMarkerSize, markerSizeMeters)); -//// point3DList.add(new Point3(-halfMarkerSize, halfMarkerSize, markerSizeMeters)); -//// point3DList.add(new Point3(halfMarkerSize, halfMarkerSize, markerSizeMeters)); -//// point3DList.add(new Point3(halfMarkerSize, -halfMarkerSize, markerSizeMeters)); -//// -//// objectPoints.fromList(point3DList); -//// } -// -// private Scalar convertImageVectorToMotionVector(Scalar imageVector) { -// double pX = -imageVector.val[1]; -// double pY = imageVector.val[0]; -// double divisor = Math.sqrt((pX * pX) + (pY * pY)); -// pX = pX / divisor; -// pY = pY / divisor; -// -// return new Scalar(pX * 0.2, pY * 0.2); -// } -//} \ No newline at end of file diff --git a/app/src/main/java/com/aros/apron/tools/RtmpPublisher.kt b/app/src/main/java/com/aros/apron/tools/RtmpPublisher.kt index 643efbd0..fcd28566 100644 --- a/app/src/main/java/com/aros/apron/tools/RtmpPublisher.kt +++ b/app/src/main/java/com/aros/apron/tools/RtmpPublisher.kt @@ -1,4 +1,4 @@ -// +package com.aros.apron.tools// // //import android.media.MediaCodec //import android.util.Pair diff --git a/app/src/main/java/com/aros/apron/tools/UploadPhotoWorker.kt b/app/src/main/java/com/aros/apron/tools/UploadPhotoWorker.kt index 3f5bace9..47bad628 100644 --- a/app/src/main/java/com/aros/apron/tools/UploadPhotoWorker.kt +++ b/app/src/main/java/com/aros/apron/tools/UploadPhotoWorker.kt @@ -1,4 +1,4 @@ -//package com.shd.nest.gateway +package com.aros.apron.tools//package com.shd.nest.gateway // //import android.provider.MediaStore //import com.amazonaws.ClientConfiguration