Commit 3d04d5b11c49dd1c1deeeaf7376c85a272b1354d
Committed by
Andrew Shvayka
1 parent
8ce022b0
Add support lwm2m edrxCycle settings
Showing
9 changed files
with
88 additions
and
13 deletions
... | ... | @@ -27,7 +27,7 @@ public class OtherConfiguration { |
27 | 27 | private Integer swUpdateStrategy; |
28 | 28 | private Integer clientOnlyObserveAfterConnect; |
29 | 29 | private PowerMode powerMode; |
30 | - private Long eDRXCycle; | |
30 | + private Long edrxCycle; | |
31 | 31 | private String fwUpdateResource; |
32 | 32 | private String swUpdateResource; |
33 | 33 | private boolean compositeOperationsSupport; | ... | ... |
... | ... | @@ -353,7 +353,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { |
353 | 353 | OtherConfiguration clientLwM2mSettings = clientProfile.getClientLwM2mSettings(); |
354 | 354 | Long timeout = null; |
355 | 355 | if (PowerMode.E_DRX.equals(clientLwM2mSettings.getPowerMode())) { |
356 | - timeout = clientLwM2mSettings.getEDRXCycle(); | |
356 | + timeout = clientLwM2mSettings.getEdrxCycle(); | |
357 | 357 | } |
358 | 358 | if (timeout == null || timeout == 0L) { |
359 | 359 | timeout = this.config.getTimeout(); | ... | ... |
... | ... | @@ -167,6 +167,17 @@ |
167 | 167 | </mat-option> |
168 | 168 | </mat-select> |
169 | 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 | 181 | </fieldset> |
171 | 182 | <mat-slide-toggle class="mat-slider" |
172 | 183 | formControlName="compositeOperationsSupport">{{ 'device-profile.lwm2m.composite-operations-support' | translate }}</mat-slide-toggle> | ... | ... |
... | ... | @@ -116,6 +116,7 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
116 | 116 | fwUpdateResource: [{value: '', disabled: true}, []], |
117 | 117 | swUpdateResource: [{value: '', disabled: true}, []], |
118 | 118 | powerMode: [PowerMode.DRX, Validators.required], |
119 | + edrxCycle: [0], | |
119 | 120 | compositeOperationsSupport: [false] |
120 | 121 | }) |
121 | 122 | }); |
... | ... | @@ -150,6 +151,20 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
150 | 151 | } |
151 | 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 | 168 | this.lwm2mDeviceProfileFormGroup.valueChanges.pipe( |
154 | 169 | takeUntil(this.destroy$) |
155 | 170 | ).subscribe((value) => { |
... | ... | @@ -256,10 +271,13 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro |
256 | 271 | fwUpdateResource: fwResource, |
257 | 272 | swUpdateResource: swResource, |
258 | 273 | powerMode: this.configurationValue.clientLwM2mSettings.powerMode || PowerMode.DRX, |
274 | + edrxCycle: this.configurationValue.clientLwM2mSettings.edrxCycle || 0, | |
259 | 275 | compositeOperationsSupport: this.configurationValue.clientLwM2mSettings.compositeOperationsSupport || false |
260 | 276 | } |
261 | 277 | }, |
262 | 278 | {emitEvent: false}); |
279 | + this.lwm2mDeviceProfileFormGroup.get('clientLwM2mSettings.powerMode') | |
280 | + .patchValue(this.configurationValue.clientLwM2mSettings.powerMode || PowerMode.DRX, {emitEvent: false, onlySelf: true}); | |
263 | 281 | this.configurationValue.clientLwM2mSettings.fwUpdateResource = fwResource; |
264 | 282 | this.configurationValue.clientLwM2mSettings.swUpdateResource = swResource; |
265 | 283 | this.isFwUpdateStrategy = this.configurationValue.clientLwM2mSettings.fwUpdateStrategy === 2; | ... | ... |
... | ... | @@ -25,4 +25,15 @@ |
25 | 25 | </mat-option> |
26 | 26 | </mat-select> |
27 | 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 | 39 | </form> | ... | ... |
... | ... | @@ -14,16 +14,16 @@ |
14 | 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 | 18 | import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; |
19 | 19 | import { Store } from '@ngrx/store'; |
20 | 20 | import { AppState } from '@app/core/core.state'; |
21 | 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 | 28 | @Component({ |
29 | 29 | selector: 'tb-lwm2m-device-transport-configuration', |
... | ... | @@ -35,7 +35,7 @@ import {PowerMode, PowerModeTranslationMap} from "@home/components/profile/devic |
35 | 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 | 40 | lwm2mDeviceTransportConfigurationFormGroup: FormGroup; |
41 | 41 | powerMods = Object.values(PowerMode); |
... | ... | @@ -53,6 +53,7 @@ export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueA |
53 | 53 | @Input() |
54 | 54 | disabled: boolean; |
55 | 55 | |
56 | + private destroy$ = new Subject(); | |
56 | 57 | private propagateChange = (v: any) => { }; |
57 | 58 | |
58 | 59 | constructor(private store: Store<AppState>, |
... | ... | @@ -68,13 +69,35 @@ export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueA |
68 | 69 | |
69 | 70 | ngOnInit() { |
70 | 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 | 92 | this.updateModel(); |
75 | 93 | }); |
76 | 94 | } |
77 | 95 | |
96 | + ngOnDestroy() { | |
97 | + this.destroy$.next(); | |
98 | + this.destroy$.complete(); | |
99 | + } | |
100 | + | |
78 | 101 | setDisabledState(isDisabled: boolean): void { |
79 | 102 | this.disabled = isDisabled; |
80 | 103 | if (this.disabled) { |
... | ... | @@ -85,13 +108,18 @@ export class Lwm2mDeviceTransportConfigurationComponent implements ControlValueA |
85 | 108 | } |
86 | 109 | |
87 | 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 | 119 | private updateModel() { |
92 | 120 | let configuration: DeviceTransportConfiguration = null; |
93 | 121 | if (this.lwm2mDeviceTransportConfigurationFormGroup.valid) { |
94 | - configuration = this.lwm2mDeviceTransportConfigurationFormGroup.getRawValue(); | |
122 | + configuration = this.lwm2mDeviceTransportConfigurationFormGroup.value; | |
95 | 123 | // configuration.type = DeviceTransportType.LWM2M; |
96 | 124 | } |
97 | 125 | this.propagateChange(configuration); | ... | ... |
... | ... | @@ -30,6 +30,7 @@ import { AbstractControl, ValidationErrors } from '@angular/forms'; |
30 | 30 | import { OtaPackageId } from '@shared/models/id/ota-package-id'; |
31 | 31 | import { DashboardId } from '@shared/models/id/dashboard-id'; |
32 | 32 | import { DataType } from '@shared/models/constants'; |
33 | +import { PowerMode } from '@home/components/profile/device/lwm2m/lwm2m-profile-config.models'; | |
33 | 34 | |
34 | 35 | export enum DeviceProfileType { |
35 | 36 | DEFAULT = 'DEFAULT', |
... | ... | @@ -573,6 +574,8 @@ export interface CoapDeviceTransportConfiguration { |
573 | 574 | } |
574 | 575 | |
575 | 576 | export interface Lwm2mDeviceTransportConfiguration { |
577 | + powerMode?: PowerMode | null; | |
578 | + edrxCycle?: number; | |
576 | 579 | [key: string]: any; |
577 | 580 | } |
578 | 581 | ... | ... |
... | ... | @@ -1222,6 +1222,9 @@ |
1222 | 1222 | "drx": "Discontinuous Reception (DRX)", |
1223 | 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 | 1228 | "lwm2m": { |
1226 | 1229 | "object-list": "Object list", |
1227 | 1230 | "object-list-empty": "No objects selected.", | ... | ... |