|
|
@ -54,6 +54,34 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control |
|
|
|
|
|
|
|
|
mqttDeviceProfileTransportConfigurationFormGroup: FormGroup; |
|
|
mqttDeviceProfileTransportConfigurationFormGroup: FormGroup; |
|
|
|
|
|
|
|
|
|
|
|
private defaultTelemetrySchema = |
|
|
|
|
|
'syntax ="proto3";\n' + |
|
|
|
|
|
'package telemetry;\n' + |
|
|
|
|
|
'\n' + |
|
|
|
|
|
'message SensorDataReading {\n' + |
|
|
|
|
|
'\n' + |
|
|
|
|
|
' double temperature = 1;\n' + |
|
|
|
|
|
' double humidity = 2;\n' + |
|
|
|
|
|
' InnerObject innerObject = 3;\n' + |
|
|
|
|
|
'\n' + |
|
|
|
|
|
' message InnerObject {\n' + |
|
|
|
|
|
' string key1 = 1;\n' + |
|
|
|
|
|
' bool key2 = 2;\n' + |
|
|
|
|
|
' double key3 = 3;\n' + |
|
|
|
|
|
' int32 key4 = 4;\n' + |
|
|
|
|
|
' string key5 = 5;\n' + |
|
|
|
|
|
' }\n' + |
|
|
|
|
|
'}\n'; |
|
|
|
|
|
|
|
|
|
|
|
private defaultAttributesSchema = |
|
|
|
|
|
'syntax ="proto3";\n' + |
|
|
|
|
|
'package attributes;\n' + |
|
|
|
|
|
'\n' + |
|
|
|
|
|
'message SensorConfiguration {\n' + |
|
|
|
|
|
' string firmwareVersion = 1;\n' + |
|
|
|
|
|
' string serialNumber = 2;\n' + |
|
|
|
|
|
'}'; |
|
|
|
|
|
|
|
|
private requiredValue: boolean; |
|
|
private requiredValue: boolean; |
|
|
|
|
|
|
|
|
get required(): boolean { |
|
|
get required(): boolean { |
|
|
@ -83,17 +111,18 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control |
|
|
|
|
|
|
|
|
ngOnInit() { |
|
|
ngOnInit() { |
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup = this.fb.group({ |
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup = this.fb.group({ |
|
|
configuration: this.fb.group({ |
|
|
|
|
|
deviceAttributesTopic: [null, [Validators.required, this.validationMQTTTopic()]], |
|
|
deviceAttributesTopic: [null, [Validators.required, this.validationMQTTTopic()]], |
|
|
deviceTelemetryTopic: [null, [Validators.required, this.validationMQTTTopic()]], |
|
|
deviceTelemetryTopic: [null, [Validators.required, this.validationMQTTTopic()]], |
|
|
transportPayloadTypeConfiguration: this.fb.group({ |
|
|
transportPayloadTypeConfiguration: this.fb.group({ |
|
|
transportPayloadType: [MqttTransportPayloadType.JSON, Validators.required] |
|
|
transportPayloadType: [MqttTransportPayloadType.JSON, Validators.required], |
|
|
|
|
|
deviceTelemetryProtoSchema: [this.defaultTelemetrySchema, Validators.required], |
|
|
|
|
|
deviceAttributesProtoSchema: [this.defaultAttributesSchema, Validators.required] |
|
|
}) |
|
|
}) |
|
|
}, {validator: this.uniqueDeviceTopicValidator}) |
|
|
}, {validator: this.uniqueDeviceTopicValidator} |
|
|
}); |
|
|
); |
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.get('configuration.transportPayloadTypeConfiguration.transportPayloadType').valueChanges.subscribe(payloadType => { |
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.get('transportPayloadTypeConfiguration.transportPayloadType') |
|
|
this.updateTransportPayloadBasedControls(payloadType); |
|
|
.valueChanges.subscribe(payloadType => { |
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.updateValueAndValidity(); |
|
|
this.updateTransportPayloadBasedControls(payloadType, true); |
|
|
}); |
|
|
}); |
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => { |
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.valueChanges.subscribe(() => { |
|
|
this.updateModel(); |
|
|
this.updateModel(); |
|
|
@ -110,58 +139,41 @@ export class MqttDeviceProfileTransportConfigurationComponent implements Control |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
get protoPayloadType(): boolean { |
|
|
get protoPayloadType(): boolean { |
|
|
let transportPayloadType = this.mqttDeviceProfileTransportConfigurationFormGroup.get('configuration.transportPayloadTypeConfiguration.transportPayloadType').value; |
|
|
const transportPayloadType = this.mqttDeviceProfileTransportConfigurationFormGroup.get('transportPayloadTypeConfiguration.transportPayloadType').value; |
|
|
return transportPayloadType === MqttTransportPayloadType.PROTOBUF; |
|
|
return transportPayloadType === MqttTransportPayloadType.PROTOBUF; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
writeValue(value: MqttDeviceProfileTransportConfiguration | null): void { |
|
|
writeValue(value: MqttDeviceProfileTransportConfiguration | null): void { |
|
|
if (isDefinedAndNotNull(value)) { |
|
|
if (isDefinedAndNotNull(value)) { |
|
|
this.updateTransportPayloadBasedControls(value.transportPayloadTypeConfiguration.transportPayloadType); |
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.patchValue(value, {emitEvent: false}); |
|
|
this.mqttDeviceProfileTransportConfigurationFormGroup.patchValue({configuration: value}, {emitEvent: false}); |
|
|
this.updateTransportPayloadBasedControls(value.transportPayloadTypeConfiguration?.transportPayloadType); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private updateModel() { |
|
|
private updateModel() { |
|
|
let configuration: DeviceProfileTransportConfiguration = null; |
|
|
let configuration: DeviceProfileTransportConfiguration = null; |
|
|
if (this.mqttDeviceProfileTransportConfigurationFormGroup.valid) { |
|
|
if (this.mqttDeviceProfileTransportConfigurationFormGroup.valid) { |
|
|
configuration = this.mqttDeviceProfileTransportConfigurationFormGroup.getRawValue().configuration; |
|
|
configuration = this.mqttDeviceProfileTransportConfigurationFormGroup.value; |
|
|
configuration.type = DeviceTransportType.MQTT; |
|
|
configuration.type = DeviceTransportType.MQTT; |
|
|
} |
|
|
} |
|
|
this.propagateChange(configuration); |
|
|
this.propagateChange(configuration); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private updateTransportPayloadBasedControls(type: MqttTransportPayloadType) { |
|
|
private updateTransportPayloadBasedControls(type: MqttTransportPayloadType, forceUpdated = false) { |
|
|
const transportPayloadTypeConfigurationFormGroup = this.mqttDeviceProfileTransportConfigurationFormGroup.get('configuration.transportPayloadTypeConfiguration') as FormGroup; |
|
|
const transportPayloadTypeForm = this.mqttDeviceProfileTransportConfigurationFormGroup |
|
|
if (type === MqttTransportPayloadType.PROTOBUF) { |
|
|
.get('transportPayloadTypeConfiguration') as FormGroup; |
|
|
const defaultTelemetrySchema = "syntax =\"proto3\";\n" + |
|
|
if (forceUpdated) { |
|
|
"package telemetry;\n" + |
|
|
transportPayloadTypeForm.patchValue({ |
|
|
"\n" + |
|
|
deviceTelemetryProtoSchema: this.defaultTelemetrySchema, |
|
|
"message SensorDataReading {\n" + |
|
|
deviceAttributesProtoSchema: this.defaultAttributesSchema |
|
|
"\n" + |
|
|
}, {emitEvent: false}); |
|
|
" double temperature = 1;\n" + |
|
|
} |
|
|
" double humidity = 2;\n" + |
|
|
if (type === MqttTransportPayloadType.PROTOBUF && !this.disabled) { |
|
|
" InnerObject innerObject = 3;\n" + |
|
|
transportPayloadTypeForm.get('deviceTelemetryProtoSchema').enable({emitEvent: false}); |
|
|
"\n" + |
|
|
transportPayloadTypeForm.get('deviceAttributesProtoSchema').enable({emitEvent: false}); |
|
|
" message InnerObject {\n" + |
|
|
|
|
|
" string key1 = 1;\n" + |
|
|
|
|
|
" bool key2 = 2;\n" + |
|
|
|
|
|
" double key3 = 3;\n" + |
|
|
|
|
|
" int32 key4 = 4;\n" + |
|
|
|
|
|
" string key5 = 5;\n" + |
|
|
|
|
|
" }\n" + |
|
|
|
|
|
"}\n"; |
|
|
|
|
|
const defaultAttributesSchema = "syntax =\"proto3\";\n" + |
|
|
|
|
|
"package attributes;\n" + |
|
|
|
|
|
"\n" + |
|
|
|
|
|
"message SensorConfiguration {\n" + |
|
|
|
|
|
" string firmwareVersion = 1;\n" + |
|
|
|
|
|
" string serialNumber = 2;\n" + |
|
|
|
|
|
"}"; |
|
|
|
|
|
transportPayloadTypeConfigurationFormGroup.registerControl('deviceTelemetryProtoSchema', this.fb.control(defaultTelemetrySchema, Validators.required)); |
|
|
|
|
|
transportPayloadTypeConfigurationFormGroup.registerControl('deviceAttributesProtoSchema', this.fb.control(defaultAttributesSchema, Validators.required)); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
transportPayloadTypeConfigurationFormGroup.removeControl('deviceTelemetryProtoSchema'); |
|
|
transportPayloadTypeForm.get('deviceTelemetryProtoSchema').disable({emitEvent: false}); |
|
|
transportPayloadTypeConfigurationFormGroup.removeControl('deviceAttributesProtoSchema'); |
|
|
transportPayloadTypeForm.get('deviceAttributesProtoSchema').disable({emitEvent: false}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|