@@ -67,7 +67,7 @@ import (
6767
6868const (
6969 BACKEND = "backend"
70- BLCU = "blcu "
70+ BLCU = "BLCU "
7171 TcpClient = "TCP_CLIENT"
7272 TcpServer = "TCP_SERVER"
7373 UDP = "UDP"
@@ -88,7 +88,7 @@ var currentVersion string
8888
8989func main () {
9090 // update() // FIXME: Updater disabled due to cross-platform and reliability issues
91-
91+
9292 traceFile := initTrace (* traceLevel , * traceFile )
9393 defer traceFile .Close ()
9494
@@ -223,16 +223,34 @@ func main() {
223223 // <--- BLCU Board --->
224224 // Register BLCU board for handling bootloader operations
225225 if blcuIP , exists := adj .Info .Addresses [BLCU ]; exists {
226- tftpConfig := boards.TFTPConfig {
227- BlockSize : config .TFTP .BlockSize ,
228- Retries : config .TFTP .Retries ,
229- TimeoutMs : config .TFTP .TimeoutMs ,
230- BackoffFactor : config .TFTP .BackoffFactor ,
231- EnableProgress : config .TFTP .EnableProgress ,
226+ blcuId , idExists := adj .Info .BoardIds ["BLCU" ]
227+ if ! idExists {
228+ trace .Error ().Msg ("BLCU IP found in ADJ but board ID missing" )
229+ } else {
230+ // Get configurable order IDs or use defaults
231+ downloadOrderId := config .Blcu .DownloadOrderId
232+ uploadOrderId := config .Blcu .UploadOrderId
233+ if downloadOrderId == 0 {
234+ downloadOrderId = boards .DefaultBlcuDownloadOrderId
235+ }
236+ if uploadOrderId == 0 {
237+ uploadOrderId = boards .DefaultBlcuUploadOrderId
238+ }
239+
240+ tftpConfig := boards.TFTPConfig {
241+ BlockSize : config .TFTP .BlockSize ,
242+ Retries : config .TFTP .Retries ,
243+ TimeoutMs : config .TFTP .TimeoutMs ,
244+ BackoffFactor : config .TFTP .BackoffFactor ,
245+ EnableProgress : config .TFTP .EnableProgress ,
246+ }
247+ blcuBoard := boards .NewWithConfig (blcuIP , tftpConfig , abstraction .BoardId (blcuId ), downloadOrderId , uploadOrderId )
248+ vehicle .AddBoard (blcuBoard )
249+ vehicle .SetBlcuId (abstraction .BoardId (blcuId ))
250+ trace .Info ().Str ("ip" , blcuIP ).Int ("id" , int (blcuId )).Uint16 ("download_order_id" , downloadOrderId ).Uint16 ("upload_order_id" , uploadOrderId ).Msg ("BLCU board registered" )
232251 }
233- blcuBoard := boards .NewWithTFTPConfig (blcuIP , tftpConfig )
234- vehicle .AddBoard (blcuBoard )
235- trace .Info ().Str ("ip" , blcuIP ).Msg ("BLCU board registered" )
252+ } else {
253+ trace .Warn ().Msg ("BLCU not found in ADJ configuration - bootloader operations unavailable" )
236254 }
237255
238256 // <--- transport --->
@@ -254,15 +272,15 @@ func main() {
254272 downloadOrderId := config .Blcu .DownloadOrderId
255273 uploadOrderId := config .Blcu .UploadOrderId
256274 if downloadOrderId == 0 {
257- downloadOrderId = boards .BlcuDownloadOrderId
275+ downloadOrderId = boards .DefaultBlcuDownloadOrderId
258276 }
259277 if uploadOrderId == 0 {
260- uploadOrderId = boards .BlcuUploadOrderId
278+ uploadOrderId = boards .DefaultBlcuUploadOrderId
261279 }
262-
280+
263281 transp .SetIdTarget (abstraction .PacketId (downloadOrderId ), abstraction .TransportTarget ("BLCU" ))
264282 transp .SetIdTarget (abstraction .PacketId (uploadOrderId ), abstraction .TransportTarget ("BLCU" ))
265-
283+
266284 // Use BLCU address from config, ADJ, or default
267285 blcuIP := config .Blcu .IP
268286 if blcuIP == "" {
@@ -289,23 +307,23 @@ func main() {
289307 }
290308 // Create TCP client config with custom parameters from config
291309 clientConfig := tcp .NewClientConfig (backendTcpClientAddr )
292-
310+
293311 // Apply custom timeout if specified
294312 if config .TCP .ConnectionTimeout > 0 {
295313 clientConfig .Timeout = time .Duration (config .TCP .ConnectionTimeout ) * time .Millisecond
296314 }
297-
315+
298316 // Apply custom keep-alive if specified
299317 if config .TCP .KeepAlive > 0 {
300318 clientConfig .KeepAlive = time .Duration (config .TCP .KeepAlive ) * time .Millisecond
301319 }
302-
320+
303321 // Apply custom backoff parameters
304322 if config .TCP .BackoffMinMs > 0 || config .TCP .BackoffMaxMs > 0 || config .TCP .BackoffMultiplier > 0 {
305323 minBackoff := 100 * time .Millisecond // default
306- maxBackoff := 5 * time .Second // default
307- multiplier := 1.5 // default
308-
324+ maxBackoff := 5 * time .Second // default
325+ multiplier := 1.5 // default
326+
309327 if config .TCP .BackoffMinMs > 0 {
310328 minBackoff = time .Duration (config .TCP .BackoffMinMs ) * time .Millisecond
311329 }
@@ -315,13 +333,13 @@ func main() {
315333 if config .TCP .BackoffMultiplier > 0 {
316334 multiplier = config .TCP .BackoffMultiplier
317335 }
318-
336+
319337 clientConfig .ConnectionBackoffFunction = tcp .NewExponentialBackoff (minBackoff , multiplier , maxBackoff )
320338 }
321-
339+
322340 // Apply max retries (0 or negative means infinite)
323341 clientConfig .MaxConnectionRetries = config .TCP .MaxRetries
324-
342+
325343 go transp .HandleClient (clientConfig , fmt .Sprintf ("%s:%d" , adj .Info .Addresses [board .Name ], adj .Info .Ports [TcpServer ]))
326344 i ++
327345 }
0 commit comments