Compare commits

...

5 Commits

Author SHA1 Message Date
znetsixe
e5c98b7d30 removed some old comments, added thresholds for safeguard 2025-11-07 15:09:35 +01:00
znetsixe
4a489acd89 some formatting 2025-11-06 16:47:17 +01:00
znetsixe
98cd44d3ae updated output utils bug fixes for formatting 2025-11-06 11:18:54 +01:00
znetsixe
44adfdece6 removed caps sensitivity 2025-11-05 17:15:32 +01:00
znetsixe
9ada6e2acd Added support for maintenance tracking in hours. "getMaintenanceTimeHours" default in output of machine now 2025-11-05 15:47:05 +01:00
12 changed files with 1511 additions and 63 deletions

View File

@@ -83,6 +83,7 @@
{
"id": "hidrostal-pump-001",
"name": "hidrostal-H05K-S03R",
"units": ["l/s"]
},
{

File diff suppressed because one or more lines are too long

View File

@@ -478,6 +478,30 @@
"min": 0,
"description": "Allowable error between inflow and outflow before adjustments are triggered (m3/h)."
}
},
"thresholdLowVolume": {
"default": 10,
"rules": {
"type": "number",
"min": 0,
"description": "Volume threshold (%) below which the station will shut down pumps to prevent dry running."
}
},
"thresholdHighVolume": {
"default": 90,
"rules": {
"type": "number",
"min": 0,
"description": "Volume threshold (%) above which the station will trigger high level alarms."
}
},
"timeThreshholdSeconds": {
"default": 120,
"rules": {
"type": "number",
"min": 0,
"description": "Time threshold (seconds) used in volume-based safety checks."
}
}
},
"alarms": {

View File

@@ -245,10 +245,6 @@
{
"value": "fysicalControl",
"description": "Controlled via physical buttons or switches; ignores external automated commands."
},
{
"value": "maintenance",
"description": "No active control from auto, virtual, or fysical sources."
}
],
"description": "The operational mode of the machine."
@@ -260,7 +256,13 @@
"type": "object",
"schema":{
"auto": {
"default": ["statusCheck", "execMovement", "execSequence", "emergencyStop"],
"default": [
"statuscheck",
"execmovement",
"execsequence",
"emergencystop",
"entermaintenance"
],
"rules": {
"type": "set",
"itemType": "string",
@@ -268,7 +270,13 @@
}
},
"virtualControl": {
"default": ["statusCheck", "execMovement", "execSequence", "emergencyStop"],
"default": [
"statuscheck",
"execmovement",
"execsequence",
"emergencystop",
"exitmaintenance"
],
"rules": {
"type": "set",
"itemType": "string",
@@ -276,24 +284,21 @@
}
},
"fysicalControl": {
"default": ["statusCheck", "emergencyStop"],
"default": [
"statuscheck",
"emergencystop",
"entermaintenance",
"exitmaintenance"
],
"rules": {
"type": "set",
"itemType": "string",
"description": "Actions allowed in fysicalControl mode."
}
},
"maintenance": {
"default": ["statusCheck"],
"rules": {
"type": "set",
"itemType": "string",
"description": "Actions allowed in maintenance mode."
}
}
},
"description": "Information about valid command sources recognized by the machine."
}
},
"allowedSources":{
"default": {},
@@ -386,6 +391,22 @@
"itemType": "string",
"description": "Sequence of states for booting up the machine."
}
},
"entermaintenance":{
"default": ["stopping","coolingdown","idle","maintenance"],
"rules": {
"type": "set",
"itemType": "string",
"description": "Sequence of states if the machine is running to put it in maintenance state"
}
},
"exitmaintenance":{
"default": ["off","idle"],
"rules": {
"type": "set",
"itemType": "string",
"description": "Sequence of states if the machine is running to put it in maintenance state"
}
}
}
},

View File

@@ -180,7 +180,6 @@ async apiCall(node) {
// Only add tagCode to URL if it exists
if (tagCode) {
apiUrl += `&asset_tag_number=${tagCode}`;
console.log('hello there');
}
assetregisterAPI += apiUrl;
@@ -461,10 +460,6 @@ populateModels(
// Store only the metadata for the selected model
node["modelMetadata"] = modelData.find((model) => model.name === selectedModel);
});
/*
console.log('hello here I am:');
console.log(node["modelMetadata"]);
*/
});
})

View File

@@ -180,7 +180,6 @@ async apiCall(node) {
// Only add tagCode to URL if it exists
if (tagCode) {
apiUrl += `&asset_tag_number=${tagCode}`;
console.log('hello there');
}
assetregisterAPI += apiUrl;
@@ -461,10 +460,7 @@ populateModels(
// Store only the metadata for the selected model
node["modelMetadata"] = modelData.find((model) => model.name === selectedModel);
});
/*
console.log('hello here I am:');
console.log(node["modelMetadata"]);
*/
});
})

View File

