#ifndef __OCPP21J_H__
#define __OCPP21J_H__
#include <stdbool.h>
#include <time.h>
#include "cJSON.h"


#define LOG_OCPP  "OCPP21"


typedef char CidString37_t[40];		 // uuid used
typedef char DateTimeTZ_t[64];		 // 3.14  Time zones &&  3.15 Time notations  == ISO 8601 date time notation
typedef char CiString20Type_t[24];	 // 7.15  CiString20Type
typedef char CiString25Type_t[28];	 // 7.16  CiString25Type
typedef char CiString50Type_t[52];	 // 7.17  CiString50Type
typedef char CiString255Type_t[256]; // 7.18  CiString255Type
typedef char CiString500Type_t[512]; // 7.19  CiString500Type

// 7.2 AuthorizationStatus
typedef enum AuthorizationStatus
{
	AuthorizationStatus_Accepted = 1,
	AuthorizationStatus_Blocked,
	AuthorizationStatus_Expired,
	AuthorizationStatus_Invalid,
	AuthorizationStatus_ConcurrentTx
} AuthorizationStatus_t;

// 7.27. IdTagInfo
typedef struct IdTagInfo
{
	time_t expiryDate;	  // Optional
	CiString20Type_t parentIdTag; // Optional
	AuthorizationStatus_t status; // Required    7.2 AuthorizationStatus  enum {Accepted, Blocked, Expired, Invalid, ConcurrentTx}
} IdTagInfo_t;

// 7.28. IdToken
typedef char IdToken_t[24];

// 7.1. AuthorizationData
typedef struct AuthorizationData
{
	IdToken_t idTag;	   // Required.  7.28. IdToken
	IdTagInfo_t idTagInfo; // Optional.  7.27. IdTagInfo
} AuthorizationData_t;

// 7.3 AvailabilityStatus
typedef enum AvailabilityStatus
{
	AvailabilityStatus_Accepted = 1,
	AvailabilityStatus_Rejected,
	AvailabilityStatus_Scheduled
} AvailabilityStatus_t;

// 7.4 AvailabilityType
typedef enum AvailabilityType
{
	AvailabilityType_Inoperative = 1,
	AvailabilityType_Operative
} AvailabilityType_t;

// 7.5 CancelReservationStatus
typedef enum CancelReservationStatus
{
	CancelReservationStatus_Accepted = 1,
	CancelReservationStatus_Rejected
} CancelReservationStatus_t;

// 7.6 ChargePointErrorCode
typedef enum ChargePointErrorCode
{
	ChargePointErrorCode_ConnectorLockFailure = 1,
	ChargePointErrorCode_EVCommunicationError,
	ChargePointErrorCode_GroundFailure,
	ChargePointErrorCode_HighTemperature,
	ChargePointErrorCode_InternalError,
	ChargePointErrorCode_LocalListConflict,
	ChargePointErrorCode_NoError,
	ChargePointErrorCode_OtherError,
	ChargePointErrorCode_OverCurrentFailure,
	ChargePointErrorCode_OverVoltage,
	ChargePointErrorCode_PowerMeterFailure,
	ChargePointErrorCode_PowerSwitchFailure,
	ChargePointErrorCode_ReaderFailure,
	ChargePointErrorCode_ResetFailure,
	ChargePointErrorCode_UnderVoltage,
	ChargePointErrorCode_WeakSignal
} ChargePointErrorCode_t;

// 7.7 ChargePointStatus
typedef enum ChargePointStatus
{
	ChargePointStatus_Available = 1,
	ChargePointStatus_Preparing,
	ChargePointStatus_Charging,
	ChargePointStatus_SuspendedEVSE,
	ChargePointStatus_SuspendedEV,
	ChargePointStatus_Finishing,
	ChargePointStatus_Reserved,
	ChargePointStatus_Unavailable,
	ChargePointStatus_Faulted
} ChargePointStatus_t;

// 7.9 ChargingProfileKindType
typedef enum ChargingProfileKindType
{
	ChargingProfileKindType_Absolute = 1,	    //绝对时间， Schedule periods are relative to a fixed point in time defined in the schedule.
	ChargingProfileKindType_Recurring,			//周期性时间，The schedule restarts periodically at the first schedule period.
	ChargingProfileKindType_Relative			//相对时间，Schedule periods are relative to a situation-specific start point (such as the start of a Transaction) that is determined by the charge point.
} ChargingProfileKindType_t;

// 7.10 ChargingProfilePurposeType
typedef enum ChargingProfilePurposeType
{
	ChargingProfilePurposeType_ChargePointMaxProfile = 1, 
	/*
In load balancing scenarios, the Charge Point has one or more local charging profiles that limit the power or
current to be shared by all connectors of the Charge Point. The Central System SHALL configure such a profile
with ChargingProfilePurpose set to “ChargePointMaxProfile”. ChargePointMaxProfile can only be set at Charge
Point ConnectorId 0	
	*/ 
	ChargingProfilePurposeType_TxDefaultProfile,

	/*
Default schedules for new transactions MAY be used to impose charging policies. An example could be a policy
that prevents charging during the day. For schedules of this purpose, ChargingProfilePurpose SHALL be set to
TxDefaultProfile.
If TxDefaultProfile is set to ConnectorId 0, the TxDefaultProfile is applicable to all Connectors.
If ConnectorId is set >0, it only applies to that specific connector.
In the event a TxDefaultProfile for connector 0 is installed, and the Central System sends a new profile with ConnectorId
>0, the TxDefaultProfile SHALL be replaced only for that specific connector.	
	*/
	ChargingProfilePurposeType_TxProfile
	/*
If a transaction-specific profile with purpose TxProfile is present, it SHALL overrule the default charging profile
with purpose TxDefaultProfile for the duration of the current transaction only. After the transaction is stopped,
the profile SHOULD be deleted. If there is no transaction active on the connector specified in a charging profile
of type TxProfile, then the Charge Point SHALL discard it and return an error status in SetChargingProfile.conf.

The final schedule constraints that apply to a transaction are determined by merging the profiles with purposes
ChargePointMaxProfile with the profile TxProfile or the TxDefaultProfile in case no profile of purpose TxProfile is
provided. TxProfile SHALL only be set at Charge Point ConnectorId >0.
	*/
} ChargingProfilePurposeType_t;

// 7.11 ChargingProfileStatus
typedef enum ChargingProfileStatus
{
	ChargingProfileStatus_Accepted = 1,
	ChargingProfileStatus_Rejected,
	ChargingProfileStatus_NotSupported
} ChargingProfileStatus_t;

// 7.12. ChargingRateUnitType
typedef enum ChargingRateUnitType
{
	ChargingRateUnitType_W = 1,
	ChargingRateUnitType_A
} ChargingRateUnitType_t;

// 7.14 ChargingSchedulePeriod
#define MAXITEMS_CHARGING_SCHEDULE_PERIOD	10
typedef struct ChargingSchedulePeriod
{
	int count;
	struct ChargingSchedulePeriod_s
	{
		int startPeriod;  // Required. Start of the period, in seconds from the start of schedule. The value of StartPeriod also defines the stop time of the previous period.
		float limit;	  // Required. Charging rate limit during the schedule period, in the applicable chargingRateUnit, for example in Amperes or Watts. Accepts at most one digit fraction (e.g. 8.1).
		int numberPhases; // Optional. The number of phases that can be used for charging. If a number of phases is needed, numberPhases=3 will be assumed unless another number is given.
	} items[MAXITEMS_CHARGING_SCHEDULE_PERIOD];
} ChargingSchedulePeriod_t;

// 7.13 ChargingSchedule
typedef struct ChargingSchedule
{
	int duration;									 // Optional. Duration of the charging schedule in seconds. If the duration is left empty, the last period will continue indefinitely or until end of the transaction in case startSchedule is absent.
	time_t startTime;							     // Optional. Starting point of an absolute schedule. If absent the schedule will be relative to start of charging.
	ChargingRateUnitType_t chargingRateUnit;		 // Required. 7.12 enum ChargingRateUnitType {W, A}
	ChargingSchedulePeriod_t chargingSchedulePeriod; // Required
	float minChargingRate;							 // Optional. Minimum charging rate supported by the electric vehicle. The unit of measure is defined by the chargingRateUnit.
													 // This parameter is intended to be used by a local smart charging algorithm to optimize the power allocation for in the case a charging process is inefficient at lower charging rates. 
													 // Accepts at most one digit fraction (e.g. 8.1)
} ChargingSchedule_t;

// 7.37 RecurrencyKindType
typedef enum RecurrencyKindType
{
	RecurrencyKindType_NULL,
	RecurrencyKindType_Daily = 1,
	RecurrencyKindType_Weekly,
} RecurrencyKindType_t;

// 7.8 ChargingProfile
typedef struct ChargingProfile
{
	int chargingProfileId;								 // Required
	int transactionId;									 // Optional,  注意此字段在存储阶段，被当作connectorId用
	int stackLevel;										 // Required
	ChargingProfilePurposeType_t chargingProfilePurpose; // Required.  7.10. ChargingProfilePurposeType  enum {ChargePointMaxProfile,  TxDefaultProfile,  TxProfile}
	ChargingProfileKindType_t chargingProfileKind;		 // Required.  7.9. ChargingProfileKindType  enum {Absolute,  Recurring,  Relative}
	RecurrencyKindType_t recurrencyKind;				 // Optional.  7.37. RecurrencyKindType  enum {Daily,  Weekly}
	time_t validFrom;								     // Optional.  Point in time at which the profile starts to be valid. If absent, the profile is valid as soon as it is received by the Charge Point.
	time_t validTo;								         // Optional.  Point in time at which the profile stops to be valid. If absent, the profile is valid until it is replaced by another profile.
	ChargingSchedule_t chargingSchedule;				 // Required
} ChargingProfile_t;

// 7.20. ClearCacheStatus
typedef enum ClearCacheStatus
{
	ClearCacheStatus_Accepted = 1,
	ClearCacheStatus_Rejected
} ClearCacheStatus_t;

// 7.21. ClearChargingProfileStatus
typedef enum ClearChargingProfileStatus
{
	ClearChargingProfileStatus_Accepted = 1,
	ClearChargingProfileStatus_Unknown
} ClearChargingProfileStatus_t;

// 7.22. ConfigurationStatus
typedef enum ConfigurationStatus
{
	ConfigurationStatus_Accepted = 1,
	ConfigurationStatus_Rejected,
	ConfigurationStatus_RebootRequired,
	ConfigurationStatus_NotSupported
} ConfigurationStatus_t;

// 7.23. DataTransferStatus
typedef enum DataTransferStatus
{
	DataTransferStatus_Accepted = 1,
	DataTransferStatus_Rejected,
	DataTransferStatus_UnknownMessageId,
	DataTransferStatus_UnknownVendorId
} DataTransferStatus_t;

// 7.24. DiagnosticsStatus
typedef enum DiagnosticsStatus
{
	DiagnosticsStatus_Idle = 1,
	DiagnosticsStatus_Uploaded,
	DiagnosticsStatus_UploadFailed,
	DiagnosticsStatus_Uploading
} DiagnosticsStatus_t;

// 7.25. FirmwareStatus
typedef enum FirmwareStatus
{
	FirmwareStatus_Downloaded = 1,
	FirmwareStatus_DownloadFailed,
	FirmwareStatus_Downloading,
	FirmwareStatus_Idle,
	FirmwareStatus_InstallationFailed,
	FirmwareStatus_Installing,
	FirmwareStatus_Installed
} FirmwareStatus_t;

// 7.26. GetCompositeScheduleStatus
typedef enum GetCompositeScheduleStatus
{
	GetCompositeScheduleStatus_Accepted = 1,
	GetCompositeScheduleStatus_Rejected
} GetCompositeScheduleStatus_t;

// 7.29 KeyValue
typedef struct KeyValue
{
	CiString50Type_t key;
	CiString50Type_t value;
	bool readonly;
} KeyValue_t;

// 7.30. Location
typedef enum Location
{
	Location_Body = 1,
	Location_Cable,
	Location_EV,
	Location_Inlet,
	Location_Outlet
} Location_t;

// 7.31. Measurand
typedef enum Measurand
{
	Measurand_Current_Export = 1,
	Measurand_Current_Import,
	Measurand_Current_Offered,

	Measurand_Energy_Active_Export_Register,
	Measurand_Energy_Active_Import_Register,

	Measurand_Energy_Reactive_Export_Register,
	Measurand_Energy_Reactive_Import_Register,

	Measurand_Energy_Active_Export_Interval,
	Measurand_Energy_Active_Import_Interval,

	Measurand_Energy_Reactive_Export_Interval,
	Measurand_Energy_Reactive_Import_Interval,

	Measurand_Frequency,

	Measurand_Power_Active_Export,
	Measurand_Power_Active_Import,

	Measurand_Power_Factor,
	Measurand_Power_Offered,

	Measurand_Power_Reactive_Export,
	Measurand_Power_Reactive_Import,
	
	Measurand_RPM,
	Measurand_SoC,
	Measurand_Temperature,
	Measurand_Voltage
} Measurand_t;

// 7.32. MessageTrigger
typedef enum MessageTrigger
{
	MessageTrigger_BootNotification = 1,
	MessageTrigger_DiagnosticsStatusNotification,
	MessageTrigger_FirmwareStatusNotification,
	MessageTrigger_Heartbeat,
	MessageTrigger_MeterValues,
	MessageTrigger_StatusNotification,
	MessageTrigger_MeterValues7,
	MessageTrigger_StatusNotification8
} MessageTrigger_t;

// 7.35 ReadingContext
typedef enum ReadingContext
{
	ReadingContext_Interruption_Begin = 1,
	ReadingContext_Interruption_End,
	ReadingContext_Other,
	ReadingContext_Sample_Clock,
	ReadingContext_Sample_Periodic,
	ReadingContext_Transaction_Begin,
	ReadingContext_Transaction_End,
	ReadingContext_Trigger
} ReadingContext_t;

// 7.49. ValueFormat
typedef enum ValueFormat
{
	ValueFormat_Raw = 1,
	ValueFormat_SignedData
} ValueFormat_t;

// 7.34. Phase
typedef enum Phase
{
	Phase_L1 = 1,
	Phase_L2,
	Phase_L3,
	Phase_N,
	Phase_L1_N,
	Phase_L2_N,
	Phase_L3_N,
	Phase_L1_L2,
	Phase_L2_L3,
	Phase_L3_L1
} Phase_t;

// 7.45. UnitOfMeasure
typedef enum UnitOfMeasure
{
	UnitOfMeasure_Wh = 1,
	UnitOfMeasure_kWh,
	UnitOfMeasure_varh,
	UnitOfMeasure_kvarh,
	UnitOfMeasure_W,
	UnitOfMeasure_kW,
	UnitOfMeasure_VA,
	UnitOfMeasure_kVA,
	UnitOfMeasure_var,
	UnitOfMeasure_kvar,
	UnitOfMeasure_A,
	UnitOfMeasure_V,
	UnitOfMeasure_Celsius,
	UnitOfMeasure_Fahrenheit,
	UnitOfMeasure_K,
	UnitOfMeasure_Percent
} UnitOfMeasure_t;

// 7.43 SampledValue
#define MAXITEMS_SAMPLED_VALUE	10
typedef struct SampledValue
{
	int count;
	struct SampledValue_s
	{
		CiString20Type_t value;
		ReadingContext_t context; // Optional.  7.35 ReadingContext enum {Interruption.Begin, Interruption.End, Other, Sample.Clock, Sample.Periodic, Transaction.Begin, Transaction.End, Trigger}
		ValueFormat_t format;	  // Optional.  7.49 ValueFormat enum {Raw, SignedData}
		Measurand_t measurand;	  // Optional.  7.31 Measurand enum {}
		Phase_t phase;			  // Optional.  7.34 Phase enum {L1, L2, L3, N, L1-N, L2-N, L3-N, L1-L2, L2-L3, L3-L1}
		Location_t location;	  // Optional.  7.30 Location enum {Body, Cable, EV, Inlet, Outlet}
		UnitOfMeasure_t unit;	  // Optional.  7.45 UnitOfMeasure enum {Wh,  kWh,  varh,  kvarh,  W,  kW,  VA,  kVA,  var,  kvar,  A,  V,  Celsius,  Fahrenheit,  K,  Percent}
	} items[MAXITEMS_SAMPLED_VALUE];
} SampledValue_t;

// 7.33. MeterValue
#define MAXITEMS_METER_VALUE	10
typedef struct MeterValue
{
	int count;
	struct MeterValue_s
	{
		DateTimeTZ_t timestamp;
		SampledValue_t sampledvalue;
	} items[MAXITEMS_METER_VALUE];
} MeterValue_t;

// 7.36. Reason
typedef enum Reason
{
	Reason_DeAuthorized = 1,
	Reason_EmergencyStop,
	Reason_EVDisconnected,
	Reason_HardReset,
	Reason_Local,
	Reason_Other,
	Reason_PowerLoss,
	Reason_Reboot,
	Reason_Remote,
	Reason_SoftReset,
	Reason_UnlockCommand
} Reason_t;

// 7.38. RegistrationStatus
typedef enum RegistrationStatus
{
	RegistrationStatus_Accepted = 1,
	RegistrationStatus_Pending,
	RegistrationStatus_Rejected
} RegistrationStatus_t;

// 7.39. RemoteStartStopStatus
typedef enum RemoteStartStopStatus
{
	RemoteStartStopStatus_Accepted = 1,
	RemoteStartStopStatus_Rejected
} RemoteStartStopStatus_t;

// 7.40. ReservationStatus
typedef enum ReservationStatus
{
	ReservationStatus_Accepted = 1,
	ReservationStatus_Faulted,
	ReservationStatus_Occupied,
	ReservationStatus_Rejected,
	ReservationStatus_Unavailable
} ReservationStatus_t;

// 7.41. ResetStatus
typedef enum ResetStatus
{
	ResetStatus_Accepted = 1,
	ResetStatus_Rejected
} ResetStatus_t;

// 7.42. ResetType
typedef enum ResetType
{
	ResetType_Hard = 1,
	ResetType_Soft,
	ResetType_UpdateTCU,
	ResetType_UpdateCCU,
	ResetType_UpdatePCU,
} ResetType_t;

// 7.44. TriggerMessageStatus
typedef enum TriggerMessageStatus
{
	TriggerMessageStatus_Accepted = 1,
	TriggerMessageStatus_Rejected,
	TriggerMessageStatus_NotImplemented
} TriggerMessageStatus_t;

// 7.46. UnlockStatus
typedef enum UnlockStatus
{
	UnlockStatus_Unlocked = 1,
	UnlockStatus_UnlockFailed,
	UnlockStatus_NotSupported
} UnlockStatus_t;

// 7.47. UpdateStatus
typedef enum UpdateStatus
{
	UpdateStatus_Accepted = 1,
	UpdateStatus_Failed,
	UpdateStatus_NotSupported,
	UpdateStatus_VersionMismatch
} UpdateStatus_t;

// 7.48. UpdateType
typedef enum UpdateType
{
	UpdateType_Differential = 1,
	UpdateType_Full
} UpdateType_t;

/*****************************************************************************************************************************************************************************************************/

// 6.1 Authorize.Req
typedef struct AuthorizeReq
{
	IdToken_t idTag; // Required.
} AuthorizeReq_t;

// 6.2 Authorize.Conf
typedef struct AuthorizeConf
{
	IdTagInfo_t idTagInfo; // Required.
} AuthorizeConf_t;

// 6.3 BootNotification.Req
typedef struct BootNotificationReq
{
	CiString20Type_t chargePointModel;		  // Required
	CiString25Type_t chargeBoxSerialNumber;	  // Optional    will be removed
	CiString25Type_t chargePointSerialNumber; // Optional
	CiString50Type_t firmwareVersion;		  // Optional
	CiString20Type_t iccid;					  // Optional
	CiString20Type_t imsi;					  // Optional
	CiString25Type_t meterSerialNumber;		  // Optional
	CiString25Type_t meterType;				  // Optional
	CiString20Type_t chargePointVendor;		  // Required
} BootNotificationReq_t;

// 6.4 BootNotification.Conf
typedef struct BootNotificationConf
{
	DateTimeTZ_t currentTime;	 // Required
	int interval;				 // Required
	RegistrationStatus_t status; // Required.  7.38. RegistrationStatus enum {Accepted, Pending, Rejected}
} BootNotificationConf_t;

// 6.5 CancelReservation.Req
typedef struct CancelReservationReq
{
	int reservationId; // Required
} CancelReservationReq_t;

// 6.6 CancelReservation.Conf
typedef struct CancelReservationConf
{
	CancelReservationStatus_t status; // Required.  7.5. CancelReservationStatus  enum {Accepted, Rejected}
} CancelReservationConf_t;

// 6.7 ChangeAvailability.Req
typedef struct ChangeAvailabilityReq
{
	int connectorId;		 // Required
	AvailabilityType_t type; // Required.  7.4. AvailabilityType  enum {Inoperative, Operative}
} ChangeAvailabilityReq_t;

// 6.8 ChangeAvailability.Conf
typedef struct ChangeAvailabilityConf
{
	AvailabilityStatus_t status; // Required.  7.3. AvailabilityStatus enum {Accepted, Rejected, Scheduled}
} ChangeAvailabilityConf_t;

// 6.9 ChangeConfiguration.Req
typedef struct ChangeConfigurationReq
{
	CiString50Type_t key;	 // Required
	CiString500Type_t value; // Required
} ChangeConfigurationReq_t;

// 6.10 ChangeConfiguration.Conf
typedef struct ChangeConfigurationConf
{
	ConfigurationStatus_t status; // Required.  7.22. ConfigurationStatus enum {Accepted, Rejected, RebootRequired. NotSupported}
} ChangeConfigurationConf_t;

// 6.11 ClearCache.Req
typedef struct ClearCacheReq
{
	// NULL
} ClearCacheReq_t;

// 6.12 ClearCache.Conf
typedef struct ClearCacheConf
{
	ClearCacheStatus_t status; // Required.  7.20. ClearCacheStatus enum {Accepted, Rejected}
} ClearCacheConf_t;

// 6.13 ClearChargingProfile.Req
typedef struct ClearChargingProfileReq
{
	int id;												 // Optional    removed Profile ID
	int connectorId;									 // Optional
	ChargingProfilePurposeType_t chargingProfilePurpose; // Optional    7.10. ChargingProfilePurposeType enum {ChargePointMaxProfile, TxDefaultProfile, TxProfile}
	int stackLevel;										 // Optional
} ClearChargingProfileReq_t;

// 6.14 ClearChargingProfile.Conf
typedef struct ClearChargingProfileConf
{
	ClearChargingProfileStatus_t status; // Required.  7.21. ClearChargingProfileStatus enum {Accepted, Unknown}
} ClearChargingProfileConf_t;

typedef struct DataTransferPrice
{
	CiString50Type_t startTime;		// Required
	CiString50Type_t stopTime;		// Required
	CiString20Type_t electrPrice;	// Optional
	CiString20Type_t servicePrice;	// Optional
	CiString20Type_t durationPrice; // Optional
} DataTransferPrice_t;

#define MAXITEMS_DATA_TRANSFER_DATA	30
typedef struct DataTransferData
{
	CiString20Type_t type;			  // Required
	CiString50Type_t timeZone;		  // Optional
	CiString20Type_t minAllowBalance; // Required
	struct DataTransferPrice_s
	{
		int count;
		DataTransferPrice_t items[MAXITEMS_DATA_TRANSFER_DATA];
	} price; // Required
} DataTransferData_t;

// 6.15 DataTransfer.Req
typedef struct DataTransferReq
{
	CiString255Type_t vendorId; // Required
	CiString50Type_t messageId; // Required
	DataTransferData_t data;	// Required
} DataTransferReq_t;

// 6.16 DataTransfer.Conf
typedef struct DataTransferConf
{
	DataTransferStatus_t status; // Required.  7.23. DataTransferStatus enum {Accepted, Rejected, UnknownMessageId, UnknownVendorId}
	DataTransferData_t data;	 // Optional
} DataTransferConf_t;

// 6.17 DiagnosticsStatusNotification.Req
typedef struct DiagnosticsStatusNotificationReq
{
	DiagnosticsStatus_t status; // Required. 7.24. DiagnosticsStatus enum {Idle, Uploaded, UploadFailed, Uploading}
} DiagnosticsStatusNotificationReq_t;

// 6.18 DiagnosticsStatusNotification.Conf
typedef struct DiagnosticsStatusNotificationConf
{
	// NULL
} DiagnosticsStatusNotificationConf_t;

// 6.19 FirmwareStatusNotification.Req
typedef struct FirmwareStatusNotificationReq
{
	FirmwareStatus_t status; // Required.  7.25. FirmwareStatus  enum {Downloaded, DownloadFailed, Downloading, Idle, InstallationFailed, Installing, Installed}
} FirmwareStatusNotificationReq_t;

// 6.20 FirmwareStatusNotification.Conf
typedef struct FirmwareStatusNotificationConf
{
	// NULL
} FirmwareStatusNotificationConf_t;

// 6.21 GetCompositeSchedule.Req
typedef struct GetCompositeScheduleReq
{
	int connectorId;						 // Required
	int duration;							 // Required
	ChargingRateUnitType_t chargingRateUnit; // Optional.  7.12. ChargingRateUnitType enum {W, A}
} GetCompositeScheduleReq_t;

// 6.22 GetCompositeSchedule.Conf
typedef struct GetCompositeScheduleConf
{
	GetCompositeScheduleStatus_t status; // Required.  7.26. GetCompositeScheduleStatus enum {Accepted, Rejected}
	int connectorId;					 // Optional
	DateTimeTZ_t scheduleStart;			 // Optional
	ChargingSchedule_t chargingSchedule; // Optional.  7.13. ChargingSchedule
} GetCompositeScheduleConf_t;

// 6.23 GetConfiguration.Req
#define MAXITEMS_CONFIGURATION_REQ	10
typedef struct GetConfigurationReq
{
	struct Configuration_s
	{
		int count;
		CiString50Type_t items[MAXITEMS_CONFIGURATION_REQ]; // Optional
	} key;
} GetConfigurationReq_t;

// 6.24 GetConfiguration.Conf
#define MAXITEMS_KEY_VALUE	50
#define MAXITEMS_UNKNOWN_KEY	50
typedef struct GetConfiguration_Conf
{
	struct KeyValue_s
	{
		int count;
		KeyValue_t items[MAXITEMS_KEY_VALUE];
	} configurationKey;

	struct UnknownKey_s
	{
		int count;
		CiString50Type_t items[MAXITEMS_UNKNOWN_KEY];
	} unknownKey;
} GetConfigurationConf_t;

// 6.25 GetDiagnostics.Req
typedef struct GetDiagnosticsReq
{
	CiString255Type_t location; // Required
	int retries;				// Optional
	int retryInterval;			// Optional
	time_t startTime;		    // Optional
	time_t stopTime;		    // Optional
} GetDiagnosticsReq_t;

// 6.26 GetDiagnostics.Conf
typedef struct GetDiagnosticsConf
{
	CiString255Type_t fileName;
} GetDiagnosticsConf_t;

// 6.27 GetLocalListVersion.Req
typedef struct GetLocalListVersionReq
{
	// NULL
} GetLocalListVersionReq_t;

// 6.28 GetLocalListVersion.Conf
typedef struct GetLocalListVersionConf
{
	int listVersion;
} GetLocalListVersionConf_t;

// 6.29 Hearbeat.Req
typedef struct HeartbeatReq
{
} HeartbeatReq_t;

// 6.30 Hearbeat.Conf
typedef struct HeartbeatConf
{
	DateTimeTZ_t currentTime;
} HeartbeatConf_t;

// 6.31
typedef struct MeterValuesReq
{
	int connectorId;		 // Required
	int transactionId;		 // Optional
	MeterValue_t meterValue; // Required
} MeterValuesReq_t;

// 6.32 MeterValues.Conf
typedef struct MeterValuesConf
{
	// NULL
} MeterValuesConf_t;

// 6.33 RemoteStartTransaction.Req
typedef struct RemoteStartTransactionReq
{
	int connectorId;				   // Optional
	IdToken_t idTag;				   // Required.  7.28. IdToken  CiString20Type
	ChargingProfile_t chargingProfile; // Optional
	int chargingProfile_used;
} RemoteStartTransactionReq_t;

// 6.34 RemoteStartTransaction.Conf
typedef struct RemoteStartTransactionConf
{
	RemoteStartStopStatus_t status; // Required.  7.39. RemoteStartStopStatus  enum {Accepted, Rejected}
} RemoteStartTransactionConf_t;

// 6.35 RemoteStopTransaction.Req
typedef struct RemoteStopTransactionReq
{
	int transactionId; // Required
} RemoteStopTransactionReq_t;

// 6.36 RemoteStopTransaction.Conf
typedef struct RemoteStopTransactionConf
{
	RemoteStartStopStatus_t status; // Required.  7.39. RemoteStartStopStatus enum {Accepted, Rejected}
} RemoteStopTransactionConf_t;

// 6.37 ReserveNow.Req
typedef struct ReserveNowReq
{
	int connectorId;		 // Required
	time_t expiryDate;       // Required
	IdToken_t idTag;		 // Required
	IdToken_t parentIdTag;	 // Optional
	int reservationId;		 // Required
} ReserveNowReq_t;

// 6.38 ReserveNow.Conf
typedef struct ReserveNowConf
{
	ReservationStatus_t status; // Required. 7.40. ReservationStatus  enum {Accepted, Faulted, Occupied, Rejected, Unavailable}
} ReserveNowConf_t;

// 6.39 Reset.Req
typedef struct ResetReq
{
	ResetType_t type; // Required.  7.42. ResetType  enum {Hard, Soft}
} ResetReq_t;

// 6.40 Reset.Conf
typedef struct ResetConf
{
	ResetStatus_t status; // Required.  7.41. ResetStatus  enum {Accepted, Rejected}
} ResetConf_t;

// 6.41 SendLocalList.Req
#define MAXITEMS_SEND_LOCAL_LIST_REQ	10
typedef struct SendLocalListReq
{
	int listVersion; // Required
	struct AuthorizationData_s
	{
		int count;
		AuthorizationData_t items[MAXITEMS_SEND_LOCAL_LIST_REQ]; // Optional.  7.1. AuthorizationData
	} localAuthorizationList;

	UpdateType_t updateType; // Required.  7.48. UpdateType  enum {Differential,  Full}
} SendLocalListReq_t;

// 6.42 SendLocalList.Conf
typedef struct SendLocalListConf
{
	UpdateStatus_t status; // Optional.  7.47. UpdateStatus  enum {Accepted,  Failed,  NotSupported,  VersionMismatch}
} SendLocalListConf_t;

// 6.43 SetChargingProfile.Req
typedef struct SetChargingProfileReq
{
	int connectorId;					  // Required
	ChargingProfile_t csChargingProfiles; // Required
} SetChargingProfileReq_t;

// 6.44 SetChargingProfile.Conf
typedef struct SetChargingProfileConf
{
	ChargingProfileStatus_t status; // Required.  7.11. ChargingProfileStatus  enum {Accepted, Rejected, NotSupported}
} SetChargingProfileConf_t;

// 6.45 StartTransaction.Req
typedef struct StartTransactionReq
{
	int connectorId;		// Required
	IdToken_t idTag;		// Required
	int meterStart;			// Required
	int reservationId;		// Optional
	time_t timestamp;       // Required
} StartTransactionReq_t;

// 6.46 StartTransaction.Conf
typedef struct StartTransactionConf
{
	IdTagInfo_t idTagInfo; // Required
	int transactionId;	   // Required
} StartTransactionConf_t;

// 6.47 StatusNotification.Req
typedef struct StatusNotificationReq
{
	int connectorId;				  // Required
	ChargePointErrorCode_t errorCode; // Required  7.6. ChargePointErrorCode  enum {ConnectorLockFailure,  EVCommunicationError,  GroundFailure,  HighTemperature,  InternalError,  LocalListConflict,  NoError,  OtherError,  OverCurrentFailure,  OverVoltage,  PowerMeterFailure,  PowerSwitchFailure,  ReaderFailure,  ResetFailure,  UnderVoltage,  WeakSignal}
	CiString50Type_t info;			  // Optional
	ChargePointStatus_t status;		  // Required  7.7. ChargePointStatus  enum {Available,  Preparing,  Charging,  SuspendedEVSE,  SuspendedEV,  Finishing,  Reserved,  Unavailable,  Faulted}
	DateTimeTZ_t timestamp;			  // Optional
	CiString255Type_t vendorId;		  // Optional
	CiString50Type_t vendorErrorCode; // Optional
} StatusNotificationReq_t;

// 6.48 StatusNotification.Conf
typedef struct StatusNotificationConf
{
	// NULL
} StatusNotificationConf_t;

// 6.49 StopTransaction.Req
typedef struct StopTransactionReq
{
	IdToken_t idTag;			  // Optional
	int meterStop;				  // Required
	time_t timestamp;		      // Required
	int transactionId;			  // Required
	Reason_t reason;			  // Optional.  7.36. Reason  enum {DeAuthorized,  EmergencyStop,  EVDisconnected,  HardReset,  Local,  Other,  PowerLoss,  Reboot,  Remote,  SoftReset,  UnlockCommand}
	MeterValue_t transactiondata; // Optional
	int transactiondata_used;
} StopTransactionReq_t;

// 6.50 StopTransaction.Conf
typedef struct StopTransactionConf
{
	IdTagInfo_t idTagInfo; // Optional
} StopTransactionConf_t;

// 6.51 TriggerMessage.Req
typedef struct TriggerMessageReq
{
	MessageTrigger_t requestedMessage; // Required.  7.32. MessageTrigger  enum {BootNotification, DiagnosticsStatusNotification, FirmwareStatusNotification, Heartbeat, MeterValues, StatusNotification}
	int connectorId;				   // Optional
} TriggerMessageReq_t;

// 6.52 TriggerMessage.Conf
typedef struct TriggerMessageConf
{
	TriggerMessageStatus_t status; // Required.  7.44. TriggerMessageStatus  enum {Accepted, Rejected, NotImplemented}
} TriggerMessageConf_t;

// 6.53 UnlockConnector.Req
typedef struct UnlockConnectorReq
{
	int connectorId; // Required
} UnlockConnectorReq_t;

// 6.54 UnlockConnector.Conf
typedef struct UnlockConnectorConf
{
	UnlockStatus_t status; // Required.  7.46. UnlockStatus  enum {Unlocked,  UnlockFailed,  NotSupported}
} UnlockConnectorConf_t;

// 6.55 UpdateFirmware.Req
typedef struct UpdateFirmwareReq
{
	CiString255Type_t location; // Required.
	int retries;			   // Optional.
	DateTimeTZ_t retrieveDate; // Required.
	int retryInterval;		   // Optional.
} UpdateFirmwareReq_t;

// 6.56 UpdateFirmware.Conf
typedef struct UpdateFirmwareConf
{
	// NULL
} UpdateFirmwareConf_t;

// ocpp-j-1.6-specification 4.2.3. CallError
typedef enum ErrorCode
{
	ErrorCode_NotImplemented = 100,			// 不识别的方法（action），
	ErrorCode_NotSupported,					// 识别了方法，但不支持这个方法（action）
	ErrorCode_InternalError,				// 识别了方法，但是发生内部错误，没有成功处理
	ErrorCode_ProtocolError,				// 识别了方法，但是协议报文不完整
	ErrorCode_SecurityError,				// 识别了方法，处理过程发生了安全故障
	ErrorCode_FormatViolation,			// 识别了方法，报文格式不正确或者不符合报文要求
	ErrorCode_PropertyConstraintViolation,	// 识别了方法，报文中至少有一个字段包含无效值
	ErrorCode_OccurenceConstraintViolation, // 识别了方法，报文中至少有一个字段违反常数约束
	ErrorCode_TypeConstraintViolation,		// 识别了方法，报文中至少一个字段类型不正确
	ErrorCode_GenericError,					// 其他错误
} ErrorCode_t;

void ocpp16_report_MeterValues(void* ocpp, void* secc);
void ocpp16_report_MeterValues_Interval(void* ocpp, int connectorId);
void ocpp16_report_StatusNotification(void* ocpp, int connectorId, int GUN_Error, int GUN_State);
int ocpp16_request_AuthorizateEMAID(void* ocpp, const char* emaid);
int ocpp16_request_TransactionStart(void* ocpp, int connectorId);
int ocpp16_request_TransactionStop(void* ocpp, int connectorId, int transactionId);

#endif //__OCPP21J_H__
