@kvaser/canking-api
Version:
CanKing API to communicate with the CanKing service using Node.js.
195 lines (194 loc) • 8.33 kB
TypeScript
import { Frame, NodeStatus, MeasurementSetup, StatusLevel, LogFileFormatInfo, SourceNodeProperties, FrameDefinition } from '../models';
import { IMeasurementSetupContext, IMeasurementStatusContext, IOnlineStatusContext } from './internalDataStores';
/**
* Options for retrieving measurement trace data in the useMeasurementTraceData hook.
*/
export type MeasurementTraceDataOptions = {
/** If true, frames from scroll mode will be included in the returned data. Defaults to true. */
includeScrollModeFrames?: boolean;
/** If true, frames from fixed position mode will be included in the returned data. Defaults to true. */
includeFixedPositionModeFrames?: boolean;
};
export declare const MAX_HISTORICAL_FRAMES = 2000;
/**
* Filters log file formats based on the available protocols.
* Formats with no protocol restrictions are always included.
* @param formats - The log file formats to filter.
* @param availableProtocols - The protocols currently available in the measurement setup.
* @returns Formats that have no protocol restriction, or that support at least one available protocol.
* @internal
*/
export declare function filterLogFileFormats(formats: LogFileFormatInfo[], availableProtocols: string[]): LogFileFormatInfo[];
/**
* Extracts and deduplicates protocols from source node properties.
* Returns `['CAN']` as a default when no protocols are found.
* @param sources - Array of source node properties to inspect.
* @returns Sorted, deduplicated array of protocol strings.
* @internal
*/
export declare function extractProtocolsFromSources(sources: SourceNodeProperties[] | undefined): string[];
/**
* Merges frame arrays and removes duplicates based on frame timestamp.
* @param existing - Existing frames to merge into.
* @param incoming - New frames to add.
* @returns Merged and deduplicated frames.
* @internal
*/
export declare function mergeAndDeduplicateFrames(existing: Frame[], incoming: Frame[]): Frame[];
/**
* Merges multiple frame data maps, deduplicating frames within each key.
* @param base - Base map to merge into (will be modified).
* @param additional - Additional map to merge from.
* @returns The merged map (same reference as base).
* @internal
*/
export declare function mergeFrameDataMaps(base: Map<string, Frame[]>, additional: Map<string, Frame[]>): Map<string, Frame[]>;
/**
* Calculates the overall status level from a bus status.
* @param busStatus - The bus status to calculate from.
* @returns The overall status level.
* @internal
*/
export declare function calculateOverallStatusLevelFromBusStatus(busStatus: NodeStatus['busStatus']): StatusLevel;
/**
* Calculates the overall status level from multiple node statuses.
* @param statuses - Array of node statuses.
* @returns The highest overall status level.
* @internal
*/
export declare function calculateOverallStatusLevel(statuses: NodeStatus[]): StatusLevel;
/**
* A hook for the measurement setup state.
* @example
* ```
* const { measurementSetup, isLoaded, error } = useMeasurementSetupState();
*
* if (!isLoaded) return <Loading />;
* if (error) return <ErrorView error={error} />;
* // measurementSetup is now safe to use
* ```
* @returns The measurement setup state.
*/
export declare const useMeasurementSetupState: () => IMeasurementSetupContext;
/**
* A hook for measurement setup.
* @returns The measurement setup.
*/
export declare const useMeasurementSetup: () => MeasurementSetup;
/**
* Hook to get all available protocols from the measurement setup.
* @returns The available protocols.
*/
export declare const useAvailableProtocols: () => string[];
/**
* Properties of the MessageDatabase React component which can be retrieved using the useMessageDatabases hook.
*/
export interface IMessageDatabase {
/** The name of the database. */
name: string;
/** Names and identifiers of all sources using this database. */
sources: {
identifier: string;
name: string;
}[];
/** Messages in this database. */
messages: FrameDefinition[];
}
/**
* Hook to get message databases available in the measurement. Will update as measurement setup changes. If nodeIdentifier is
* specified, only databases available on that node will be included.
*/
export declare const useMessageDatabases: (nodeIdentifier?: string) => IMessageDatabase[];
/**
* A hook for measurement status state.
* @example
* ```
* const { nodeStatuses, isLoaded, error } = useMeasurementStatusState();
*
* if (!isLoaded) return <Loading />;
* if (error) return <ErrorView error={error} />;
* // nodeStatuses value is now safe to use
* ```
* @returns The measurement status state.
*/
export declare const useMeasurementStatusState: () => IMeasurementStatusContext;
/**
* A hook for measurement status.
* @returns The measurement status.
*/
export declare const useMeasurementStatus: () => NodeStatus[];
/**
* Hook to get status for one node.
* @returns The node status.
*/
export declare const useNodeStatus: (id: string) => NodeStatus | null;
/**
* Hook to get the measurement's highest overall status level.
* @returns The measurement's highest overall status.
*/
export declare const useOverallStatusLevel: () => StatusLevel;
/**
* A hook for online status.
* @example
* ```
* const { onlineStatus, isLoaded, error } = useOnlineStatus();
*
* if (!isLoaded) return <Loading />;
* if (error) return <ErrorView error={error} />;
* // onlineStatus is now safe to use
* ```
* @returns The online status.
*/
export declare const useOnlineStatus: () => IOnlineStatusContext;
/**
* Hook keeping track of if the measurement is online.
* @returns A flag that indicates if a measurement is started.
* @example
* ```
* const isOnline = useIsOnline();
*
* if (isOnline) {
* // Measurement is online
* } else {
* // Measurement is offline
* }
* ```
*/
export declare const useIsOnline: () => boolean;
/**
* A hook for running periodic transmissions.
* @returns The running periodic transmissions.
*/
export declare const useRunningPeriodicTransmissions: () => string[];
/**
* A hook for new measurement data.
* @param numberOfHistoryFrames - Optional number of history frames to read from data buffer when this hook initializes.
* @param predicate - An optional predicate to filter out which data to return. Make sure to memoize this function if you are defining it inline
* to avoid unnecessary re-renders.
* @returns The new measurement data.
* @deprecated Use `useScrollModeMeasurementData`, `useFixedPositionModeMeasurementData`, `useMessageData` or `useSignalData` instead.
*/
export declare const useNewMeasurementData: (numberOfHistoryFrames?: number, predicate?: (frame: Frame) => boolean) => Frame[];
/**
* A hook for scroll mode measurement data. Will return the latest measurement data. Will include at most 500 frames.
* @param startUs - Optional start time (in microseconds) to read from the scroll data buffer. Any frame with a timestamp less than this will be excluded.
* @returns The measurement data.
*/
export declare const useScrollModeMeasurementData: (startUs?: number) => Frame[];
/**
* A hook for fixed position mode measurement data. Will return the latest measurement data for each unique frame id and type.
* @param startUs - Optional start time (in microseconds) to read from the fixed position data buffer. Any frame with a timestamp less than this will be excluded.
* @returns The measurement data.
*/
export declare const useFixedPositionModeMeasurementData: (startUs?: number) => Frame[];
/**
* A hook for combined measurement trace data from both scroll mode and fixed position mode. Will return the latest measurement data, with at most 500 frames from
* scroll mode and one frame for each unique frame id and type from fixed position mode.
* @param startUs - Optional start time (in microseconds) to read from the fixed position data buffer. Any frame with a timestamp less than this will be excluded.
* @param options - Optional options to customize the measurement trace data retrieval.
* @returns The combined measurement trace data.
*/
export declare const useCombinedMeasurementTraceData: (startUs?: number, options?: MeasurementTraceDataOptions) => {
scrollModeFrames: Frame[];
fixedPositionModeFrames: Frame[];
};