Commit 3d04d5b11c49dd1c1deeeaf7376c85a272b1354d

Authored by Vladyslav_Prykhodko
Committed by Andrew Shvayka
1 parent 8ce022b0

Add support lwm2m edrxCycle settings

@@ -27,7 +27,7 @@ public class OtherConfiguration { @@ -27,7 +27,7 @@ public class OtherConfiguration {
27 private Integer swUpdateStrategy; 27 private Integer swUpdateStrategy;
28 private Integer clientOnlyObserveAfterConnect; 28 private Integer clientOnlyObserveAfterConnect;
29 private PowerMode powerMode; 29 private PowerMode powerMode;
30 - private Long eDRXCycle; 30 + private Long edrxCycle;
31 private String fwUpdateResource; 31 private String fwUpdateResource;
32 private String swUpdateResource; 32 private String swUpdateResource;
33 private boolean compositeOperationsSupport; 33 private boolean compositeOperationsSupport;
@@ -353,7 +353,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { @@ -353,7 +353,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
353 OtherConfiguration clientLwM2mSettings = clientProfile.getClientLwM2mSettings(); 353 OtherConfiguration clientLwM2mSettings = clientProfile.getClientLwM2mSettings();
354 Long timeout = null; 354 Long timeout = null;
355 if (PowerMode.E_DRX.equals(clientLwM2mSettings.getPowerMode())) { 355 if (PowerMode.E_DRX.equals(clientLwM2mSettings.getPowerMode())) {
356 - timeout = clientLwM2mSettings.getEDRXCycle(); 356 + timeout = clientLwM2mSettings.getEdrxCycle();
357 } 357 }
358 if (timeout == null || timeout == 0L) { 358 if (timeout == null || timeout == 0L) {
359 timeout = this.config.getTimeout(); 359 timeout = this.config.getTimeout();
@@ -167,6 +167,17 @@ @@ -167,6 +167,17 @@
167 </mat-option> 167 </mat-option>
168 </mat-select> 168 </mat-select>
169 </mat-form-field> 169 </mat-form-field>
  170 + <mat-form-field class="mat-block" fxFlex *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.powerMode').value === 'E_DRX'">
  171 + <mat-label>{{ 'device-profile.edrx-cycle' | translate }}</mat-label>
  172 + <input matInput type="number" min="0" formControlName="edrxCycle" required>
  173 + <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').hasError('required')">
  174 + {{ 'device-profile.edrx-cycle-required' | translate }}
  175 + </mat-error>
  176 + <mat-error *ngIf="lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').hasError('pattern') ||
  177 + lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').hasError('min')">
  178 + {{ 'device-profile.edrx-cycle-pattern' | translate }}
  179 + </mat-error>
  180 + </mat-form-field>
170 </fieldset> 181 </fieldset>
171 <mat-slide-toggle class="mat-slider" 182 <mat-slide-toggle class="mat-slider"
172 formControlName="compositeOperationsSupport">{{ 'device-profile.lwm2m.composite-operations-support' | translate }}</mat-slide-toggle> 183 formControlName="compositeOperationsSupport">{{ 'device-profile.lwm2m.composite-operations-support' | translate }}</mat-slide-toggle>
@@ -116,6 +116,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -116,6 +116,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
116 fwUpdateResource: [{value: '', disabled: true}, []], 116 fwUpdateResource: [{value: '', disabled: true}, []],
117 swUpdateResource: [{value: '', disabled: true}, []], 117 swUpdateResource: [{value: '', disabled: true}, []],
118 powerMode: [PowerMode.DRX, Validators.required], 118 powerMode: [PowerMode.DRX, Validators.required],
  119 + edrxCycle: [0],
119 compositeOperationsSupport: [false] 120 compositeOperationsSupport: [false]
120 }) 121 })
121 }); 122 });
@@ -150,6 +151,20 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -150,6 +151,20 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
150 } 151 }
151 this.otaUpdateSwStrategyValidate(true); 152 this.otaUpdateSwStrategyValidate(true);
152 }); 153 });
  154 + this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.powerMode').valueChanges.pipe(
  155 + takeUntil(this.destroy$)
  156 + ).subscribe((powerMode: PowerMode) => {
  157 + if (powerMode === PowerMode.E_DRX) {
  158 + this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').enable({emitEvent: false});
  159 + this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').patchValue(0, {emitEvent: false});
  160 + this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle')
  161 + .setValidators([Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]);
  162 + } else {
  163 + this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').disable({emitEvent: false});
  164 + this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').clearValidators();
  165 + }
  166 + this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.edrxCycle').updateValueAndValidity({emitEvent: false});
  167 + });
153 this.lwm2mDeviceProfileFormGroup.valueChanges.pipe( 168 this.lwm2mDeviceProfileFormGroup.valueChanges.pipe(
154 takeUntil(this.destroy$) 169 takeUntil(this.destroy$)
155 ).subscribe((value) => { 170 ).subscribe((value) => {
@@ -256,10 +271,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro @@ -256,10 +271,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro
256 fwUpdateResource: fwResource, 271 fwUpdateResource: fwResource,
257 swUpdateResource: swResource, 272 swUpdateResource: swResource,
258 powerMode: this.configurationValue.clientLwM2mSettings.powerMode || PowerMode.DRX, 273 powerMode: this.configurationValue.clientLwM2mSettings.powerMode || PowerMode.DRX,
  274 + edrxCycle: this.configurationValue.clientLwM2mSettings.edrxCycle || 0,
259 compositeOperationsSupport: this.configurationValue.clientLwM2mSettings.compositeOperationsSupport || false 275 compositeOperationsSupport: this.configurationValue.clientLwM2mSettings.compositeOperationsSupport || false
260 } 276 }
261 }, 277 },
262 {emitEvent: false}); 278 {emitEvent: false});
  279 + this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.powerMode')
  280 + .patchValue(this.configurationValue.clientLwM2mSettings.powerMode || PowerMode.DRX, {emitEvent: false, onlySelf: true});
263 this.configurationValue.clientLwM2mSettings.fwUpdateResource = fwResource; 281 this.configurationValue.clientLwM2mSettings.fwUpdateResource = fwResource;
264 this.configurationValue.clientLwM2mSettings.swUpdateResource = swResource; 282 this.configurationValue.clientLwM2mSettings.swUpdateResource = swResource;
265 this.isFwUpdateStrategy = this.configurationValue.clientLwM2mSettings.fwUpdateStrategy === 2; 283 this.isFwUpdateStrategy = this.configurationValue.clientLwM2mSettings.fwUpdateStrategy === 2;
@@ -169,6 +169,7 @@ export interface ClientLwM2mSettings { @@ -169,6 +169,7 @@ export interface ClientLwM2mSettings {
169 fwUpdateResource: string; 169 fwUpdateResource: string;
170 swUpdateResource: string; 170 swUpdateResource: string;
171 powerMode: PowerMode; 171 powerMode: PowerMode;
  172 + edrxCycle?: number;
172 compositeOperationsSupport: boolean; 173 compositeOperationsSupport: boolean;
173 } 174 }
174 175
@@ -25,4 +25,15 @@ @@ -25,4 +25,15 @@
25 </mat-option> 25 </mat-option>
26 </mat-select> 26 </mat-select>
27 </mat-form-field> 27 </mat-form-field>
  28 + <mat-form-field class="mat-block" fxFlex *ngIf="lwm2mDeviceTransportConfigurationFormGroup.get('powerMode').value === 'E_DRX'">
  29 + <mat-label>{{ 'device-profile.edrx-cycle' | translate }}</mat-label>
  30 + <input matInput type="number" min="0" formControlName="edrxCycle" required>
  31 + <mat-error *ngIf="lwm2mDeviceTransportConfigurationFormGroup.get('edrxCycle').hasError('required')">
  32 + {{ 'device-profile.edrx-cycle-required' | translate }}
  33 + </mat-error>
  34 + <mat-error *ngIf="lwm2mDeviceTransportConfigurationFormGroup.get('edrxCycle').hasError('pattern') ||
  35 + lwm2mDeviceTransportConfigurationFormGroup.get('edrxCycle').hasError('min')">
  36 + {{ 'device-profile.edrx-cycle-pattern' | translate }}
  37 + </mat-error>
  38 + </mat-form-field>
