@citrineos/base
Version:
The base module for OCPP v2.0.1 including all interfaces. This module is not intended to be used directly, but rather as a dependency for other modules.
76 lines (75 loc) • 3.84 kB
TypeScript
import { Ajv, ErrorObject } from 'ajv';
import { Call, CallAction, CallResult, ICache, IMessage, IMessageConfirmation, IMessageHandler, IMessageSender, MessageOrigin, OcppError, OcppRequest, OcppResponse, OCPPVersionType, SystemConfig } from '../..';
import { ILogObj, Logger } from 'tslog';
import { IMessageRouter } from './Router';
export declare abstract class AbstractMessageRouter implements IMessageRouter {
/**
* Fields
*/
protected _ajv: Ajv;
protected _cache: ICache;
protected _config: SystemConfig;
protected _logger: Logger<ILogObj>;
protected readonly _handler: IMessageHandler;
protected readonly _sender: IMessageSender;
protected _networkHook: (identifier: string, message: string) => Promise<void>;
/**
* Constructor of abstract ocpp router.
*
* @param {Ajv} ajv - The Ajv instance to use for schema validation.
*/
constructor(config: SystemConfig, cache: ICache, handler: IMessageHandler, sender: IMessageSender, networkHook: (identifier: string, message: string) => Promise<void>, logger?: Logger<ILogObj>, ajv?: Ajv);
/**
* Getters & Setters
*/
get cache(): ICache;
get sender(): IMessageSender;
get handler(): IMessageHandler;
get config(): SystemConfig;
set networkHook(value: (identifier: string, message: string) => Promise<void>);
/**
* Sets the system configuration for the module.
*
* @param {SystemConfig} config - The new configuration to set.
*/
set config(config: SystemConfig);
/**
* Public Methods
*/
handle(message: IMessage<OcppRequest | OcppResponse | OcppError>): Promise<void>;
/**
* Protected Methods
*/
/**
* Validates a Call object against its schema.
*
* @param {string} identifier - The identifier of the EVSE.
* @param {Call} message - The Call object to validate.
* @param {string} protocol - The subprotocol of the Websocket, i.e. "ocpp1.6" or "ocpp2.0.1".
* @return {boolean} - Returns true if the Call object is valid, false otherwise.
*/
protected _validateCall(identifier: string, message: Call, protocol: string): {
isValid: boolean;
errors?: ErrorObject[] | null;
};
/**
* Validates a CallResult object against its schema.
*
* @param {string} identifier - The identifier of the EVSE.
* @param {CallAction} action - The original CallAction.
* @param {CallResult} message - The CallResult object to validate.
* @param {string} protocol - The protocol of the Websocket.
* @return {boolean} - Returns true if the CallResult object is valid, false otherwise.
*/
protected _validateCallResult(identifier: string, action: CallAction, message: CallResult, protocol: string): {
isValid: boolean;
errors?: ErrorObject[] | null;
};
abstract onMessage(identifier: string, message: string, timestamp: Date, protocol: string): Promise<boolean>;
abstract registerConnection(connectionIdentifier: string, protocol: string): Promise<boolean>;
abstract deregisterConnection(connectionIdentifier: string): Promise<boolean>;
abstract sendCall(identifier: string, tenantId: string, protocol: OCPPVersionType, action: CallAction, payload: OcppRequest, correlationId?: string, origin?: MessageOrigin): Promise<IMessageConfirmation>;
abstract sendCallResult(correlationId: string, identifier: string, tenantId: string, protocol: OCPPVersionType, action: CallAction, payload: OcppResponse, origin?: MessageOrigin): Promise<IMessageConfirmation>;
abstract sendCallError(correlationId: string, identifier: string, tenantId: string, protocol: OCPPVersionType, action: CallAction, error: OcppError, origin?: MessageOrigin): Promise<IMessageConfirmation>;
abstract shutdown(): Promise<void>;
}