Search in sources :

Example 6 with LwM2MClientSwOtaInfo

use of org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo in project thingsboard by thingsboard.

the class DefaultLwM2MOtaUpdateService method getOrInitSwInfo.

private LwM2MClientSwOtaInfo getOrInitSwInfo(LwM2mClient client) {
    return this.swStates.computeIfAbsent(client.getEndpoint(), endpoint -> {
        LwM2MClientSwOtaInfo info = otaInfoStore.getSw(endpoint);
        if (info == null) {
            var profile = clientContext.getProfile(client.getProfileId());
            info = new LwM2MClientSwOtaInfo(endpoint, profile.getClientLwM2mSettings().getSwUpdateResource(), LwM2MSoftwareUpdateStrategy.fromStrategySwByCode(profile.getClientLwM2mSettings().getSwUpdateStrategy()));
            update(info);
        }
        return info;
    });
}
Also used : LwM2MClientSwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo)

Example 7 with LwM2MClientSwOtaInfo

use of org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo in project thingsboard by thingsboard.

the class DefaultLwM2MOtaUpdateService method init.

@Override
public void init(LwM2mClient client) {
    // TODO: add locks by client fwInfo.
    // TODO: check that the client supports FW and SW by checking the supported objects in the model.
    List<String> attributesToFetch = new ArrayList<>();
    LwM2MClientFwOtaInfo fwInfo = getOrInitFwInfo(client);
    if (fwInfo.isSupported()) {
        attributesToFetch.add(FIRMWARE_TITLE);
        attributesToFetch.add(FIRMWARE_VERSION);
        attributesToFetch.add(FIRMWARE_TAG);
        attributesToFetch.add(FIRMWARE_URL);
    }
    LwM2MClientSwOtaInfo swInfo = getOrInitSwInfo(client);
    if (swInfo.isSupported()) {
        attributesToFetch.add(SOFTWARE_TITLE);
        attributesToFetch.add(SOFTWARE_VERSION);
        attributesToFetch.add(SOFTWARE_TAG);
        attributesToFetch.add(SOFTWARE_URL);
    }
    var clientSettings = clientContext.getProfile(client.getProfileId()).getClientLwM2mSettings();
    initFwStrategy(client, clientSettings);
    initSwStrategy(client, clientSettings);
    if (!attributesToFetch.isEmpty()) {
        var future = attributesService.getSharedAttributes(client, attributesToFetch);
        DonAsynchron.withCallback(future, attrs -> {
            if (fwInfo.isSupported()) {
                Optional<String> newFwTitle = getAttributeValue(attrs, FIRMWARE_TITLE);
                Optional<String> newFwVersion = getAttributeValue(attrs, FIRMWARE_VERSION);
                Optional<String> newFwTag = getAttributeValue(attrs, FIRMWARE_TAG);
                Optional<String> newFwUrl = getAttributeValue(attrs, FIRMWARE_URL);
                if (newFwTitle.isPresent() && newFwVersion.isPresent() && !isOtaDownloading(client) && !UPDATING.equals(fwInfo.status)) {
                    onTargetFirmwareUpdate(client, newFwTitle.get(), newFwVersion.get(), newFwUrl, newFwTag);
                }
            }
            if (swInfo.isSupported()) {
                Optional<String> newSwTitle = getAttributeValue(attrs, SOFTWARE_TITLE);
                Optional<String> newSwVersion = getAttributeValue(attrs, SOFTWARE_VERSION);
                Optional<String> newSwTag = getAttributeValue(attrs, SOFTWARE_TAG);
                Optional<String> newSwUrl = getAttributeValue(attrs, SOFTWARE_URL);
                if (newSwTitle.isPresent() && newSwVersion.isPresent()) {
                    onTargetSoftwareUpdate(client, newSwTitle.get(), newSwVersion.get(), newSwUrl, newSwTag);
                }
            }
        }, throwable -> {
            if (fwInfo.isSupported()) {
                update(fwInfo);
            }
        }, executor);
    }
}
Also used : LwM2MClientSwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo) LwM2MClientFwOtaInfo(org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo) ArrayList(java.util.ArrayList)

Aggregations

LwM2MClientSwOtaInfo (org.thingsboard.server.transport.lwm2m.server.ota.software.LwM2MClientSwOtaInfo)7 OtaPackageUpdateStatus (org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus)2 LwM2MClientFwOtaInfo (org.thingsboard.server.transport.lwm2m.server.ota.firmware.LwM2MClientFwOtaInfo)2 ArrayList (java.util.ArrayList)1 SoftwareUpdateResult (org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateResult)1 SoftwareUpdateState (org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateState)1