|
|
|
@ -20,11 +20,20 @@ import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Valida |
|
|
|
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
|
|
|
import { |
|
|
|
ATTRIBUTE, |
|
|
|
BINDING_MODE, |
|
|
|
BINDING_MODE_NAMES, |
|
|
|
BingingMode, |
|
|
|
BingingModeTranslationsMap, |
|
|
|
DEFAULT_BINDING, |
|
|
|
DEFAULT_FW_UPDATE_RESOURCE, |
|
|
|
DEFAULT_ID_SERVER, |
|
|
|
DEFAULT_LIFE_TIME, |
|
|
|
DEFAULT_MIN_PERIOD, |
|
|
|
DEFAULT_NOTIF_IF_DESIBLED, |
|
|
|
DEFAULT_SW_UPDATE_RESOURCE, |
|
|
|
getDefaultProfileConfig, |
|
|
|
getDefaultBootstrapServerSecurityConfig, |
|
|
|
getDefaultBootstrapServersSecurityConfig, |
|
|
|
getDefaultLwM2MServerSecurityConfig, |
|
|
|
getDefaultProfileClientLwM2mSettingsConfig, |
|
|
|
getDefaultProfileObserveAttrConfig, |
|
|
|
Instance, |
|
|
|
INSTANCES, |
|
|
|
KEY_NAME, |
|
|
|
@ -32,8 +41,11 @@ import { |
|
|
|
ModelValue, |
|
|
|
ObjectLwM2M, |
|
|
|
OBSERVE, |
|
|
|
OBSERVE_ATTR_TELEMETRY, PowerMode, PowerModeTranslationMap, |
|
|
|
OBSERVE_ATTR_TELEMETRY, |
|
|
|
PowerMode, |
|
|
|
PowerModeTranslationMap, |
|
|
|
RESOURCES, |
|
|
|
ServerSecurityConfig, |
|
|
|
TELEMETRY |
|
|
|
} from './lwm2m-profile-config.models'; |
|
|
|
import { DeviceProfileService } from '@core/http/device-profile.service'; |
|
|
|
@ -61,14 +73,10 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
private disabled = false; |
|
|
|
private destroy$ = new Subject(); |
|
|
|
|
|
|
|
bindingModeType = BINDING_MODE; |
|
|
|
bindingModeTypes = Object.keys(BINDING_MODE); |
|
|
|
bindingModeTypeNamesMap = BINDING_MODE_NAMES; |
|
|
|
bindingModeTypes = Object.values(BingingMode); |
|
|
|
bindingModeTypeNamesMap = BingingModeTranslationsMap; |
|
|
|
lwm2mDeviceProfileFormGroup: FormGroup; |
|
|
|
lwm2mDeviceConfigFormGroup: FormGroup; |
|
|
|
bootstrapServers: string; |
|
|
|
bootstrapServer: string; |
|
|
|
lwm2mServer: string; |
|
|
|
sortFunction: (key: string, value: object) => object; |
|
|
|
isFwUpdateStrategy: boolean; |
|
|
|
isSwUpdateStrategy: boolean; |
|
|
|
@ -92,46 +100,54 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
this.lwm2mDeviceProfileFormGroup = this.fb.group({ |
|
|
|
objectIds: [null, Validators.required], |
|
|
|
observeAttrTelemetry: [null, Validators.required], |
|
|
|
shortId: [null, Validators.required], |
|
|
|
lifetime: [null, Validators.required], |
|
|
|
defaultMinPeriod: [null, Validators.required], |
|
|
|
notifIfDisabled: [true, []], |
|
|
|
binding: [], |
|
|
|
bootstrapServer: [null, Validators.required], |
|
|
|
lwm2mServer: [null, Validators.required], |
|
|
|
clientOnlyObserveAfterConnect: [1, []], |
|
|
|
fwUpdateStrategy: [1, []], |
|
|
|
swUpdateStrategy: [1, []], |
|
|
|
fwUpdateResource: [{value: '', disabled: true}, []], |
|
|
|
swUpdateResource: [{value: '', disabled: true}, []], |
|
|
|
powerMode: [null, Validators.required] |
|
|
|
bootstrap: this.fb.group({ |
|
|
|
servers: this.fb.group({ |
|
|
|
binding: [DEFAULT_BINDING], |
|
|
|
shortId: [DEFAULT_ID_SERVER, [Validators.required, Validators.min(1), Validators.max(65534), Validators.pattern('[0-9]*')]], |
|
|
|
lifetime: [DEFAULT_LIFE_TIME, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]], |
|
|
|
notifIfDisabled: [DEFAULT_NOTIF_IF_DESIBLED, []], |
|
|
|
defaultMinPeriod: [DEFAULT_MIN_PERIOD, [Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]], |
|
|
|
}), |
|
|
|
bootstrapServer: [null, Validators.required], |
|
|
|
lwm2mServer: [null, Validators.required] |
|
|
|
}), |
|
|
|
clientLwM2mSettings: this.fb.group({ |
|
|
|
clientOnlyObserveAfterConnect: [1, []], |
|
|
|
fwUpdateStrategy: [1, []], |
|
|
|
swUpdateStrategy: [1, []], |
|
|
|
fwUpdateResource: [{value: '', disabled: true}, []], |
|
|
|
swUpdateResource: [{value: '', disabled: true}, []], |
|
|
|
powerMode: [null, Validators.required] |
|
|
|
}) |
|
|
|
}); |
|
|
|
this.lwm2mDeviceConfigFormGroup = this.fb.group({ |
|
|
|
configurationJson: [null, Validators.required] |
|
|
|
}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('fwUpdateStrategy').valueChanges.pipe( |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateStrategy').valueChanges.pipe( |
|
|
|
takeUntil(this.destroy$) |
|
|
|
).subscribe((fwStrategy) => { |
|
|
|
if (fwStrategy === 2) { |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('fwUpdateResource').enable({emitEvent: false}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('fwUpdateResource').patchValue(DEFAULT_FW_UPDATE_RESOURCE, {emitEvent: false}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').enable({emitEvent: false}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource') |
|
|
|
.patchValue(DEFAULT_FW_UPDATE_RESOURCE, {emitEvent: false}); |
|
|
|
this.isFwUpdateStrategy = true; |
|
|
|
} else { |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('fwUpdateResource').disable({emitEvent: false}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').disable({emitEvent: false}); |
|
|
|
this.isFwUpdateStrategy = false; |
|
|
|
} |
|
|
|
this.otaUpdateFwStrategyValidate(true); |
|
|
|
}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('swUpdateStrategy').valueChanges.pipe( |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateStrategy').valueChanges.pipe( |
|
|
|
takeUntil(this.destroy$) |
|
|
|
).subscribe((swStrategy) => { |
|
|
|
if (swStrategy === 2) { |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('swUpdateResource').enable({emitEvent: false}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('swUpdateResource').patchValue(DEFAULT_SW_UPDATE_RESOURCE, {emitEvent: false}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').enable({emitEvent: false}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource') |
|
|
|
.patchValue(DEFAULT_SW_UPDATE_RESOURCE, {emitEvent: false}); |
|
|
|
this.isSwUpdateStrategy = true; |
|
|
|
} else { |
|
|
|
this.isSwUpdateStrategy = false; |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('swUpdateResource').disable({emitEvent: false}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').disable({emitEvent: false}); |
|
|
|
} |
|
|
|
this.otaUpdateSwStrategyValidate(true); |
|
|
|
}); |
|
|
|
@ -171,12 +187,12 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
writeValue(value: Lwm2mProfileConfigModels | null): void { |
|
|
|
async writeValue(value: Lwm2mProfileConfigModels | null) { |
|
|
|
if (isDefinedAndNotNull(value)) { |
|
|
|
if (Object.keys(value).length !== 0 && (value?.clientLwM2mSettings || value?.observeAttr || value?.bootstrap)) { |
|
|
|
if (value?.clientLwM2mSettings || value?.observeAttr || value?.bootstrap) { |
|
|
|
this.configurationValue = value; |
|
|
|
} else { |
|
|
|
this.configurationValue = getDefaultProfileConfig(); |
|
|
|
this.configurationValue = await this.defaultProfileConfig(); |
|
|
|
} |
|
|
|
this.lwm2mDeviceConfigFormGroup.patchValue({ |
|
|
|
configurationJson: this.configurationValue |
|
|
|
@ -185,6 +201,29 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private async defaultProfileConfig(): Promise<Lwm2mProfileConfigModels> { |
|
|
|
let bootstrap: ServerSecurityConfig; |
|
|
|
let lwm2m: ServerSecurityConfig; |
|
|
|
try { |
|
|
|
[bootstrap, lwm2m] = await Promise.all([ |
|
|
|
this.deviceProfileService.getLwm2mBootstrapSecurityInfoBySecurityType(true).toPromise(), |
|
|
|
this.deviceProfileService.getLwm2mBootstrapSecurityInfoBySecurityType(false).toPromise() |
|
|
|
]); |
|
|
|
} catch (e) { |
|
|
|
bootstrap = getDefaultBootstrapServerSecurityConfig(); |
|
|
|
lwm2m = getDefaultLwM2MServerSecurityConfig(); |
|
|
|
} |
|
|
|
return { |
|
|
|
observeAttr: getDefaultProfileObserveAttrConfig(), |
|
|
|
bootstrap: { |
|
|
|
servers: getDefaultBootstrapServersSecurityConfig(), |
|
|
|
bootstrapServer: bootstrap, |
|
|
|
lwm2mServer: lwm2m |
|
|
|
}, |
|
|
|
clientLwM2mSettings: getDefaultProfileClientLwM2mSettingsConfig() |
|
|
|
}; |
|
|
|
} |
|
|
|
|
|
|
|
private initWriteValue = (): void => { |
|
|
|
const modelValue = {objectIds: [], objectsList: []} as ModelValue; |
|
|
|
modelValue.objectIds = this.getObjectsFromJsonAllConfig(); |
|
|
|
@ -212,19 +251,15 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
this.lwm2mDeviceProfileFormGroup.patchValue({ |
|
|
|
objectIds: value, |
|
|
|
observeAttrTelemetry: this.getObserveAttrTelemetryObjects(value.objectsList), |
|
|
|
shortId: this.configurationValue.bootstrap.servers.shortId, |
|
|
|
lifetime: this.configurationValue.bootstrap.servers.lifetime, |
|
|
|
defaultMinPeriod: this.configurationValue.bootstrap.servers.defaultMinPeriod, |
|
|
|
notifIfDisabled: this.configurationValue.bootstrap.servers.notifIfDisabled, |
|
|
|
binding: this.configurationValue.bootstrap.servers.binding, |
|
|
|
bootstrapServer: this.configurationValue.bootstrap.bootstrapServer, |
|
|
|
lwm2mServer: this.configurationValue.bootstrap.lwm2mServer, |
|
|
|
clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect, |
|
|
|
fwUpdateStrategy: this.configurationValue.clientLwM2mSettings.fwUpdateStrategy || 1, |
|
|
|
swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy || 1, |
|
|
|
fwUpdateResource: fwResource, |
|
|
|
swUpdateResource: swResource, |
|
|
|
powerMode: this.configurationValue.clientLwM2mSettings.powerMode |
|
|
|
bootstrap: this.configurationValue.bootstrap, |
|
|
|
clientLwM2mSettings: { |
|
|
|
clientOnlyObserveAfterConnect: this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect, |
|
|
|
fwUpdateStrategy: this.configurationValue.clientLwM2mSettings.fwUpdateStrategy || 1, |
|
|
|
swUpdateStrategy: this.configurationValue.clientLwM2mSettings.swUpdateStrategy || 1, |
|
|
|
fwUpdateResource: fwResource, |
|
|
|
swUpdateResource: swResource, |
|
|
|
powerMode: this.configurationValue.clientLwM2mSettings.powerMode |
|
|
|
} |
|
|
|
}, |
|
|
|
{emitEvent: false}); |
|
|
|
this.configurationValue.clientLwM2mSettings.fwUpdateResource = fwResource; |
|
|
|
@ -253,22 +288,12 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
private updateDeviceProfileValue(config): void { |
|
|
|
if (this.lwm2mDeviceProfileFormGroup.valid) { |
|
|
|
this.updateObserveAttrTelemetryFromGroupToJson(config.observeAttrTelemetry.clientLwM2M); |
|
|
|
this.configurationValue.bootstrap.bootstrapServer = config.bootstrapServer; |
|
|
|
this.configurationValue.bootstrap.lwm2mServer = config.lwm2mServer; |
|
|
|
const bootstrapServers = this.configurationValue.bootstrap.servers; |
|
|
|
bootstrapServers.shortId = config.shortId; |
|
|
|
bootstrapServers.lifetime = config.lifetime; |
|
|
|
bootstrapServers.defaultMinPeriod = config.defaultMinPeriod; |
|
|
|
bootstrapServers.notifIfDisabled = config.notifIfDisabled; |
|
|
|
bootstrapServers.binding = config.binding; |
|
|
|
this.configurationValue.clientLwM2mSettings.clientOnlyObserveAfterConnect = config.clientOnlyObserveAfterConnect; |
|
|
|
this.configurationValue.clientLwM2mSettings.fwUpdateStrategy = config.fwUpdateStrategy; |
|
|
|
this.configurationValue.clientLwM2mSettings.swUpdateStrategy = config.swUpdateStrategy; |
|
|
|
this.configurationValue.clientLwM2mSettings.fwUpdateResource = config.fwUpdateResource; |
|
|
|
this.configurationValue.clientLwM2mSettings.swUpdateResource = config.swUpdateResource; |
|
|
|
this.configurationValue.clientLwM2mSettings.powerMode = config.powerMode; |
|
|
|
this.upDateJsonAllConfig(); |
|
|
|
} |
|
|
|
this.configurationValue.bootstrap.bootstrapServer = config.bootstrap.bootstrapServer; |
|
|
|
this.configurationValue.bootstrap.lwm2mServer = config.bootstrap.lwm2mServer; |
|
|
|
this.configurationValue.bootstrap.servers = config.bootstrap.servers; |
|
|
|
this.configurationValue.clientLwM2mSettings = config.clientLwM2mSettings; |
|
|
|
this.upDateJsonAllConfig(); |
|
|
|
this.updateModel(); |
|
|
|
} |
|
|
|
|
|
|
|
@ -544,20 +569,20 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
|
|
|
|
|
|
|
private otaUpdateFwStrategyValidate(updated = false): void { |
|
|
|
if (this.isFwUpdateStrategy) { |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('fwUpdateResource').setValidators([Validators.required]); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').setValidators([Validators.required]); |
|
|
|
} else { |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('fwUpdateResource').clearValidators(); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').clearValidators(); |
|
|
|
} |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('fwUpdateResource').updateValueAndValidity({emitEvent: updated}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.fwUpdateResource').updateValueAndValidity({emitEvent: updated}); |
|
|
|
} |
|
|
|
|
|
|
|
private otaUpdateSwStrategyValidate(updated = false): void { |
|
|
|
if (this.isSwUpdateStrategy) { |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('swUpdateResource').setValidators([Validators.required]); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').setValidators([Validators.required]); |
|
|
|
} else { |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('swUpdateResource').clearValidators(); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').clearValidators(); |
|
|
|
} |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('swUpdateResource').updateValueAndValidity({emitEvent: updated}); |
|
|
|
this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.swUpdateResource').updateValueAndValidity({emitEvent: updated}); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|