Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ make SUBMODULES_INIT=true

#### C. Authorization

- :white_check_mark: Authorize
- :white_check_mark: ClearCache

#### D. LocalAuthorizationListManagement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,11 @@ const resolvePhasedValue = (
// (`Helpers.getPhaseRotationValue` branches only on {0, 1, 3}).
// Return `undefined` on any non-3-phase configuration so the
// caller can log-and-skip rather than emit a physically
// meaningless sqrt(2) * V_LN value.
// meaningless value. The sqrt(3) factor comes from the 30-degree
// phase separation in a balanced Y system, not from the phase
// count itself.
if (numberOfPhases !== 3) return undefined
return Math.sqrt(numberOfPhases) * sample.voltageV
return Math.sqrt(3) * sample.voltageV
}
return sample.voltageV
default:
Expand Down
32 changes: 22 additions & 10 deletions src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ const moduleName = 'OCPP16IncomingRequestService'
*/

export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
protected readonly csmsName = 'central system'
protected readonly csmsName = 'Central System'
protected readonly incomingRequestHandlers: Map<IncomingRequestCommand, IncomingRequestHandler>

protected readonly moduleName = moduleName
Expand Down Expand Up @@ -956,14 +956,16 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
chargingStation: ChargingStation,
commandPayload: OCPP16DataTransferRequest
): OCPP16DataTransferResponse {
const { messageId, vendorId } = commandPayload
const { vendorId } = commandPayload
try {
if (vendorId !== chargingStation.stationInfo?.chargePointVendor) {
return OCPP16Constants.OCPP_DATA_TRANSFER_RESPONSE_UNKNOWN_VENDOR_ID
}
if (messageId != null) {
return OCPP16Constants.OCPP_DATA_TRANSFER_RESPONSE_UNKNOWN_MESSAGE_ID
}
// OCPP 1.6 §4.3: `UnknownMessageId` is reserved for the case where the
// vendor is known but the messageId is not recognized by the Charge
// Point. The simulator does not maintain a per-vendor messageId
// registry, so any messageId (including undefined) is accepted when
// the vendor matches.
return OCPP16Constants.OCPP_DATA_TRANSFER_RESPONSE_ACCEPTED
} catch (error) {
const errorResponse: OCPP16DataTransferResponse =
Expand Down Expand Up @@ -1138,7 +1140,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
return OCPP16Constants.OCPP_RESPONSE_EMPTY
}
const logFiles = readdirSync(
resolve((fileURLToPath(import.meta.url), '../', dirname(logFile)))
resolve(dirname(fileURLToPath(import.meta.url)), '../', dirname(logFile))
)
.filter(file => file.endsWith(extname(logFile)))
.map(file => join(dirname(logFile), file))
Expand Down Expand Up @@ -1249,7 +1251,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
}

