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