import { BaseDataType } from './ethercat';
import { ParameterValueType } from './types';
import { EthercatState } from './ethercat';
/**
 * Represents a parsed parameter object returned from the GET /odl endpoint.
 */
export interface EthernetDeviceParameter {
    /**
     * The index of the parameter.
     */
    index: number;
    /**
     * The subindex of the parameter.
     */
    subindex: number;
    /**
     * The name of the parameter, providing a descriptive label.
     */
    name: string;
    /**
     * The object type code that represents the category of the parameter (e.g., "VAR", "ARRAY", "RECORD").
     * For more information, refer to {@link ObjectCodeDefinition}.
     */
    objectCode: number;
    /**
     * The value type is a base data type index that specifies the data type or encoding of the parameter's value.
     * For more information, refer to {@link allBaseDataTypes}.
     */
    valueType: number;
    /**
     * Flags representing additional attributes or configuration settings for the parameter, used for various operational purposes.
     * For more information, refer to {@link https://github.com/synapticon/somanet_software/blob/develop/arm_application/Components/cifXApplicationStackDefinitions/Includes/ECS_API/Ecs_Defines.h#L90}
     */
    flags: number;
}
/**
 * Represents a single PDO (Process Data Object) entry.
 * The index, subindex, and bit length are derived from the actual value of the PDO object, such as 0x1600:01.
 * The data type is included to ensure correct interpretation when receiving or sending PDO entry values.
 */
export interface EthernetPdoEntry {
    index: number;
    subindex: number;
    bitLen: number;
    dataType: BaseDataType;
}
/**
 * Represents a single Ethernet device.
 * Each Ethernet device hosts a web server, and the base URL uniquely identifies the device.
 */
export declare class EthernetDevice {
    readonly baseUrl: string;
    /**
     * A collection of previously retrieved device parameters.
     * These cached parameters assist in determining the correct data type and decoding parameter values during parameter upload.
     * They are also used to identify the list of PDO entries and their configurations.
     */
    parameters?: EthernetDeviceParameter[];
    /**
     * Cached RxPDO entries used to determine the type and size when sending PDO values.
     */
    rxPdoEntries?: EthernetPdoEntry[];
    /**
     * Cached TxPDO entries used to determine the type and size when receiving PDO values.
     */
    txPdoEntries?: EthernetPdoEntry[];
    /**
     * Default headers for all requests to the Integro device web server.
     */
    private readonly headers;
    /**
     * Creates an instance of the class with the specified base URL.
     *
     * @param baseUrl - The base URL for accessing the device API.
     */
    constructor(baseUrl: string);
    /**
     * Clears the internal cache by resetting parameters and PDO entries.
     *
     * This method sets the `parameters`, `rxPdoEntries`, and `txPdoEntries` to `undefined`,
     * effectively clearing any stored configuration or data for these properties.
     */
    clearCache(): void;
    /**
     * Parses a single entry (array of strings) representing information about a parameter from the GET /odl endpoint.
     * For example, the following entry corresponds to "0x2111:1" (Encoder 1 feedback - Raw position):
     * [
     *   "2111",         // Index in hexadecimal format
     *   "1",            // Subindex in decimal format
     *   "Raw position", // Parameter name
     *   "0",            // Object code
     *   "7",            // Value type
     *   "87"            // Flags
     * ]
     *
     * @param entry - An array of strings containing the parameter information.
     * @returns An object of type EthernetDeviceParameter containing the parsed values.
     */
    parseEthernetDeviceParameterEntry(entry: string[]): EthernetDeviceParameter;
    /**
     * Retrieves the list of available parameters on the device.
     *
     * Command Code: CMD=0x05
     *
     * @param uid - An optional unique identifier for the request.
     * @returns A promise that resolves to the list of available parameters.
     */
    getParameters(uid?: string): Promise<EthernetDeviceParameter[]>;
    /**
     * Retrieves the cached parameters.
     * If the parameters are not cached, a request is made to the device to fetch them.
     *
     * @returns A promise that resolves to an array of cached parameters.
     */
    getCachedParameters(): Promise<EthernetDeviceParameter[]>;
    /**
     * Retrieves and caches PDO entries, including index, subindex, bit length, and data type,
     * for efficient reuse in operations like sending and receiving PDO values.
     *
     * Note that requests to NetX must be made sequentially; otherwise, a fetch call in Node.js may time out, resulting in a 'ConnectTimeoutError'.
     *
     * @param key - Specifies which PDO entries to retrieve ('rxPdoEntries' or 'txPdoEntries').
     * @returns A promise that resolves to an array of cached PDO entries.
     */
    getCachedPdoEntries(key: keyof Pick<EthernetDevice, 'rxPdoEntries' | 'txPdoEntries'>): Promise<EthernetPdoEntry[]>;
    /**
     * Uploads a single parameter value from the device.
     *
     * Command Code: CMD=0x01
     *
     * @param index - The index of the parameter to upload.
     * @param subindex - The subindex of the parameter to upload.
     * @param uid - An optional unique identifier for the request.
     * @returns - A promise that resolves with the uploaded parameter value.
     */
    upload(index: number, subindex: number, uid?: string): Promise<ParameterValueType>;
    /**
     * Downloads the specified parameter value to the device.
     *
     * Command Code: CMD=0x02
     *
     * @param index - The index of the parameter to be downloaded.
     * @param subindex - The subindex of the parameter to be downloaded.
     * @param value - The value to set for the parameter.
     * @param uid - An optional unique identifier for the request.
     * @returns A promise that resolves when the download is complete.
     */
    download(index: number, subindex: number, value: ParameterValueType, uid?: string): Promise<void>;
    /**
     * Retrieves the EtherCAT-compatible state of the device as defined by {@link EthercatState}.
     *
     * Command Code: CMD=0x06
     *
     * @param uid - An optional unique identifier for the request.
     * @returns {Promise<number>} A promise that resolves to the current state as a number.
     */
    getState(uid?: string): Promise<number>;
    /**
     * Sets the EtherCAT-compatible state of the device as defined by {@link EthercatState}.
     *
     * Command Code: CMD=0x07
     *
     * @param state - The target state to set for the device, based on the {@link EthercatState} enumeration.
     * @param uid - An optional unique identifier for the request.
     * @returns A promise that resolves when the state has been successfully set.
     */
    setState(state: EthercatState, uid?: string): Promise<void>;
    /**
     * Resets or restarts both NetX firmware components: COM and CORE.
     * This operation is typically performed after completing a firmware installation.
     *
     * Note that the device will respond before the actual restart occurs,
     * so please allow a few seconds for the restart to complete.
     *
     * Command Code: CMD=0x09
     *
     * @param {boolean} [clearCache=true] - Specifies whether to clear the parameters and PDO entries cache during the reset.
     * @returns A promise that resolves when the reset request is complete.
     */
    reset(clearCache?: boolean): Promise<void>;
    /**
     * Reads a file from the specified device.
     *
     * Command Code: CMD=0x03
     *
     * @todo Implement the function to fetch the file data from the device.
     * @param filename - The name of the file to be read.
     * @param uid - An optional unique identifier for the request.
     * @returns A promise that resolves to a Uint8Array containing the file data.
     */
    readFile(filename: string, uid?: string): Promise<Uint8Array>;
    /**
     * Writes the specified file content to the device.
     *
     * Command Code: CMD=0x04
     *
     * @todo Implement the function to write the file content to the device.
     * @param filename - The name of the file to be created or overwritten on the device.
     * @param content - The file content to be written, provided as a Uint8Array.
     * @param uid - An optional unique identifier for the request.
     * @returns A promise that resolves when the file has been successfully written.
     */
    writeFile(filename: string, content: Uint8Array, uid?: string): Promise<void>;
    /**
     * Send PDO values to the device.
     *
     * The provided array of values will be converted into a byte array based on parameters' data types.
     *
     * Command Code: CMD=0x0B
     *
     * @param values
     * @returns
     */
    sendPdoValues(values: number[], uid?: string): Promise<void>;
    /**
     * Receives PDO values from the device.
     *
     * The device sends an array of bytes, and this function processes the parameters, their data types,
     * and the PDO entries to convert the byte array into an array of received PDO entry values.
     *
     * Command Code: CMD=0x0A
     *
     * @param uid - An optional unique identifier for the request.
     * @returns An array of received PDO entry values.
     */
    receivePdoValues(uid?: string): Promise<number[]>;
    /**
     * Uploads the firmware file to the device. Call the reset method to apply the changes.
     *
     * @todo This function has not been tested. Verify its functionality by uploading a firmware file.
     * @param buffer - The firmware data to upload.
     * @param filename - The name of the firmware file.
     * @returns A promise that resolves when the upload is complete.
     */
    uploadFirmware(buffer: ArrayBuffer, filename: string): Promise<void>;
    /**
     * Updates the firmware by uploading it to the device and restarting the NetX.
     *
     * @todo This function has not been tested. Verify its functionality by uploading a firmware file.
     * @param buffer - The firmware data to upload.
     * @param filename - The name of the firmware file.
     */
    updateFirmware(buffer: ArrayBuffer, filename: string): Promise<void>;
}
