From a3e0c8ae283ae39b6a58e167312e5434d3bcc329 Mon Sep 17 00:00:00 2001 From: pjv Date: Thu, 21 Sep 2023 18:22:13 +0200 Subject: [PATCH] Ocpp: add transaction id to TxProfile (#9766) --- charger/ocpp.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/charger/ocpp.go b/charger/ocpp.go index 3cf655d17..e8aa04edb 100644 --- a/charger/ocpp.go +++ b/charger/ocpp.go @@ -319,7 +319,7 @@ func (c *OCPP) Enable(enable bool) (err error) { rc <- err }, c.idtag, func(request *core.RemoteStartTransactionRequest) { request.ConnectorId = &c.connector - request.ChargingProfile = getTxChargingProfile(c.current, c.phases) + request.ChargingProfile = getTxChargingProfile(c.current, c.phases, 0) }) } else { // if no transaction is running, the vehicle may have stopped it (which is ok) or an unknown transaction is running @@ -368,9 +368,14 @@ func (c *OCPP) updatePeriod(current float64, phases int) error { return err } + txn, err := c.cp.TransactionID() + if err != nil { + return err + } + current = math.Trunc(10*current) / 10 - err := c.setChargingProfile(c.connector, getTxChargingProfile(current, phases)) + err = c.setChargingProfile(c.connector, getTxChargingProfile(current, phases, txn)) if err != nil { err = fmt.Errorf("set charging profile: %w", err) } @@ -378,7 +383,7 @@ func (c *OCPP) updatePeriod(current float64, phases int) error { return err } -func getTxChargingProfile(current float64, phases int) *types.ChargingProfile { +func getTxChargingProfile(current float64, phases, transactionId int) *types.ChargingProfile { period := types.NewChargingSchedulePeriod(0, current) // TODO add phases support @@ -388,6 +393,7 @@ func getTxChargingProfile(current float64, phases int) *types.ChargingProfile { return &types.ChargingProfile{ ChargingProfileId: 1, + TransactionId: transactionId, StackLevel: 0, ChargingProfilePurpose: types.ChargingProfilePurposeTxProfile, ChargingProfileKind: types.ChargingProfileKindRelative,