Ocpp: generate globally unique transaction ids (#15951)
This commit is contained in:
parent
3b3ac4df59
commit
cbafc3e0c3
4 changed files with 16 additions and 29 deletions
|
|
@ -29,9 +29,8 @@ type Connector struct {
|
|||
meterUpdated time.Time
|
||||
measurements map[types.Measurand]types.SampledValue
|
||||
|
||||
txnCount int // change initial value to the last known global transaction. Needs persistence
|
||||
txnId int
|
||||
idTag string
|
||||
txnId int
|
||||
idTag string
|
||||
|
||||
remoteIdTag string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func (conn *Connector) MeterValues(request *core.MeterValuesRequest) (*core.Mete
|
|||
(conn.status.Status == core.ChargePointStatusCharging ||
|
||||
conn.status.Status == core.ChargePointStatusSuspendedEV ||
|
||||
conn.status.Status == core.ChargePointStatusSuspendedEVSE) {
|
||||
conn.log.DEBUG.Printf("hijacking transaction: %d", *request.TransactionId)
|
||||
conn.log.DEBUG.Printf("recovered transaction: %d", *request.TransactionId)
|
||||
conn.txnId = *request.TransactionId
|
||||
}
|
||||
|
||||
|
|
@ -91,19 +91,7 @@ func (conn *Connector) StartTransaction(request *core.StartTransactionRequest) (
|
|||
conn.mu.Lock()
|
||||
defer conn.mu.Unlock()
|
||||
|
||||
// expired request
|
||||
if request.Timestamp != nil && conn.clock.Since(request.Timestamp.Time) > Timeout {
|
||||
res := &core.StartTransactionConfirmation{
|
||||
IdTagInfo: &types.IdTagInfo{
|
||||
Status: types.AuthorizationStatusExpired, // reject
|
||||
},
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
conn.txnCount++
|
||||
conn.txnId = conn.txnCount
|
||||
conn.txnId = instance.NewTransactionID()
|
||||
conn.idTag = request.IdTag
|
||||
|
||||
res := &core.StartTransactionConfirmation{
|
||||
|
|
@ -140,17 +128,6 @@ func (conn *Connector) StopTransaction(request *core.StopTransactionRequest) (*c
|
|||
conn.mu.Lock()
|
||||
defer conn.mu.Unlock()
|
||||
|
||||
// expired request
|
||||
if request.Timestamp != nil && conn.clock.Since(request.Timestamp.Time) > Timeout {
|
||||
res := &core.StopTransactionConfirmation{
|
||||
IdTagInfo: &types.IdTagInfo{
|
||||
Status: types.AuthorizationStatusExpired, // reject
|
||||
},
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
conn.txnId = 0
|
||||
conn.idTag = ""
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ type CS struct {
|
|||
mu sync.Mutex
|
||||
log *util.Logger
|
||||
ocpp16.CentralSystem
|
||||
cps map[string]*CP
|
||||
cps map[string]*CP
|
||||
txnId int
|
||||
}
|
||||
|
||||
// Register registers a charge point with the central system.
|
||||
|
|
@ -106,3 +107,12 @@ func (cs *CS) ChargePointDisconnected(chargePoint ocpp16.ChargePointConnection)
|
|||
cp.connect(false)
|
||||
}
|
||||
}
|
||||
|
||||
// NewTransactionID returns a CS-wide unique transactionId
|
||||
func (cs *CS) NewTransactionID() int {
|
||||
cs.mu.Lock()
|
||||
defer cs.mu.Unlock()
|
||||
|
||||
cs.txnId++
|
||||
return cs.txnId
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ func Instance() *CS {
|
|||
log: log,
|
||||
cps: make(map[string]*CP),
|
||||
CentralSystem: cs,
|
||||
txnId: int(time.Now().UTC().Unix()),
|
||||
}
|
||||
|
||||
ocppj.SetLogger(instance)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue