feat[设备管理]:设备控制

This commit is contained in:
2025-01-02 21:34:47 +08:00
parent db17e4c6e9
commit d9aab272ff
358 changed files with 1582 additions and 49234 deletions
@@ -0,0 +1,95 @@
package com.central.device.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.shaded.com.google.gson.Gson;
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
import com.central.common.model.Result;
import com.central.device.message.ControlMessageConstant;
import com.central.device.util.MapUtil;
import com.central.device.util.RequestUtils;
import com.central.device.util.http.HeaderUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.*;
/**
* 设备操作controller
* @author lishilin
* @date 2024-12-31
*/
@Tag(name = "MQTT设备管理")
@Slf4j
@RestController
@RequestMapping("/device")
public class ApiDeviceController {
// @Value("${jetlinks.server.url}")
private String baseUrl = "http://119.45.169.13:8848/";
@Autowired
private HeaderUtils headerUtils;
@Autowired
private RequestUtils requestUtils;
/**
* 获取设备属性
*/
@Operation(summary = "获取设备属性")
@GetMapping("/property/_query/{deviceId}/{property}")
public Result getProperty(@RequestParam Map<String,Object> param,@PathVariable("deviceId") String deviceId) throws IOException {
//温度属性,属性在设备管理的设备型号中设置
String property = MapUtil.getStrValue(param, "property");
String url = baseUrl + "/device/" + deviceId + "/property/" + property;
Map<String, String> result = requestUtils.getGetRequestResultMap(url,new HashMap<>());
return Result.succeed(result,"查询成功");
}
/**
* 设置设备属性测试
*/
@Operation(summary = "设备属性设置")
@PostMapping("/setting/{deviceId}/property")
public Result writeProperties(@RequestBody Map<String,Object> param, @PathVariable("deviceId") String deviceId) throws IOException {
String url = baseUrl + "/device/instance/" + deviceId + "/property";
// JSONObject jsonObject = new JSONObject();
// for (Map.Entry entry : param.entrySet()){
// jsonObject.put(entry.getKey().toString(),entry.getValue());
// }
String json = "{\n" +
" \"data\": {\n" +
"\t \"flight_id\": flight_id,\n" +
"\t \"max_speed\": 5,\n" +
"\t \"rc_lost_action\": 2,\n" +
"\t \"rth_altitude\": 60.0,\n" +
"\t \"rth_mode\": 1,\n" +
"\t \"security_takeoff_height\": 60.0,\n" +
"\t \"target_height\": 70.0,\n" +
"\t \"target_latitude\": 39.102603,\n" +
"\t \"target_longitude\": 117.711972,\n" +
"\t \"commander_mode_lost_action\": 0,\n" +
"\t \"commander_flight_mode\": 1,\n" +
"\t \"commander_flight_height\": 70.0,\n" +
"\t \"simulate_mission\": {\n" +
"\t },\n" +
"\t \"flight_safety_advance_check\": 0\n" +
"\t},\n" +
"\t\"method\": \"takeoff_to_point\"\n" +
"}";
Gson gson = new Gson();
JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
Map<String, String> result = requestUtils.getPostRequestResultMap(url, jsonObject.toString());
return Result.succeed(result,"设置成功");
}
}
@@ -0,0 +1,56 @@
package com.central.device.controller.token;
import com.alibaba.fastjson.JSON;
import com.central.common.model.Result;
import com.central.device.util.Utils;
import com.central.device.util.http.HeaderUtils;
import com.central.device.util.http.HttpRequest;
import com.central.device.util.http.Response;
import com.central.device.util.http.SimpleHttpRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
/**
* token获取
* @author lishilin
* @date 2024-12-31
*/
@Tag(name = "token获取")
@RestController
@RequestMapping("/api/v1/token")
public class ApiTokenController {
// @Value("${jetlinks.server.url}")
private String jetlinksServiceUrl = "http://119.45.169.13:8848/";
@Autowired
private HeaderUtils headerUtils;
@Operation(summary = "客户端获取通信平台token")
@GetMapping("_query")
public Result token() throws IOException {
String url = jetlinksServiceUrl+"/api/v1/token";
HttpRequest request = new SimpleHttpRequest(url);
Map<String,Object> param = new HashMap<>(2);
param.put("expires",7200*24);
request.headers(headerUtils.createHeadersOfJsonString(JSON.toJSONString(param)));
request.requestBody(JSON.toJSONString(param));
Response response = request.post();
Map<String, String> result = Utils.queryStringToMap(new String(response.asBytes(), "utf8"), "utf8");
return Result.succeed("data",result.get(""));
}
}
@@ -0,0 +1,16 @@
package com.central.device.message;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ControlEnum {
RETURN_HOME("return_home"),
TAKEOFF_TO_POINT("takeoff_to_point"),
FLY_TO_POINT("fly_to_point"),
FLY_TO_POINT_STOP("fly_to_point_stop"),
FLY_TO_POINT_UPDATE("fly_to_point_stop");
private final String name;
}
@@ -0,0 +1,69 @@
package com.central.device.message;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class ControlMessageConstant {
public final static String TAKEOFF_TO_POINT = "{\n" +
" \"data\": {\n" +
"\t \"flight_id\": flight_id,\n" +
"\t \"max_speed\": 5,\n" +
"\t \"rc_lost_action\": 2,\n" +
"\t \"rth_altitude\": 60.0,\n" +
"\t \"rth_mode\": 1,\n" +
"\t \"security_takeoff_height\": 60.0,\n" +
"\t \"target_height\": 70.0,\n" +
"\t \"target_latitude\": 39.102603,\n" +
"\t \"target_longitude\": 117.711972,\n" +
"\t \"commander_mode_lost_action\": 0,\n" +
"\t \"commander_flight_mode\": 1,\n" +
"\t \"commander_flight_height\": 70.0,\n" +
"\t \"simulate_mission\": {\n" +
"\t },\n" +
"\t \"flight_safety_advance_check\": 0\n" +
"\t},\n" +
"\t\"method\": \"takeoff_to_point\"\n" +
"}";
public final static String FLY_TO_ID = "{\n" +
"\t\"data\": {\n" +
"\t\t\"fly_to_id\": \"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx\",\n" +
"\t\t\"max_speed\": 12,\n" +
"\t\t\"points\": [\n" +
"\t\t\t{\n" +
"\t\t\t\t\"height\": 100,\n" +
"\t\t\t\t\"latitude\": 12.23,\n" +
"\t\t\t\t\"longitude\": 12.23\n" +
"\t\t\t}\n" +
"\t\t]\n" +
"\t},\n" +
"\t\"method\": \"fly_to_point\"\n" +
"}";
public final static String FLY_TO_ID_STOP = "{\n" +
"\t\"data\": {},\n" +
"\t\"method\": \"fly_to_point_stop\"\n" +
"}";
public final static String FLY_TO_POINT_UPDATE = "{\n" +
"\t\"data\": {\n" +
"\t\t\"max_speed\": 12,\n" +
"\t\t\"points\": [\n" +
"\t\t\t{\n" +
"\t\t\t\t\"height\": 100,\n" +
"\t\t\t\t\"latitude\": 12.23,\n" +
"\t\t\t\t\"longitude\": 12.23\n" +
"\t\t\t}\n" +
"\t\t]\n" +
"\t},\n" +
"\t\"method\": \"fly_to_point_update\"\n" +
"}";
public final static String RETURN_HOME = "{\n" +
"\t\"data\": {},\n" +
"\t\"method\": \"return_home\"\n" +
"}";
}
@@ -0,0 +1,747 @@
# iot说明
# 上报主题说明:
设备运行日志上报主题:/fire_alarm
# 上报内容:
## 状态包:
| home_position_is_valid | Home 点有效性 | enum_int | {"0":"无效","1":"有效"} | | r | 0 |
| --- | --- | --- | --- | --- | --- | --- |
| heading | 机场朝向角 | double | {"max":"180","min":"-180","step":"","unit_name":"度 / °"} | | r | 0 |
| rtcm_info | 机场 RTK 标定源 | struct | | | r | 1 |
| »mount_point | 网络 RTK 挂载点信息 | text | | | | 0 |
| »port | 网络端口信息 | text | | | | 0 |
| »host | 网络 host 信息 | text | | | | 0 |
| »rtcm_device_type | 设备类型 | enum_int | {"1":"机场"} | | | 0 |
| »source_type | 标定类型 | enum_int | {"0":"未标定","1":"自收敛标定","2":"手动标定","3":"网络RTK标定"} | | | 0 |
| wireless_link_topo | 图传连接拓扑 | struct | | | r | 1 |
| »secret_code | 加密编码 | array | {"size": 28, "item_type": int} | | | 0 |
| »center_node | 飞行器对频信息 | struct | | | | 0 |
| »»sdr_id | 扰码信息 | int | | | | 0 |
| »»sn | 设备sn | text | | | | 0 |
| »leaf_nodes | 机场或遥控器对频信息 | array | {"size": -, "item_type": struct} | | | 0 |
| »»sdr_id | 扰码信息 | int | | | | 0 |
| »»sn | 设备sn | text | | | | 0 |
| »»control_source_index | 控制源序号 | int | {"max":"2","min":"1","step":"1","unit_name":"无 / "} | | | 0 |
| air_conditioner | 机场空调工作状态信息 | struct | | | r | 0 |
| »air_conditioner_state | 机场空调状态 | enum_int | {"0":"空闲模式(无制冷、制热、除湿等)","1":"制冷模式","2":"制热模式","3":"除湿模式","4":"制冷退出模式","5":"制热退出模式","6":"除湿退出模式","7":"制冷准备模式","8":"制热准备模式","9":"除湿准备模式"} | 机场空调工作状态信息,空调仅存在一种工作模式 | | 0 |
| »switch_time | 剩余等待可切换时间 | int | {"unit_name":"秒 / s"} | 空调状态顺序为准备模式切换到工作状模式、随后可操作后切换到退出模式、退出完成后切换到空闲模式,因此本物模型表示进行某个指令操作后还需要多久可以切换至下一状态。例如当前为空闲状态,开启制冷模式后将进入制冷准备模式,则本时间表示还需要多久可以进入制冷工作模式。以此类推 | | 0 |
| air_transfer_enable | 空中回传 | bool | {"false":"关闭","true":"开启"} | 用户在指令飞行过程中拍照的照片快速回传至云端 | rw | 1 |
| silent_mode | 机场静音模式 | enum_int | {"0":"非静音模式","1":"静音模式"} | 开启静音模式,意味着:1. 风扇转速降低、空调制冷性能下降、炎热天气下作业间隔变长。2. 蜂鸣器声音将关闭,开关舱盖时请注意周围安全。3. 机场待机状态的白色指示灯关闭,其他运行状态的指示灯正常。 | rw | 1 |
| user_experience_improvement | 用户体验改善计划 | enum_int | {"0":"初始状态","1":"拒绝加入用户体验改善计划","2":"同意加入用户体验改善计划"} | | rw | 1 |
| dongle_infos | 4G Dongle信息 | array | {"size": -, "item_type": struct} | | r | 1 |
| »imei | dongle imei | text | | Dongle 的唯一识别标志 | r | 0 |
| »dongle_type | Dongle 类型 | enum_int | {"6":"旧 Dongle","10":"支持 eSIM 的新 Dongle"} | Dongle 类型 | r | 0 |
| »eid | dongle eid | text | | eSIM 的唯一识别标志,用于公众号查询套餐、购买服务 | r | 0 |
| »esim_activate_state | eSIM 激活状态 | enum_int | {"0":"未激活","1":"已激活"} | 需要激活才能使用 | r | 0 |
| »sim_card_state | SIM 卡状态 | enum_int | {"0":"未插入","1":"已插入"} | Dongle 中实体 SIM 卡的插入状态 | r | 0 |
| »sim_slot | SIM 卡槽使能状态 | enum_int | {"0":"未知","1":"实体 SIM 卡","2":"eSIM"} | 标识 Dongle 当前正在使用的 SIM 卡槽 | r | 0 |
| »esim_infos | eSIM 信息 | array | {"size": -, "item_type": struct} | | r | 0 |
| »»telecom_operator | 支持的运营商 | enum_int | {"0":"未知","1":"移动","2":"联通","3":"电信"} | eSIM 支持的运营商 | r | 0 |
| »»enabled | eSIM 使能状态 | bool | {"false":"未使用","true":"使用中"} | 同时刻只能有一个 eSIM 是使能的 | r | 0 |
| »»iccid | sim iccid | text | | SIM 卡的唯一识别标志,可以用于实体 SIM 卡的套餐购买 | r | 0 |
| »sim_info | SIM 卡信息 | struct | | 可插入 Dongle 的实体 SIM 卡信息 | r | 0 |
| »»telecom_operator | 支持的运营商 | enum_int | {"0":"未知","1":"移动","2":"联通","3":"电信"} | SIM 卡支持的运营商 | r | 0 |
| »»sim_type | SIM 卡类型 | enum_int | {"0":"未知","1":"其他普通 SIM 卡","2":"三网卡"} | 实体 SIM 卡的类型 | r | 0 |
| »»iccid | sim iccid | text | | SIM 卡的唯一识别标志,可以用于实体 SIM 卡的套餐购买 | r | 0 |
| drone_battery_maintenance_info | 飞行器电池保养信息 | struct | | | | 0 |
| »maintenance_state | 保养状态 | enum_int | {"0":"无需保养","1":"待保养","2":"正在保养"} | | | 0 |
| »maintenance_time_left | 电池保养剩余时间 | int | {"unit_name":"小时 / h"} | 向下取整 | | 0 |
| »heat_state | 电池加热保温状态 | enum_int | {"0":"电池未开启加热或保温","1":"电池在加热中","2":"电池在保温中"} | 当飞行器舱内关机时由本物模型上报机场连接飞行器的电池加热保温信息 | | 0 |
| »batteries | 电池详细信息 | array | {"size": -, "item_type": struct} | 当飞行器舱内关机时由本物模型上报机场连接飞行器的电池信息,基本数据与飞行器物模型中电池信息基本保持一致 | | 0 |
| »»capacity_percent | 电池剩余电量 | int | {"max":100,"min":0} | 保留小数点后一位,正常范围0-100,设备端获取不到数据的异常值为 32767 | | 0 |
| »»index | 电池序号 | enum_int | {"0":"左电池","1":"右电池"} | | | 0 |
| »»voltage | 电压 | int | {"unit_name":"毫伏 / mV"} | 正常范围0-28000mV,设备端获取不到数据的异常值为32767 | | 0 |
| »»temperature | 温度 | float | {"unit_name":"摄氏度 / °C"} | 保留小数点后一位,正常范围-40-150°C,设备端获取不到数据的异常值为32767 | | 0 |
| air_conditioner | 机场空调工作状态信息 | struct | | | r | 0 |
| »air_conditioner_state | 机场空调状态 | enum_int | {"0":"空闲模式(无制冷、制热、除湿等)","1":"制冷模式","2":"制热模式","3":"除湿模式","4":"制冷退出模式","5":"制热退出模式","6":"除湿退出模式","7":"制冷准备模式","8":"制热准备模式","9":"除湿准备模式"} | 机场空调工作状态信息,空调仅存在一种工作模式 | | 0 |
| »switch_time | 剩余等待可切换时间 | int | {"unit_name":"秒 / s"} | 模式切换顺序为准备模式、工作(制冷、制热、除湿)模式、退出模式、空闲模式。本属性将上报,可以切换下一个模式指令还需要等待的时间。例如当前机场空调在进入制冷模式后,必须制冷5分钟后才可以退出制冷模式,本属性将上报还需要多久退出制冷模式,为0表示随时可退出 | | 0 |
| maintain_status | 保养信息 | struct | | | r | 0 |
| »maintain_status_array | 保养信息数组 | array | {"size": -, "item_type": struct} | | | 0 |
| »»state | 保养状态 | enum_int | {"0":"无保养","1":"有保养"} | | | 0 |
| »»last_maintain_type | 上一次保养类型 | enum_int | {"0":"无保养","17":"机场常规保养","18":"机场深度保养"} | | | 0 |
| »»last_maintain_time | 上一次保养时间 | date | {"unit_name":"秒 / s"} | | | 0 |
| »»last_maintain_work_sorties | 上一次保养时作业架次 | int | {"max":"2147483647","min":"0","step":"1"} | | | 0 |
| position_state | 搜星状态 | struct | | | r | 0 |
| »is_calibration | 是否标定 | enum_int | {"0":"未标定","1":"已标定"} | | | 0 |
| »is_fixed | 是否收敛 | enum_int | {"0":"未开始","1":"收敛中","2":"收敛成功","3":"收敛失败"} | | | 0 |
| »quality | 搜星档位 | enum_int | {"1":"1档","2":"2档","3":"3档","4":"4档","5":"5档","10":"RTK fixed"} | | | 0 |
| »gps_number | GPS 搜星数量 | int | | | | 0 |
| »rtk_number | RTK 搜星数量 | int | | | | 0 |
| emergency_stop_state | 紧急停止按钮状态 | enum_int | {"0":"关闭","1":"开启"} | | r | 0 |
| drone_charge_state | 飞行器充电状态 | struct | | 飞行器充电状态 | r | 0 |
| »capacity_percent | 电量百分比 | int | {"max":"100","min":"0"} | | | 0 |
| »state | 充电状态 | enum_int | {"0":"空闲","1":"充电中"} | | | 0 |
| backup_battery | 机场备用电池信息 | struct | | | r | 0 |
| »switch | 备用电池开关 | enum_int | {"0":"关闭","1":"开启"} | | | 0 |
| »voltage | 备用电池电压 | int | {"desc":"备用电池关闭时电压为0","max":"30000","min":"0","step":"1","unit_name":"毫伏 / mV"} | | | 0 |
| »temperature | 备用电池温度 | float | {"step":"0.1","unit_name":"摄氏度 / °C"} | 保留小数点后一位 | | 0 |
| alarm_state | 机场声光报警状态 | enum_int | {"0":"关闭","1":"开启"} | | r | 0 |
| battery_store_mode | 电池运行模式 | enum_int | {"1":"计划模式","2":"待命模式"} | 计划模式适合规律作业场景,无任务时电池电量保持在55%~60%,电池寿命较长。待命模式适合应急作业场景,无任务时电池电量保持在90%~95%,电池寿命较短。 | r | 0 |
| activation_time | 机场激活时间(unix 时间戳) | int | {"unit_name":"秒 / s"} | | r | 0 |
| height | 椭球高度 | double | {"unit_name":"米 / m"} | | r | 0 |
| alternate_land_point | 备降点 | struct | | | r | 0 |
| »longitude | 经度 | float | {} | | | 0 |
| »latitude | 纬度 | float | {} | | | 0 |
| »safe_land_height | 安全高度(备降转移高) | float | {} | | | 0 |
| »is_configured | 是否设置备降点 | enum_int | {"0":"未设置","1":"已设置"} | | | 0 |
| »height | 椭球高度 | float | | | | 0 |
| compatible_status | 固件一致性 | enum_int | {"0":"不需要一致性升级","1":"需要一致性升级"} | 一致性升级:指飞行器某些模块的固件版本与系统匹配版本不一致,需要进行升级。常见的情况例如:飞行器与遥控器已经升级至最新版本,但替换电池时发现电池未升级,此时一致性升级将被提示。普通升级:开发者将飞行器所有模块升级至指定固件版本。 | r | 1 |
| acc_time | 机场累计运行时长 | int | {"unit_name":"秒 / s"} | | r | 1 |
| first_power_on | 首次上电时间 | int | {"unit_name":"毫秒 / ms"} | | r | 0 |
| storage | 存储容量 | struct | | | r | 0 |
| »total | 总容量 | int | {"unit_name":"千字节 / KB"} | | | 0 |
| »used | 已使用容量 | int | {"unit_name":"千字节 / KB"} | | | 0 |
| working_current | 工作电流 | float | {"unit_name":"毫安 / mA"} | | r | 0 |
| working_voltage | 工作电压 | int | {"unit_name":"毫伏 / mV"} | | r | 0 |
| humidity | 舱内湿度 | float | {"max":"100","min":"0","step":"0.1","unit_name":"相对湿度 / %RH"} | | r | 0 |
| temperature | 舱内温度 | float | {"unit_name":"摄氏度 / °C"} | | r | 0 |
| environment_temperature | 环境温度 | float | {"unit_name":"摄氏度 / °C"} | | r | 0 |
| wind_speed | 风速 | float | {"unit_name":"米每秒 / m/s"} | | r | 0 |
| rainfall | 降雨量 | enum_int | {"0":"无雨","1":"小雨","2":"中雨","3":"大雨"} | | r | 0 |
| live_capacity | 网关设备直播能力 | struct | | | r | 1 |
| »available_video_number | 可选择推流的码流数量 | int | | | | 0 |
| »coexist_video_number_max | 可同时推流的最大码流数量 | int | | | | 0 |
| »device_list | 可选择的视频设备源 | array | {"size": -, "item_type": struct} | 可选择的视频设备源(设备层,比如飞行器) | | 0 |
| »»sn | 飞行器等视频源设备序列号(SN) | text | | | | 0 |
| »»available_video_number | 该序列号设备可以被选择推流的码流数 | int | | | | 0 |
| »»coexist_video_number_max | 该序列号设备可以同时被推流的码流数 | int | | | | 0 |
| »»camera_list | 该序列号设备上的相机列表 | array | {"size": -, "item_type": struct} | | | 0 |
| »»»camera_index | 相机索引 | text | | 使用 *{type-subtype-gimbalindex}* 的格式 | | 0 |
| »»»available_video_number | 该相机级别的视频源可以被选择推流的码流数 | int | | | | 0 |
| »»»coexist_video_number_max | 该相机级别的视频源可以同时被推流的码流数 | int | | | | 0 |
| »»»video_list | 该相机级别的视频源可以选择的码流列表 | array | {"size": -, "item_type": struct} | | | 0 |
| »»»»video_index | 该相机级别的视频源可以选择的码流索引 | text | | | | 0 |
| »»»»video_type | 该相机级别的视频源可以选择的码流类型 | text | | | | 0 |
| »»»»switchable_video_types | 该视频流支持切换的视频镜头类型 | array | {"size": -, "item_type": text} | | | 0 |
| live_status | 网关当前整体直播状态推送 | array | {"size": -, "item_type": struct} | | r | 1 |
| »video_id | 直播码流标识符 | text | | 某路在推视频码流的标识符,格式为 *{sn}/{camera_index}/{video_index}*。其中 *{sn}* 为视频源设备序列号。*{camera_index}* 为相机索引,使用 *{type-subtype-gimbalindex}* 的格式。*{video_index}* 为该相机级别的视频源可以选择的码流索引。 | | 0 |
| »video_type | 视频类型 | text | {"length":"24"} | 表明视频镜头的类型,如normal/wide/zoom/infrared等 | | 0 |
| »video_quality | 直播码流的质量 | enum_int | {"0":"自适应","1":"流畅","2":"标清","3":"高清","4":"超清"} | | | 0 |
| »status | 直播状态 | enum_int | {"0":"未直播","1":"在直播"} | | | 0 |
| »error_status | 错误码 | int | {"length":6} | | | 0 |
| wireless_link | 图传链路 | struct | | | r | 0 |
| »dongle_number | 飞行器上 Dongle 数量 | int | | | | 0 |
| »4g_link_state | 4G 链路连接状态 | enum_int | {"0":"断开","1":"连接"} | | | 0 |
| »sdr_link_state | SDR 链路连接状态 | enum_int | {"0":"断开","1":"连接"} | | | 0 |
| »link_workmode | 机场的图传链路模式 | enum_int | {"0":"SDR 模式","1":"4G 融合模式"} | | | 0 |
| »sdr_quality | SDR 信号质量 | int | {"max":"5","min":"0","step":"1"} | | | 0 |
| »4g_quality | 总体 4G 信号质量 | int | {"max":"5","min":"0","step":"1"} | | | 0 |
| »4g_uav_quality | 天端 4G 信号质量 | int | {"max":"5","min":"0","step":"1"} | 飞行器端与 4G 服务器之间的信号质量 | | 0 |
| »4g_gnd_quality | 地端 4G 信号质量 | int | {"max":"5","min":"0","step":"1"} | 地面端(如遥控器、DJI Dock等)与 4G 服务器之间的信号质量 | | 0 |
| »sdr_freq_band | SDR 频段 | float | | | | 0 |
| »4g_freq_band | 4G 频段 | float | | | | 0 |
| media_file_detail | 媒体文件上传细节 | struct | | | r | 0 |
| »remain_upload | 待上传数量 | int | | | | 0 |
| job_number | 机场累计作业次数 | int | {"unit_name":"次 / count"} | | r | 0 |
| drone_in_dock | 飞行器是否在舱 | enum_int | {"0":"舱外","1":"舱内"} | | r | 0 |
| network_state | 网络状态 | struct | | | r | 0 |
| »type | 网络类型 | enum_int | {"1":"4G","2":"以太网"} | | | 0 |
| »quality | 网络质量 | enum_int | {"0":"无信号","1":"差","2":"较差","3":"一般","4":"较好","5":"好"} | | | 0 |
| »rate | 网络速率 | float | {"unit_name":"千字节每秒 / KB/s"} | | | 0 |
| supplement_light_state | 补光灯状态 | enum_int | {"0":"关闭","1":"打开"} | | r | 0 |
| cover_state | 舱盖状态 | enum_int | {"0":"关闭","1":"打开","2":"半开","3":"舱盖状态异常"} | | r | 0 |
| sub_device | 子设备状态 | struct | | | r | 0 |
| »device_sn | 子设备序列号(SN) | text | | | | 0 |
| »device_model_key | 子设备枚举值 | text | | 格式为 *{domain-type-subtype}* | | 0 |
| »device_online_status | 机场停机坪上的飞行器开机状态 | enum_int | {"0":"关机","1":"开机"} | | | 0 |
| »device_paired | 机场停机坪上的飞行器是否与机场对频 | enum_int | {"0":"未对频","1":"已对频"} | | | 0 |
| flighttask_step_code | 机场任务状态 | enum_int | {"0":"作业准备中","1":"飞行作业中","2":"作业后状态恢复","3":"自定义飞行区更新中","4":"地形障碍物更新中","5":"任务空闲","255":"飞行器异常","256":"未知状态"} | | r | 0 |
| mode_code | 机场状态 | enum_int | {"0":"空闲中","1":"现场调试","2":"远程调试","3":"固件升级中","4":"作业中"} | | r | 0 |
| firmware_upgrade_status | 固件升级状态 | enum_int | {"0":"未升级","1":"升级中"} | | r | 1 |
| firmware_version | 固件版本 | text | {"length":"64"} | | r | 1 |
| latitude | 纬度 | double | {"max":"90","min":"-90","step":"0.01"} | | r | 0 |
| longitude | 经度 | double | {"max":"180","min":"-180","step":"0.01"} | 网关设备的经度 | r | |
```json
{
"bid": "939bf66d-eb0a-4804-baad-7cbc4e175253",
"data": {
"drc_state": 0,
"flighttask_prepare_capacity": 1,
"flighttask_step_code": 1,
"media_file_detail": { "remain_upload": 0 },
"sdr": { "down_quality": 100, "frequency_band": 2.4, "up_quality": 100 },
"user_experience_improvement": 3,
"wireless_link": {
"4g_freq_band": 5.8,
"4g_gnd_quality": 5,
"4g_link_state": 1,
"4g_quality": 5,
"4g_uav_quality": 5,
"dongle_number": 1,
"link_workmode": 1,
"sdr_freq_band": 5.8,
"sdr_link_state": 1,
"sdr_quality": 5
}
},
"tid": "795e35f0-109c-4ff5-bd83-f9a7ceb8e2c6",
"timestamp": 1735466829704,
"gateway": "7CTDM6F00B744S"
}
```
```json
{
"tid": "3c2afb04-e637-4b16-8cd0-c15094527398",
"bid": "933bac6c-338e-4ecd-90b9-951308c439e0",
"timestamp": 1735466829710,
"data": {
"network_state": { "type": 2, "quality": 0, "rate": 32 },
"drone_charge_state": { "state": 0, "capacity_percent": 72 },
"drone_in_dock": 0,
"rainfall": 0,
"wind_speed": 0,
"environment_temperature": 7.1,
"temperature": 6.6,
"humidity": 45,
"heading": -72.980140686035156,
"home_position_is_valid": 1,
"latitude": 39.10260381347603,
"longitude": 117.71197297315571,
"height": 5.8588995933532715,
"alternate_land_point": {
"latitude": 39.102598739909752,
"longitude": 117.71198964942272,
"height": 0,
"safe_land_height": 30,
"is_configured": 1
},
"first_power_on": 1631945855969,
"position_state": {
"is_calibration": 1,
"is_fixed": 2,
"quality": 5,
"gps_number": 7,
"rtk_number": 36
},
"storage": { "total": 79981124, "used": 69124 },
"mode_code": 4,
"cover_state": 0,
"silent_mode": 1,
"supplement_light_state": 0,
"emergency_stop_state": 0,
"air_conditioner": { "air_conditioner_state": 0, "switch_time": 0 },
"battery_store_mode": 2,
"alarm_state": 0,
"putter_state": 0,
"sub_device": {
"device_sn": "1581F6QAD249M00GCRF5",
"device_online_status": 1,
"device_paired": 1
}
},
"gateway": "7CTDM6F00B744S"
}
```
```json
{
"tid": "f219d8d5-2c57-4a0e-b9a9-d72c77ea7dbe",
"bid": "f188e509-41d3-4e70-bb63-938b15193387",
"timestamp": 1735466829726,
"data": {
"job_number": 48,
"acc_time": 618911,
"activation_time": 1734482524,
"maintain_status": {
"maintain_status_array": [
{
"state": 0,
"last_maintain_type": 17,
"last_maintain_time": 0,
"last_maintain_work_sorties": 0
},
{
"state": 0,
"last_maintain_type": 18,
"last_maintain_time": 0,
"last_maintain_work_sorties": 0
}
]
},
"electric_supply_voltage": 32767,
"working_voltage": 27742,
"working_current": 0,
"backup_battery": { "voltage": 13601, "temperature": 12.4, "switch": 1 },
"drone_battery_maintenance_info": {
"maintenance_state": 0,
"maintenance_time_left": 0,
"heat_state": 0,
"batteries": [
{
"index": 0,
"capacity_percent": 72,
"voltage": 15366,
"temperature": 24.9
}
]
}
},
"gateway": "7CTDM6F00B744S"
}
```
```json
{
"bid": "883e903f-1ff7-4015-8c5c-a0c0c267aff5",
"data": {
"rtcm_info": {
"host": "120.253.226.97",
"mount_point": "RTCM33_GRCEJ",
"port": "8002",
"rtcm_device_type": 1,
"source_type": 3
}
},
"need_reply": 1,
"tid": "3116ca3e-3335-4467-8b8e-c2b028fce07f",
"timestamp": 1735466831441,
"gateway": "7CTDM6F00B744S"
}
```
飞机:
| best_link_gateway | 飞行器图传连接质量最好的网关SN | text | | 蛙跳任务场景下,当飞行器对频了两个机场后,推送连接最好的机场SN | r | 1 |
| --- | --- | --- | --- | --- | --- | --- |
| wireless_link_topo | 图传连接拓扑 | struct | | | r | 1 |
| »secret_code | 加密编码 | array | {"size": 28, "item_type": int} | | | 0 |
| »center_node | 飞行器对频信息 | struct | | | | 0 |
| »»sdr_id | 扰码信息 | int | | | | 0 |
| »»sn | 设备sn | text | | | | 0 |
| »leaf_nodes | 当前连接的机场或遥控器对频信息 | array | {"size": -, "item_type": struct} | | | 0 |
| »»sdr_id | 扰码信息 | int | | | | 0 |
| »»sn | 设备sn | text | | | | 0 |
| »»control_source_index | 控制源序号 | int | {"max":"2","min":"1","step":"1","unit_name":"无 / "} | | | 0 |
| cameras | 飞行器相机信息 | array | {"size": -, "item_type": struct} | | r | 0 |
| »remain_photo_num | 剩余拍照张数 | int | | 剩余拍照张数 | | 0 |
| »remain_record_duration | 剩余录像时间 | int | {"unit_name":"秒 / s"} | 剩余录像时间 | | 0 |
| »record_time | 视频录制时长 | int | {"unit_name":"秒 / s"} | 视频录制时长 | | 0 |
| »payload_index | 负载编号 | text | | 负载编号,相机枚举值。非标准的 device_mode_key,格式为 {type-subtype-gimbalindex},可以参考[**产品支持open in new window**](https://developer.dji.com/doc/cloud-api-tutorial/cn/overview/product-support.html) | | 0 |
| »camera_mode | 相机模式 | enum_int | {"0":"拍照","1":"录像","2":"智能低光","3":"全景拍照"} | 相机模式 | | 0 |
| »photo_state | 拍照状态 | enum_int | {"0":"空闲","1":"拍照中"} | 拍照状态 | | 0 |
| »screen_split_enable | 分屏是否使能 | bool | {"0":"分屏使能关闭","1":"分屏使能开启"} | | | 0 |
| »recording_state | 录像状态 | enum_int | {"0":"空闲","1":"录像中"} | 录像状态 | | 0 |
| »zoom_factor | 变焦倍数 | float | | | | 0 |
| »ir_zoom_factor | 红外变焦倍数 | float | | 红外变焦倍数 | | 0 |
| »liveview_world_region | 视场角(FOV)在 liveview 中的区域 | struct | | 变焦相机的视场角相对于广角相机或者红外相机的视场角,在 liveview 中会有所不同。坐标原点为镜头左上角。 | | 0 |
| »»left | 左上角的 x 轴起始点 | float | | 左上角的 x 轴起始点 | r | 0 |
| »»top | 左上角的 y 轴起始点 | float | | 左上角的 y 轴起始点 | r | 0 |
| »»right | 右下角的 x 轴起始点 | float | | 右下角的 x 轴起始点 | r | 0 |
| »»bottom | 右下角的 y 轴起始点 | float | | 右下角的 y 轴起始点 | r | 0 |
| »photo_storage_settings | 照片存储设置集合 | array | {"size": -, "item_type": enum_string} | 取值范围{current, vision, ir} | | 0 |
| »video_storage_settings | 视频存储设置集合 | array | {"size": -, "item_type": enum_string} | 取值范围{current, vision, ir} | | 0 |
| »wide_exposure_mode | 广角镜头曝光模式 | enum_int | {"1":"自动","2":"快门优先曝光","3":"光圈优先曝光","4":"手动曝光"} | 当前配置的广角镜头曝光模式 | | 0 |
| »wide_iso | 广角镜头感光度 | enum_int | {"0":"Auto","1":"Auto(High Sense)","2":"50","3":"100","4":"200","5":"400","6":"800","7":"1600","8":"3200","9":"6400","10":"12800","11":"25600","255":"FIXED"} | 当前配置的广角镜头感光度 | | 0 |
| »wide_shutter_speed | 广角镜头快门速度 | enum_int | {"0":"1/8000 s","1":"1/6400 s","2":"1/6000 s","3":"1/5000 s","4":"1/4000 s","5":"1/3200 s","6":"1/3000 s","7":"1/2500 s","8":"1/2000 s","9":"1/1600 s","10":"1/1500 s","11":"1/1250 s","12":"1/1000 s","13":"1/800 s","14":"1/725 s","15":"1/640 s","16":"1/500 s","17":"1/400 s","18":"1/350 s","19":"1/320 s","20":"1/250 s","21":"1/240 s","22":"1/200 s","23":"1/180 s","24":"1/160 s","25":"1/125 s","26":"1/120 s","27":"1/100 s","28":"1/90 s","29":"1/80 s","30":"1/60 s","31":"1/50 s","32":"1/40 s","33":"1/30 s","34":"1/25 s","35":"1/20 s","36":"1/15 s","37":"1/12.5 s","38":"1/10 s","39":"1/8 s","40":"1/6.25 s","41":"1/5 s","42":"1/4 s","43":"1/3 s","44":"1/2.5 s","45":"1/2 s","46":"1/1.67 s","47":"1/1.25 s","48":"1.0 s","49":"1.3 s","50":"1.6 s","51":"2.0 s","52":"2.5 s","53":"3.0 s","54":"3.2 s","55":"4.0 s","56":"5.0 s","57":"6.0 s","58":"7.0 s","59":"8.0 s","65534":"Auto"} | 当前配置的广角镜头快门速度 | | 0 |
| »wide_exposure_value | 广角镜头曝光值 | enum_int | {"1":"-5.0EV","2":"-4.7EV","3":"-4.3EV","4":"-4.0EV","5":"-3.7EV","6":"-3.3EV","7":"-3.0EV","8":"-2.7EV","9":"-2.3EV","10":"-2.0EV","11":"-1.7EV","12":"-1.3EV","13":"-1.0EV","14":"-0.7EV","15":"-0.3EV","16":"0EV","17":"0.3EV","18":"0.7EV","19":"1.0EV","20":"1.3EV","21":"1.7EV","22":"2.0EV","23":"2.3EV","24":"2.7EV","25":"3.0EV","26":"3.3EV","27":"3.7EV","28":"4.0EV","29":"4.3EV","30":"4.7EV","31":"5.0EV","255":"FIXED"} | 当前配置的广角镜头曝光值 | | 0 |
| »zoom_exposure_mode | 变焦镜头曝光模式 | enum_int | {"1":"自动","2":"快门优先曝光","3":"光圈优先曝光","4":"手动曝光"} | 当前配置的变焦镜头曝光模式 | | 0 |
| »zoom_iso | 变焦镜头感光度 | enum_int | {"0":"Auto","1":"Auto(High Sense)","2":"50","3":"100","4":"200","5":"400","6":"800","7":"1600","8":"3200","9":"6400","10":"12800","11":"25600","255":"FIXED"} | 当前配置的变焦镜头感光度 | | 0 |
| »zoom_shutter_speed | 变焦镜头快门速度 | enum_int | {"0":"1/8000 s","1":"1/6400 s","2":"1/6000 s","3":"1/5000 s","4":"1/4000 s","5":"1/3200 s","6":"1/3000 s","7":"1/2500 s","8":"1/2000 s","9":"1/1600 s","10":"1/1500 s","11":"1/1250 s","12":"1/1000 s","13":"1/800 s","14":"1/725 s","15":"1/640 s","16":"1/500 s","17":"1/400 s","18":"1/350 s","19":"1/320 s","20":"1/250 s","21":"1/240 s","22":"1/200 s","23":"1/180 s","24":"1/160 s","25":"1/125 s","26":"1/120 s","27":"1/100 s","28":"1/90 s","29":"1/80 s","30":"1/60 s","31":"1/50 s","32":"1/40 s","33":"1/30 s","34":"1/25 s","35":"1/20 s","36":"1/15 s","37":"1/12.5 s","38":"1/10 s","39":"1/8 s","40":"1/6.25 s","41":"1/5 s","42":"1/4 s","43":"1/3 s","44":"1/2.5 s","45":"1/2 s","46":"1/1.67 s","47":"1/1.25 s","48":"1.0 s","49":"1.3 s","50":"1.6 s","51":"2.0 s","52":"2.5 s","53":"3.0 s","54":"3.2 s","55":"4.0 s","56":"5.0 s","57":"6.0 s","58":"7.0 s","59":"8.0 s","65534":"Auto"} | 当前配置的变焦镜头快门速度 | | 0 |
| »zoom_exposure_value | 变焦镜头曝光值 | enum_int | {"1":"-5.0EV","2":"-4.7EV","3":"-4.3EV","4":"-4.0EV","5":"-3.7EV","6":"-3.3EV","7":"-3.0EV","8":"-2.7EV","9":"-2.3EV","10":"-2.0EV","11":"-1.7EV","12":"-1.3EV","13":"-1.0EV","14":"-0.7EV","15":"-0.3EV","16":"0EV","17":"0.3EV","18":"0.7EV","19":"1.0EV","20":"1.3EV","21":"1.7EV","22":"2.0EV","23":"2.3EV","24":"2.7EV","25":"3.0EV","26":"3.3EV","27":"3.7EV","28":"4.0EV","29":"4.3EV","30":"4.7EV","31":"5.0EV","255":"FIXED"} | 当前配置的变焦镜头曝光值 | | 0 |
| »zoom_focus_mode | 变焦镜头对焦模式 | enum_int | {"0":"MF","1":"AFS","2":"AFC"} | | | 0 |
| »zoom_focus_value | 变焦镜头对焦值 | int | | | | 0 |
| »zoom_max_focus_value | 变焦镜头最大对焦值 | int | | | | 0 |
| »zoom_min_focus_value | 变焦镜头最小对焦值 | int | | | | 0 |
| »zoom_calibrate_farthest_focus_value | 变焦镜头标定的最远对焦值 | int | | 最清晰的最远位置对焦值 | | 0 |
| »zoom_calibrate_nearest_focus_value | 变焦镜头标定的最近对焦值 | int | | 最清晰的最近位置对焦值 | | 0 |
| »zoom_focus_state | 变焦镜头对焦状态 | enum_int | {"0":"空闲","1":"对焦中","2":"对焦成功","3":"对焦失败"} | | | 0 |
| »ir_metering_mode | 红外测温模式 | enum_int | {"0":"关闭测温","1":"点测温","2":"区域测温"} | | | 0 |
| »ir_metering_point | 红外测温点 | struct | | 红外测温点相关信息 | | 0 |
| »»x | 测温点坐标 x | double | {"max":1,"min":0} | 以镜头的左上角为坐标中心点,水平方向为 x | r | 0 |
| »»y | 测温点坐标 y | double | {"max":1,"min":0} | 以镜头的左上角为坐标中心点,竖直方向为 y | r | 0 |
| »»temperature | 测温点的温度 | double | | | r | 0 |
| »ir_metering_area | 红外测温区域 | struct | | 红外测温区域相关信息 | | 0 |
| »»x | 测温区域左上角点坐标 x | double | {"max":1,"min":0} | 以镜头的左上角为坐标中心点,水平方向为 x | r | 0 |
| »»y | 测温区域左上角点坐标 y | double | {"max":1,"min":0} | 以镜头的左上角为坐标中心点,竖直方向为 y | r | 0 |
| »»width | 测温区域宽度 | double | {"max":1,"min":0} | 测温区域宽度 | r | 0 |
| »»height | 测温区域高度 | double | {"max":1,"min":0} | 测温区域高度 | r | 0 |
| »»aver_temperature | 测温区域平均温度 | double | | 测温区域平均温度 | r | 0 |
| »»min_temperature_point | 测温区域最低温度点 | struct | | 测温区域最低温度点相关信息 | r | 0 |
| »»»x | 最低温度点坐标 x | double | {"max":1,"min":0} | 以镜头的左上角为坐标中心点,水平方向为 x | r | 0 |
| »»»y | 最低温度点坐标 y | double | {"max":1,"min":0} | 以镜头的左上角为坐标中心点,竖直方向为 y | r | 0 |
| »»»temperature | 最低温度点的温度 | double | | 最低温度点的温度 | r | 0 |
| »»max_temperature_point | 测温区域最高温度点 | struct | | 测温区域最高温度点相关信息 | r | 0 |
| »»»x | 最高温度点坐标 x | double | {"max":1,"min":0} | 以镜头的左上角为坐标中心点,水平方向为 x | r | 0 |
| »»»y | 最高温度点坐标 y | double | {"max":1,"min":0} | 以镜头的左上角为坐标中心点,竖直方向为 y | r | 0 |
| »»»temperature | 最高温度点的温度 | double | | 最高温度点的温度 | r | 0 |
| flysafe_database_version | 飞行安全数据库版本 | text | {"length":"64"} | | r | 1 |
| offline_map_enable | 离线地图开关 | bool | {"0":"关闭","1":"开启"} | 当离线地图关闭后,离线地图同步不再进行自动同步 | r | 1 |
| dongle_infos | 4G Dongle信息 | array | {"size": -, "item_type": struct} | | r | 1 |
| »imei | dongle imei | text | | Dongle 的唯一识别标志 | r | 0 |
| »dongle_type | Dongle 类型 | enum_int | {"6":"旧 Dongle","10":"支持 eSIM 的新 Dongle"} | Dongle 类型 | r | 0 |
| »eid | dongle eid | text | | eSIM 的唯一识别标志,用于公众号查询套餐、购买服务 | r | 0 |
| »esim_activate_state | eSIM 激活状态 | enum_int | {"0":"未激活","1":"已激活"} | 需要激活才能使用 | r | 0 |
| »sim_card_state | SIM 卡状态 | enum_int | {"0":"未插入","1":"已插入"} | Dongle 中实体 SIM 卡的插入状态 | r | 0 |
| »sim_slot | SIM 卡槽使能状态 | enum_int | {"0":"未知","1":"实体 SIM 卡","2":"eSIM"} | 标识 Dongle 当前正在使用的 SIM 卡槽 | r | 0 |
| »esim_infos | eSIM 信息 | array | {"size": -, "item_type": struct} | | r | 0 |
| »»telecom_operator | 支持的运营商 | enum_int | {"0":"未知","1":"移动","2":"联通","3":"电信"} | eSIM 支持的运营商 | r | 0 |
| »»enabled | eSIM 使能状态 | bool | {"false":"未使用","true":"使用中"} | 同时刻只能有一个 eSIM 是使能的 | r | 0 |
| »»iccid | sim iccid | text | | SIM 卡的唯一识别标志,可以用于实体 SIM 卡的套餐购买 | r | 0 |
| »sim_info | SIM 卡信息 | struct | | 可插入 Dongle 的实体 SIM 卡信息 | r | 0 |
| »»telecom_operator | 支持的运营商 | enum_int | {"0":"未知","1":"移动","2":"联通","3":"电信"} | SIM 卡支持的运营商 | r | 0 |
| »»sim_type | SIM 卡类型 | enum_int | {"0":"未知","1":"其他普通 SIM 卡","2":"三网卡"} | 实体 SIM 卡的类型 | r | 0 |
| »»iccid | sim iccid | text | | SIM 卡的唯一识别标志,可以用于实体 SIM 卡的套餐购买 | r | 0 |
| current_rth_mode | 返航高度模式当前值 | enum_int | {"0":"智能高度","1":"设定高度"} | 大疆机场当前实际使用的返航高度模式 | r | 1 |
| rth_mode | 返航高度模式设置值 | enum_int | {"0":"智能高度","1":"设定高度"} | 智能返航模式下,飞行器将自动规划最佳返航高度。大疆机场当前不支持设置返航高度模式,只能选择'设定高度'模式。当环境,光线不满足视觉系统要求时(譬如傍晚阳光直射、夜间弱光无光),飞行器将使用您设定的返航高度进行直线返航 | r | 1 |
| obstacle_avoidance | 飞行器避障状态 | struct | | | rw | 0 |
| »horizon | 水平避障状态 | enum_int | {"0":"关闭","1":"开启"} | | | 0 |
| »upside | 上视避障状态 | enum_int | {"0":"关闭","1":"开启"} | | | 0 |
| »downside | 下视避障状态 | enum_int | {"0":"关闭","1":"开启"} | | | 0 |
| is_near_area_limit | 是否接近限飞区 | enum_int | {"0":"未达到限飞区","1":"接近限飞区"} | | r | 0 |
| is_near_height_limit | 是否接近设定的限制高度 | enum_int | {"0":"未达到设定的限制高度","1":"接近设定的限制高度"} | | r | 0 |
| height_limit | 飞行器限高 | int | {"max":"1500","min":"20","step":"1","unit_name":"米 / m"} | | rw | 0 |
| night_lights_state | 飞行器夜航灯状态 | enum_int | {"0":"关闭","1":"打开"} | | rw | 0 |
| activation_time | 飞行器激活时间(unix 时间戳) | int | {"unit_name":"秒 / s"} | | r | 0 |
| maintain_status | 保养信息 | struct | | | r | 0 |
| »maintain_status_array | 保养信息数组 | array | {"size": -, "item_type": struct} | | | 0 |
| »»state | 保养状态 | enum_int | {"0":"无保养","1":"有保养"} | | | 0 |
| »»last_maintain_type | 上一次保养类型 | enum_int | {"1":"飞行器基础保养","2":"飞行器常规保养","3":"飞行器深度保养"} | | | 0 |
| »»last_maintain_time | 上一次保养时间 | date | {"unit_name":"秒 / s"} | | | 0 |
| »»last_maintain_flight_time | 上一次保养时飞行航时 | int | {"unit_name":"小时 / h"} | | | 0 |
| »»last_maintain_flight_sorties | 上一次保养时飞行架次 | int | {"max":"2147483647","min":"0","step":"1"} | | | 0 |
| total_flight_sorties | 飞行器累计飞行总架次 | int | {"max":"2147483647","min":"0","step":"1"} | | r | 0 |
| type_subtype_gimbalindex | 负载编号 | struct | | 与字段 payload_index 保持一致 | r | 0 |
| »gimbal_pitch | 云台俯仰轴角度 | double | {"max":"180","min":"-180","step":0.1,"unit_name":"度 / °"} | | | 0 |
| »gimbal_roll | 云台横滚轴角度 | double | {"max":"180","min":"-180","step":0.1,"unit_name":"度 / °"} | | | 0 |
| »gimbal_yaw | 云台偏航轴角度 | double | {"max":"180","min":"-180","step":0.1,"unit_name":"度 / °"} | | | 0 |
| »payload_index | 负载索引,格式为 *{type-subtype-gimbalindex}* | text | | | | 0 |
| »zoom_factor | 变焦倍数 | double | | | | 0 |
| track_id | 航迹 ID | text | {"length":"64"} | | r | 0 |
| position_state | 搜星状态 | struct | | | r | 0 |
| »is_fixed | 是否收敛 | enum_int | {"0":"未开始","1":"收敛中","2":"收敛成功","3":"收敛失败"} | | | 0 |
| »quality | 搜星档位 | enum_int | {"1":"1档","2":"2档","3":"3档","4":"4档","5":"5档","10":"RTK fixed"} | | | 0 |
| »gps_number | GPS 搜星数量 | int | | | | 0 |
| »rtk_number | RTK 搜星数量 | int | | | | 0 |
| storage | 存储容量 | struct | | kb | r | 0 |
| »total | 总容量 | int | {"unit_name":"千字节 / KB"} | | | 0 |
| »used | 已使用容量 | int | {"unit_name":"千字节 / KB"} | | | 0 |
| battery | 飞行器电池信息 | struct | | | r | 0 |
| »capacity_percent | 电池的总剩余电量 | int | {"max":100,"min":0} | | | 0 |
| »remain_flight_time | 剩余飞行时间 | int | {"unit_name":"秒 / s"} | | | 0 |
| »return_home_power | 返航所需电量百分比 | int | {"max":100,"min":0} | | | 0 |
| »landing_power | 强制降落电量百分比 | int | {"max":100,"min":0} | | | 0 |
| »batteries | 电池详细信息 | array | {"size": -, "item_type": struct} | | | 0 |
| »»capacity_percent | 电池剩余电量 | int | {"max":100,"min":0} | | | 0 |
| »»index | 电池序号 | int | {"min":"0"} | | | 0 |
| »»sn | 电池序列号(SN) | text | | | | 0 |
| »»type | 电池类型 | enum_int | {} | | | 0 |
| »»sub_type | 电池子类型 | enum_int | {} | | | 0 |
| »»firmware_version | 固件版本 | text | | | | 0 |
| »»loop_times | 电池循环次数 | int | | | | 0 |
| »»voltage | 电压 | int | {"unit_name":"毫伏 / mV"} | | | 0 |
| »»temperature | 温度 | float | {"unit_name":"摄氏度 / °C"} | 保留小数点后一位 | | 0 |
| »»high_voltage_storage_days | 高电压存储天数 | int | {"unit_name":"日 / day"} | | | 0 |
| total_flight_distance | 飞行器累计飞行总里程 | float | {"unit_name":"米 / m"} | | r | 0 |
| total_flight_time | 飞行器累计飞行航时 | int | {"unit_name":"秒 / s"} | | r | 0 |
| serious_low_battery_warning_threshold | 严重低电量告警 | int | | 用户设置的电池严重低电量告警百分比 | r | 1 |
| low_battery_warning_threshold | 低电量告警 | int | | 用户设置的电池低电量告警百分比 | r | 1 |
| control_source | 当前控制源 | text | | 可以为设备,也可以为某个浏览器。设备使用 A/B 表示 A 控,B 控,浏览器以自生成的 uuid 作为标识符 | r | 1 |
| wind_direction | 当前风向 | enum_int | {"1":"正北","2":"东北","3":"东","4":"东南","5":"南","6":"西南","7":"西","8":"西北"} | | r | 0 |
| wind_speed | 风速 | float | | 风速估计,该风速是通过飞行器姿态推测出的,有一定的误差,仅供参考,不能作为气象数据使用 | r | 0 |
| home_distance | 距离 Home 点的距离 | float | | | r | 0 |
| home_latitude | Home 点纬度 | float | | | r | 1 |
| home_longitude | Home 点经度 | float | | | r | 1 |
| attitude_head | 偏航轴角度 | int | | 偏航轴角度与真北角(经线)的角度,0到6点钟方向为正值,6到12点钟方向为负值 | r | 0 |
| attitude_roll | 横滚轴角度 | float | | | r | 0 |
| attitude_pitch | 俯仰轴角度 | float | | | r | 0 |
| elevation | 相对起飞点高度 | float | | | r | 0 |
| height | 绝对高度 | float | | 相对地球椭球面高度, 计算:相对起飞点的高度 + 起飞点的椭球高 | r | 0 |
| latitude | 当前位置纬度 | float | {"max":"3.4028235E38","min":"-1.4E-45","step":"0.1"} | | r | 0 |
| longitude | 当前位置经度 | float | {"max":"3.4028235E38","min":"-1.4E-45","step":"0.1"} | | r | 0 |
| vertical_speed | 垂直速度 | float | {"unit_name":"米每秒 / m/s"} | | r | 0 |
| horizontal_speed | 水平速度 | float | | | r | 0 |
| firmware_upgrade_status | 固件升级状态 | enum_int | {"0":"未升级","1":"升级中"} | | r | 1 |
| compatible_status | 固件一致性 | enum_int | {"0":"不需要一致性升级","1":"需要一致性升级"} | 一致性升级:指飞行器某些模块的固件版本与系统匹配版本不一致,需要进行升级。常见的情况例如:飞行器与遥控器已经升级至最新版本,但替换电池时发现电池未升级,此时一致性升级将被提示。普通升级:开发者将飞行器所有模块升级至指定固件版本。 | r | 1 |
| firmware_version | 固件版本 | text | {"length":"64"} | | r | 1 |
| gear | 档位 | enum_int | {"0":"A","1":"P","2":"NAV","3":"FPV","4":"FARM","5":"S","6":"F","7":"M","8":"G","9":"T"} | | r | 0 |
| mode_code_reason | 飞行器进入当前状态的原因 | enum_int | {"0":"无意义","1":"电池电量不足(返航、降落)","2":"电池电压不足(返航、降落)","3":"电压严重过低(返航、降落)","4":"遥控器按键请求(起飞、返航、降落)","5":"App 请求(起飞、返航、降落)","6":"遥控信号丢失(返航、降落、悬停)","7":"导航、SDK 等外部设备触发(起飞、返航、降落)","8":"进入机场限飞区(降落)","9":"虽然触发了返航但是因为距离 Home 点距离太近(降落)","10":"虽然触发了返航但是因为距离 Home 点距离太远(降落)","11":"执行航点任务时请求(起飞)","12":"返航阶段到达 Home 点上方后请求(降落)","13":"飞行器高度下降,距地面 0.7m(二段降落限低)时,继续下降导致(降落)","14":"App、SDK 等设备强制突破限低保护进行(降落)","15":"因为周围有航班经过而请求(返航、降落)","16":"因为高度控制失败请求(返航、降落)","17":"智能低电量返航后进入(降落)","18":"AP控制飞行模式(手动飞行)","19":"硬件异常(返航、降落)","20":"防触地保护结束(降落)","21":"返航取消 (悬停)","22":"返航时遇到障碍物(降落)","23":"机场场景下大风触发(返航)"} | | r | 1 |
| commander_flight_height | 指点飞行高度 | float | {"max":3000,"min":2,"step":0.1,"unit_name":"米 / m"} | 相对(机场)起飞点的高度,相对高 ALT | rw | 1 |
| commander_flight_mode | 指点飞行模式设置值 | enum_int | {"0":"智能高度飞行","1":"设定高度飞行"} | 指点飞行模式设置值 | rw | 1 |
| commander_mode_lost_action | 指点飞行失控动作 | enum_int | {"0":"继续执行指点飞行任务","1":"退出指点飞行任务,执行普通失控行为"} | 执行指点飞行时失控了,选择继续执行完,还是执行普通失控行为 | rw | 1 |
| camera_watermark_settings | 相机水印设置 | struct | | 用户对相机拍摄的照片和录像文件进行水印配置, 目前暂不支持直播画面水印 | rw | 1 |
| »global_enable | 水印显示全局开关 | enum_int | {"0":"关闭","1":"开启"} | 需要开启全局开关才能显示水印 | rw | 1 |
| »drone_type_enable | 机型显示开关 | enum_int | {"0":"关闭","1":"开启"} | | rw | 1 |
| »drone_sn_enable | 飞行器序列号显示开关 | enum_int | {"0":"关闭","1":"开启"} | | rw | 1 |
| »datetime_enable | 日期时间显示开关 | enum_int | {"0":"关闭","1":"开启"} | 时区默认为当地时区 | rw | 1 |
| »gps_enable | 经纬度&海拔高显示开关 | enum_int | {"0":"关闭","1":"开启"} | | rw | 1 |
| »user_custom_string_enable | 自定义文案显示开关 | enum_int | {"0":"关闭","1":"开启"} | | rw | 1 |
| »user_custom_string | 自定义文案内容 | text | | 最多可显示 250 字节 | rw | 1 |
| »layout | 水印在画面中位置 | enum_int | {"0":"左上","1":"左下","2":"右上","3":"右下"} | | rw | 1 |
| mode_code | 飞行器状态 | enum_int | {"0":"待机","1":"起飞准备","2":"起飞准备完毕","3":"手动飞行","4":"自动起飞","5":"航线飞行","6":"全景拍照","7":"智能跟随","8":"ADS-B 躲避","9":"自动返航","10":"自动降落","11":"强制降落","12":"三桨叶降落","13":"升级中","14":"未连接","15":"APAS","16":"虚拟摇杆状态","17":"指令飞行","18":"空中 RTK 收敛模式","19":"机场选址中"} | 机场选址指飞行器在空中悬停,为机场选址以及检查 RTK 信号质量 | r | 0 |
```json
{
"bid": "f7f2dd20-a08a-4865-9211-f0ced31a798c",
"data": {
"80-0-0": {
"gimbal_pitch": 0,
"gimbal_roll": 0,
"gimbal_yaw": -72.9804724552571,
"payload_index": "80-0-0",
"zoom_factor": 0.56782334384858046
},
"activation_time": 1734637617,
"attitude_head": -72.9,
"attitude_pitch": -0.4,
"attitude_roll": -3,
"battery": {
"batteries": [
{
"capacity_percent": 78,
"firmware_version": "26.03.00.48",
"high_voltage_storage_days": 8,
"index": 0,
"loop_times": 6,
"sn": "6Q7PM4ADA100QQ",
"sub_type": 0,
"temperature": 23.9,
"type": 0,
"voltage": 15544
}
],
"capacity_percent": 78,
"landing_power": 8,
"remain_flight_time": 1553,
"return_home_power": 26
},
"best_link_gateway": "7CTDM6F00B744S",
"cameras": [
{
"camera_mode": 1,
"liveview_world_region": {
"bottom": 1,
"left": 1,
"right": 1,
"top": 1
},
"payload_index": "80-0-0",
"photo_state": 0,
"record_time": 0,
"recording_state": 0,
"remain_photo_num": 0,
"remain_record_duration": 29207,
"wide_calibrate_farthest_focus_value": 35,
"wide_calibrate_nearest_focus_value": 84,
"wide_exposure_mode": 1,
"wide_exposure_value": 16,
"wide_focus_mode": 2,
"wide_focus_state": 1,
"wide_focus_value": 26,
"wide_iso": 9,
"wide_max_focus_value": 84,
"wide_min_focus_value": 35,
"wide_shutter_speed": 33,
"zoom_calibrate_farthest_focus_value": 35,
"zoom_calibrate_nearest_focus_value": 84,
"zoom_exposure_mode": 1,
"zoom_exposure_value": 16,
"zoom_factor": 1,
"zoom_focus_mode": 2,
"zoom_focus_state": 1,
"zoom_focus_value": 26,
"zoom_iso": 9,
"zoom_max_focus_value": 84,
"zoom_min_focus_value": 35,
"zoom_shutter_speed": 33
}
],
"country": "CN",
"distance_limit_status": {
"distance_limit": 5000,
"is_near_distance_limit": 0,
"state": 0
},
"elevation": 64,
"gear": 1,
"height": 69.8617935180664,
"height_limit": 220,
"home_distance": 0.11966302990913391,
"horizontal_speed": 0,
"is_near_area_limit": 1,
"is_near_height_limit": 0,
"latitude": 39.102602928799222,
"longitude": 117.71197176283638,
"maintain_status": {
"maintain_status_array": [
{
"last_maintain_flight_sorties": 0,
"last_maintain_flight_time": 0,
"last_maintain_time": 0,
"last_maintain_type": 1,
"state": 0
},
{
"last_maintain_flight_sorties": 0,
"last_maintain_flight_time": 0,
"last_maintain_time": 0,
"last_maintain_type": 2,
"state": 0
},
{
"last_maintain_flight_sorties": 0,
"last_maintain_flight_time": 0,
"last_maintain_time": 0,
"last_maintain_type": 3,
"state": 0
}
]
},
"mode_code": 9,
"night_lights_state": 0,
"obstacle_avoidance": { "downside": 0, "horizon": 0, "upside": 0 },
"position_state": {
"gps_number": 32,
"is_fixed": 2,
"quality": 5,
"rtk_number": 33
},
"rc_lost_action": 2,
"rid_state": true,
"rth_altitude": 60,
"storage": { "total": 243702000, "used": 4000 },
"total_flight_distance": 174010.89760393579,
"total_flight_sorties": 57,
"total_flight_time": 28866.739354778081,
"track_id": "586f7b33-4727-4026-a203-cf35a68626e5",
"vertical_speed": 0,
"wind_direction": 6,
"wind_speed": 35
},
"tid": "795fbf18-8bc1-43f7-bd10-895973319cb5",
"timestamp": 1735473362062,
"gateway": "7CTDM6F00B744S"
}
```
```json
{
"bid": "78f3725d-34c3-4498-b0d5-98d50dc0310d",
"data": { "mode_code_reason": 12 },
"need_reply": 1,
"tid": "88933f47-e55e-4e9e-a100-7a073cc09086",
"timestamp": 1735473362258,
"gateway": "7CTDM6F00B744S"
}
```
## 指令
### 起飞指令:
| target_latitude | 目标点纬度 | double | {"max":90,"min":-90} | 目标点纬度,角度值,南纬是负,北纬是正,精度到小数点后6位 |
| --- | --- | --- | --- | --- |
| target_longitude | 目标点经度 | double | {"max":180,"min":-180} | 目标点经度,角度值,东经是正,西经是负,精度到小数点后6位 |
| target_height | 目标点高度 | float | {"max":1500,"min":2,"step":0.1,"unit_name":"米 / m"} | 目标点高度(椭球高),使用 WGS84 模型,飞行器到点后默认行为:悬停 |
| security_takeoff_height | 安全起飞高度 | float | {"max":1500,"min":20,"step":0.1,"unit_name":"米 / m"} | 相对(机场)起飞点的高度(ALT),飞行器先升到特定的高度,然后再飞向目标点。 |
| rth_mode | 【必填】返航模式设置值 | enum_int | {"0":"智能高度","1":"设定高度"} | 智能返航模式下,飞行器将自动规划最佳返航高度。大疆机场当前不支持设置返航高度模式,只能选择'设定高度'模式。当环境,光线不满足视觉系统要求时(譬如傍晚阳光直射、夜间弱光无光),飞行器将使用您设定的返航高度进行直线返航 |
| rth_altitude | 返航高度 | int | {"max":1500,"min":2,"step":1,"unit_name":"米 / m"} | 相对(机场)起飞点的高度,相对高 ALT |
| rc_lost_action | 遥控器失控动作 | enum_int | {"0":"悬停","1":"着陆(降落)","2":"返航"} | 遥控器失控动作 |
| commander_mode_lost_action | 【必填】指点飞行失控动作 | enum_int | {"0":"继续执行指点飞行任务","1":"退出指点飞行任务,执行普通失控行为"} | |
| commander_flight_mode | 【必填】指点飞行模式设置值 | enum_int | {"0":"智能高度飞行","1":"设定高度飞行"} | |
| commander_flight_height | 【必填】指点飞行高度 | float | {"max":3000,"min":2,"step":0.1,"unit_name":"米 / m"} | 相对(机场)起飞点的高度,相对高 ALT |
| flight_id | 一键起飞任务 UUID | text | | 任务 UUID,全局唯一,用于染色,云端区分该值是普通计划任务还是一键起飞任务 |
| max_speed | 一键起飞的飞行过程中能达到的最大速度 | int | {"max":15,"min":1,"unit_name":"米每秒 / m/s"} | |
| simulate_mission | 是否在模拟器中执行任务 | struct | | 可选字段,用于在室内进行模拟任务调试。 |
| »is_enable | 是否开启模拟器任务 | enum_int | {"0":"不开启","1":"开启"} | 当次任务打开或关闭模拟器 |
| »latitude | 纬度 | double | {"max":"90.0","min":"-90.0"} | |
| »longitude | 经度 | double | {"max":"180.0","min":"-180.0"} | |
| flight_safety_advance_check | 飞行安全预检查 | bool | {"0":"关闭","1":"开启"} | 设置一键起飞和航线任务中的飞行安全是否预先检查。此字段为可选,默认为0,值为0表示关闭,1表示开启。飞行安全预先检查表示: 飞行器执行任务前,检查自身作业区文件是否与云端一致,如果不一致则拉取文件更新,如果一致则不处理 |
```json
{
"data": {
"flight_id": flight_id,
"max_speed": 5,
"rc_lost_action": 2,
"rth_altitude": 60.0,
"rth_mode": 1,
"security_takeoff_height": 60.0,
"target_height": 70.0,
"target_latitude": 39.102603,
"target_longitude": 117.711972,
"commander_mode_lost_action": 0,
"commander_flight_mode": 1,
"commander_flight_height": 70.0,
"simulate_mission": {
},
"flight_safety_advance_check": 0
},
"method": "takeoff_to_point"
}
```
### 飞向目标点:
| fly_to_id | 飞向目标点 ID | text | | |
| --- | --- | --- | --- | --- |
| max_speed | flyto 的飞行过程中能达到的最大速度 | int | {"max":15,"min":0,"unit_name":"米每秒 / m/s"} | |
| points | flyto 目标点列表 | array | {"size": -, "item_type": struct} | 仅支持 1 个目标点 |
| »latitude | 目标点纬度 | double | {"max":90,"min":-90} | 目标点纬度,角度值,南纬是负,北纬是正,精度到小数点后6位 |
| »longitude | 目标点经度 | double | {"max":180,"min":-180} | 目标点经度,角度值,东经是正,西经是负,精度到小数点后6位 |
| »height | 目标点高度 | float | {"max":10000,"min":2,"step":0.1,"unit_name":"米 / m"} | 目标点高度(椭球高),使用 WGS84 模型 |
```json
{
"data": {
"fly_to_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx",
"max_speed": 12,
"points": [
{
"height": 100,
"latitude": 12.23,
"longitude": 12.23
}
]
},
"method": "fly_to_point"
}
```
### 结束飞向目标点:
```json
{
"data": {},
"method": "fly_to_point_stop"
}
```
### 更新飞向目标点:
| max_speed | 指令飞行过程中能达到的最大速度 | int | {"max":15,"min":1,"unit_name":"米每秒 / m/s"} | |
| --- | --- | --- | --- | --- |
| points | 更新的目标点列表 | array | {"size": -, "item_type": struct} | 仅支持 1 个目标点 |
| »latitude | 目标点纬度 | double | {"max":90,"min":-90} | 目标点纬度,角度值,南纬是负,北纬是正,精度到小数点后6位 |
| »longitude | 目标点经度 | double | {"max":180,"min":-180} | 目标点经度,角度值,东经是正,西经是负,精度到小数点后6位 |
| »height | 目标点高度 | float | {"max":10000,"min":2,"step":0.1,"unit_name":"米 / m"} | 目标点高度(椭球高),使用 WGS84 模型 |
```json
{
"data": {
"max_speed": 12,
"points": [
{
"height": 100,
"latitude": 12.23,
"longitude": 12.23
}
]
},
"method": "fly_to_point_update"
}
```
### 返航:
```json
{
"data": {},
"method": "return_home"
}
```
@@ -0,0 +1,52 @@
package com.central.device.util;
import java.util.Map;
/**
* 获取map各类型值工具类
* @author lishilin
* @date 2020/03/12
*/
public class MapUtil {
public static String getStrValue(Map<String, Object> param, String id) {
Object val = getValue(param, id);
if (null == val) {
return null;
}
return val.toString();
}
public static Integer getIntValue(Map<String, Object> param, String id) {
Object val = getValue(param, id);
if (null == val) {
return null;
}
try {
return Integer.parseInt(param.get(id).toString());
} catch (NumberFormatException exp) {
return null;
}
}
public static Long getLongValue(Map<String, Object> param, String id) {
Object val = getValue(param, id);
if (null == val) {
return null;
}
try {
return Long.parseLong(param.get(id).toString());
} catch (NumberFormatException exp) {
return null;
}
}
public static Object getValue(Map<String, Object> param, String id) {
if (null == param && null == id) {
return null;
}
if (param.containsKey(id)) {
return param.get(id);
}
return null;
}
}
@@ -0,0 +1,119 @@
package com.central.device.util;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.central.device.util.http.HeaderUtils;
import com.central.device.util.http.HttpRequest;
import com.central.device.util.http.Response;
import com.central.device.util.http.SimpleHttpRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.io.IOException;
import java.util.Map;
/**
* @author LSL
*/
@Slf4j
@Component
public class RequestUtils {
@Autowired
private HeaderUtils headerUtils;
/**
* 获取post请求result
* @param url 请求url
* @param jsonObject 请求参数
* @return
* @throws IOException
*/
public Map<String, String> getPostRequestResultMap(String url, JSONObject jsonObject) throws IOException {
System.out.println(url);
HttpRequest request = new SimpleHttpRequest(url);
request.headers(headerUtils.createHeadersOfJsonString(jsonObject.toJSONString()));
request.requestBody(jsonObject.toJSONString());
Response response = request.post();
Map<String, String> result = Utils.queryStringToMap(new String(response.asBytes(), "utf8"), "utf8");
return result;
}
/**
* 获取post请求result
* @param url 请求url
* @param param 请求参数
* @return
* @throws IOException
*/
public Map<String, String> getPostRequestResultMap(String url, Map param) throws IOException {
System.out.println(url);
HttpRequest request = new SimpleHttpRequest(url);
request.headers(headerUtils.createHeadersOfJsonString(JSON.toJSONString(param)));
request.requestBody(JSON.toJSONString(param));
Response response = request.post();
Map<String, String> result = Utils.queryStringToMap(new String(response.asBytes(), "utf8"), "utf8");
return result;
}
/**
* 获取post请求result
* @param url 请求url
* @param body 请求参数
* @return
* @throws IOException
*/
public Map<String, String> getPostRequestResultMap(String url, String body) throws IOException {
System.out.println(url);
HttpRequest request = new SimpleHttpRequest(url);
request.headers(headerUtils.createHeadersOfJsonString(body));
request.requestBody(body);
Response response = request.post();
Map<String, String> result = Utils.queryStringToMap(new String(response.asBytes(), "utf8"), "utf8");
System.out.println(result);
return result;
}
/**
* @param url 请求url
* @param map 请求参数map
* @return
* @throws IOException
*/
public Map<String, String> getGetRequestResultMap(String url,Map map) throws IOException {
HttpRequest request = new SimpleHttpRequest(url);
request.headers(headerUtils.createHeadersOfParams(map));
Response response = request.get();
Map<String, String> result = Utils.queryStringToMap(new String(response.asBytes(), "utf8"), "utf8");
return result;
}
/**
* 获取post请求result
* @param url 请求url
* @param param 请求参数
* @return
* @throws IOException
*/
public Map<String, String> getThirdPartyPostRequestResultMap(String url, Map param) {
log.info("url:{} , {}",url,param);
HttpRequest request = new SimpleHttpRequest(url);
request.headers(headerUtils.createHeadersOfJsonString(JSON.toJSONString(param)));
request.requestBody(JSON.toJSONString(param));
Response response;
Map<String, String> result = null;
try {
response = request.post();
result = Utils.queryStringToMap(new String(response.asBytes(), "utf8"), "utf8");
} catch (IOException e) {
log.info("查询异常:{}",e.getMessage());
e.printStackTrace();
}
// log.info("获取post请求result结果:{}" ,JSON.toJSONString(result));
return result;
}
}
@@ -0,0 +1,47 @@
package com.central.device.util;
import java.io.*;
import java.net.URLDecoder;
import java.util.HashMap;
import java.util.Map;
/**
* @author lishilin
* @see
* @since 2.0
*/
public class Utils {
public static Map<String,String> queryStringToMap(String queryString, String charset){
try {
Map<String,String> map = new HashMap<>();
String[] decode = URLDecoder.decode(queryString,charset).split("&");
for (String keyValue : decode) {
String[] kv = keyValue.split("[=]",2);
map.put(kv.length>1?kv[1]:"",kv[0]);
}
return map;
} catch (UnsupportedEncodingException e) {
throw new UnsupportedOperationException(e);
}
}
/**
* 读文件
*
* @param file 文件
* @return
* @throws IOException
* @throws IOException
*/
public static String readTxt(File file) throws IOException {
String s = "";
InputStreamReader in = new InputStreamReader(new FileInputStream(file), "UTF-8");
BufferedReader br = new BufferedReader(in);
StringBuffer content = new StringBuffer();
while ((s = br.readLine()) != null) {
content = content.append(s);
}
return content.toString();
}
}
@@ -0,0 +1,81 @@
package com.central.device.util.http;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;
/**
* @author lishilin
* @see
* @since 1.0
*/
@Component
public class HeaderUtils {
// @Value("${jetlinks.clientId}")
private String xClientId = "WFMfEGS8iHrEPRBH" ;
// @Value("${jetlinks.secureKey}")
private String secureKey = "ihat3zHC6T7xPZYFAEnG3tExQiFANd2n" ;
public Map<String, String> createHeadersOfParams(Map<String, Object> params) {
//时间戳
String xTimestamp = String.valueOf(System.currentTimeMillis());
//openApi客户端id
// String xClientId = "rN7cpmQb884W4hcH";
//密钥
// String secureKey = "hBYtiNxQrA8FZbtetGhCZJPi";
//将参数按ASCII排序后拼接为k1=v1&k2=v2的格式
String paramString = new TreeMap<>(params).entrySet()
.stream()
.map(e -> e.getKey().concat("=").concat(String.valueOf(e.getValue())))
.collect(Collectors.joining("&"));
System.out.println(paramString);
//param+X-Timestamp+SecureKey通过MD5加密
MessageDigest digest = DigestUtils.getMd5Digest();
System.out.println(paramString + xTimestamp + secureKey);
digest.update(paramString.getBytes());
digest.update(xTimestamp.getBytes());
digest.update(secureKey.getBytes());
Map<String, String> headers = new HashMap<>();
headers.put("X-Sign", Hex.encodeHexString(digest.digest()));
headers.put("X-Client-Id", xClientId);
headers.put("X-Timestamp", xTimestamp);
return headers;
}
public Map<String, String> createHeadersOfJsonString(String jsonString) {
//时间戳
String xTimestamp = String.valueOf(System.currentTimeMillis());
//openApi客户端id
// String xClientId = "rN7cpmQb884W4hcH";
//密钥
// String secureKey = "hBYtiNxQrA8FZbtetGhCZJPi";
//param+X-Timestamp+SecureKey通过MD5加密
MessageDigest digest = DigestUtils.getMd5Digest();
System.out.println(jsonString + xTimestamp + secureKey);
digest.update(jsonString.getBytes());
digest.update(xTimestamp.getBytes());
digest.update(secureKey.getBytes());
Map<String, String> headers = new HashMap<>(5);
headers.put("X-Sign", Hex.encodeHexString(digest.digest()));
headers.put("X-Client-Id", xClientId);
headers.put("X-Timestamp", xTimestamp);
return headers;
}
}
@@ -0,0 +1,39 @@
package com.central.device.util.http;
import java.io.Closeable;
import java.io.IOException;
import java.util.Map;
/**
* @author wang
* @see
* @since 1.0
*/
public interface HttpRequest extends Closeable {
Response get() throws IOException;
Response post() throws IOException;
Response put() throws IOException;
Response delete() throws IOException;
Response patch() throws IOException;
HttpRequest encode(String encode);
HttpRequest contentType(String type);
HttpRequest param(String name, String value);
HttpRequest params(Map<String, Object> params);
HttpRequest header(String name, String value);
HttpRequest headers(Map<String, String> headers);
HttpRequest requestBody(String body);
HttpRequest resultAsJsonString();
}
@@ -0,0 +1,13 @@
package com.central.device.util.http;
import java.io.IOException;
/**
* @author wang
* @see
* @since 1.0
*/
public interface Response {
byte[] asBytes() throws IOException;
}
@@ -0,0 +1,184 @@
package com.central.device.util.http;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.*;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author wang
* @see
* @since 1.0
*/
public class SimpleHttpRequest implements HttpRequest {
private Map<String, Object> params = new LinkedHashMap<>();
private Map<String, String> headers = new LinkedHashMap<>();
private String url;
private String requestBody;
private String contentType;
private String encode = "utf-8";
protected HttpClient httpClient;
public SimpleHttpRequest(String url) {
this.url = url;
createHttpClient();
}
public SimpleHttpRequest(String url, HttpClient client) {
this.url = url;
this.httpClient = client;
}
protected void createHttpClient() {
if (httpClient == null) {
HttpClientBuilder builder = HttpClientBuilder.create();
httpClient = builder.build();
}
}
@Override
public Response get() throws IOException {
String param = EntityUtils.toString(createUrlEncodedFormEntity());
String tmpUrl = url + (url.contains("?") ? "&" : "?") + param;
HttpGet get = new HttpGet(tmpUrl);
HttpResponse response = execute(get);
return getResultValue(response);
}
@Override
public Response post() throws IOException {
HttpPost post = new HttpPost(url);
if (requestBody != null)
post.setEntity(new StringEntity(requestBody, ContentType.create(contentType,encode)));
else {
post.setEntity(createUrlEncodedFormEntity());
}
HttpResponse response = execute(post);
return getResultValue(response);
}
@Override
public Response put() throws IOException {
HttpPut put = new HttpPut(url);
if (requestBody != null)
put.setEntity(new StringEntity(requestBody, ContentType.create(contentType, encode)));
else {
put.setEntity(createUrlEncodedFormEntity());
}
HttpResponse response = execute(put);
return getResultValue(response);
}
protected UrlEncodedFormEntity createUrlEncodedFormEntity() throws UnsupportedEncodingException {
List<NameValuePair> nameValuePair = params.entrySet()
.stream().map(stringStringEntry ->
new BasicNameValuePair(stringStringEntry.getKey(), String.valueOf(stringStringEntry.getValue())))
.collect(Collectors.toList());
return new UrlEncodedFormEntity(nameValuePair, encode);
}
@Override
public Response delete() throws IOException {
HttpDelete delete = new HttpDelete(url);
HttpResponse response = execute(delete);
return getResultValue(response);
}
@Override
public Response patch() throws IOException {
HttpPatch delete = new HttpPatch(url);
if (requestBody != null)
delete.setEntity(new StringEntity(requestBody, ContentType.create(contentType)));
else {
delete.setEntity(createUrlEncodedFormEntity());
}
return getResultValue(execute(delete));
}
@Override
public void close() throws IOException {
if (httpClient != null && httpClient instanceof CloseableHttpClient) {
((CloseableHttpClient) httpClient).close();
}
}
@Override
public HttpRequest resultAsJsonString() {
header("Accept", "application/json");
return this;
}
@Override
public HttpRequest requestBody(String body) {
contentType("application/json");
this.requestBody = body;
return this;
}
@Override
public HttpRequest encode(String encode) {
this.encode = encode;
return this;
}
@Override
public HttpRequest contentType(String type) {
this.contentType = type;
return this;
}
@Override
public HttpRequest param(String name, String value) {
this.params.put(name, value);
return this;
}
@Override
public HttpRequest params(Map<String, Object> params) {
this.params.putAll(params);
return this;
}
@Override
public HttpRequest header(String name, String value) {
this.headers.put(name, value);
return this;
}
@Override
public HttpRequest headers(Map<String, String> header) {
this.headers.putAll(header);
return this;
}
private Response getResultValue(HttpResponse res) throws IOException {
return new SimpleResponse(res);
}
private HttpResponse execute(HttpRequestBase request) throws IOException {
putHeader(request);
return httpClient.execute(request);
}
private void putHeader(HttpUriRequest request) {
headers.forEach(request::setHeader);
}
}
@@ -0,0 +1,26 @@
package com.central.device.util.http;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
/**
* @author wang
* @see
* @since 1.0
*/
public class SimpleResponse implements Response {
HttpResponse response;
public SimpleResponse(HttpResponse response) {
this.response = response;
}
@Override
public byte[] asBytes() throws IOException {
return EntityUtils.toByteArray(response.getEntity());
}
}
@@ -1,6 +1,7 @@
spring:
datasource:
url: jdbc:mysql://${zlt.datasource.ip}:3306/device-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
# url: jdbc:mysql://${zlt.datasource.ip}:3306/device-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
url: jdbc:mysql://${zlt.datasource.ip}/device-center?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&useSSL=false&zeroDateTimeBehavior=convertToNull&serverTimezone=Asia/Shanghai
username: ${zlt.datasource.username}
password: ${zlt.datasource.password}
driver-class-name: com.mysql.cj.jdbc.Driver