Skip to content

Commit

Permalink
Send DFU with exponential backoff
Browse files Browse the repository at this point in the history
  • Loading branch information
krksgbr committed Apr 3, 2024
1 parent 1a2caf1 commit 6442aac
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/dividat-driver/firmware/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"time"

"github.com/cenkalti/backoff"
"github.com/grandcat/zeroconf"
"github.com/pin/tftp"
)
Expand Down Expand Up @@ -81,7 +82,19 @@ func Update(parentCtx context.Context, image io.Reader, deviceSerial *string, co

// 2: Switch the Senso to bootloader mode
if controllerHost != "" {
err := sendDfuCommand(controllerHost, controllerPort, onProgress)

trySendDfu := func() error {
err := sendDfuCommand(controllerHost, controllerPort, onProgress)
return err
}

backoffStrategy := backoff.NewExponentialBackOff()
backoffStrategy.MaxElapsedTime = 30 * time.Second
backoffStrategy.MaxInterval = 10 * time.Second
err := backoff.RetryNotify(trySendDfu, backoffStrategy, func(e error, d time.Duration) {
onProgress(fmt.Sprintf("%v\nRetrying in %v", e, d))
})

if err != nil {
// Log the failure, but continue anyway, as the Senso might have been left in
// bootloader mode when a previous update process failed. Not all versions of
Expand Down

0 comments on commit 6442aac

Please sign in to comment.