@@ -64,7 +64,7 @@ class OutputUtils {
influxDBFormat(changedFields, config , flatTags) {
// Create the measurement and topic using softwareType and name config.functionality.softwareType + .
const measurement = config.general.name;
const measurement = `${config.functionality?.softwareType}_${config.general?.id}`;
const payload = {
measurement: measurement,
fields: changedFields,
@@ -104,24 +104,23 @@ class OutputUtils {
return {
// general properties
id: config.general?.id,
name: config.general?.name,
unit: config.general?.unit,
// functionality properties
softwareType: config.functionality?.softwareType,
role: config.functionality?.role,
// asset properties (exclude machineCurve)
uuid: config.asset?.uuid,
tagcode: config.asset?.tagcode,
geoLocation: config.asset?.geoLocation,
supplier: config.asset?.supplier,
category: config.asset?.category,
type: config.asset?.type,
subType: config.asset?.subType,
model: config.asset?.model,
unit: config.general?.unit,
};
}
processFormat(changedFields,config) {
// Create the measurement and topic using softwareType and name config.functionality.softwareType + .
const measurement = config.general.name;
const measurement = `${config.functionality?.softwareType}_${config.general?.id}`;
const payload = changedFields;
const topic = measurement;
const msg = { topic: topic, payload: payload };

View File

@@ -113,7 +113,7 @@ class Measurement {
// Create a new measurement that is the difference between two positions
static createDifference(upstreamMeasurement, downstreamMeasurement) {
console.log('hello:');
if (upstreamMeasurement.type !== downstreamMeasurement.type ||
upstreamMeasurement.variant !== downstreamMeasurement.variant) {
throw new Error('Cannot calculate difference between different measurement types or variants');

View File

@@ -52,6 +52,10 @@ class state{
return this.stateManager.getRunTimeHours();
}
getMaintenanceTimeHours(){
return this.stateManager.getMaintenanceTimeHours();
}
async moveTo(targetPosition) {

View File

@@ -205,6 +205,10 @@
{
"value": "off",
"description": "Machine is off."
},
{
"value": "maintenance",
"description": "Machine locked for inspection or repair; automatic control disabled."
}
],
"description": "Current state of the machine."
@@ -216,7 +220,7 @@
"type": "object",
"schema": {
"idle": {
"default": ["starting", "off","emergencystop"],
"default": ["starting", "off","emergencystop","maintenance"],
"rules":{
"type": "set",
"itemType": "string",
@@ -280,7 +284,7 @@
}
},
"off": {
"default": ["idle","emergencystop"],
"default": ["idle","emergencystop","maintenance"],
"rules":{
"type": "set",
"itemType": "string",
@@ -288,12 +292,20 @@
}
},
"emergencystop": {
"default": ["idle","off"],
"default": ["idle","off","maintenance"],
"rules":{
"type": "set",
"itemType": "string",
"description": "Allowed transitions from emergency stop state."
}
},
"maintenance": {
"default": ["maintenance","idle","off"],
"rules":{
"type": "set",
"itemType": "string",
"description": "Allowed transitions for maintenance mode"
}
}
},
"description": "Allowed transitions between states."

View File

@@ -48,10 +48,14 @@ class stateManager {
// Define valid transitions (can be extended dynamically if needed)
this.validTransitions = config.state.allowedTransitions;
// NEW: Initialize runtime tracking
//runtime tracking
this.runTimeHours = 0; // cumulative runtime in hours
this.runTimeStart = null; // timestamp when active state began
//maintenance tracking
this.maintenanceTimeStart = null; //timestamp when active state began
this.maintenanceTimeHours = 0; //cumulative
// Define active states (runtime counts only in these states)
this.activeStates = config.state.activeStates;
}
@@ -73,8 +77,9 @@ class stateManager {
); //go back early and reject promise
}
// NEW: Handle runtime tracking based on active states
//Time tracking based on active states
this.handleRuntimeTracking(newState);
this.handleMaintenancetimeTracking(newState);
const transitionDuration = this.transitionTimes[this.currentState] || 0; // Default to 0 if no transition time
this.logger.debug(
@@ -100,7 +105,7 @@ class stateManager {
}
handleRuntimeTracking(newState) {
// NEW: Handle runtime tracking based on active states
//Handle runtime tracking based on active states
const wasActive = this.activeStates.has(this.currentState);
const willBeActive = this.activeStates.has(newState);
if (wasActive && !willBeActive && this.runTimeStart) {
@@ -120,6 +125,28 @@ class stateManager {
}
}
handleMaintenancetimeTracking(newState) {
//is this maintenance time ?
const wasActive = (this.currentState == "maintenance"? true:false);
const willBeActive = ( newState == "maintenance" ? true:false );
if (wasActive && this.maintenanceTimeStart) {
// stop runtime timer and accumulate elapsed time
const elapsed = (Date.now() - this.maintenanceTimeStart) / 3600000; // hours
this.maintenanceTimeHours += elapsed;
this.maintenanceTimeStart = null;
this.logger.debug(
`Maintenance timer stopped; elapsed=${elapsed.toFixed(
3
)}h, total=${this.maintenanceTimeHours.toFixed(3)}h.`
);
} else if (willBeActive && !this.runTimeStart) {
// starting new runtime
this.maintenanceTimeStart = Date.now();
this.logger.debug("Runtime timer started.");
}
}
isValidTransition(newState) {
this.logger.debug(
`Check 1 Transition valid ? From ${
@@ -150,7 +177,6 @@ class stateManager {
return this.descriptions[state] || "No description available.";
}
// NEW: Getter to retrieve current cumulative runtime (active time) in hours.
getRunTimeHours() {
// If currently active add the ongoing duration.
let currentElapsed = 0;
@@ -159,6 +185,15 @@ class stateManager {
}
return this.runTimeHours + currentElapsed;
}
getMaintenanceTimeHours() {
// If currently active add the ongoing duration.
let currentElapsed = 0;
if (this.maintenanceTimeStart) {
currentElapsed = (Date.now() - this.maintenanceTimeStart) / 3600000;
}
return this.maintenanceTimeHours + currentElapsed;
}
}
module.exports = stateManager;