LWM2M: add response FirmWareUpdate
This commit is contained in:
parent
d469672706
commit
45fa1a7bd2
@ -89,4 +89,6 @@ public abstract class AbstractLwm2mTransportResource extends LwM2mCoapResource {
|
|||||||
exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
|
exchange.respond(CoAP.ResponseCode.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -139,6 +139,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
|||||||
public final LwM2mClientContext clientContext;
|
public final LwM2mClientContext clientContext;
|
||||||
public final LwM2mTransportRequest lwM2mTransportRequest;
|
public final LwM2mTransportRequest lwM2mTransportRequest;
|
||||||
private final Map<UUID, Long> rpcSubscriptions;
|
private final Map<UUID, Long> rpcSubscriptions;
|
||||||
|
private final Map<Integer, String> getCoapResource;
|
||||||
|
|
||||||
public DefaultLwM2MTransportMsgHandler(TransportService transportService, LwM2MTransportServerConfig config, LwM2mTransportServerHelper helper,
|
public DefaultLwM2MTransportMsgHandler(TransportService transportService, LwM2MTransportServerConfig config, LwM2mTransportServerHelper helper,
|
||||||
LwM2mClientContext clientContext,
|
LwM2mClientContext clientContext,
|
||||||
@ -154,6 +155,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
this.adaptor = adaptor;
|
this.adaptor = adaptor;
|
||||||
this.rpcSubscriptions = new ConcurrentHashMap<>();
|
this.rpcSubscriptions = new ConcurrentHashMap<>();
|
||||||
|
this.getCoapResource = new ConcurrentHashMap<>();
|
||||||
this.sessionStore = sessionStore;
|
this.sessionStore = sessionStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +201,7 @@ public class DefaultLwM2MTransportMsgHandler implements LwM2mTransportMsgHandler
|
|||||||
.setSessionType(TransportProtos.SessionType.ASYNC).build())
|
.setSessionType(TransportProtos.SessionType.ASYNC).build())
|
||||||
.build(), null);
|
.build(), null);
|
||||||
this.getInfoFirmwareUpdate(lwM2MClient, null);
|
this.getInfoFirmwareUpdate(lwM2MClient, null);
|
||||||
this.getInfoSoftwareUpdate(lwM2MClient, null);
|
// this.getInfoSoftwareUpdate(lwM2MClient, null);
|
||||||
this.initLwM2mFromClientValue(registration, lwM2MClient);
|
this.initLwM2mFromClientValue(registration, lwM2MClient);
|
||||||
this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration.getId());
|
this.sendLogsToThingsboard(LOG_LW2M_INFO + ": Client create after Registration", registration.getId());
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -30,6 +30,9 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.FW_COAP_RESOURCE;
|
||||||
|
import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportUtil.SW_COAP_RESOURCE;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class LwM2mTransportCoapResource extends AbstractLwm2mTransportResource {
|
public class LwM2mTransportCoapResource extends AbstractLwm2mTransportResource {
|
||||||
private final ConcurrentMap<String, ObserveRelation> tokenToObserveRelationMap = new ConcurrentHashMap<>();
|
private final ConcurrentMap<String, ObserveRelation> tokenToObserveRelationMap = new ConcurrentHashMap<>();
|
||||||
@ -65,8 +68,8 @@ public class LwM2mTransportCoapResource extends AbstractLwm2mTransportResource {
|
|||||||
protected void processHandleGet(CoapExchange exchange) {
|
protected void processHandleGet(CoapExchange exchange) {
|
||||||
log.warn("1) processHandleGet [{}]", exchange);
|
log.warn("1) processHandleGet [{}]", exchange);
|
||||||
// exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
|
// exchange.respond(CoAP.ResponseCode.BAD_REQUEST);
|
||||||
// int ver = 10;
|
int ver = 10;
|
||||||
int ver = 9;
|
// int ver = 9;
|
||||||
UUID currentId;
|
UUID currentId;
|
||||||
if (ver == 10) {
|
if (ver == 10) {
|
||||||
long mSB = 4951557297924280811L;
|
long mSB = 4951557297924280811L;
|
||||||
@ -77,10 +80,37 @@ public class LwM2mTransportCoapResource extends AbstractLwm2mTransportResource {
|
|||||||
long lSb = -9086716326447629319L;
|
long lSb = -9086716326447629319L;
|
||||||
currentId = new UUID(mSB, lSb);
|
currentId = new UUID(mSB, lSb);
|
||||||
}
|
}
|
||||||
String resource = exchange.getRequestOptions().getUriPath().get(0);
|
|
||||||
String token = exchange.getRequestOptions().getUriPath().get(1);
|
|
||||||
|
|
||||||
exchange.respond(CoAP.ResponseCode.CONTENT, this.getFwData(currentId));
|
String coapResource = exchange.getRequestOptions().getUriPath().get(0);
|
||||||
|
String token = exchange.getRequestOptions().getUriPath().get(1);
|
||||||
|
if (exchange.getRequestOptions().getBlock2() != null) {
|
||||||
|
int chunkSize = exchange.getRequestOptions().getBlock2().getSzx();
|
||||||
|
int chunk = 0;
|
||||||
|
Response response = new Response(CoAP.ResponseCode.CONTENT);
|
||||||
|
byte[] fwData = this.getFwData(currentId);
|
||||||
|
if (fwData != null && fwData.length > 0) {
|
||||||
|
response.setPayload(fwData);
|
||||||
|
boolean moreFlag = fwData.length > chunkSize;
|
||||||
|
response.getOptions().setBlock2(chunkSize, moreFlag, chunk);
|
||||||
|
exchange.respond(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
// List<String> options = exchange.advanced().getRequest().getOptions().getUriPath();
|
||||||
|
// options.stream()
|
||||||
|
// .filter(o -> FW_COAP_RESOURCE.equals(o))
|
||||||
|
// .findFirst()
|
||||||
|
// .ifPresent(o -> System.err.println(o.getNumber() + " " + o.getStringValue()));
|
||||||
|
|
||||||
|
if (FW_COAP_RESOURCE.equals(coapResource)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (SW_COAP_RESOURCE.equals(coapResource)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,9 +168,7 @@ public class LwM2mTransportCoapResource extends AbstractLwm2mTransportResource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private byte[] getFwData(UUID currentId) {
|
private byte[] getFwData(UUID currentId) {
|
||||||
int chunkSize = 0;
|
return ((DefaultLwM2MTransportMsgHandler) handler).otaPackageDataCache.get(currentId.toString());
|
||||||
int chunk = 0;
|
|
||||||
return ((DefaultLwM2MTransportMsgHandler) handler).otaPackageDataCache.get(currentId.toString(), chunkSize, chunk);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user