/**
* Handles OCPP 1.6 GetLocalListVersion request from central system.
* Handles OCPP 1.6 GetLocalListVersion request from Central System.
* Returns the version number of the local authorization list.
* @param chargingStation - The charging station instance processing the request
* @returns GetLocalListVersionResponse with list version
Expand Down Expand Up @@ -1283,7 +1285,7 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
}

/**
* Handles OCPP 1.6 RemoteStartTransaction request from central system
* Handles OCPP 1.6 RemoteStartTransaction request from Central System
* Initiates charging transaction on specified or available connector
* @param chargingStation - The charging station instance processing the request
* @param commandPayload - RemoteStartTransaction request payload with connector and ID tag
Expand Down Expand Up @@ -1534,11 +1536,11 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
try {
const authService = OCPPAuthServiceFactory.getInstance(chargingStation)
if (!chargingStation.getLocalAuthListEnabled()) {
return OCPP16Constants.OCPP_SEND_LOCAL_LIST_RESPONSE_NOT_SUPPORTED
return OCPP16Constants.OCPP_SEND_LOCAL_LIST_RESPONSE_FAILED
}
const manager = authService.getLocalAuthListManager()
if (manager == null) {
return OCPP16Constants.OCPP_SEND_LOCAL_LIST_RESPONSE_NOT_SUPPORTED
return OCPP16Constants.OCPP_SEND_LOCAL_LIST_RESPONSE_FAILED
}
if (commandPayload.listVersion <= 0) {
return OCPP16Constants.OCPP_SEND_LOCAL_LIST_RESPONSE_FAILED
Expand Down Expand Up @@ -1925,6 +1927,16 @@ export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
chargingStation.stationInfo.firmwareUpgrade.failureStatus
return
}
await sleep(secondsToMilliseconds(randomInt(minDelay, maxDelay + 1)))
await chargingStation.ocppRequestService.requestHandler<
OCPP16FirmwareStatusNotificationRequest,
OCPP16FirmwareStatusNotificationResponse
>(chargingStation, OCPP16RequestCommand.FIRMWARE_STATUS_NOTIFICATION, {
status: OCPP16FirmwareStatus.Installed,
})
if (chargingStation.stationInfo != null) {
chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Installed
Comment on lines +1937 to +1938

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic Error: TriggerMessage(FirmwareStatusNotification) does not reflect the new Installed status

After this PR adds the Installed emission to updateFirmwareSimulation, the firmwareStatus field can now hold Installed. However, the TRIGGER_MESSAGE event handler only treats Downloading, Downloaded, and Installing as passthrough values — falling back to Idle for everything else. A TriggerMessage(FirmwareStatusNotification) received while the station is in the Installed state will incorrectly report Idle.

Should add OCPP16FirmwareStatus.Installed to the passthrough condition.

Suggested change
if (chargingStation.stationInfo != null) {
chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Installed
if (chargingStation.stationInfo != null) {
chargingStation.stationInfo.firmwareStatus = OCPP16FirmwareStatus.Installed
}

Double-check suggestion before committing. Edit this comment for amendments.


Please provide feedback on the review comment by checking the appropriate box:

  • 🌟 Awesome comment, a human might have missed that.
  • ✅ Helpful comment
  • 🤷 Neutral
  • ❌ This comment is not helpful

}
if (chargingStation.stationInfo?.firmwareUpgrade?.reset === true) {
await sleep(secondsToMilliseconds(randomInt(minDelay, maxDelay + 1)))
await chargingStation.reset(OCPP16StopTransactionReason.REBOOT)
Expand Down
8 changes: 4 additions & 4 deletions src/charging-station/ocpp/1.6/OCPP16RequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const moduleName = 'OCPP16RequestService'
/**
* OCPP 1.6 Request Service
*
* Handles outgoing OCPP 1.6 requests from the charging station to the central system.
* Handles outgoing OCPP 1.6 requests from the charging station to the Central System.
* This service is responsible for:
* - Building and validating request payloads according to OCPP 1.6 specification
* - Managing request-response cycles with proper error handling
Expand Down Expand Up @@ -71,18 +71,18 @@ export class OCPP16RequestService extends OCPPRequestService {
* It performs the following operations:
* - Validates that the requested command is supported by the charging station
* - Builds and validates the request payload according to OCPP 1.6 schemas
* - Sends the request to the central system with proper error handling
* - Sends the request to the Central System with proper error handling
* - Processes responses with comprehensive logging and error recovery
*
* The method ensures type safety through generic type parameters while maintaining
* backward compatibility with the OCPP 1.6 specification.
* @template RequestType - The expected type of the request parameters
* @template ResponseType - The expected type of the response from the central system
* @template ResponseType - The expected type of the response from the Central System
* @param chargingStation - The charging station instance making the request
* @param commandName - The OCPP 1.6 command to execute (e.g., 'StartTransaction', 'StopTransaction')
* @param commandParams - Optional parameters specific to the command being executed
* @param params - Optional request parameters for controlling request behavior
* @returns Promise resolving to the typed response from the central system
* @returns Promise resolving to the typed response from the Central System
* @throws {OCPPError} When the command is not supported or validation fails
*/
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters
Expand Down
4 changes: 2 additions & 2 deletions src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
>

protected readonly bootNotificationRequestCommand = OCPP16RequestCommand.BOOT_NOTIFICATION
protected readonly csmsName = 'central system'
protected readonly csmsName = 'Central System'
protected readonly moduleName = moduleName

protected payloadValidatorFunctions: Map<OCPP16RequestCommand, ValidateFunction<JsonType>>
Expand Down Expand Up @@ -283,7 +283,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
}
const logMsg = `${chargingStation.logPrefix()} ${moduleName}.handleResponseBootNotification: Charging station in '${
payload.status
}' state on the central system`
}' state on the Central System`
payload.status === RegistrationStatusEnumType.REJECTED
? logger.warn(logMsg)
: logger.info(logMsg)
Expand Down
8 changes: 4 additions & 4 deletions src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -855,11 +855,11 @@ export class OCPP16ServiceUtils {
}

