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