Merge branch 'dev-V0.4.5' of https://gitee.com/iotkit-open-source/iotkit-parent into dev-V0.4.5
commit
c6ea4a9759
|
@ -29,15 +29,16 @@ public class ThingModelMessage {
|
|||
public static final String TYPE_LIFETIME = "lifetime";
|
||||
public static final String TYPE_STATE = "state";
|
||||
public static final String TYPE_PROPERTY = "property";
|
||||
|
||||
public static final String TYPE_EVENT = "event";
|
||||
public static final String TYPE_SERVICE = "service";
|
||||
public static final String TYPE_CONFIG = "config";
|
||||
|
||||
public static final String TYPE_OTA = "ota";
|
||||
public static final String TYPE_CONFIG = "config";
|
||||
public static final String ID_PROPERTY_GET = "get";
|
||||
public static final String ID_PROPERTY_SET = "set";
|
||||
public static final String ID_CONFIG_GET = "get";
|
||||
public static final String ID_CONFIG_SET = "set";
|
||||
|
||||
public static final String ID_DEREGISTER = "deregister";
|
||||
|
||||
private String id;
|
||||
|
|
|
@ -23,6 +23,10 @@ public class OtaPackage implements Id<String> {
|
|||
|
||||
private String sign;
|
||||
|
||||
private Boolean isDiff;
|
||||
|
||||
private String md5;
|
||||
|
||||
private String name;
|
||||
|
||||
private String desc;
|
||||
|
|
|
@ -23,6 +23,10 @@ public class TbOtaPackage {
|
|||
|
||||
private String sign;
|
||||
|
||||
private Boolean isDiff;
|
||||
|
||||
private String md5;
|
||||
|
||||
private String name;
|
||||
|
||||
private String desc;
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
var mid = 1;
|
||||
|
||||
function getMid() {
|
||||
|
@ -39,6 +38,18 @@ this.decode = function (msg) {
|
|||
time: new Date().getTime(), //时间戳,消息上报时间
|
||||
data: payload.params,
|
||||
};
|
||||
} else if (topic.indexOf("/ota/") > 0) {
|
||||
//事件上报
|
||||
return {
|
||||
mid: msg.mid,
|
||||
productKey: msg.productKey,
|
||||
deviceName: msg.deviceName,
|
||||
type: "ota",
|
||||
identifier: "ota",
|
||||
occur: new Date().getTime(),
|
||||
time: new Date().getTime(),
|
||||
data: payload.params,
|
||||
};
|
||||
} else if (topic.indexOf("/event/") > 0) {
|
||||
//事件上报
|
||||
return {
|
||||
|
@ -143,6 +154,9 @@ this.encode = function (service,device) {
|
|||
} else if (type == "service") {
|
||||
method += identifier;
|
||||
topic += identifier;
|
||||
} else if (type == "ota") {
|
||||
method += identifier;
|
||||
topic = "/ota/device/upgrade/" + service.productKey + "/" + service.deviceName;
|
||||
} else if (type == "config") {
|
||||
//设备配置下发
|
||||
method += identifier;
|
||||
|
|
|
@ -73,8 +73,10 @@ public class DeviceService {
|
|||
args, ThingModelMessage.TYPE_SERVICE, service);
|
||||
}
|
||||
|
||||
public String otaUpgrade(String token, boolean checkOwner) {
|
||||
return null;
|
||||
public String otaUpgrade(String deviceId, boolean checkOwner, Object data) {
|
||||
DeviceInfo device = getAndCheckDevice(deviceId, checkOwner);
|
||||
return send(deviceId, device.getProductKey(), device.getDeviceName(),
|
||||
data, ThingModelMessage.TYPE_OTA, "OTA");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,7 @@ import cc.iotkit.data.manager.IOtaDeviceData;
|
|||
import cc.iotkit.data.manager.IOtaPackageData;
|
||||
import cc.iotkit.model.alert.AlertConfig;
|
||||
import cc.iotkit.model.ota.OtaPackage;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
@ -63,9 +64,27 @@ public class OtaService {
|
|||
/**
|
||||
* 开始升级
|
||||
*/
|
||||
public void startUpgrade() {
|
||||
public void startUpgrade(String otaId, String deviceId) {
|
||||
OtaPackage otaPackage = iOtaPackageData.findById(otaId);
|
||||
//构建升级包
|
||||
deviceService.otaUpgrade("", true);
|
||||
JsonObject buildOtaPackage = buildOtaPackage(otaPackage);
|
||||
String id = deviceService.otaUpgrade(deviceId, true, buildOtaPackage);
|
||||
}
|
||||
|
||||
private JsonObject buildOtaPackage(OtaPackage otaPackage) {
|
||||
JsonObject ota = new JsonObject();
|
||||
JsonObject extData = new JsonObject();
|
||||
extData.addProperty("key1", "测试1");
|
||||
extData.addProperty("key2", "测试2");
|
||||
ota.addProperty("size", otaPackage.getSize());
|
||||
ota.addProperty("sign", otaPackage.getSign());
|
||||
ota.addProperty("version", otaPackage.getVersion());
|
||||
ota.addProperty("isDiff", Boolean.toString(otaPackage.getIsDiff()));
|
||||
ota.addProperty("url", otaPackage.getUrl());
|
||||
ota.addProperty("signMethod", "MD5");
|
||||
ota.addProperty("module", "MCU");
|
||||
ota.add("extData", extData);
|
||||
return ota;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue