Introduce JSON type and use it for OCPP and internal message structure
[e-mobility-charging-stations-simulator.git] / src / types / ocpp / 1.6 / Requests.ts
index e8368793e5835f56a141c9268317767f7bffffc8..97b5d756e440b9478c573e48762aa9f6a7205456 100644 (file)
@@ -1,16 +1,42 @@
-import { ChargePointErrorCode } from './ChargePointErrorCode';
-import { ChargePointStatus } from './ChargePointStatus';
-import { ChargingProfile } from './ChargingProfile';
-import OCPPError from '../../../charging-station/OcppError';
+import { ChargingProfilePurposeType, OCPP16ChargingProfile } from './ChargingProfile';
 
-export default interface Requests {
-  [id: string]: [(payload?, requestPayload?) => void, (error?: OCPPError) => void, Record<string, unknown>];
+import { EmptyObject } from '../../EmptyObject';
+import { JsonType } from '../../JsonType';
+import { OCPP16ChargePointErrorCode } from './ChargePointErrorCode';
+import { OCPP16ChargePointStatus } from './ChargePointStatus';
+import { OCPP16DiagnosticsStatus } from './DiagnosticsStatus';
+import { OCPP16StandardParametersKey } from './Configuration';
+
+export enum OCPP16RequestCommand {
+  BOOT_NOTIFICATION = 'BootNotification',
+  HEARTBEAT = 'Heartbeat',
+  STATUS_NOTIFICATION = 'StatusNotification',
+  CHANGE_CONFIGURATION = 'ChangeConfiguration',
+  AUTHORIZE = 'Authorize',
+  START_TRANSACTION = 'StartTransaction',
+  STOP_TRANSACTION = 'StopTransaction',
+  METER_VALUES = 'MeterValues',
+  DIAGNOSTICS_STATUS_NOTIFICATION = 'DiagnosticsStatusNotification'
+}
+
+export enum OCPP16IncomingRequestCommand {
+  RESET = 'Reset',
+  CLEAR_CACHE = 'ClearCache',
+  CHANGE_AVAILABILITY = 'ChangeAvailability',
+  UNLOCK_CONNECTOR = 'UnlockConnector',
+  GET_CONFIGURATION = 'GetConfiguration',
+  CHANGE_CONFIGURATION = 'ChangeConfiguration',
+  SET_CHARGING_PROFILE = 'SetChargingProfile',
+  CLEAR_CHARGING_PROFILE = 'ClearChargingProfile',
+  REMOTE_START_TRANSACTION = 'RemoteStartTransaction',
+  REMOTE_STOP_TRANSACTION = 'RemoteStopTransaction',
+  GET_DIAGNOSTICS = 'GetDiagnostics',
+  TRIGGER_MESSAGE = 'TriggerMessage'
 }
 
-// eslint-disable-next-line @typescript-eslint/no-empty-interface
-export interface HeartbeatRequest {}
+export type HeartbeatRequest = EmptyObject;
 
-export interface BootNotificationRequest {
+export interface OCPP16BootNotificationRequest extends JsonType {
   chargeBoxSerialNumber?: string;
   chargePointModel: string;
   chargePointSerialNumber?: string;
@@ -22,37 +48,37 @@ export interface BootNotificationRequest {
   meterType?: string;
 }
 
-export interface StatusNotificationRequest {
+export interface StatusNotificationRequest extends JsonType {
   connectorId: number;
-  errorCode: ChargePointErrorCode;
+  errorCode: OCPP16ChargePointErrorCode;
   info?: string;
-  status: ChargePointStatus;
+  status: OCPP16ChargePointStatus;
   timestamp?: string;
   vendorId?: string;
   vendorErrorCode?: string;
 }
 
-export interface ChangeConfigurationRequest {
-  key: string;
+export interface ChangeConfigurationRequest extends JsonType {
+  key: string | OCPP16StandardParametersKey;
   value: string;
 }
 
-export interface RemoteStartTransactionRequest {
+export interface RemoteStartTransactionRequest extends JsonType {
   connectorId: number;
   idTag: string;
-  chargingProfile?: ChargingProfile;
+  chargingProfile?: OCPP16ChargingProfile;
 }
 
-export interface RemoteStopTransactionRequest {
+export interface RemoteStopTransactionRequest extends JsonType {
   transactionId: number;
 }
 
-export interface UnlockConnectorRequest {
+export interface UnlockConnectorRequest extends JsonType {
   connectorId: number;
 }
 
-export interface GetConfigurationRequest {
-  key?: string[];
+export interface GetConfigurationRequest extends JsonType {
+  key?: string | OCPP16StandardParametersKey[];
 }
 
 export enum ResetType {
@@ -60,11 +86,54 @@ export enum ResetType {
   SOFT = 'Soft'
 }
 
-export interface ResetRequest {
+export interface ResetRequest extends JsonType {
   type: ResetType;
 }
 
-export interface SetChargingProfileRequest {
+export interface SetChargingProfileRequest extends JsonType {
   connectorId: number;
-  csChargingProfiles: ChargingProfile;
+  csChargingProfiles: OCPP16ChargingProfile;
+}
+
+export enum OCPP16AvailabilityType {
+  INOPERATIVE = 'Inoperative',
+  OPERATIVE = 'Operative'
+}
+
+export interface ChangeAvailabilityRequest extends JsonType {
+  connectorId: number;
+  type: OCPP16AvailabilityType;
+}
+
+export interface ClearChargingProfileRequest extends JsonType {
+  id?: number;
+  connectorId?: number;
+  chargingProfilePurpose?: ChargingProfilePurposeType;
+  stackLevel?: number;
+}
+
+export interface GetDiagnosticsRequest extends JsonType {
+  location: string;
+  retries?: number;
+  retryInterval?: number;
+  startTime?: Date;
+  stopTime?: Date;
+}
+
+export interface DiagnosticsStatusNotificationRequest extends JsonType {
+  status: OCPP16DiagnosticsStatus
+}
+
+export enum MessageTrigger {
+  BootNotification = 'BootNotification',
+  DiagnosticsStatusNotification = 'DiagnosticsStatusNotification',
+  FirmwareStatusNotification = 'FirmwareStatusNotification',
+  Heartbeat = 'Heartbeat',
+  MeterValues = 'MeterValues',
+  StatusNotification = 'StatusNotification'
+}
+
+export interface OCPP16TriggerMessageRequest extends JsonType {
+  requestedMessage: MessageTrigger;
+  connectorId?: number
 }