28 </form> 39 </form>
@@ -14,16 +14,16 @@ @@ -14,16 +14,16 @@
14 /// limitations under the License. 14 /// limitations under the License.
15 /// 15 ///
16 16
17 -import { Component, forwardRef, Input, OnInit } from '@angular/core'; 17 +import { Component, forwardRef, Input, OnDestroy, OnInit } from '@angular/core';
18 import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; 18 import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
19 import { Store } from '@ngrx/store'; 19 import { Store } from '@ngrx/store';
20 import { AppState } from '@app/core/core.state'; 20 import { AppState } from '@app/core/core.state';
21 import { coerceBooleanProperty } from '@angular/cdk/coercion'; 21 import { coerceBooleanProperty } from '@angular/cdk/coercion';
22 -import {  
23 - DeviceTransportConfiguration,  
24 - DeviceTransportType, Lwm2mDeviceTransportConfiguration  
25 -} from '@shared/models/device.models';  
26 -import {PowerMode, PowerModeTranslationMap} from "@home/components/profile/device/lwm2m/lwm2m-profile-config.models"; 22 +import { DeviceTransportConfiguration, Lwm2mDeviceTransportConfiguration } from '@shared/models/device.models';
  23 +import { PowerMode, PowerModeTranslationMap } from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models';
  24 +import { takeUntil } from 'rxjs/operators';
  25 +import { Subject } from 'rxjs';
  26 +import { isDefinedAndNotNull } from '@core/utils';
