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