'use strict'; const { BaseNodeAdapter } = require('generalFunctions'); const Measurement = require('./specificClass'); const commands = require('./commands'); class nodeClass extends BaseNodeAdapter { static DomainClass = Measurement; static commands = commands; // Tick drives the simulator's random walk when enabled. Disabled mode is // event-driven via the `output-changed` emit from the analog Channel. static tickInterval = 1000; static statusInterval = 1000; buildDomainConfig(uiConfig, _nodeId) { let channels = []; if (typeof uiConfig.channels === 'string' && uiConfig.channels.trim()) { try { channels = JSON.parse(uiConfig.channels); } catch (e) { this.node.warn(`Invalid channels JSON: ${e.message}`); channels = []; } } else if (Array.isArray(uiConfig.channels)) { channels = uiConfig.channels; } const mode = (typeof uiConfig.mode === 'string' && uiConfig.mode.toLowerCase() === 'digital') ? 'digital' : 'analog'; return { scaling: { enabled: uiConfig.scaling, inputMin: uiConfig.i_min, inputMax: uiConfig.i_max, absMin: uiConfig.o_min, absMax: uiConfig.o_max, offset: uiConfig.i_offset, }, smoothing: { smoothWindow: uiConfig.count, smoothMethod: uiConfig.smooth_method }, simulation: { enabled: uiConfig.simulator }, calibration: { stabilityThreshold: uiConfig.stabilityThreshold }, mode: { current: mode }, channels, }; } } module.exports = nodeClass;