27 27
28 @Component({ 28 @Component({
29 selector: 'tb-lwm2m-device-transport-configuration', 29 selector: 'tb-lwm2m-device-transport-configuration',
@@ -35,7 +35,7 @@ import {PowerMode, PowerModeTranslationMap} from "@home/components/profile/devic @@ -35,7 +35,7 @@ import {PowerMode, PowerModeTranslationMap} from "@home/components/profile/devic
35 multi: true 35 multi: true
36 }] 36 }]
37 }) 37 })
38 -export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueAccessor, OnInit { 38 +export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueAccessor, OnInit, OnDestroy {
39 39
40 lwm2mDeviceTransportConfigurationFormGroup: FormGroup; 40 lwm2mDeviceTransportConfigurationFormGroup: FormGroup;
41 powerMods = Object.values(PowerMode); 41 powerMods = Object.values(PowerMode);
@@ -53,6 +53,7 @@ export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueA @@ -53,6 +53,7 @@ export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueA
53 @Input() 53 @Input()
54 disabled: boolean; 54 disabled: boolean;
55 55
  56 + private destroy$ = new Subject();
56 private propagateChange = (v: any) => { }; 57 private propagateChange = (v: any) => { };
57 58
58 constructor(private store: Store<AppState>, 59 constructor(private store: Store<AppState>,
@@ -68,13 +69,35 @@ export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueA @@ -68,13 +69,35 @@ export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueA
68 69
69 ngOnInit() { 70 ngOnInit() {
70 this.lwm2mDeviceTransportConfigurationFormGroup = this.fb.group({ 71 this.lwm2mDeviceTransportConfigurationFormGroup = this.fb.group({
71 - powerMode: [null] 72 + powerMode: [null],
  73 + edrxCycle: [0]
72 }); 74 });
73 - this.lwm2mDeviceTransportConfigurationFormGroup.valueChanges.subscribe(() => { 75 + this.lwm2mDeviceTransportConfigurationFormGroup.get('powerMode').valueChanges.pipe(
  76 + takeUntil(this.destroy$)
  77 + ).subscribe((powerMode: PowerMode) => {
  78 + if (powerMode === PowerMode.E_DRX) {
  79 + this.lwm2mDeviceTransportConfigurationFormGroup.get('edrxCycle').enable({emitEvent: false});
  80 + this.lwm2mDeviceTransportConfigurationFormGroup.get('edrxCycle').patchValue(0, {emitEvent: false});
  81 + this.lwm2mDeviceTransportConfigurationFormGroup.get('edrxCycle')
  82 + .setValidators([Validators.required, Validators.min(0), Validators.pattern('[0-9]*')]);
  83 + } else {
  84 + this.lwm2mDeviceTransportConfigurationFormGroup.get('edrxCycle').disable({emitEvent: false});
  85 + this.lwm2mDeviceTransportConfigurationFormGroup.get('edrxCycle').clearValidators();
  86 + }
  87 + this.lwm2mDeviceTransportConfigurationFormGroup.get('edrxCycle').updateValueAndValidity({emitEvent: false});
  88 + });
  89 + this.lwm2mDeviceTransportConfigurationFormGroup.valueChanges.pipe(
  90 + takeUntil(this.destroy$)
  91 + ).subscribe(() => {
74 this.updateModel(); 92 this.updateModel();
75 }); 93 });
76 } 94 }
77 95
  96 + ngOnDestroy() {
  97 + this.destroy$.next();
  98 + this.destroy$.complete();
  99 + }
  100 +
78 setDisabledState(isDisabled: boolean): void { 101 setDisabledState(isDisabled: boolean): void {
79 this.disabled = isDisabled; 102 this.disabled = isDisabled;
80 if (this.disabled) { 103 if (this.disabled) {
@@ -85,13 +108,18 @@ export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueA @@ -85,13 +108,18 @@ export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueA
85 } 108 }
86 109
87 writeValue(value: Lwm2mDeviceTransportConfiguration | null): void { 110 writeValue(value: Lwm2mDeviceTransportConfiguration | null): void {
88 - this.lwm2mDeviceTransportConfigurationFormGroup.patchValue(value, {emitEvent: false}); 111 + if (isDefinedAndNotNull(value)) {
  112 + this.lwm2mDeviceTransportConfigurationFormGroup.get('powerMode').patchValue(value.powerMode, {emitEvent: false, onlySelf: true});
  113 + this.lwm2mDeviceTransportConfigurationFormGroup.get('edrxCycle').patchValue(value.edrxCycle || 0, {emitEvent: false});
  114 + } else {
  115 + this.lwm2mDeviceTransportConfigurationFormGroup.patchValue({powerMode: null, edrxCycle: 0}, {emitEvent: false});
  116 + }
89 } 117 }
90 118
91 private updateModel() { 119 private updateModel() {
92 let configuration: DeviceTransportConfiguration = null; 120 let configuration: DeviceTransportConfiguration = null;
93 if (this.lwm2mDeviceTransportConfigurationFormGroup.valid) { 121 if (this.lwm2mDeviceTransportConfigurationFormGroup.valid) {
94 - configuration = this.lwm2mDeviceTransportConfigurationFormGroup.getRawValue(); 122 + configuration = this.lwm2mDeviceTransportConfigurationFormGroup.value;
95 // configuration.type = DeviceTransportType.LWM2M; 123 // configuration.type = DeviceTransportType.LWM2M;
96 } 124 }
97 this.propagateChange(configuration); 125 this.propagateChange(configuration);
@@ -30,6 +30,7 @@ import { AbstractControl, ValidationErrors } from '@angular/forms'; @@ -30,6 +30,7 @@ import { AbstractControl, ValidationErrors } from '@angular/forms';
30 import { OtaPackageId } from '@shared/models/id/ota-package-id'; 30 import { OtaPackageId } from '@shared/models/id/ota-package-id';
31 import { DashboardId } from '@shared/models/id/dashboard-id'; 31 import { DashboardId } from '@shared/models/id/dashboard-id';
32 import { DataType } from '@shared/models/constants'; 32 import { DataType } from '@shared/models/constants';
  33 +import { PowerMode } from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models';
33 34
34 export enum DeviceProfileType { 35 export enum DeviceProfileType {
35 DEFAULT = 'DEFAULT', 36 DEFAULT = 'DEFAULT',
@@ -573,6 +574,8 @@ export interface CoapDeviceTransportConfiguration { @@ -573,6 +574,8 @@ export interface CoapDeviceTransportConfiguration {
573 } 574 }
574 575
575 export interface Lwm2mDeviceTransportConfiguration { 576 export interface Lwm2mDeviceTransportConfiguration {
  577 + powerMode?: PowerMode | null;
  578 + edrxCycle?: number;
576 [key: string]: any; 579 [key: string]: any;
577 } 580 }
578 581
@@ -1222,6 +1222,9 @@ @@ -1222,6 +1222,9 @@
1222 "drx": "Discontinuous Reception (DRX)", 1222 "drx": "Discontinuous Reception (DRX)",
1223 "edrx": "Extended Discontinuous Reception (eDRX)" 1223 "edrx": "Extended Discontinuous Reception (eDRX)"
1224 }, 1224 },
  1225 + "edrx-cycle": "eDRX cycle",
  1226 + "edrx-cycle-required": "eDRX cycle is required.",
  1227 + "edrx-cycle-pattern": "eDRX cycle must be a positive integer.",
1225 "lwm2m": { 1228 "lwm2m": {
1226 "object-list": "Object list", 1229 "object-list": "Object list",
1227 "object-list-empty": "No objects selected.", 1230 "object-list-empty": "No objects selected.",