From 36ba04dd6b0d04c90b77298ef16ae806373cd31c Mon Sep 17 00:00:00 2001 From: Marc Sanchis Date: Sun, 8 Jun 2025 17:33:29 +0200 Subject: [PATCH] feat: implement BLCU board registration and packet mapping --- backend/cmd/main.go | 42 +++++++++++++++++++--- backend/pkg/broker/topics/blcu/download.go | 2 +- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/backend/cmd/main.go b/backend/cmd/main.go index cc046a872..261f0d843 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -221,13 +221,20 @@ func main() { vehicle.SetTransport(transp) // <--- BLCU Board ---> - // Register BLCU board for handling bootloader operations - if blcuIP, exists := adj.Info.Addresses[BLCU]; exists { + // 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 + } + } blcuBoard := boards.New(blcuIP) vehicle.AddBoard(blcuBoard) trace.Info().Str("ip", blcuIP).Msg("BLCU board registered") - } else { - trace.Warn().Msg("BLCU address not found in ADJ") } // <--- transport ---> @@ -243,6 +250,33 @@ func main() { transp.SetTargetIp(adj.Info.Addresses[board.Name], abstraction.TransportTarget(board.Name)) } + // Set BLCU packet ID mappings if BLCU is configured + if common.Contains(config.Vehicle.Boards, "BLCU") { + // Use configurable packet IDs or defaults + downloadOrderId := config.Blcu.DownloadOrderId + uploadOrderId := config.Blcu.UploadOrderId + if downloadOrderId == 0 { + downloadOrderId = boards.BlcuDownloadOrderId + } + if uploadOrderId == 0 { + uploadOrderId = boards.BlcuUploadOrderId + } + + transp.SetIdTarget(abstraction.PacketId(downloadOrderId), abstraction.TransportTarget("BLCU")) + transp.SetIdTarget(abstraction.PacketId(uploadOrderId), abstraction.TransportTarget("BLCU")) + + // Use BLCU address from config, ADJ, or default + blcuIP := config.Blcu.IP + if blcuIP == "" { + if adjBlcuIP, exists := adj.Info.Addresses[BLCU]; exists { + blcuIP = adjBlcuIP + } else { + blcuIP = "127.0.0.1" + } + } + transp.SetTargetIp(blcuIP, abstraction.TransportTarget("BLCU")) + } + // Start handling TCP client connections i := 0 serverTargets := make(map[string]abstraction.TransportTarget) diff --git a/backend/pkg/broker/topics/blcu/download.go b/backend/pkg/broker/topics/blcu/download.go index 2910831a3..8ee022956 100644 --- a/backend/pkg/broker/topics/blcu/download.go +++ b/backend/pkg/broker/topics/blcu/download.go @@ -87,7 +87,7 @@ func (download *Download) handleDownload(message *websocket.Message) error { return err } - pushErr := download.api.UserPush(downloadRequest) + pushErr := download.api.UserPush(&downloadRequest) return pushErr }