Skip to content

Commit 458aec9

Browse files
fix(backend): on interval break log board
1 parent 4fce47f commit 458aec9

5 files changed

Lines changed: 24 additions & 8 deletions

File tree

backend/cmd/config.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010

1111
# Vehicle Configuration
1212
[vehicle]
13-
boards = ["BCU", "BMSL", "HVSCU", "HVSCU-Cabinet", "LCU", "PCU", "VCU", "BLCU"]
13+
boards = ["TEST"]
1414

1515
# ADJ (Architecture Description JSON) Configuration
1616
[adj]
17-
branch = "main" # Leave blank when using ADJ as a submodule (like this: "")
17+
branch = "mensajes-test" # Leave blank when using ADJ as a submodule (like this: "")
1818
validate = true # Execute ADJ validator before starting backend
1919

2020
# Transport Configuration
2121
[transport]
2222
propagate_fault = true
23-
max_packet_interval_us = 100000 # Max interval (us) between two UDP packets of the same id before propagating a fault (0 disables the check)
23+
max_packet_interval_us = 100000 # Max interval (us) between two UDP packets of the same id before propagating a fault (omitted/0 = default 100ms, negative disables the check)
2424

2525
# TCP Configuration
2626
# These settings control how the backend reconnects to boards when connections are lost

backend/cmd/dev-config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ validate = true # Execute ADJ validator before starting backend
2222
# Transport Configuration
2323
[transport]
2424
propagate_fault = false
25-
max_packet_interval_us = 100 # Max interval (us) between two UDP packets of the same id before propagating a fault (0 disables the check)
25+
max_packet_interval_us = 100000 # Max interval (us) between two UDP packets of the same id before propagating a fault (omitted/0 = default 100ms, negative disables the check)
2626

2727
# TCP Configuration
2828
# These settings control how the backend reconnects to boards when connections are lost

backend/cmd/main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@ func main() {
9898
// <--- transport --->
9999
transp := transport.NewTransport(trace.Logger)
100100
transp.SetpropagateFault(config.Transport.PropagateFault)
101-
transp.SetMaxPacketInterval(time.Duration(config.Transport.MaxPacketIntervalUs) * time.Microsecond)
101+
// Keep the transport default (100ms) when the setting is omitted; a
102+
// negative value disables the check.
103+
if config.Transport.MaxPacketIntervalUs != 0 {
104+
transp.SetMaxPacketInterval(time.Duration(config.Transport.MaxPacketIntervalUs) * time.Microsecond)
105+
}
102106

103107
// <--- vehicle --->
104108
err = configureVehicle(

backend/pkg/transport/constructor.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ import (
1010
"github.com/rs/zerolog"
1111
)
1212

13+
// defaultMaxPacketInterval is the maximum interval allowed between two UDP
14+
// packets of the same id when no value is provided in the configuration.
15+
const defaultMaxPacketInterval = 100 * time.Millisecond
16+
1317
func NewTransport(baseLogger zerolog.Logger) *Transport {
1418
transport := &Transport{
1519
connectionsMx: &sync.RWMutex{},
1620
connections: make(map[abstraction.TransportTarget]net.Conn),
1721
idToTarget: make(map[abstraction.PacketId]abstraction.TransportTarget),
1822
ipToTarget: make(map[string]abstraction.TransportTarget),
1923

20-
lastPacketTime: make(map[abstraction.PacketId]time.Time),
24+
lastPacketTime: make(map[abstraction.PacketId]time.Time),
25+
maxPacketInterval: defaultMaxPacketInterval,
2126

2227
logger: baseLogger,
2328
errChan: make(chan error, 100),

backend/pkg/transport/transport.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,10 +445,17 @@ func (transport *Transport) checkPacketInterval(id abstraction.PacketId, timesta
445445
return
446446
}
447447

448+
board := "unknown"
449+
if target, ok := transport.idToTarget[id]; ok {
450+
board = string(target)
451+
}
452+
448453
transport.logger.Warn().
449454
Uint16("id", uint16(id)).
450-
Dur("interval", interval).
451-
Dur("threshold", transport.maxPacketInterval).
455+
Str("board", board).
456+
Int64("intervalUs", interval.Microseconds()).
457+
Int64("thresholdUs", transport.maxPacketInterval.Microseconds()).
458+
Int64("exceededByUs", (interval - transport.maxPacketInterval).Microseconds()).
452459
Msg("packet interval exceeded, propagating fault")
453460
transport.SendFault()
454461
}

0 commit comments

Comments
 (0)