UNPKG

@iotize/device-client.js

Version:

IoTize Device client for Javascript

118 lines (117 loc) 6.04 kB
import { EncoderDecoder } from "../../core/converter/encoder-decoder.interface"; import { DefaultVariableMonitor } from './monitor/default-variable-monitor'; import { VariableInteraction } from './variable-interaction.interface'; import { MemoryInfo, ModbusOptions, ModbusWriteOptions, MemoryWriteInfo, VariableType } from "../model"; import { VariableMonitor } from "./monitor/variable-monitor.interface"; import { Response } from "../../client/api/response/response.interface"; import { VariableConfigPredefined } from "./config/variable-config"; import { Tap } from "../iotize-device"; import { StringConverter } from "../../client/impl"; import { BodyConverter } from "../converter/import-adapter"; export declare type VariableMonitorFactory<DataType> = (that: VariableInteraction<DataType>) => VariableMonitor<DataType>; export declare function defaultVariableMonitorFactory<DataType>(that: VariableInteraction<DataType>): DefaultVariableMonitor<DataType>; export declare abstract class GenericVariableInteraction<DataType> implements VariableInteraction<DataType> { private monitorFactory; protected _monitor?: VariableMonitor<DataType>; protected _identifier: string; converter?: EncoderDecoder<DataType, Uint8Array>; constructor(identifier: string, monitorFactory?: VariableMonitorFactory<DataType>); read(): Promise<DataType>; write(value: DataType): Promise<any>; abstract readRaw(): Promise<Uint8Array>; abstract writeRaw(value: Uint8Array): Promise<any>; identifier(): string; monitor(): VariableMonitor<DataType>; } export declare namespace VariableMemory { type ServiceType = { readAddress: (data: MemoryInfo) => Promise<Response<Uint8Array>>; writeAddress: (data: MemoryWriteInfo) => Promise<Response<void>>; }; } /** * Dynamic variable. * It represents a virtual variable. It means that variable is not stored in the tap configuration. * We use direct memory access to read/write value */ export declare class VariableMemory<DataType> extends GenericVariableInteraction<DataType> { converter?: EncoderDecoder<DataType, Uint8Array>; service: VariableMemory.ServiceType; info: MemoryInfo; constructor(identifier: string, info: MemoryInfo, service: VariableMemory.ServiceType, converter?: EncoderDecoder<DataType, Uint8Array>); static createRaw(identifier: string, info: MemoryInfo, service: VariableMemory.ServiceType): VariableMemory<Uint8Array>; static create<DataType>(identifier: string, info: MemoryInfo, service: VariableMemory.ServiceType, converter: EncoderDecoder<DataType, Uint8Array>): VariableMemory<DataType>; readRaw(): Promise<Uint8Array>; writeRaw(encodedValue: Uint8Array): Promise<any>; private static _create; } export declare namespace ModbusRegister { type ServiceType = { modbusRead: (data: ModbusOptions) => Promise<Response<Uint8Array>>; modbusWrite: (data: ModbusWriteOptions) => Promise<Response<void>>; }; } export declare class ModbusRegister<DataType> extends GenericVariableInteraction<DataType> { converter?: EncoderDecoder<DataType, Uint8Array>; service: ModbusRegister.ServiceType; info: ModbusOptions; constructor(identifier: string, info: ModbusOptions, service: ModbusRegister.ServiceType, converter?: EncoderDecoder<DataType, Uint8Array>); readRaw(): Promise<Uint8Array>; writeRaw(value: Uint8Array): Promise<void>; } export declare namespace VariableConfig { type ServiceType = { getValue: (id: number) => Promise<Response<Uint8Array>>; setValue: (id: number, data: Uint8Array) => Promise<Response<void>>; }; } /** * Represents a configured TAP variable */ export declare class VariableConfig<DataType> extends GenericVariableInteraction<DataType> { static createFromTap<T = any>(id: number, tap: Tap, configRead?: VariableConfigurationReader): Promise<VariableConfig<T>>; static createAllFromConfig(config: VariableConfigPredefined<any>[], variableService: VariableConfig.ServiceType, monitorFactory?: VariableMonitorFactory<any>): VariableInteraction<any>[]; service: VariableConfig.ServiceType; config: VariableConfigPredefined<DataType>; readonly variableId: number; converter: EncoderDecoder<DataType, Uint8Array> | undefined; constructor(config: VariableConfigPredefined<DataType>, service: VariableConfig.ServiceType, variabeMonitorFactory?: VariableMonitorFactory<DataType>); /** * @deprecated use @{link createFromConfig} * @param identifier * @param variableId * @param service */ static createRaw<Uint8Array>(identifier: string, variableId: number, service: VariableConfig.ServiceType): VariableConfig<Uint8Array>; /** * @deprecated use @{link createFromConfig} * @param identifier * @param variableId * @param service * @param converter */ static create<DataType>(identifier: string, variableId: number, service: VariableConfig.ServiceType, converter: EncoderDecoder<DataType, Uint8Array>): VariableConfig<DataType>; static createFromConfig<T>(config: VariableConfigPredefined<T>, service: VariableConfig.ServiceType, variabeMonitorFactory?: VariableMonitorFactory<T>): VariableConfig<T>; private static _create; readRaw(): Promise<Uint8Array>; writeRaw(value: Uint8Array): Promise<void>; } export declare class VariableConfigurationReader { stringConverter: StringConverter; read(id: number, tap: Tap): Promise<VariableConfigPredefined<any>>; private _decodeMetaData; private readVariableAddress; private readVariableType; } /** * TODO * @param format * @param length */ export declare function getConverterFromFormat(type: VariableType, length: number): BodyConverter<any> | undefined; /** * TODO * @param format * @param length */ export declare function getRawConverterFromFormat(type: VariableType): BodyConverter<any> | undefined;