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