111 lines
2.2 KiB
JavaScript
111 lines
2.2 KiB
JavaScript
const { MeasurementContainer } = require('generalFunctions');
|
|
|
|
function makeMachineConfig(overrides = {}) {
|
|
return {
|
|
general: {
|
|
id: 'rm-test-1',
|
|
name: 'rotating-machine-test',
|
|
unit: 'm3/h',
|
|
logging: { enabled: false, logLevel: 'error' },
|
|
},
|
|
functionality: {
|
|
positionVsParent: 'atEquipment',
|
|
},
|
|
asset: {
|
|
supplier: 'hidrostal',
|
|
category: 'machine',
|
|
type: 'pump',
|
|
model: 'hidrostal-H05K-S03R',
|
|
unit: 'm3/h',
|
|
},
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function makeStateConfig(overrides = {}) {
|
|
return {
|
|
general: {
|
|
logging: { enabled: false, logLevel: 'error' },
|
|
},
|
|
state: {
|
|
current: 'idle',
|
|
},
|
|
movement: {
|
|
mode: 'staticspeed',
|
|
speed: 1000,
|
|
maxSpeed: 1000,
|
|
interval: 10,
|
|
},
|
|
time: {
|
|
starting: 0,
|
|
warmingup: 0,
|
|
stopping: 0,
|
|
coolingdown: 0,
|
|
},
|
|
...overrides,
|
|
};
|
|
}
|
|
|
|
function makeChildMeasurement({ id = 'child-1', name = 'PT-1', positionVsParent = 'downstream', type = 'pressure', unit = 'mbar' } = {}) {
|
|
const measurements = new MeasurementContainer({
|
|
autoConvert: true,
|
|
defaultUnits: {
|
|
pressure: 'mbar',
|
|
flow: 'm3/h',
|
|
temperature: 'C',
|
|
power: 'kW',
|
|
},
|
|
});
|
|
|
|
return {
|
|
config: {
|
|
general: { id, name },
|
|
functionality: { positionVsParent },
|
|
asset: { type, unit },
|
|
},
|
|
measurements,
|
|
};
|
|
}
|
|
|
|
function makeNodeStub() {
|
|
const handlers = {};
|
|
const sent = [];
|
|
const statuses = [];
|
|
const errors = [];
|
|
const warns = [];
|
|
return {
|
|
id: 'node-1',
|
|
source: null,
|
|
send(msg) { sent.push(msg); },
|
|
status(s) { statuses.push(s); },
|
|
error(e) { errors.push(e); },
|
|
warn(w) { warns.push(w); },
|
|
on(event, cb) { handlers[event] = cb; },
|
|
_handlers: handlers,
|
|
_sent: sent,
|
|
_statuses: statuses,
|
|
_errors: errors,
|
|
_warns: warns,
|
|
};
|
|
}
|
|
|
|
function makeREDStub(nodeMap = {}) {
|
|
return {
|
|
nodes: {
|
|
getNode(id) {
|
|
return nodeMap[id] || null;
|
|
},
|
|
createNode() {},
|
|
registerType() {},
|
|
},
|
|
};
|
|
}
|
|
|
|
module.exports = {
|
|
makeMachineConfig,
|
|
makeStateConfig,
|
|
makeChildMeasurement,
|
|
makeNodeStub,
|
|
makeREDStub,
|
|
};
|