@citrineos/ocpprouter
Version:
The ocpprouter module for OCPP v2.0.1. This module is not intended to be used directly, but rather as a dependency for other modules.
114 lines (113 loc) • 6.51 kB
TypeScript
import { AbstractMessageRouter, Ajv, Call, CallAction, CallError, CallResult, ICache, IMessageConfirmation, IMessageHandler, IMessageRouter, IMessageSender, MessageOrigin, OcppError, OcppRequest, OcppResponse, OCPPVersion, OCPPVersionType, SystemConfig } from '@citrineos/base';
import { ILogObj, Logger } from 'tslog';
import { ILocationRepository, ISubscriptionRepository } from '@citrineos/data';
import { WebhookDispatcher } from './webhook.dispatcher';
/**
* Implementation of the ocpp router
*/
export declare class MessageRouterImpl extends AbstractMessageRouter implements IMessageRouter {
/**
* Fields
*/
private _webhookDispatcher;
protected _cache: ICache;
protected _sender: IMessageSender;
protected _handler: IMessageHandler;
protected _networkHook: (identifier: string, message: string) => Promise<void>;
protected _locationRepository: ILocationRepository;
subscriptionRepository: ISubscriptionRepository;
/**
* Constructor for the class.
*
* @param {SystemConfig} config - the system configuration
* @param {ICache} cache - the cache object
* @param {IMessageSender} [sender] - the message sender
* @param {IMessageHandler} [handler] - the message handler
* @param {WebhookDispatcher} [dispatcher] - the webhook dispatcher
* @param {Function} networkHook - the network hook needed to send messages to chargers
* @param {ILocationRepository} [locationRepository] - An optional parameter of type {@link ILocationRepository} which
* represents a repository for accessing and manipulating variable data.
* If no `locationRepository` is provided, a default {@link sequelize.LocationRepository} instance is created and used.
*
* @param {ISubscriptionRepository} [subscriptionRepository] - the subscription repository
* @param {Logger<ILogObj>} [logger] - the logger object (optional)
* @param {Ajv} [ajv] - the Ajv object, for message validation (optional)
*/
constructor(config: SystemConfig, cache: ICache, sender: IMessageSender, handler: IMessageHandler, dispatcher: WebhookDispatcher, networkHook: (identifier: string, message: string) => Promise<void>, logger?: Logger<ILogObj>, ajv?: Ajv, locationRepository?: ILocationRepository, subscriptionRepository?: ISubscriptionRepository);
registerConnection(connectionIdentifier: string, protocol: OCPPVersion): Promise<boolean>;
deregisterConnection(connectionIdentifier: string): Promise<boolean>;
onMessage(identifier: string, message: string, timestamp: Date, protocol: OCPPVersionType): Promise<boolean>;
/**
* Sends a Call message to a charging station with given identifier.
*
* @param {string} identifier - The identifier of the charging station.
* @param {Call} message - The Call message to send.
* @return {Promise<boolean>} A promise that resolves to a boolean indicating if the call was sent successfully.
*/
sendCall(identifier: string, tenantId: string, protocol: OCPPVersionType, action: CallAction, payload: OcppRequest, correlationId?: string, origin?: MessageOrigin): Promise<IMessageConfirmation>;
/**
* Sends the CallResult to a charging station with given identifier.
*
* @param {string} identifier - The identifier of the charging station.
* @param {CallResult} message - The CallResult message to send.
* @return {Promise<boolean>} A promise that resolves to true if the call result was sent successfully, or false otherwise.
*/
sendCallResult(correlationId: string, identifier: string, tenantId: string, protocol: OCPPVersionType, action: CallAction, payload: OcppResponse, origin?: MessageOrigin): Promise<IMessageConfirmation>;
/**
* Sends a CallError message to a charging station with given identifier.
*
* @param {string} identifier - The identifier of the charging station.
* @param {CallError} message - The CallError message to send.
* @return {Promise<boolean>} - A promise that resolves to true if the message was sent successfully.
*/
sendCallError(correlationId: string, identifier: string, tenantId: string, protocol: OCPPVersionType, action: CallAction, error: OcppError, origin?: MessageOrigin | undefined): Promise<IMessageConfirmation>;
shutdown(): Promise<void>;
/**
* Private Methods
*/
/**
* Handles an incoming Call message from a client connection.
*
* @param {string} identifier - The client identifier.
* @param {Call} message - The Call message received.
* @param {Date} timestamp Time at which the message was received from the charger.
* @param {string} protocol The OCPP protocol version of the message
* @return {void}
*/
_onCall(identifier: string, message: Call, timestamp: Date, protocol: OCPPVersionType): Promise<void>;
/**
* Handles a CallResult made by the client.
*
* @param {string} identifier - The client identifier that made the call.
* @param {CallResult} message - The OCPP CallResult message.
* @param {Date} timestamp Time at which the message was received from the charger.
* @param {OCPPVersionType} protocol The OCPP protocol version of the message
* @return {void}
*/
_onCallResult(identifier: string, message: CallResult, timestamp: Date, protocol: OCPPVersionType): void;
/**
* Handles the CallError that may have occured during a Call exchange.
*
* @param {string} identifier - The client identifier.
* @param {CallError} message - The error message.
* @param {Date} timestamp Time at which the message was received from the charger.
* @param {OCPPVersionType} protocol The OCPP protocol version of the message
* @return {void} This function doesn't return anything.
*/
_onCallError(identifier: string, message: CallError, timestamp: Date, protocol: OCPPVersionType): void;
/**
* Determine if the given action for identifier is allowed.
*
* @param {CallAction} action - The action to be checked.
* @param {string} identifier - The identifier to be checked.
* @return {Promise<boolean>} A promise that resolves to a boolean indicating if the action and identifier are allowed.
*/
private _onCallIsAllowed;
private _sendMessage;
private _sendCallIsAllowed;
private _routeCall;
private _routeCallResult;
private _routeCallError;
private _handleMessageApiCallback;
private removeNulls;
}