MessageTrigger,
OCPP16AvailabilityType,
OCPP16IncomingRequestCommand,
+ OCPP16RequestCommand,
OCPP16TriggerMessageRequest,
RemoteStartTransactionRequest,
RemoteStopTransactionRequest,
case MessageTrigger.Heartbeat:
setTimeout(() => {
this.chargingStation.ocppRequestService
- .sendHeartbeat({ triggerMessage: true })
+ .sendMessageHandler(OCPP16RequestCommand.HEARTBEAT, null, { triggerMessage: true })
.catch(() => {
/* This is intentional */
});
StatusNotificationRequest,
} from '../../../types/ocpp/1.6/Requests';
import { MeterValuesRequest, OCPP16MeterValue } from '../../../types/ocpp/1.6/MeterValues';
+import { ResponseType, SendParams } from '../../../types/ocpp/Requests';
import type ChargingStation from '../../ChargingStation';
import Constants from '../../../utils/Constants';
import OCPPError from '../../../exception/OCPPError';
import OCPPRequestService from '../OCPPRequestService';
import type OCPPResponseService from '../OCPPResponseService';
-import { SendParams } from '../../../types/ocpp/Requests';
import Utils from '../../../utils/Utils';
const moduleName = 'OCPP16RequestService';
super(chargingStation, ocppResponseService);
}
- public async sendHeartbeat(params?: SendParams): Promise<void> {
- const payload: HeartbeatRequest = {};
- await this.sendMessage(Utils.generateUUID(), payload, OCPP16RequestCommand.HEARTBEAT, params);
+ public async sendMessageHandler(
+ commandName: OCPP16RequestCommand,
+ commandParams?: JsonType,
+ params?: SendParams
+ ): Promise<ResponseType> {
+ if (Object.values(OCPP16RequestCommand).includes(commandName)) {
+ return this.sendMessage(
+ Utils.generateUUID(),
+ this.buildCommandPayload(commandName, commandParams),
+ commandName,
+ params
+ );
+ }
+ throw new OCPPError(
+ ErrorType.NOT_SUPPORTED,
+ `${moduleName}.sendMessageHandler: Unsupported OCPP command ${commandName}`,
+ commandName,
+ { commandName }
+ );
}
public async sendBootNotification(
transactionId: number,
interval: number
): Promise<void> {
- const meterValue = OCPP16ServiceUtils.buildMeterValue(
+ const meterValue: OCPP16MeterValue = OCPP16ServiceUtils.buildMeterValue(
this.chargingStation,
connectorId,
transactionId,
private buildCommandPayload(
commandName: OCPP16RequestCommand,
- commandParams: JsonType
+ commandParams?: JsonType
): JsonType {
switch (commandName) {
case OCPP16RequestCommand.AUTHORIZE:
throw new OCPPError(
ErrorType.NOT_SUPPORTED,
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
- `Unsupported OCPP command: ${commandName}`,
+ `${moduleName}.buildCommandPayload: Unsupported OCPP command: ${commandName}`,
commandName,
{ commandName }
);
) {
this.chargingStation = chargingStation;
this.ocppResponseService = ocppResponseService;
+ this.sendMessageHandler.bind(this);
}
public static getInstance<T extends OCPPRequestService>(
}
}
- public abstract sendHeartbeat(params?: SendParams): Promise<void>;
+ public abstract sendMessageHandler(
+ commandName: RequestCommand,
+ commandParams?: JsonType,
+ params?: SendParams
+ ): Promise<ResponseType>;
+
public abstract sendBootNotification(
chargePointModel: string,
chargePointVendor: string,