/**
* Sends a StartTransaction request to the central system for the given connector.
* Sends a StartTransaction request to the Central System for the given connector.
* @param chargingStation - Target charging station
* @param connectorId - Connector identifier to start the transaction on
* @param idTag - Optional RFID tag for the transaction
* @returns Start transaction response from the central system
* @returns Start transaction response from the Central System
*/
public static async startTransactionOnConnector (
chargingStation: ChargingStation,
Expand Down Expand Up @@ -938,11 +938,11 @@ export class OCPP16ServiceUtils {
}

/**
* Sends a StopTransaction request to the central system for the given connector.
* Sends a StopTransaction request to the Central System for the given connector.
* @param chargingStation - Target charging station
* @param connectorId - Connector identifier with the active transaction
* @param reason - Optional stop transaction reason
* @returns Stop transaction response from the central system
* @returns Stop transaction response from the Central System
*/
public static async stopTransactionOnConnector (
chargingStation: ChargingStation,
Expand Down
32 changes: 16 additions & 16 deletions src/charging-station/ocpp/1.6/__testable__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import type { OCPP16RequestService } from '../OCPP16RequestService.js'
*/
export interface TestableOCPP16IncomingRequestService {
/**
* Handles OCPP 1.6 CancelReservation request from central system.
* Handles OCPP 1.6 CancelReservation request from Central System.
* Cancels an existing reservation on the charging station.
*/
handleRequestCancelReservation: (
Expand All @@ -71,7 +71,7 @@ export interface TestableOCPP16IncomingRequestService {
) => Promise<GenericResponse>

/**
* Handles OCPP 1.6 ChangeAvailability request from central system.
* Handles OCPP 1.6 ChangeAvailability request from Central System.
* Changes availability status of a connector or the entire station.
*/
handleRequestChangeAvailability: (
Expand All @@ -80,7 +80,7 @@ export interface TestableOCPP16IncomingRequestService {
) => Promise<OCPP16ChangeAvailabilityResponse>

/**
* Handles OCPP 1.6 ChangeConfiguration request from central system.
* Handles OCPP 1.6 ChangeConfiguration request from Central System.
* Changes the value of a configuration key.
*/
handleRequestChangeConfiguration: (
Expand All @@ -94,7 +94,7 @@ export interface TestableOCPP16IncomingRequestService {
handleRequestClearCache: (chargingStation: ChargingStation) => ClearCacheResponse

/**
* Handles OCPP 1.6 ClearChargingProfile request from central system.
* Handles OCPP 1.6 ClearChargingProfile request from Central System.
* Clears charging profiles matching the specified criteria.
*/
handleRequestClearChargingProfile: (
Expand All @@ -103,7 +103,7 @@ export interface TestableOCPP16IncomingRequestService {
) => OCPP16ClearChargingProfileResponse

/**
* Handles OCPP 1.6 DataTransfer request from central system.
* Handles OCPP 1.6 DataTransfer request from Central System.
* Processes vendor-specific data transfer messages.
*/
handleRequestDataTransfer: (
Expand All @@ -112,7 +112,7 @@ export interface TestableOCPP16IncomingRequestService {
) => OCPP16DataTransferResponse

/**
* Handles OCPP 1.6 GetCompositeSchedule request from central system.
* Handles OCPP 1.6 GetCompositeSchedule request from Central System.
* Returns the composite charging schedule for a connector.
*/
handleRequestGetCompositeSchedule: (
Expand All @@ -121,7 +121,7 @@ export interface TestableOCPP16IncomingRequestService {
) => OCPP16GetCompositeScheduleResponse

/**
* Handles OCPP 1.6 GetConfiguration request from central system.
* Handles OCPP 1.6 GetConfiguration request from Central System.
* Returns configuration keys and their values.
*/
handleRequestGetConfiguration: (
Expand All @@ -130,7 +130,7 @@ export interface TestableOCPP16IncomingRequestService {
) => GetConfigurationResponse

/**
* Handles OCPP 1.6 GetDiagnostics request from central system.
* Handles OCPP 1.6 GetDiagnostics request from Central System.
* Uploads diagnostics data to the specified location.
*/
handleRequestGetDiagnostics: (
Expand All @@ -143,7 +143,7 @@ export interface TestableOCPP16IncomingRequestService {
) => OCPP16GetLocalListVersionResponse

/**
* Handles OCPP 1.6 RemoteStartTransaction request from central system.
* Handles OCPP 1.6 RemoteStartTransaction request from Central System.
* Initiates charging transaction on specified or available connector.
*/
handleRequestRemoteStartTransaction: (
Expand All @@ -152,7 +152,7 @@ export interface TestableOCPP16IncomingRequestService {
) => Promise<GenericResponse>

/**
* Handles OCPP 1.6 RemoteStopTransaction request from central system.
* Handles OCPP 1.6 RemoteStopTransaction request from Central System.
* Stops an ongoing transaction by transaction ID.
*/
handleRequestRemoteStopTransaction: (
Expand All @@ -161,7 +161,7 @@ export interface TestableOCPP16IncomingRequestService {
) => GenericResponse

/**
* Handles OCPP 1.6 ReserveNow request from central system.
* Handles OCPP 1.6 ReserveNow request from Central System.
* Creates a reservation on a connector for a specific ID tag.
*/
handleRequestReserveNow: (
Expand All @@ -170,7 +170,7 @@ export interface TestableOCPP16IncomingRequestService {
) => Promise<OCPP16ReserveNowResponse>

/**
* Handles OCPP 1.6 Reset request from central system.
* Handles OCPP 1.6 Reset request from Central System.
* Performs immediate or scheduled reset of the charging station.
*/
handleRequestReset: (
Expand All @@ -184,7 +184,7 @@ export interface TestableOCPP16IncomingRequestService {
) => OCPP16SendLocalListResponse

/**
* Handles OCPP 1.6 SetChargingProfile request from central system.
* Handles OCPP 1.6 SetChargingProfile request from Central System.
* Sets or updates a charging profile on a connector.
*/
handleRequestSetChargingProfile: (
Expand All @@ -193,7 +193,7 @@ export interface TestableOCPP16IncomingRequestService {
) => SetChargingProfileResponse

/**
* Handles OCPP 1.6 TriggerMessage request from central system.
* Handles OCPP 1.6 TriggerMessage request from Central System.
* Triggers the station to send a specific message type.
*/
handleRequestTriggerMessage: (
Expand All @@ -202,7 +202,7 @@ export interface TestableOCPP16IncomingRequestService {
) => OCPP16TriggerMessageResponse

/**
* Handles OCPP 1.6 UnlockConnector request from central system.
* Handles OCPP 1.6 UnlockConnector request from Central System.
* Unlocks a connector and optionally stops any ongoing transaction.
*/
handleRequestUnlockConnector: (
Expand All @@ -211,7 +211,7 @@ export interface TestableOCPP16IncomingRequestService {
) => Promise<UnlockConnectorResponse>

/**
* Handles OCPP 1.6 UpdateFirmware request from central system.
* Handles OCPP 1.6 UpdateFirmware request from Central System.
* Initiates firmware download and installation simulation.
*/
handleRequestUpdateFirmware: (
Expand Down
3 changes: 1 addition & 2 deletions src/charging-station/ocpp/OCPPConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,7 @@ export class OCPPConstants {
status: TriggerMessageStatus.REJECTED,
})

static readonly OCPP_WEBSOCKET_TIMEOUT_MS = 60000

static readonly OCPP_WEBSOCKET_TIMEOUT_MS = 60_000
static readonly UNKNOWN_OCPP_COMMAND = 'unknown OCPP command' as
IncomingRequestCommand | RequestCommand

Expand Down
10 changes: 6 additions & 4 deletions src/charging-station/ocpp/OCPPServiceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1251,10 +1251,12 @@ export const buildMeterValue = (
? ((phase + 1) % chargingStation.getNumberOfPhases()).toString()
: chargingStation.getNumberOfPhases().toString()
const lineToLineLabel = `L${phase.toString()}-L${nextPhase}` as MeterValuePhase
const lineToLineNominalVoltage = roundTo(
Math.sqrt(chargingStation.getNumberOfPhases()) * chargingStation.getVoltageOut(),
2
)
// `V_LL = sqrt(3) * V_LN` in a balanced 3-phase Y system; the
// sqrt(3) factor comes from the 30-degree phase separation, not
// from the phase count itself. Emitting L-L values makes physical
// sense only for `numberOfPhases === 3`; single-phase has no L-L
// pair, and `numberOfPhases === 2` is unsupported by contract.
const lineToLineNominalVoltage = roundTo(Math.sqrt(3) * chargingStation.getVoltageOut(), 2)
addPhaseVoltageToMeterValue(
chargingStation,
connectorId,
Expand Down
Loading
Loading