Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ words:
- entrancy
- recurrency
- shutdowning
- subclassing
- VCAP
- workerd
- yxxx
Expand Down
4 changes: 2 additions & 2 deletions src/charging-station/ChargingStation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1607,7 +1607,7 @@ export class ChargingStation extends EventEmitter {
return this.stationInfo?.reconnectExponentialDelay === true
? computeExponentialBackOffDelay({
baseDelayMs: Constants.DEFAULT_EXPONENTIAL_BACKOFF_BASE_DELAY_MS,
jitterPercent: 0.2,
jitterPercent: Constants.DEFAULT_RECONNECT_JITTER_PERCENT,
retryNumber: this.wsConnectionRetryCount,
})
: secondsToMilliseconds(Constants.DEFAULT_WS_RECONNECT_DELAY_SECONDS)
Expand Down Expand Up @@ -2787,7 +2787,7 @@ export class ChargingStation extends EventEmitter {
sleep(
computeExponentialBackOffDelay({
baseDelayMs: Constants.DEFAULT_EXPONENTIAL_BACKOFF_BASE_DELAY_MS,
jitterPercent: 0.2,
jitterPercent: Constants.DEFAULT_RECONNECT_JITTER_PERCENT,
retryNumber: messageIdx ?? 0,
})
)
Expand Down
2 changes: 1 addition & 1 deletion src/charging-station/CoherentMeterValuesManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import type { ChargingStation } from './ChargingStation.js'
import { BaseError } from '../exception/index.js'
import { isEmpty, logger } from '../utils/index.js'
import { getEvProfilesFile } from './Helpers.js'
import { disposeCoherentSessionRuntime } from './meter-values/CoherentSampleComputer.js'
import {
type CoherentSession,
createCoherentSession,
disposeCoherentSessionRuntime,
type EvProfilesFile,
loadEvProfilesFile,
resolveRootSeed,
Expand Down
6 changes: 3 additions & 3 deletions src/charging-station/HelpersConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,13 @@ export const getAmperageLimitationUnitDivider = (stationInfo: ChargingStationInf
let unitDivider = 1
switch (stationInfo.amperageLimitationUnit) {
case AmpereUnits.CENTI_AMPERE:
unitDivider = 100
unitDivider = Constants.UNIT_DIVIDER_CENTI
break
case AmpereUnits.DECI_AMPERE:
unitDivider = 10
unitDivider = Constants.UNIT_DIVIDER_DECI
break
case AmpereUnits.MILLI_AMPERE:
unitDivider = 1000
unitDivider = Constants.UNIT_DIVIDER_KILO
Comment thread
jerome-benoit marked this conversation as resolved.
Resolved
break
}
return unitDivider
Expand Down
5 changes: 1 addition & 4 deletions src/charging-station/TemplateValidation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,7 @@ function transformTemplate (
validated: Record<string, unknown>,
filePath: string
): ChargingStationTemplate {
if (
validated.idTagsFile == null ||
(typeof validated.idTagsFile === 'string' && !isNotEmptyString(validated.idTagsFile))
) {
if (!isNotEmptyString(validated.idTagsFile)) {
Comment thread
jerome-benoit marked this conversation as resolved.
Resolved
logger.warn(
`${moduleName}.transformTemplate: Missing id tags file in template file ${filePath}. That can lead to issues with the Automatic Transaction Generator`
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import type { AbstractUIService } from '../ui-server/ui-services/AbstractUIService.js'
// Type-only edge, erased at compile time. A value import through this barrel
// would pull `UIHttpServer` / `UIMCPServer` / `UIServiceFactory` transitively
// and close a runtime cycle.
import type { AbstractUIService } from '../ui-server/index.js'

import {
type BroadcastChannelResponse,
Expand Down
9 changes: 2 additions & 7 deletions src/charging-station/meter-values/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,7 @@

export { buildCoherentMeterValue } from './CoherentMeterValueBuilder.js'
export type { BuildVersionedSampledValue } from './CoherentMeterValueBuilder.js'
export { disposeCoherentSessionRuntime } from './CoherentSampleComputer.js'
export { createCoherentSession, isCoherentModeActive, resolveRootSeed } from './CoherentSession.js'
export { loadEvProfilesFile } from './EvProfiles.js'
export type {
ChargingCurvePoint,
CoherentSession,
EvProfile,
EvProfilesFile,
ICoherentContext,
} from './types.js'
export type { CoherentSession, EvProfile, EvProfilesFile, ICoherentContext } from './types.js'
5 changes: 1 addition & 4 deletions src/charging-station/ocpp/1.6/OCPP16RequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ export class OCPP16RequestService extends OCPPRequestService {
)
return response
} catch (error) {
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.requestHandler: Error processing '${commandName}' request:`,
error
)
this.logRequestHandlerError(chargingStation, moduleName, commandName, error)
throw error
}
}
Expand Down
10 changes: 8 additions & 2 deletions src/charging-station/ocpp/1.6/OCPP16ServiceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
} from '../../../types/index.js'
import {
clampToSafeTimerValue,
Constants,
convertToBoolean,
convertToDate,
convertToInt,
Expand Down Expand Up @@ -223,7 +224,9 @@ export class OCPP16ServiceUtils {
const sampledValueTemplate = getSampledValueTemplate(chargingStation, connectorId)
if (sampledValueTemplate != null) {
const unitDivider =
sampledValueTemplate.unit === OCPP16MeterValueUnit.KILO_WATT_HOUR ? 1000 : 1
sampledValueTemplate.unit === OCPP16MeterValueUnit.KILO_WATT_HOUR
? Constants.UNIT_DIVIDER_KILO
: 1
meterValue.sampledValue.push(
buildOCPP16SampledValue(
sampledValueTemplate,
Expand Down Expand Up @@ -294,7 +297,10 @@ export class OCPP16ServiceUtils {
`Missing MeterValues for default measurand '${OCPP16MeterValueMeasurand.ENERGY_ACTIVE_IMPORT_REGISTER}' in template on connector id ${connectorId.toString()}`
)
}
const unitDivider = sampledValueTemplate.unit === OCPP16MeterValueUnit.KILO_WATT_HOUR ? 1000 : 1
const unitDivider =
sampledValueTemplate.unit === OCPP16MeterValueUnit.KILO_WATT_HOUR
? Constants.UNIT_DIVIDER_KILO
: 1
const meterValue = buildEmptyMeterValue() as OCPP16MeterValue
meterValue.sampledValue.push(
buildOCPP16SampledValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
OCPP20RequestCommand,
} from '../../../types/index.js'
import { computeExponentialBackOffDelay, logger } from '../../../utils/index.js'
import { OCPP20Constants } from './OCPP20Constants.js'
import { OCPP20ServiceUtils } from './OCPP20ServiceUtils.js'

const moduleName = 'OCPP20CertSigningRetryManager'
Expand Down Expand Up @@ -90,7 +91,7 @@ export class OCPP20CertSigningRetryManager {
this.chargingStation,
OCPP20ComponentName.SecurityCtrlr,
OCPP20OptionalVariableName.CertSigningWaitMinimum,
60
OCPP20Constants.DEFAULT_CERT_SIGNING_WAIT_MINIMUM_SECONDS
)
)
const delayMs = computeExponentialBackOffDelay({
Expand Down
8 changes: 8 additions & 0 deletions src/charging-station/ocpp/2.0/OCPP20Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,16 @@ export class OCPP20Constants extends OCPPConstants {
// { from: OCPP20ConnectorStatusEnumType.Faulted, to: OCPP20ConnectorStatusEnumType.Faulted }
])

static readonly DEFAULT_CERT_SIGNING_WAIT_MINIMUM_SECONDS = 60

static readonly DEFAULT_CONNECTION_URL = 'ws://localhost'

static readonly DEFAULT_RETRY_BACKOFF_RANDOM_RANGE_SECONDS = 10

static readonly DEFAULT_RETRY_BACKOFF_REPEAT_TIMES = 5

static readonly DEFAULT_RETRY_BACKOFF_WAIT_MINIMUM_SECONDS = 30

static readonly FIRMWARE_INSTALL_DELAY_MS = 5000
static readonly FIRMWARE_STATUS_DELAY_MS = 2000
static readonly FIRMWARE_VERIFY_DELAY_MS = 500
Expand Down
5 changes: 1 addition & 4 deletions src/charging-station/ocpp/2.0/OCPP20RequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ export class OCPP20RequestService extends OCPPRequestService {
)
return response
} catch (error) {
logger.error(
`${chargingStation.logPrefix()} ${moduleName}.requestHandler: Error processing '${commandName}' request:`,
error
)
this.logRequestHandlerError(chargingStation, moduleName, commandName, error)
throw error
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/charging-station/ocpp/2.0/OCPP20ServiceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import {
createPayloadConfigs,
PayloadValidatorOptions,
} from '../OCPPServiceUtils.js'
import { OCPP20Constants } from './OCPP20Constants.js'
import { mapStopReasonToOCPP20 } from './OCPP20RequestBuilders.js'
import { OCPP20VariableManager } from './OCPP20VariableManager.js'

Expand Down Expand Up @@ -236,19 +237,19 @@ export class OCPP20ServiceUtils {
chargingStation,
OCPP20ComponentName.OCPPCommCtrlr,
OCPP20OptionalVariableName.RetryBackOffWaitMinimum,
30
OCPP20Constants.DEFAULT_RETRY_BACKOFF_WAIT_MINIMUM_SECONDS
)
const randomRange = OCPP20ServiceUtils.readVariableAsInteger(
chargingStation,
OCPP20ComponentName.OCPPCommCtrlr,
OCPP20OptionalVariableName.RetryBackOffRandomRange,
10
OCPP20Constants.DEFAULT_RETRY_BACKOFF_RANDOM_RANGE_SECONDS
)
const repeatTimes = OCPP20ServiceUtils.readVariableAsInteger(
chargingStation,
OCPP20ComponentName.OCPPCommCtrlr,
OCPP20OptionalVariableName.RetryBackOffRepeatTimes,
5
OCPP20Constants.DEFAULT_RETRY_BACKOFF_REPEAT_TIMES
)
return computeExponentialBackOffDelay({
baseDelayMs: secondsToMilliseconds(waitMinimum),
Expand Down
10 changes: 2 additions & 8 deletions src/charging-station/ocpp/2.0/__testable__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ import type { OCPP20IncomingRequestService } from '../OCPP20IncomingRequestServi
* Interface exposing private handler methods of OCPP20IncomingRequestService for testing.
* Each method signature matches the corresponding private method in the service class.
*/
export interface TestableOCPP20IncomingRequestService {
interface TestableOCPP20IncomingRequestService {

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.

Bug: TestableOCPP20IncomingRequestService was changed from export interface to a non-exported interface, but createTestableIncomingRequestService still returns it as TestableOCPP20IncomingRequestService. Any test file that previously imported and named this type (e.g. import type { TestableOCPP20IncomingRequestService }) will now get a compile error since it is no longer exported. Similarly, SendMessageFn, TestableRequestServiceOptions, and TestableRequestServiceResult were removed from the barrel re-exports while their definitions remain in OCPP20RequestServiceTestable.ts. If any test file imports these types from the barrel, it will break.


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

/**
* Builds report data for the device model report.
* Used internally by handleRequestGetBaseReport.
Expand Down Expand Up @@ -313,19 +313,13 @@ export function createTestableIncomingRequestService (

export {
createTestableRequestService,
type SendMessageFn,
type SendMessageMock,
type TestableOCPP20RequestService,
type TestableRequestServiceOptions,
type TestableRequestServiceResult,
} from './OCPP20RequestServiceTestable.js'

export {
createTestableResponseService,
type TestableOCPP20ResponseService,
} from './OCPP20ResponseServiceTestable.js'

export {
createTestableVariableManager,
type TestableOCPP20VariableManager,
} from './OCPP20VariableManagerTestable.js'
export { createTestableVariableManager } from './OCPP20VariableManagerTestable.js'
12 changes: 12 additions & 0 deletions src/charging-station/ocpp/OCPPRequestService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ export abstract class OCPPRequestService {
}
}

protected logRequestHandlerError (
chargingStation: ChargingStation,
subclassModuleName: string,
commandName: RequestCommand,
error: unknown
): void {
logger.error(
`${chargingStation.logPrefix()} ${subclassModuleName}.requestHandler: Error processing '${commandName}' request:`,
error
)
}

protected async sendMessage (
chargingStation: ChargingStation,
messageId: string,
Expand Down
6 changes: 2 additions & 4 deletions src/charging-station/ocpp/OCPPServiceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ import {

const moduleName = 'OCPPServiceUtils'

const SOC_MAXIMUM_VALUE = 100

const isOCPP20FlagEnabled = (
chargingStation: ChargingStation,
component: OCPP20ComponentName,
Expand Down Expand Up @@ -262,7 +260,7 @@ const buildSocMeasurandValue = (
return null
}

const socMaximumValue = SOC_MAXIMUM_VALUE
const socMaximumValue = Constants.SOC_MAXIMUM_PERCENT
const socMinimumValue = socSampledValueTemplate.minimumValue ?? 0
const socSampledValueTemplateValue = isNotEmptyString(socSampledValueTemplate.value)
? getRandomFloatFluctuatedRounded(
Expand Down Expand Up @@ -1210,7 +1208,7 @@ export const buildMeterValue = (
connectorId,
convertToInt(socSampledValue.value),
socMeasurand.template.minimumValue ?? 0,
SOC_MAXIMUM_VALUE,
Constants.SOC_MAXIMUM_PERCENT,
socSampledValue.measurand,
debug
)
Expand Down
4 changes: 2 additions & 2 deletions src/charging-station/ocpp/OCPPSignedMeterDataGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MeterValueUnit,
SigningMethodEnumType,
} from '../../types/index.js'
import { roundTo } from '../../utils/index.js'
import { Constants, roundTo } from '../../utils/index.js'

export interface SignedMeterData extends JsonObject {
encodingMethod: EncodingMethodEnumType
Expand Down Expand Up @@ -53,7 +53,7 @@ export const generateSignedMeterData = (
const meterValueKwh =
params.meterValueUnit === MeterValueUnit.KILO_WATT_HOUR
? roundTo(params.meterValue, 3)
: roundTo(params.meterValue / 1000, 3)
: roundTo(params.meterValue / Constants.UNIT_DIVIDER_KILO, 3)

const ocmfPayload = {
FV: '1.0',
Expand Down
19 changes: 8 additions & 11 deletions src/charging-station/ocpp/auth/cache/InMemoryAuthCache.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { secondsToMilliseconds } from 'date-fns'
import { millisecondsToSeconds, secondsToMilliseconds } from 'date-fns'

import type { AuthCache, CacheStats } from '../interfaces/OCPPAuthService.js'
import type { AuthorizationResult } from '../types/AuthTypes.js'
Expand Down Expand Up @@ -65,9 +65,6 @@ interface RateLimitStats {
* - Bounded rate limits map prevents unbounded memory growth
*/
export class InMemoryAuthCache implements AuthCache {
// Implementation-specific safety limit (not mandated by OCPP spec)
private static readonly DEFAULT_MAX_ABSOLUTE_LIFETIME_MS = 86_400_000 // 24 hours

/** Cache storage: identifier -> entry */
private readonly cache = new Map<string, CacheEntry>()

Expand Down Expand Up @@ -108,14 +105,14 @@ export class InMemoryAuthCache implements AuthCache {
/**
* Create an in-memory auth cache
* @param options - Cache configuration options
* @param options.cleanupIntervalSeconds - Periodic cleanup interval in seconds (default: 300, 0 to disable)
* @param options.defaultTtl - Default TTL in seconds (default: 3600)
* @param options.maxAbsoluteLifetimeMs - Absolute lifetime cap in milliseconds (default: 86400000)
* @param options.cleanupIntervalSeconds - Periodic cleanup interval in seconds (default: Constants.DEFAULT_AUTH_CACHE_CLEANUP_INTERVAL_SECONDS, 0 to disable)
* @param options.defaultTtl - Default TTL in seconds (default: Constants.DEFAULT_AUTH_CACHE_TTL_SECONDS)
* @param options.maxAbsoluteLifetimeMs - Absolute lifetime cap in milliseconds (default: Constants.DEFAULT_AUTH_CACHE_MAX_ABSOLUTE_LIFETIME_MS)
* @param options.maxEntries - Maximum number of cache entries (default: Constants.DEFAULT_AUTH_CACHE_MAX_ENTRIES)
* @param options.rateLimit - Rate limiting configuration
* @param options.rateLimit.enabled - Enable rate limiting (default: false)
* @param options.rateLimit.maxRequests - Max requests per window (default: 10)
* @param options.rateLimit.windowMs - Time window in milliseconds (default: 60000)
* @param options.rateLimit.maxRequests - Max requests per window (default: Constants.DEFAULT_AUTH_CACHE_RATE_LIMIT_MAX_REQUESTS)
* @param options.rateLimit.windowMs - Time window in milliseconds (default: Constants.DEFAULT_AUTH_CACHE_RATE_LIMIT_WINDOW_MS)
*/
constructor (options?: {
cleanupIntervalSeconds?: number
Expand All @@ -126,7 +123,7 @@ export class InMemoryAuthCache implements AuthCache {
}) {
this.defaultTtl = options?.defaultTtl ?? Constants.DEFAULT_AUTH_CACHE_TTL_SECONDS
this.maxAbsoluteLifetimeMs =
options?.maxAbsoluteLifetimeMs ?? InMemoryAuthCache.DEFAULT_MAX_ABSOLUTE_LIFETIME_MS
options?.maxAbsoluteLifetimeMs ?? Constants.DEFAULT_AUTH_CACHE_MAX_ABSOLUTE_LIFETIME_MS
this.maxEntries = Math.max(1, options?.maxEntries ?? Constants.DEFAULT_AUTH_CACHE_MAX_ENTRIES)
this.rateLimit = {
enabled: options?.rateLimit?.enabled ?? false,
Expand Down Expand Up @@ -341,7 +338,7 @@ export class InMemoryAuthCache implements AuthCache {
}

const ttlSeconds = ttl ?? this.defaultTtl
const maxTtlSeconds = this.maxAbsoluteLifetimeMs / 1000
const maxTtlSeconds = millisecondsToSeconds(this.maxAbsoluteLifetimeMs)
const clampedTtl = Math.min(Math.max(0, ttlSeconds), maxTtlSeconds)
const now = Date.now()
const expiresAt = now + secondsToMilliseconds(clampedTtl)
Expand Down
4 changes: 0 additions & 4 deletions src/charging-station/ocpp/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ export { InMemoryLocalAuthListManager } from './cache/InMemoryLocalAuthListManag
export type {
AuthCache,
AuthComponentFactory,
AuthStats,
AuthStrategy,
CacheStats,
CertificateAuthProvider,
CertificateInfo,
DifferentialAuthEntry,
LocalAuthEntry,
LocalAuthListManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
import type { AuthConfiguration, AuthorizationResult, AuthRequest } from '../types/AuthTypes.js'

import {
Constants,
ensureError,
getErrorMessage,
logger,
Expand Down Expand Up @@ -382,8 +383,7 @@ export class RemoteAuthStrategy implements AuthStrategy {
}

try {
// Use provided TTL or default cache lifetime
const cacheTtl = ttl ?? result.cacheTtl ?? 300 // Default 5 minutes
const cacheTtl = ttl ?? result.cacheTtl ?? Constants.DEFAULT_REMOTE_AUTH_CACHE_TTL_SECONDS
this.authCache.set(identifier, result, cacheTtl)
logger.debug(
`${moduleName}: Cached result for '${truncateId(identifier)}' (TTL: ${String(cacheTtl)}s)`
Expand Down
Loading
Loading