Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions backend/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,18 @@ type Transport struct {
PropagateFault bool
}

type TFTP struct {
BlockSize int `toml:"block_size"`
Retries int `toml:"retries"`
TimeoutMs int `toml:"timeout_ms"`
BackoffFactor int `toml:"backoff_factor"`
EnableProgress bool `toml:"enable_progress"`

type Blcu struct {
IP string
DownloadOrderId uint16
UploadOrderId uint16

}

type Config struct {
Expand All @@ -30,5 +38,6 @@ type Config struct {
Adj Adj
Network Network
Transport Transport
TFTP TFTP
Blcu Blcu
}
9 changes: 8 additions & 1 deletion backend/cmd/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ manual = true # Manual network device selection

# Transport Configuration
[transport]
propagate_fault = true # Propagate fault messages like VCU
propagate_fault = true

[tftp]
block_size = 131072 # TFTP block size in bytes (128kB)
retries = 3 # Maximum number of retries before aborting transfer
timeout_ms = 5000 # Timeout between retries in milliseconds
backoff_factor = 2 # Backoff multiplier for retry delays
enable_progress = true # Enable progress callbacks during transfers
20 changes: 9 additions & 11 deletions backend/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,18 +221,16 @@ func main() {
vehicle.SetTransport(transp)

// <--- BLCU Board --->
// Register BLCU board for handling bootloader operations if configured
if common.Contains(config.Vehicle.Boards, "BLCU") {
// Use BLCU address from config, ADJ, or default localhost
blcuIP := config.Blcu.IP
if blcuIP == "" {
if adjBlcuIP, exists := adj.Info.Addresses[BLCU]; exists {
blcuIP = adjBlcuIP
} else {
blcuIP = "127.0.0.1" // Default TFTP server address
}
// Register BLCU board for handling bootloader operations
if blcuIP, exists := adj.Info.Addresses[BLCU]; exists {
tftpConfig := boards.TFTPConfig{
BlockSize: config.TFTP.BlockSize,
Retries: config.TFTP.Retries,
TimeoutMs: config.TFTP.TimeoutMs,
BackoffFactor: config.TFTP.BackoffFactor,
EnableProgress: config.TFTP.EnableProgress,
}
blcuBoard := boards.New(blcuIP)
blcuBoard := boards.NewWithTFTPConfig(blcuIP, tftpConfig)
vehicle.AddBoard(blcuBoard)
trace.Info().Str("ip", blcuIP).Msg("BLCU board registered")
}
Expand Down
42 changes: 35 additions & 7 deletions backend/pkg/boards/blcu.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,36 @@ const (
BlcuUploadOrderId = 2
)

type TFTPConfig struct {
BlockSize int
Retries int
TimeoutMs int
BackoffFactor int
EnableProgress bool
}

type BLCU struct {
api abstraction.BoardAPI
ackChan chan struct{}
ip string
api abstraction.BoardAPI
ackChan chan struct{}
ip string
tftpConfig TFTPConfig
}

func New(ip string) *BLCU {
return NewWithTFTPConfig(ip, TFTPConfig{
BlockSize: 131072, // 128kB
Retries: 3,
TimeoutMs: 5000,
BackoffFactor: 2,
EnableProgress: true,
})
}

func NewWithTFTPConfig(ip string, tftpConfig TFTPConfig) *BLCU {
return &BLCU{
ackChan: make(chan struct{}),
ip: ip,
ackChan: make(chan struct{}),
ip: ip,
tftpConfig: tftpConfig,
}
}
func (boards *BLCU) Id() abstraction.BoardId {
Expand Down Expand Up @@ -96,7 +116,11 @@ func (boards *BLCU) download(notification DownloadEvent) error {

// TODO! Notify on progress

client, err := tftp.NewClient(boards.ip)
client, err := tftp.NewClient(boards.ip,
tftp.WithBlockSize(boards.tftpConfig.BlockSize),
tftp.WithRetries(boards.tftpConfig.Retries),
tftp.WithTimeout(time.Duration(boards.tftpConfig.TimeoutMs) * time.Millisecond),
)
if err != nil {
return ErrNewClientFailed{
Addr: boards.ip,
Expand Down Expand Up @@ -164,7 +188,11 @@ func (boards *BLCU) upload(notification UploadEvent) error {

// TODO! Notify on progress

client, err := tftp.NewClient(boards.ip)
client, err := tftp.NewClient(boards.ip,
tftp.WithBlockSize(boards.tftpConfig.BlockSize),
tftp.WithRetries(boards.tftpConfig.Retries),
tftp.WithTimeout(time.Duration(boards.tftpConfig.TimeoutMs) * time.Millisecond),
)
if err != nil {
return ErrNewClientFailed{
Addr: boards.ip,
Expand Down
Loading