Commit 7edcc605e91a8f5b174bb4ccf651a01c1ffd687b
1 parent
edc99342
Firmware CoAP and transport improvement
Showing
4 changed files
with
19 additions
and
11 deletions
... | ... | @@ -33,6 +33,7 @@ import org.thingsboard.server.common.data.Device; |
33 | 33 | import org.thingsboard.server.common.data.DeviceProfile; |
34 | 34 | import org.thingsboard.server.common.data.EntityType; |
35 | 35 | import org.thingsboard.server.common.data.Firmware; |
36 | +import org.thingsboard.server.common.data.FirmwareInfo; | |
36 | 37 | import org.thingsboard.server.common.data.ResourceType; |
37 | 38 | import org.thingsboard.server.common.data.TbResource; |
38 | 39 | import org.thingsboard.server.common.data.TenantProfile; |
... | ... | @@ -471,19 +472,22 @@ public class DefaultTransportApiService implements TransportApiService { |
471 | 472 | if (firmwareId == null) { |
472 | 473 | builder.setResponseStatus(TransportProtos.ResponseStatus.NOT_FOUND); |
473 | 474 | } else { |
474 | - Firmware firmware = firmwareService.findFirmwareById(tenantId, firmwareId); | |
475 | + FirmwareInfo firmwareInfo = firmwareService.findFirmwareInfoById(tenantId, firmwareId); | |
475 | 476 | |
476 | - if (firmware == null) { | |
477 | + if (firmwareInfo == null) { | |
477 | 478 | builder.setResponseStatus(TransportProtos.ResponseStatus.NOT_FOUND); |
478 | 479 | } else { |
479 | 480 | builder.setResponseStatus(TransportProtos.ResponseStatus.SUCCESS); |
480 | 481 | builder.setFirmwareIdMSB(firmwareId.getId().getMostSignificantBits()); |
481 | 482 | builder.setFirmwareIdLSB(firmwareId.getId().getLeastSignificantBits()); |
482 | - builder.setTitle(firmware.getTitle()); | |
483 | - builder.setVersion(firmware.getVersion()); | |
484 | - builder.setFileName(firmware.getFileName()); | |
485 | - builder.setContentType(firmware.getContentType()); | |
486 | - firmwareDataCache.put(firmwareId.toString(), firmware.getData().array()); | |
483 | + builder.setTitle(firmwareInfo.getTitle()); | |
484 | + builder.setVersion(firmwareInfo.getVersion()); | |
485 | + builder.setFileName(firmwareInfo.getFileName()); | |
486 | + builder.setContentType(firmwareInfo.getContentType()); | |
487 | + if (!firmwareDataCache.has(firmwareId.toString())) { | |
488 | + Firmware firmware = firmwareService.findFirmwareById(tenantId, firmwareId); | |
489 | + firmwareDataCache.put(firmwareId.toString(), firmware.getData().array()); | |
490 | + } | |
487 | 491 | } |
488 | 492 | } |
489 | 493 | ... | ... |
... | ... | @@ -24,4 +24,9 @@ public interface FirmwareDataCache { |
24 | 24 | void put(String key, byte[] value); |
25 | 25 | |
26 | 26 | void evict(String key); |
27 | + | |
28 | + default boolean has(String firmwareId) { | |
29 | + byte[] data = get(firmwareId, 1, 0); | |
30 | + return data != null && data.length > 0; | |
31 | + } | |
27 | 32 | } | ... | ... |
common/transport/coap/src/main/java/org/thingsboard/server/transport/coap/CoapTransportResource.java
... | ... | @@ -20,7 +20,6 @@ import com.google.protobuf.Descriptors; |
20 | 20 | import com.google.protobuf.DynamicMessage; |
21 | 21 | import lombok.Data; |
22 | 22 | import lombok.extern.slf4j.Slf4j; |
23 | -import org.apache.commons.lang3.StringUtils; | |
24 | 23 | import org.eclipse.californium.core.coap.CoAP; |
25 | 24 | import org.eclipse.californium.core.coap.Request; |
26 | 25 | import org.eclipse.californium.core.coap.Response; |
... | ... | @@ -34,6 +33,7 @@ import org.thingsboard.server.coapserver.TbCoapDtlsSessionInfo; |
34 | 33 | import org.thingsboard.server.common.data.DataConstants; |
35 | 34 | import org.thingsboard.server.common.data.DeviceProfile; |
36 | 35 | import org.thingsboard.server.common.data.DeviceTransportType; |
36 | +import org.thingsboard.server.common.data.StringUtils; | |
37 | 37 | import org.thingsboard.server.common.data.TransportPayloadType; |
38 | 38 | import org.thingsboard.server.common.data.device.profile.CoapDeviceProfileTransportConfiguration; |
39 | 39 | import org.thingsboard.server.common.data.device.profile.CoapDeviceTypeConfiguration; |
... | ... | @@ -448,7 +448,7 @@ public class CoapTransportResource extends AbstractCoapTransportResource { |
448 | 448 | if (msg.getResponseStatus().equals(TransportProtos.ResponseStatus.SUCCESS)) { |
449 | 449 | if (msg.getTitle().equals(title) && msg.getVersion().equals(version)) { |
450 | 450 | String firmwareId = new UUID(msg.getFirmwareIdMSB(), msg.getFirmwareIdLSB()).toString(); |
451 | - String strChunkSize = exchange.getQueryParameter("chunkSize"); | |
451 | + String strChunkSize = exchange.getQueryParameter("size"); | |
452 | 452 | String strChunk = exchange.getQueryParameter("chunk"); |
453 | 453 | int chunkSize = StringUtils.isEmpty(strChunkSize) ? 0 : Integer.parseInt(strChunkSize); |
454 | 454 | int chunk = StringUtils.isEmpty(strChunk) ? 0 : Integer.parseInt(strChunk); | ... | ... |
... | ... | @@ -539,8 +539,7 @@ public class DefaultTransportService implements TransportService { |
539 | 539 | new TbProtoQueueMsg<>(UUID.randomUUID(), TransportProtos.TransportApiRequestMsg.newBuilder().setFirmwareRequestMsg(msg).build()); |
540 | 540 | |
541 | 541 | AsyncCallbackTemplate.withCallback(transportApiRequestTemplate.send(protoMsg), response -> { |
542 | - TransportProtos.GetFirmwareResponseMsg firmwareResponseMsg = response.getValue().getFirmwareResponseMsg(); | |
543 | - callback.onSuccess(firmwareResponseMsg); | |
542 | + callback.onSuccess(response.getValue().getFirmwareResponseMsg()); | |
544 | 543 | }, callback::onError, transportCallbackExecutor); |
545 | 544 | } |
546 | 545 | } | ... | ... |