-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Felix Manke
committed
Oct 17, 2021
1 parent
5bf21dc
commit 1e61b93
Showing
8 changed files
with
134 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { HeartbeatRequest } from "./ocpp/messages/heartBeat"; | ||
|
||
const DEFAULT_INTERVAL_SECONDS = 300; | ||
|
||
let heartbeatTimer: NodeJS.Timeout; | ||
|
||
/** | ||
* Start sending OCPP hearbeat messages in regular intervals (default: every 5 minutes). | ||
* | ||
* @param intervalSeconds The interval (in seconds) for the OCPP heartbeat message to be sent. | ||
*/ | ||
export function startHeartbeat( | ||
websocket: WebSocket, | ||
intervalSeconds = DEFAULT_INTERVAL_SECONDS | ||
) { | ||
heartbeatTimer = setTimeout(function () { | ||
sendHeartbeatMessage(websocket); | ||
}, intervalSeconds * 1000); | ||
|
||
console.log(`OCPP Heartbeat initialized with ${intervalSeconds} seconds.`); | ||
} | ||
|
||
/** | ||
* Reset the timer for the OCPP heartbeat message. Trigger this, whenever you send any other OCPP | ||
* message to the backend. | ||
* | ||
* (Reasoning: the heartbeat message should only be sent after the wallbox has been idling for the | ||
* specified amount of time...). | ||
* | ||
* @param intervalSeconds The interval (in seconds) for the OCPP heartbeat message to be sent. | ||
*/ | ||
export function resetHeartbeatTimer( | ||
websocket: WebSocket, | ||
intervalSeconds = DEFAULT_INTERVAL_SECONDS | ||
) { | ||
stopHeartbeat(); | ||
startHeartbeat(websocket, intervalSeconds); | ||
} | ||
|
||
/** | ||
* Clears the OCPP heartbeat timer so that the wallbox simulator stops sending heartbeat messages. | ||
*/ | ||
export function stopHeartbeat() { | ||
if (heartbeatTimer) { | ||
clearTimeout(heartbeatTimer); | ||
} | ||
heartbeatTimer = undefined; | ||
console.log(`OCPP Heartbeat timer cleared.`); | ||
} | ||
|
||
/** | ||
* Sends an OCPP heartbeat message. | ||
*/ | ||
function sendHeartbeatMessage(websocket: WebSocket) { | ||
HeartbeatRequest(websocket, {}); | ||
} |
20 changes: 8 additions & 12 deletions
20
src/lib/wallbox-simulator/ocpp/messages/bootNotification.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { OcppCallMessageBuilder } from "./ocppMessage"; | ||
|
||
export type HeartBeatRequestPayload = {}; | ||
|
||
/** | ||
* ### 1.29.1. HeartbeatRequest | ||
* | ||
* This contains the field definition of the HeartbeatRequest PDU sent by the | ||
* Charging Station to the CSMS. No fields are defined. | ||
*/ | ||
export const HeartbeatRequest = | ||
OcppCallMessageBuilder<HeartBeatRequestPayload>("Heartbeat"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/lib/wallbox-simulator/ocpp/types/bootNotificationRequestType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import type { BootReasonEnumType } from "./bootReasonEnumType"; | ||
import type { ChargingStationType } from "./chargingStationType"; | ||
|
||
/** | ||
* ### 1.2.1. BootNotificationRequest | ||
* | ||
* This contains the field definition of the BootNotificationRequest PDU sent by | ||
* the Charging Station to the CSMS. | ||
*/ | ||
export type BootNotificationRequestType = { | ||
reason: BootReasonEnumType; | ||
chargingStation: ChargingStationType; | ||
}; |
19 changes: 19 additions & 0 deletions
19
src/lib/wallbox-simulator/ocpp/types/bootReasonEnumType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* ### 2.5. BootReasonEnumType | ||
* _Enumeration_ | ||
* | ||
* BootReasonEnumType is used by: `bootNotification:BootNotificationRequest` | ||
*/ | ||
export type BootReasonEnumType = typeof bootReasons[number]; | ||
|
||
export const bootReasons = [ | ||
"ApplicationReset", // The Charging Station rebooted due to an application error. | ||
"FirmwareUpdate", // The Charging Station rebooted due to a firmware update. | ||
"LocalReset", // The Charging Station rebooted due to a local reset command. | ||
"PowerUp", // The Charging Station powered up and registers itself with the CSMS. | ||
"RemoteReset", // The Charging Station rebooted due to a remote reset command. | ||
"ScheduledReset", // The Charging Station rebooted due to a scheduled reset command. | ||
"Triggered", // Requested by the CSMS via a TriggerMessage | ||
"Unknown", // The boot reason is unknown. | ||
"Watchdog", // The Charging Station rebooted due to an elapsed watchdog timer. | ||
] as const; |
14 changes: 14 additions & 0 deletions
14
src/lib/wallbox-simulator/ocpp/types/chargingStationType.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* ### 1.13. ChargingStationType | ||
* _Class_ | ||
* | ||
* The physical system where an Electrical Vehicle (EV) can be charged. | ||
* ChargingStationType is used by: _BootNotificationRequest_ | ||
*/ | ||
export type ChargingStationType = { | ||
serialNumber?: string; // string[0..20] 0..1 Optional. Vendor-specific device identifier. | ||
model: string; // string[0..20] 1..1 Required. Defines the model of the device. | ||
vendorName: string; // string[0..50] 1..1 Required. Identifies the vendor (not necessarily in a unique manner). | ||
firmwareVersion?: string; // string[0..50] 0..1 Optional. This contains the firmware version of the Charging Station. | ||
modem?: any; // ModemType 0..1 Optional. Defines the functional | ||
}; |