Skip to content

Support for ota download progress #156

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 7 commits into from
Jul 3, 2024

Conversation

rjtokenring
Copy link
Collaborator

Motivation

Add support for fetch progress for ota download

Reviewer checklist

  • PR address a single concern.
  • PR title and description are properly filled.
  • Changes will be merged in main.
  • Changes are covered by tests.
  • Logging is meaningful in case of troubleshooting.
  • History is clean, commit messages are meaningful (see CONTRIBUTING.md) and are well formatted.

Comment on lines 171 to 175
for _, s := range states {
if s.State == "flash" {
return true
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sometimes we aren't receiving all the states from the board, so I will change this to just check that there is at least another state after fetch

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer to map possible state after fetch. I've added reboot also.
If fetch fail, error is written in state_data for fetch or is added an additional fail state?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If fetch fail, error is written in state_data for fetch or is added an additional fail state?

the board will send a fail state

if hasReceivedFlashState {
return buildSimpleProgressBar(float64(100))
}
if strings.ToLower(data) == "unknown" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all the errors in the data part always start with the upper case letter, so you could only check against

Suggested change
if strings.ToLower(data) == "unknown" {
if data == "Unknown" {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I was not sure, so I moved to a more flexible approach. BTW, since you have confirmed, I've removed toLower()

percentage := (float64(actualDownloadedData) / float64(*firmware_size)) * 100
return buildSimpleProgressBar(percentage)
}
if strings.ToLower(data) == "unknown" {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to check state here not data right?

Suggested change
if strings.ToLower(data) == "unknown" {
if state == "unknown" {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No I want to check data. I received 'Unknown' from api on state_data
{ "state": "start", "state_data": "Unknown", "timestamp": "2024-06-26T07:28:31.000001Z" },

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mhm in that case I think you can add only one unknown check at the top instead of two one inside the fetch branch and another outside

@@ -154,15 +159,68 @@ func (r OtaStatusDetail) String() string {
if len(r.Details) > 0 {
t = table.New()
t.SetHeader("Time", "Status", "Detail")
fwSize := int64(0)
if r.FirmwareSize != nil {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can also remove the pointer from FirmwareSize. IMHO there isn't a real reason to use a pointer

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a pointer because is doc it is stated that firmware size may not be present. In case it is missing, is it rmeoved from api response or returned as a 0 value?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't be present in the response, but anyway, for Golang that doesn't make any difference you will get a 0 either if the field is not present or if it is an actual 0.

@rjtokenring rjtokenring merged commit a17c934 into main Jul 3, 2024
9 checks passed
@rjtokenring rjtokenring deleted the support-for-ota-download-progress branch July 3, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants