Documentation
¶
Index ¶
- Constants
- Variables
- func CreateCallErrorMessage(messageId, errorCode, errorDescription string, errorDetails interface{}) ([]byte, error)
- func CreateCallMessage(messageId, action string, payload interface{}) ([]byte, error)
- func CreateCallResultMessage(messageId string, payload interface{}) ([]byte, error)
- func FormatTimestamp(t time.Time) string
- func ParseOCPPMessage(data []byte) (messageType int, messageId string, action string, payload json.RawMessage, ...)
- type AuthorizationData
- type BootNotificationRequest
- type BootNotificationResponse
- type ChangeAvailabilityRequest
- type ChangeAvailabilityResponse
- type ChangeConfigurationRequest
- type ChangeConfigurationResponse
- type ChargingProfile
- type ChargingSchedule
- type ChargingSchedulePeriod
- type ClearCacheRequest
- type ClearCacheResponse
- type ClearChargingProfileRequest
- type ClearChargingProfileResponse
- type ConfigurationKey
- type Connector
- type DataTransferRequest
- type DataTransferResponse
- type GetCompositeScheduleRequest
- type GetCompositeScheduleResponse
- type GetConfigurationRequest
- type GetConfigurationResponse
- type GetLocalListVersionRequest
- type GetLocalListVersionResponse
- type HeartbeatRequest
- type HeartbeatResponse
- type IdTagInfo
- type MeterValue
- type MeterValuesDebug
- type MeterValuesRequest
- type MeterValuesResponse
- type OCPPError
- type RemoteStartTransactionRequest
- type RemoteStartTransactionResponse
- type RemoteStopTransactionRequest
- type RemoteStopTransactionResponse
- type ResetRequest
- type ResetResponse
- type SampledValue
- type SendLocalListRequest
- type SendLocalListResponse
- type Server
- func (s *Server) Address() string
- func (s *Server) ApplyConfiguration(config map[string]string)
- func (s *Server) Category() device.Category
- func (s *Server) GenerateValues(simTime time.Time)
- func (s *Server) GetConnectors() map[int]*Connector
- func (s *Server) GetLogs(limit int) []device.LogEntry
- func (s *Server) GetMeterValuesDebug() MeterValuesDebug
- func (s *Server) GetOCPPURL() string
- func (s *Server) GetState() map[string]interface{}
- func (s *Server) GetTransactions() map[int]*Transaction
- func (s *Server) Protocol() device.Protocol
- func (s *Server) SerialNumber() string
- func (s *Server) SetOCPPURL(url string)
- func (s *Server) SetPort(port int)
- func (s *Server) SetSerialNumber(sn string)
- func (s *Server) SetValue(key string, value interface{}) error
- func (s *Server) SetVendorModel(vendor, model string)
- func (s *Server) Start() error
- func (s *Server) Stop() error
- type SetChargingProfileRequest
- type SetChargingProfileResponse
- type StartTransactionRequest
- type StartTransactionResponse
- type StatusNotificationRequest
- type StatusNotificationResponse
- type StopTransactionRequest
- type StopTransactionResponse
- type Transaction
- type TriggerMessageRequest
- type TriggerMessageResponse
- type UnlockConnectorRequest
- type UnlockConnectorResponse
Constants ¶
const ( MessageTypeCall = 2 MessageTypeCallResult = 3 MessageTypeCallError = 4 )
OCPP 1.6 Message Types
const ( ActionBootNotification = "BootNotification" ActionHeartbeat = "Heartbeat" ActionStatusNotification = "StatusNotification" ActionStartTransaction = "StartTransaction" ActionStopTransaction = "StopTransaction" ActionMeterValues = "MeterValues" ActionRemoteStartTransaction = "RemoteStartTransaction" ActionRemoteStopTransaction = "RemoteStopTransaction" ActionChangeConfiguration = "ChangeConfiguration" ActionGetConfiguration = "GetConfiguration" ActionReset = "Reset" ActionSetChargingProfile = "SetChargingProfile" ActionClearChargingProfile = "ClearChargingProfile" ActionGetLocalListVersion = "GetLocalListVersion" ActionSendLocalList = "SendLocalList" ActionTriggerMessage = "TriggerMessage" ActionUnlockConnector = "UnlockConnector" ActionDataTransfer = "DataTransfer" ActionChangeAvailability = "ChangeAvailability" ActionClearCache = "ClearCache" ActionGetCompositeSchedule = "GetCompositeSchedule" )
OCPP 1.6 Actions
const ( StatusAvailable = "Available" // No vehicle plugged in, ready for new vehicle StatusPreparing = "Preparing" // Vehicle plugged in, waiting for auth/communication StatusCharging = "Charging" // Actively charging StatusSuspendedEVSE = "SuspendedEVSE" // Vehicle plugged in, charger not delivering power (charger-side reason) StatusSuspendedEV = "SuspendedEV" // Vehicle plugged in, vehicle not accepting power (vehicle-side reason) StatusFinishing = "Finishing" // Charging ended, vehicle still plugged in StatusReserved = "Reserved" // Reserved for specific user/vehicle StatusFaulted = "Faulted" // Experiencing fault or issue )
Connector Status values (OCPP 1.6)
Variables ¶
var (
ErrInvalidMessage = &OCPPError{Code: "FormationViolation", Description: "Invalid message format"}
)
Error types
Functions ¶
func CreateCallErrorMessage ¶
func CreateCallErrorMessage(messageId, errorCode, errorDescription string, errorDetails interface{}) ([]byte, error)
CreateCallErrorMessage creates an OCPP CallError message
func CreateCallMessage ¶
CreateCallMessage creates an OCPP Call message
func CreateCallResultMessage ¶
CreateCallResultMessage creates an OCPP CallResult message
func FormatTimestamp ¶
FormatTimestamp formats a time as OCPP timestamp
func ParseOCPPMessage ¶
func ParseOCPPMessage(data []byte) (messageType int, messageId string, action string, payload json.RawMessage, err error)
ParseOCPPMessage parses an OCPP WebSocket message
Types ¶
type AuthorizationData ¶
type AuthorizationData struct {
IdTag string `json:"idTag"`
IdTagInfo IdTagInfo `json:"idTagInfo,omitempty"`
}
AuthorizationData represents an authorization entry in the local list
type BootNotificationRequest ¶
type BootNotificationRequest struct {
ChargePointVendor string `json:"chargePointVendor"`
ChargePointModel string `json:"chargePointModel"`
ChargePointSerialNumber string `json:"chargePointSerialNumber,omitempty"`
ChargeBoxSerialNumber string `json:"chargeBoxSerialNumber,omitempty"`
FirmwareVersion string `json:"firmwareVersion,omitempty"`
Iccid string `json:"iccid,omitempty"`
Imsi string `json:"imsi,omitempty"`
MeterType string `json:"meterType,omitempty"`
MeterSerialNumber string `json:"meterSerialNumber,omitempty"`
}
BootNotificationRequest represents a BootNotification.req
type BootNotificationResponse ¶
type BootNotificationResponse struct {
Status string `json:"status"`
CurrentTime string `json:"currentTime"`
Interval int `json:"interval"`
}
BootNotificationResponse represents a BootNotification.conf
type ChangeAvailabilityRequest ¶
type ChangeAvailabilityRequest struct {
ConnectorId int `json:"connectorId"`
Type string `json:"type"` // Operative or Inoperative
}
ChangeAvailabilityRequest represents a ChangeAvailability.req from central system
type ChangeAvailabilityResponse ¶
type ChangeAvailabilityResponse struct {
Status string `json:"status"` // Accepted, Rejected, Scheduled
}
ChangeAvailabilityResponse represents a ChangeAvailability.conf
type ChangeConfigurationRequest ¶
ChangeConfigurationRequest represents a ChangeConfiguration.req from central system
type ChangeConfigurationResponse ¶
type ChangeConfigurationResponse struct {
Status string `json:"status"` // Accepted, Rejected, RebootRequired, NotSupported
}
ChangeConfigurationResponse represents a ChangeConfiguration.conf
type ChargingProfile ¶
type ChargingProfile struct {
ChargingProfileId int64 `json:"chargingProfileId"`
TransactionId *int64 `json:"transactionId,omitempty"`
StackLevel int `json:"stackLevel"`
ChargingProfilePurpose string `json:"chargingProfilePurpose"`
ChargingProfileKind string `json:"chargingProfileKind"`
RecurrencyKind string `json:"recurrencyKind,omitempty"`
ValidFrom string `json:"validFrom,omitempty"`
ValidTo string `json:"validTo,omitempty"`
ChargingSchedule ChargingSchedule `json:"chargingSchedule"`
}
ChargingProfile represents a ChargingProfile object (OCPP 1.6) Note: Date fields are kept as strings to avoid parsing at the emulator layer.
type ChargingSchedule ¶
type ChargingSchedule struct {
Duration *int64 `json:"duration,omitempty"`
StartSchedule string `json:"startSchedule,omitempty"`
ChargingRateUnit string `json:"chargingRateUnit"`
ChargingSchedulePeriod []ChargingSchedulePeriod `json:"chargingSchedulePeriod"`
MinChargingRate *float64 `json:"minChargingRate,omitempty"`
}
ChargingSchedule represents a ChargingSchedule object (OCPP 1.6)
type ChargingSchedulePeriod ¶
type ChargingSchedulePeriod struct {
StartPeriod int64 `json:"startPeriod"`
Limit float64 `json:"limit"`
NumberPhases *int `json:"numberPhases,omitempty"`
}
ChargingSchedulePeriod represents a ChargingSchedulePeriod object (OCPP 1.6)
type ClearCacheRequest ¶
type ClearCacheRequest struct{}
ClearCacheRequest represents a ClearCache.req from central system
type ClearCacheResponse ¶
type ClearCacheResponse struct {
Status string `json:"status"` // Accepted, Rejected
}
ClearCacheResponse represents a ClearCache.conf
type ClearChargingProfileRequest ¶
type ClearChargingProfileRequest struct {
Id *int64 `json:"id,omitempty"`
ConnectorId *int `json:"connectorId,omitempty"`
ChargingProfilePurpose string `json:"chargingProfilePurpose,omitempty"`
StackLevel *int `json:"stackLevel,omitempty"`
}
ClearChargingProfileRequest represents a ClearChargingProfile.req
type ClearChargingProfileResponse ¶
type ClearChargingProfileResponse struct {
Status string `json:"status"`
}
ClearChargingProfileResponse represents a ClearChargingProfile.conf
type ConfigurationKey ¶
type ConfigurationKey struct {
Key string `json:"key"`
Readonly bool `json:"readonly"`
Value string `json:"value,omitempty"`
}
ConfigurationKey represents a single configuration key-value pair
type Connector ¶
type Connector struct {
ID int `json:"id"`
Status string `json:"status"`
ErrorCode string `json:"errorCode"`
CurrentPower float64 `json:"currentPower"`
EnergyWh float64 `json:"energyWh"`
}
Connector represents a charging connector
type DataTransferRequest ¶
type DataTransferRequest struct {
VendorId string `json:"vendorId"`
MessageId string `json:"messageId,omitempty"`
Data string `json:"data,omitempty"`
}
DataTransferRequest represents a DataTransfer.req from central system
type DataTransferResponse ¶
type DataTransferResponse struct {
Status string `json:"status"`
Data string `json:"data,omitempty"`
}
DataTransferResponse represents a DataTransfer.conf
type GetCompositeScheduleRequest ¶
type GetCompositeScheduleRequest struct {
ConnectorId int `json:"connectorId"`
Duration int `json:"duration"`
ChargingRateUnit string `json:"chargingRateUnit,omitempty"` // W or A
}
GetCompositeScheduleRequest represents a GetCompositeSchedule.req from central system
type GetCompositeScheduleResponse ¶
type GetCompositeScheduleResponse struct {
Status string `json:"status"` // Accepted, Rejected
ConnectorId *int `json:"connectorId,omitempty"`
ScheduleStart string `json:"scheduleStart,omitempty"`
ChargingSchedule *ChargingSchedule `json:"chargingSchedule,omitempty"`
}
GetCompositeScheduleResponse represents a GetCompositeSchedule.conf
type GetConfigurationRequest ¶
type GetConfigurationRequest struct {
Key []string `json:"key,omitempty"`
}
GetConfigurationRequest represents a GetConfiguration.req from central system
type GetConfigurationResponse ¶
type GetConfigurationResponse struct {
ConfigurationKey []ConfigurationKey `json:"configurationKey,omitempty"`
UnknownKey []string `json:"unknownKey,omitempty"`
}
GetConfigurationResponse represents a GetConfiguration.conf
type GetLocalListVersionRequest ¶
type GetLocalListVersionRequest struct{}
GetLocalListVersionRequest represents a GetLocalListVersion.req from central system
type GetLocalListVersionResponse ¶
type GetLocalListVersionResponse struct {
ListVersion int `json:"listVersion"`
}
GetLocalListVersionResponse represents a GetLocalListVersion.conf
type HeartbeatResponse ¶
type HeartbeatResponse struct {
CurrentTime string `json:"currentTime"`
}
HeartbeatResponse represents a Heartbeat.conf
type IdTagInfo ¶
type IdTagInfo struct {
ExpiryDate string `json:"expiryDate,omitempty"`
ParentIdTag string `json:"parentIdTag,omitempty"`
Status string `json:"status"`
}
IdTagInfo represents authorization info
type MeterValue ¶
type MeterValue struct {
Timestamp string `json:"timestamp"`
SampledValue []SampledValue `json:"sampledValue"`
}
MeterValue represents a meter value sample
type MeterValuesDebug ¶
type MeterValuesDebug struct {
VoltageL1 float64 `json:"voltage_L1"`
VoltageL2 float64 `json:"voltage_L2"`
VoltageL3 float64 `json:"voltage_L3"`
CurrentL1 float64 `json:"current_L1"`
CurrentL2 float64 `json:"current_L2"`
CurrentL3 float64 `json:"current_L3"`
PowerW float64 `json:"power_W"`
EnergyWh float64 `json:"energy_Wh"`
SampleJSON string `json:"sample_meter_values_json"`
ExpectedCSMS map[string]interface{} `json:"expected_csms_output"`
}
MeterValuesDebug contains debug information about current meter values
type MeterValuesRequest ¶
type MeterValuesRequest struct {
ConnectorId int `json:"connectorId"`
TransactionId int `json:"transactionId,omitempty"`
MeterValue []MeterValue `json:"meterValue"`
}
MeterValuesRequest represents a MeterValues.req
type MeterValuesResponse ¶
type MeterValuesResponse struct{}
MeterValuesResponse represents a MeterValues.conf
type RemoteStartTransactionRequest ¶
type RemoteStartTransactionRequest struct {
ConnectorId int `json:"connectorId,omitempty"`
IdTag string `json:"idTag"`
ChargingProfile *ChargingProfile `json:"chargingProfile,omitempty"`
}
RemoteStartTransactionRequest represents a RemoteStartTransaction.req from central system
type RemoteStartTransactionResponse ¶
type RemoteStartTransactionResponse struct {
Status string `json:"status"`
}
RemoteStartTransactionResponse represents a RemoteStartTransaction.conf
type RemoteStopTransactionRequest ¶
type RemoteStopTransactionRequest struct {
TransactionId int `json:"transactionId"`
}
RemoteStopTransactionRequest represents a RemoteStopTransaction.req from central system
type RemoteStopTransactionResponse ¶
type RemoteStopTransactionResponse struct {
Status string `json:"status"`
}
RemoteStopTransactionResponse represents a RemoteStopTransaction.conf
type ResetRequest ¶
type ResetRequest struct {
Type string `json:"type"` // Hard or Soft
}
ResetRequest represents a Reset.req from central system
type ResetResponse ¶
type ResetResponse struct {
Status string `json:"status"` // Accepted, Rejected
}
ResetResponse represents a Reset.conf
type SampledValue ¶
type SampledValue struct {
Value string `json:"value"`
Context string `json:"context,omitempty"`
Format string `json:"format,omitempty"`
Measurand string `json:"measurand,omitempty"`
Phase string `json:"phase,omitempty"`
Location string `json:"location,omitempty"`
Unit string `json:"unit,omitempty"`
}
SampledValue represents a single sampled value
type SendLocalListRequest ¶
type SendLocalListRequest struct {
ListVersion int `json:"listVersion"`
LocalAuthorizationList []AuthorizationData `json:"localAuthorizationList,omitempty"`
UpdateType string `json:"updateType"`
}
SendLocalListRequest represents a SendLocalList.req from central system
type SendLocalListResponse ¶
type SendLocalListResponse struct {
Status string `json:"status"`
}
SendLocalListResponse represents a SendLocalList.conf
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server represents an OCPP charge point simulator
func NewServer ¶
func NewServer(id int, port int, vendor, model string, numConnectors int, maxPowerKW float64) *Server
NewServer creates a new OCPP charge point simulator
func (*Server) ApplyConfiguration ¶
ApplyConfiguration merges configuration values into the OCPP configuration map
func (*Server) GenerateValues ¶
GenerateValues generates simulated values based on time
func (*Server) GetConnectors ¶
GetConnectors returns all connectors
func (*Server) GetMeterValuesDebug ¶
func (s *Server) GetMeterValuesDebug() MeterValuesDebug
GetMeterValuesDebug returns debug information about current meter values
func (*Server) GetOCPPURL ¶
GetOCPPURL returns the configured Central System URL
func (*Server) GetTransactions ¶
func (s *Server) GetTransactions() map[int]*Transaction
GetTransactions returns all active transactions
func (*Server) SerialNumber ¶
SerialNumber returns the serial number
func (*Server) SetOCPPURL ¶
SetOCPPURL sets the Central System URL to connect to (enables client mode)
func (*Server) SetSerialNumber ¶
SetSerialNumber sets the serial number
func (*Server) SetVendorModel ¶
SetVendorModel updates the vendor and model
type SetChargingProfileRequest ¶
type SetChargingProfileRequest struct {
ConnectorId int `json:"connectorId"`
CsChargingProfiles ChargingProfile `json:"csChargingProfiles"`
}
SetChargingProfileRequest represents a SetChargingProfile.req
type SetChargingProfileResponse ¶
type SetChargingProfileResponse struct {
Status string `json:"status"`
}
SetChargingProfileResponse represents a SetChargingProfile.conf
type StartTransactionRequest ¶
type StartTransactionRequest struct {
ConnectorId int `json:"connectorId"`
IdTag string `json:"idTag"`
MeterStart int `json:"meterStart"`
Timestamp string `json:"timestamp"`
ReservationId int `json:"reservationId,omitempty"`
}
StartTransactionRequest represents a StartTransaction.req
type StartTransactionResponse ¶
type StartTransactionResponse struct {
IdTagInfo IdTagInfo `json:"idTagInfo"`
TransactionId int `json:"transactionId"`
}
StartTransactionResponse represents a StartTransaction.conf
type StatusNotificationRequest ¶
type StatusNotificationRequest struct {
ConnectorId int `json:"connectorId"`
ErrorCode string `json:"errorCode"`
Status string `json:"status"`
Timestamp string `json:"timestamp,omitempty"`
Info string `json:"info,omitempty"`
VendorId string `json:"vendorId,omitempty"`
VendorErrorCode string `json:"vendorErrorCode,omitempty"`
}
StatusNotificationRequest represents a StatusNotification.req
type StatusNotificationResponse ¶
type StatusNotificationResponse struct{}
StatusNotificationResponse represents a StatusNotification.conf
type StopTransactionRequest ¶
type StopTransactionRequest struct {
IdTag string `json:"idTag,omitempty"`
MeterStop int `json:"meterStop"`
Timestamp string `json:"timestamp"`
TransactionId int `json:"transactionId"`
Reason string `json:"reason,omitempty"`
TransactionData []MeterValue `json:"transactionData,omitempty"`
}
StopTransactionRequest represents a StopTransaction.req
type StopTransactionResponse ¶
type StopTransactionResponse struct {
IdTagInfo *IdTagInfo `json:"idTagInfo,omitempty"`
}
StopTransactionResponse represents a StopTransaction.conf
type Transaction ¶
type Transaction struct {
ID int `json:"id"`
ConnectorID int `json:"connectorId"`
IdTag string `json:"idTag"`
StartTime time.Time `json:"startTime"`
MeterStart int `json:"meterStart"`
MeterNow int `json:"meterNow"`
}
Transaction represents an active charging transaction
type TriggerMessageRequest ¶
type TriggerMessageRequest struct {
RequestedMessage string `json:"requestedMessage"`
ConnectorId *int `json:"connectorId,omitempty"`
}
TriggerMessageRequest represents a TriggerMessage.req from central system
type TriggerMessageResponse ¶
type TriggerMessageResponse struct {
Status string `json:"status"`
}
TriggerMessageResponse represents a TriggerMessage.conf
type UnlockConnectorRequest ¶
type UnlockConnectorRequest struct {
ConnectorId int `json:"connectorId"`
}
UnlockConnectorRequest represents an UnlockConnector.req from central system
type UnlockConnectorResponse ¶
type UnlockConnectorResponse struct {
Status string `json:"status"`
}
UnlockConnectorResponse represents an UnlockConnector.conf