993ba086a2d62ffd5e1bf6728787548743eedf46
[e-mobility-charging-stations-simulator.git] / src / types / ocpp / Requests.ts
1 import type ChargingStation from '../../charging-station/ChargingStation';
2 import type OCPPError from '../../exception/OCPPError';
3 import type { JsonType } from '../JsonType';
4 import { OCPP16DiagnosticsStatus } from './1.6/DiagnosticsStatus';
5 import type { OCPP16MeterValuesRequest } from './1.6/MeterValues';
6 import {
7 OCPP16AvailabilityType,
8 type OCPP16BootNotificationRequest,
9 type OCPP16DataTransferRequest,
10 type OCPP16DiagnosticsStatusNotificationRequest,
11 OCPP16FirmwareStatus,
12 type OCPP16FirmwareStatusNotificationRequest,
13 type OCPP16HeartbeatRequest,
14 OCPP16IncomingRequestCommand,
15 OCPP16MessageTrigger,
16 OCPP16RequestCommand,
17 type OCPP16StatusNotificationRequest,
18 } from './1.6/Requests';
19 import {
20 type OCPP20BootNotificationRequest,
21 OCPP20IncomingRequestCommand,
22 OCPP20RequestCommand,
23 } from './2.0/Requests';
24 import type { MessageType } from './MessageType';
25
26 export const RequestCommand = {
27 ...OCPP16RequestCommand,
28 ...OCPP20RequestCommand,
29 } as const;
30 export type RequestCommand = OCPP16RequestCommand | OCPP20RequestCommand;
31
32 export type OutgoingRequest = [MessageType.CALL_MESSAGE, string, RequestCommand, JsonType];
33
34 export type RequestParams = {
35 skipBufferingOnError?: boolean;
36 triggerMessage?: boolean;
37 throwError?: boolean;
38 };
39
40 export const IncomingRequestCommand = {
41 ...OCPP16IncomingRequestCommand,
42 ...OCPP20IncomingRequestCommand,
43 } as const;
44 export type IncomingRequestCommand = OCPP16IncomingRequestCommand | OCPP20IncomingRequestCommand;
45
46 export type IncomingRequest = [MessageType.CALL_MESSAGE, string, IncomingRequestCommand, JsonType];
47
48 export type ResponseCallback = (payload: JsonType, requestPayload: JsonType) => void;
49
50 export type ErrorCallback = (error: OCPPError, requestStatistic?: boolean) => void;
51
52 export type CachedRequest = [
53 ResponseCallback,
54 ErrorCallback,
55 RequestCommand | IncomingRequestCommand,
56 JsonType
57 ];
58
59 export const MessageTrigger = {
60 ...OCPP16MessageTrigger,
61 } as const;
62 export type MessageTrigger = OCPP16MessageTrigger;
63
64 export type BootNotificationRequest = OCPP16BootNotificationRequest | OCPP20BootNotificationRequest;
65
66 export type HeartbeatRequest = OCPP16HeartbeatRequest;
67
68 export type StatusNotificationRequest = OCPP16StatusNotificationRequest;
69
70 export type MeterValuesRequest = OCPP16MeterValuesRequest;
71
72 export type DataTransferRequest = OCPP16DataTransferRequest;
73
74 export type DiagnosticsStatusNotificationRequest = OCPP16DiagnosticsStatusNotificationRequest;
75
76 export type FirmwareStatusNotificationRequest = OCPP16FirmwareStatusNotificationRequest;
77
78 export type IncomingRequestHandler = (
79 chargingStation: ChargingStation,
80 commandPayload: JsonType
81 ) => JsonType | Promise<JsonType>;
82
83 export const AvailabilityType = {
84 ...OCPP16AvailabilityType,
85 } as const;
86 export type AvailabilityType = OCPP16AvailabilityType;
87
88 export const DiagnosticsStatus = {
89 ...OCPP16DiagnosticsStatus,
90 } as const;
91 export type DiagnosticsStatus = OCPP16DiagnosticsStatus;
92
93 export const FirmwareStatus = {
94 ...OCPP16FirmwareStatus,
95 } as const;
96 export type FirmwareStatus = OCPP16FirmwareStatus;
97
98 export type ResponseType = JsonType | OCPPError;