import Constants from '../utils/Constants';
import { ErrorType } from '../types/ocpp/ErrorType';
import FileUtils from '../utils/FileUtils';
+import { JsonType } from '../types/JsonType';
import { MessageType } from '../types/ocpp/MessageType';
import OCPP16IncomingRequestService from './ocpp/1.6/OCPP16IncomingRequestService';
import OCPP16RequestService from './ocpp/1.6/OCPP16RequestService';
return this?.wsConnection?.readyState === OPEN;
}
- public isRegistered(): boolean {
+ public getRegistrationStatus(): RegistrationStatus {
+ return this?.bootNotificationResponse?.status;
+ }
+
+ public isInUnknownState(): boolean {
+ return Utils.isNullOrUndefined(this?.bootNotificationResponse?.status);
+ }
+
+ public isInPendingState(): boolean {
+ return this?.bootNotificationResponse?.status === RegistrationStatus.PENDING;
+ }
+
+ public isInAcceptedState(): boolean {
return this?.bootNotificationResponse?.status === RegistrationStatus.ACCEPTED;
}
+ public isInRejectedState(): boolean {
+ return this?.bootNotificationResponse?.status === RegistrationStatus.REJECTED;
+ }
+
+ public isRegistered(): boolean {
+ return !this.isInUnknownState() && (this.isInAcceptedState() || this.isInPendingState());
+ }
+
public isChargingStationAvailable(): boolean {
return this.getConnectorStatus(0).availability === AvailabilityType.OPERATIVE;
}
return this.stationInfo.currentOutType ?? CurrentType.AC;
}
+ public getOcppStrictCompliance(): boolean {
+ return this.stationInfo.ocppStrictCompliance ?? false;
+ }
+
public getVoltageOut(): number | undefined {
const errMsg = `${this.logPrefix()} Unknown ${this.getCurrentOutType()} currentOutType in template file ${this.stationTemplateFile}, cannot define default voltage out`;
let defaultVoltageOut: number;
private async onOpen(): Promise<void> {
logger.info(`${this.logPrefix()} Connected to OCPP server through ${this.wsConnectionUrl.toString()}`);
- if (!this.isRegistered()) {
+ if (!this.isInAcceptedState()) {
// Send BootNotification
let registrationRetryCount = 0;
do {
this.bootNotificationResponse = await this.ocppRequestService.sendBootNotification(this.bootNotificationRequest.chargePointModel,
this.bootNotificationRequest.chargePointVendor, this.bootNotificationRequest.chargeBoxSerialNumber, this.bootNotificationRequest.firmwareVersion);
- if (!this.isRegistered()) {
- registrationRetryCount++;
+ if (!this.isInAcceptedState()) {
+ this.getRegistrationMaxRetries() !== -1 && registrationRetryCount++;
await Utils.sleep(this.bootNotificationResponse?.interval ? this.bootNotificationResponse.interval * 1000 : Constants.OCPP_DEFAULT_BOOT_NOTIFICATION_INTERVAL);
}
- } while (!this.isRegistered() && (registrationRetryCount <= this.getRegistrationMaxRetries() || this.getRegistrationMaxRetries() === -1));
+ } while (!this.isInAcceptedState() && (registrationRetryCount <= this.getRegistrationMaxRetries() || this.getRegistrationMaxRetries() === -1));
}
- if (this.isRegistered() && this.stationInfo.autoRegister) {
+ if (this.isInAcceptedState() && this.stationInfo.autoRegister) {
await this.ocppRequestService.sendBootNotification(this.bootNotificationRequest.chargePointModel,
this.bootNotificationRequest.chargePointVendor, this.bootNotificationRequest.chargeBoxSerialNumber, this.bootNotificationRequest.firmwareVersion);
}
- if (this.isRegistered()) {
+ if (this.isInAcceptedState()) {
await this.startMessageSequence();
this.stopped && (this.stopped = false);
if (this.wsConnectionRestarted && this.isWebSocketConnectionOpened()) {
private async onMessage(data: Data): Promise<void> {
let [messageType, messageId, commandName, commandPayload, errorDetails]: IncomingRequest = [0, '', '' as IncomingRequestCommand, {}, {}];
- let responseCallback: (payload: Record<string, unknown> | string, requestPayload: Record<string, unknown>) => void;
+ let responseCallback: (payload: JsonType | string, requestPayload: JsonType | OCPPError) => void;
let rejectCallback: (error: OCPPError, requestStatistic?: boolean) => void;
let requestCommandName: RequestCommand | IncomingRequestCommand;
- let requestPayload: Record<string, unknown>;
+ let requestPayload: JsonType | OCPPError;
let cachedRequest: CachedRequest;
let errMsg: string;
try {