bug fixes

This commit is contained in:
znetsixe
2025-07-02 10:54:01 +02:00
parent a2018509ef
commit 4665949c88
2 changed files with 37 additions and 29 deletions

View File

@@ -7,9 +7,11 @@ class ChildRegistrationUtils {
async registerChild(child, positionVsParent) {
this.logger.debug(`Registering child: ${child.id} with position=${positionVsParent}`);
const { softwareType } = child.config.functionality;
const { name, id, unit } = child.config.general;
const { type = "", subType = "" } = child.config.asset || {};
const { category = "", type = "" } = child.config.asset || {};
console.log(`Registering child: ${name}, id: ${id}, softwareType: ${softwareType}, category: ${category}, type: ${type}, positionVsParent: ${positionVsParent}` );
const emitter = child.emitter;
//define position vs parent in child
@@ -19,33 +21,33 @@ class ChildRegistrationUtils {
if (!this.mainClass.child) this.mainClass.child = {};
if (!this.mainClass.child[softwareType])
this.mainClass.child[softwareType] = {};
if (!this.mainClass.child[softwareType][type])
this.mainClass.child[softwareType][type] = {};
if (!this.mainClass.child[softwareType][type][subType])
this.mainClass.child[softwareType][type][subType] = {};
if (!this.mainClass.child[softwareType][category])
this.mainClass.child[softwareType][category] = {};
if (!this.mainClass.child[softwareType][category][type])
this.mainClass.child[softwareType][category][type] = {};
// Use an array to handle multiple subtypes
if (!Array.isArray(this.mainClass.child[softwareType][type][subType])) {
this.mainClass.child[softwareType][type][subType] = [];
// Use an array to handle multiple categories
if (!Array.isArray(this.mainClass.child[softwareType][category][type])) {
this.mainClass.child[softwareType][category][type] = [];
}
// Push the new child to the array of the mainclass so we can track the childs
this.mainClass.child[softwareType][type][subType].push({
this.mainClass.child[softwareType][category][type].push({
name,
id,
unit,
emitter,
});
//then connect the child depending on the type subtype etc..
//then connect the child depending on the type type etc..
this.connectChild(
id,
softwareType,
emitter,
type,
category,
child,
subType,
type,
positionVsParent
);
}
@@ -54,21 +56,21 @@ class ChildRegistrationUtils {
id,
softwareType,
emitter,
type,
category,
child,
subType,
type,
positionVsParent
) {
this.logger.debug(
`Connecting child id=${id}: desc=${softwareType}, type=${type},subType=${subType}, position=${positionVsParent}`
`Connecting child id=${id}: desc=${softwareType}, category=${category},type=${type}, position=${positionVsParent}`
);
switch (softwareType) {
case "measurement":
this.logger.debug(
`Registering measurement child: ${id} with type=${type}`
`Registering measurement child: ${id} with category=${category}`
);
this.connectMeasurement(child, subType, positionVsParent);
this.connectMeasurement(child, type, positionVsParent);
break;
case "machine":
@@ -92,34 +94,34 @@ class ChildRegistrationUtils {
}
}
connectMeasurement(child, subType, position) {
connectMeasurement(child, type, position) {
this.logger.debug(
`Connecting measurement child: ${subType} with position=${position}`
`Connecting measurement child: ${type} with position=${position}`
);
// Check if subType is valid
if (!subType) {
this.logger.error(`Invalid subType for measurement: ${subType}`);
// Check if type is valid
if (!type) {
this.logger.error(`Invalid type for measurement: ${type}`);
return;
}
// initialize the measurement to a number - logging each step for debugging
try {
this.logger.debug(
`Initializing measurement: ${subType}, position: ${position} value: 0`
`Initializing measurement: ${type}, position: ${position} value: 0`
);
const typeResult = this.mainClass.measurements.type(subType);
const typeResult = this.mainClass.measurements.type(type);
const variantResult = typeResult.variant("measured");
const positionResult = variantResult.position(position);
positionResult.value(0);
this.logger.debug(
`Subscribing on mAbs event for measurement: ${subType}, position: ${position}`
`Subscribing on mAbs event for measurement: ${type}, position: ${position}`
);
// Listen for the mAbs event and update the measurement
this.logger.debug(
`Successfully initialized measurement: ${subType}, position: ${position}`
`Successfully initialized measurement: ${type}, position: ${position}`
);
} catch (error) {
this.logger.error(`Failed to initialize measurement: ${error.message}`);
@@ -129,12 +131,12 @@ class ChildRegistrationUtils {
child.emitter.on("mAbs", (value) => {
// Use the same method chaining approach that worked during initialization
this.mainClass.measurements
.type(subType)
.type(type)
.variant("measured")
.position(position)
.value(value);
this.mainClass.updateMeasurement("measured", subType, value, position);
//this.logger.debug(`--------->>>>>>>>>Updated measurement: ${subType}, value: ${value}, position: ${position}`);
this.mainClass.updateMeasurement("measured", type, value, position);
//this.logger.debug(`--------->>>>>>>>>Updated measurement: ${type}, value: ${value}, position: ${position}`);
});
}