-
Notifications
You must be signed in to change notification settings - Fork 5
DIV-33 Update firmware via websocket command #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
aabb427
Introduce callback for firmware update messages
krksgbr 333ac8d
Receive firmware update command and send progress messages
krksgbr c3e331d
Ignore commands while firmware update is in progress
krksgbr ccd94c9
Add some more firmware update progress messages
krksgbr 71b4137
Use libp2p/zeroconf
krksgbr c3f027f
Report firmware update errors on the command line
krksgbr fb1a472
Configure exponential backoff on TFTP client
krksgbr 262aadd
Add more messages
krksgbr 94b819a
Wait 10 seconds for tcp connection teardown
krksgbr 0e9025a
Make firmware update commands specify serial instead of address
krksgbr 85bc280
Check for null when dereferencing address
krksgbr a23e6c3
Allow Discovery and GetStatus commands while updating firmware
krksgbr 4201904
Wait 15 seconds for tftp startup
krksgbr 03b962d
Send DFU with exponential backoff
krksgbr bd1fa13
Do not abort discovery when device serials don't match
krksgbr c7608d7
Refactor discovery code
krksgbr 8e57f6b
Separate updating by different inputs
krksgbr 38c2516
Move cli-specific code to another file
krksgbr 340ba57
Simplify code
krksgbr 66d2bb8
Add some helpers for constructing firmware update messages
krksgbr b7338d8
Reduce timeouts
krksgbr 6da5b8b
Fix build
krksgbr 0aac1a1
Merge branch 'main' into remote-firmware-update
krksgbr 7252777
Document and re-organize service module
krksgbr c66c09c
Add some docs to the firmware modules
krksgbr 22f6e33
Encapsulate state management in firmware module
krksgbr 28fe54e
Update changelog
krksgbr ccb18c5
Improve clarity of firmware update message
krksgbr b806116
Merge branch 'main' into remote-firmware-update
krksgbr 8097df3
Allow 60 seconds for mDNS discovery
krksgbr a59e24e
Prevent unnecessary TFTP send failure messages
krksgbr 5bb2e6d
Fix TFTP send fail message
krksgbr 7349c61
Capitalize "Senso" where appropriate
krksgbr 5f03ddf
Remove unused nix files
krksgbr b335212
Format file
krksgbr ffa7b58
Increase wait time before attempting TFTP transfer
krksgbr 1233e05
Do not proceed with firmware update if image could not be decoded
krksgbr 8743fda
Remove firmware update by fixed address
krksgbr cb649fc
Communicate power cycling suggestion only when updating via CLI
krksgbr 0121d02
Improve log messages about ignored commands during firmware update
krksgbr 80dfde6
Implement pretty-printing for UpdateFirmware command
krksgbr 81d9acd
Log messages about ignored commands at debug level
krksgbr ad56fd2
Add notes about libp2p/zeroconf dependency choice
krksgbr 8e0e4a7
Deduplicate firmware update success messages sent via websockets
krksgbr 57b821c
Refine vocabulary and punctuation of firmware update messages
krksgbr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package firmware | ||
|
|
||
| import ( | ||
| "context" | ||
| "flag" | ||
| "fmt" | ||
| "io" | ||
| "os" | ||
|
|
||
| "github.com/dividat/driver/src/dividat-driver/service" | ||
| ) | ||
|
|
||
| // Command-line interface to running a firmware update | ||
| func Command(flags []string) { | ||
| updateFlags := flag.NewFlagSet("update", flag.ExitOnError) | ||
| imagePath := updateFlags.String("i", "", "Firmware image path") | ||
| sensoSerial := updateFlags.String("s", "", "Senso serial (optional)") | ||
| updateFlags.Parse(flags) | ||
|
|
||
| if *imagePath == "" { | ||
| flag.PrintDefaults() | ||
| return | ||
| } | ||
| file, err := os.Open(*imagePath) | ||
| if err != nil { | ||
| fmt.Printf("Could not open image file: %v\n", err) | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| onProgress := func(progressMsg string) { | ||
| fmt.Println(progressMsg) | ||
| } | ||
|
|
||
| tryPowerCycling := "Try turning the Senso off and on, waiting for 30 seconds and then running this update tool again." | ||
| suggestPowerCycling := false | ||
|
|
||
| if *sensoSerial != "" { | ||
| err = UpdateBySerial(context.Background(), *sensoSerial, file, onProgress) | ||
| if err != nil { | ||
| suggestPowerCycling = true | ||
| } | ||
| } else { | ||
| err, suggestPowerCycling = updateByDiscovery(context.Background(), file, onProgress) | ||
| } | ||
|
|
||
| if err != nil { | ||
| fmt.Println() | ||
| fmt.Printf("Update failed: %v \n", err) | ||
| if suggestPowerCycling { | ||
| fmt.Println(tryPowerCycling) | ||
| } | ||
| os.Exit(1) | ||
| } | ||
|
|
||
| fmt.Println("Success! Firmware transmitted to Senso.") | ||
| } | ||
|
|
||
| func updateByDiscovery(ctx context.Context, image io.Reader, onProgress OnProgress) (err error, suggestPowerCycling bool) { | ||
| onProgress("Discovering Sensos") | ||
| services := service.List(ctx, discoveryTimeout) | ||
| if len(services) == 1 { | ||
| target := services[0] | ||
| onProgress(fmt.Sprintf("Discovered Senso: %s (%s)", target.Text.Serial, target.Address)) | ||
| err = update(ctx, target, image, onProgress) | ||
| if err != nil { | ||
| suggestPowerCycling = true | ||
| } | ||
| } else if len(services) == 0 { | ||
| err = fmt.Errorf("Could not find any Sensos.") | ||
| suggestPowerCycling = true | ||
| } else { | ||
| err = fmt.Errorf("discovered multiple Sensos: %v, please specify a serial or IP", services) | ||
| suggestPowerCycling = false | ||
| } | ||
| return | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.