import { Observable } from 'rxjs'; import { MonitoringConfig } from './monitoring-config'; import { MotionMasterClient } from './motion-master-client'; import { DeviceParameterIds, ParameterValueType } from './types'; /** * Tracks and collects device parameter values over time. * * Unlike {@link MotionMasterClient#startMonitoring}, which returns an * observable that does not complete on its own, this class provides * explicit control over starting, stopping, and collecting monitoring * data. It supports exporting the data in CSV format and provides * statistical analysis of the sampling intervals. */ export declare class DataMonitoring { readonly client: MotionMasterClient; readonly ids: DeviceParameterIds; readonly monitoringInterval: number; readonly config?: MonitoringConfig | undefined; /** * Stores the collected monitoring data. * * Each element of the outer array represents a single monitoring sample, * which is an array of parameter values corresponding to {@link ids}. * Use {@link clear} to reset this array before starting a new monitoring session. */ readonly data: ParameterValueType[][]; /** * Determines whether incoming monitoring data should be collected. * * When `true`, each emitted value from the monitoring observable is * appended to the {@link data} array. Set to `false` to receive data * without storing it. */ collect: boolean; /** * Internal flag indicating whether monitoring has been stopped. * * Used by {@link start} and {@link stop} to control the observable pipeline. * When `true`, the observable returned by `start` completes on the next emission. */ private stopped; /** * The internal RxJS subscription used to manage the monitoring stream * started by {@link start}. * * This reference is used by {@link stop} to ensure a clean unsubscribe. */ private subscription?; /** * Creates a new `DataMonitoring` instance for collecting device parameter values. * * @param client - The Motion Master client used to communicate with the device. * @param ids - An array of device parameter IDs to monitor. Each ID can be a string * or a tuple `[deviceRef, index, subindex]`. * @param monitoringInterval - The interval, in microseconds, at which parameter * values should be sampled. * @param config - Optional monitoring configuration, such as filters or buffering * options. */ constructor(client: MotionMasterClient, ids: DeviceParameterIds, monitoringInterval: number, config?: MonitoringConfig | undefined); /** * Indicates whether monitoring has been stopped. * * @returns `true` if {@link stop} has been called and the internal * stop flag is set, otherwise `false`. */ get isStopped(): boolean; /** * Indicates whether monitoring is currently active. * * @returns `true` if monitoring has been started via {@link start} and * has not yet been stopped, otherwise `false`. */ get isStarted(): boolean; /** * Generates a CSV header string from the monitored parameter IDs. * * Each parameter ID in {@link ids} is converted to a string representation * using {@link makeParameterId}. String IDs are parsed with * {@link splitDeviceParameterId}, while tuple IDs `[deviceRef, index, subindex]` * are converted directly. * * @example * // Possible output: "0x6040:00,0x6060:00,0x6071:00,0x607A:00,0x60FF:00" * * @returns A comma-separated string representing the header for CSV export. */ get header(): string; /** * Converts the collected monitoring data into CSV (Comma-Separated Values) format. * * The first row contains the CSV header generated from {@link header}, * followed by one row per collected sample in {@link data}. Each row * represents the parameter values at a given monitoring interval. * * @returns A string representing the collected data in CSV format, * ready for export or analysis. */ get csv(): string; /** * Finds the zero-based index of the timestamp field in the monitored parameters. * * The timestamp field is identified as object 0x20F0 with subindex 0x00. * Parameter IDs in {@link ids} may be strings (parsed using * {@link splitDeviceParameterId}) or tuples in the form `[deviceRef, index, subindex]`. * * @returns The index of the timestamp entry in {@link ids}, or `-1` if * no timestamp field exists. */ get timestampIndex(): number; /** * Extracts the timestamp values from the collected monitoring data. * * The timestamp column is determined by {@link timestampIndex}, which * locates the entry corresponding to object 0x20F0:00 in the monitored * parameter list. If no timestamp index is found, an empty array is * returned. * * @returns An array of numeric timestamps aligned with the collected * monitoring samples, or an empty array if no timestamp field * is configured. */ get timestamps(): number[]; /** * Returns the time differences (in microseconds) between consecutive * timestamp values. * * Each duration is computed as: * * `durations[i] = timestamps[i] - timestamps[i - 1]` * * If fewer than two timestamps are available, an empty array is * returned. * * @returns An array of durations representing the time between * successive timestamp samples. */ get durations(): number[]; /** * Returns a statistical analysis of the measured timestamp durations. * * The analysis is computed by {@link analyzeTimeDurations}, which * includes a variety of metrics such as minimum, maximum, mean, * median, standard deviation, percentiles, and interquartile range. * It also provides filtered statistics based on outlier removal using * the IQR method. * * @returns An object containing both raw and filtered duration * statistics for the monitoring session. */ get analysis(): { count: number; filteredCount: number; durations: number[]; filtered: number[]; fullStats: { min: number; max: number; mean: number; median: number; std: number; p95: number; q1: number; q3: number; iqr: number; }; filteredStats: { min: number; max: number; mean: number; median: number; std: number; p95: number; q1: number; q3: number; iqr: number; }; }; /** * Clears all previously collected monitoring data. * * This resets the {@link data} array to an empty state. Call this * method before {@link start} if you want to begin a new monitoring * session with no existing samples. */ clear(): void; /** * Starts a new monitoring session and returns an observable that emits * device parameter values as they arrive. * * This method first calls {@link stop} to ensure any existing session is cleanly * terminated. It then resets the internal state and, if `clear` is true, * removes all previously collected data. * * The returned observable emits values until {@link stop} is called, * at which point the internal {@link stopped} flag is set, causing the stream to * complete on its next emission via `takeWhile()`. This mechanism ensures that * all internal and external subscriptions are cleanly shut down, preventing * resource leaks. * * If {@link collect} is enabled, each emitted value is also appended to the * {@link data} array for later retrieval or analysis. * * @param clear - Whether to clear previously collected data in {@link data} before * starting the monitoring session. Defaults to `false`. * @returns An observable that emits arrays of parameter values until * the monitoring is stopped or the source observable completes. */ start(clear?: boolean): Observable; /** * Stops the active monitoring session and unsubscribes from the source observable. * * This method sets the internal stop flag, causing the observable created in {@link start} * to complete on its next emission. If a subscription was created during `start()`, * it is explicitly unsubscribed and cleared. This ensures that no monitoring pipeline * remains active and prevents resource leaks when creating new `DataMonitoring` instances. * * Calling this method has no effect if monitoring is not currently active. */ stop(): void; }