Add upstream and downstream reactor handling; improve error logging
This commit is contained in:
@@ -68,6 +68,10 @@ class Machine {
|
||||
this.updatePosition();
|
||||
});
|
||||
|
||||
// used for holding the source and sink unit operations or other object with setInfluent / getEffluent method for e.g. recirculation.
|
||||
this.upstreamReactor = null;
|
||||
this.downstreamReactor = null;
|
||||
|
||||
this.child = {}; // object to hold child information so we know on what to subscribe
|
||||
this.childRegistrationUtils = new childRegistrationUtils(this); // Child registration utility
|
||||
|
||||
@@ -92,7 +96,7 @@ class Machine {
|
||||
|
||||
_connectMeasurement(measurementChild) {
|
||||
if (!measurementChild) {
|
||||
this.logger.warn("Invalid measurement provided.");
|
||||
this.logger.error("Invalid measurement provided.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -107,8 +111,6 @@ class Machine {
|
||||
measurementChild.measurements.emitter.on(eventName, (eventData) => {
|
||||
this.logger.debug(`🔄 ${position} ${measurementType} from ${eventData.childName}: ${eventData.value} ${eventData.unit}`);
|
||||
|
||||
|
||||
console.log(` Emitting... ${eventName} with data:`);
|
||||
// Store directly in parent's measurement container
|
||||
this.measurements
|
||||
.type(measurementType)
|
||||
@@ -135,7 +137,12 @@ class Machine {
|
||||
}
|
||||
|
||||
_connectReactor(reactorChild) {
|
||||
this.logger.error("Reactor child not implemented yet.");
|
||||
if (!reactorChild) {
|
||||
this.logger.error("Invalid measurement provided.");
|
||||
return;
|
||||
}
|
||||
|
||||
this.downstreamReactor = reactorChild; // downstream from the pumps perpective
|
||||
}
|
||||
|
||||
//---------------- END child stuff -------------//
|
||||
@@ -499,6 +506,7 @@ class Machine {
|
||||
|
||||
// NEW: Flow handler
|
||||
updateMeasuredFlow(value, position, context = {}) {
|
||||
|
||||
if (!this._isOperationalState()) {
|
||||
this.logger.warn(`Machine not operational, skipping flow update from ${context.childName || 'unknown'}`);
|
||||
return;
|
||||
@@ -506,6 +514,10 @@ class Machine {
|
||||
|
||||
this.logger.debug(`Flow update: ${value} at ${position} from ${context.childName || 'child'}`);
|
||||
|
||||
if (this.upstreamReactor && this.downstreamReactor){
|
||||
this._updateConnectedReactor();
|
||||
}
|
||||
|
||||
// Store in parent's measurement container
|
||||
this.measurements.type("flow").variant("measured").position(position).value(value, context.timestamp, context.unit);
|
||||
|
||||
@@ -515,6 +527,10 @@ class Machine {
|
||||
}
|
||||
}
|
||||
|
||||
_updateConnectedReactor() {
|
||||
this.downstreamReactor.setInfluent = this.upstreamReactor.getEffluent[1];
|
||||
}
|
||||
|
||||
// Helper method for operational state check
|
||||
_isOperationalState() {
|
||||
const state = this.state.getCurrentState();
|
||||
|
||||
Reference in New Issue
Block a user