18
18
package otaapi
19
19
20
20
import (
21
+ "fmt"
21
22
"strconv"
22
23
"strings"
23
24
"time"
@@ -31,22 +32,24 @@ const progressBarMultiplier = 2
31
32
32
33
type (
33
34
OtaStatusResponse struct {
34
- FirmwareSize * int64 `json:"firmware_size,omitempty"`
35
- Ota Ota `json:"ota"`
36
- States []State `json:"states,omitempty"`
35
+ Ota Ota `json:"ota"`
36
+ States []State `json:"states,omitempty"`
37
37
}
38
38
39
39
OtaStatusList struct {
40
40
Ota []Ota `json:"ota"`
41
41
}
42
42
43
43
Ota struct {
44
- ID string `json:"id,omitempty" yaml:"id,omitempty"`
45
- DeviceID string `json:"device_id,omitempty" yaml:"device_id,omitempty"`
46
- Status string `json:"status" yaml:"status"`
47
- StartedAt string `json:"started_at" yaml:"started_at"`
48
- EndedAt string `json:"ended_at,omitempty" yaml:"ended_at,omitempty"`
49
- ErrorReason string `json:"error_reason,omitempty" yaml:"error_reason,omitempty"`
44
+ ID string `json:"id,omitempty" yaml:"id,omitempty"`
45
+ DeviceID string `json:"device_id,omitempty" yaml:"device_id,omitempty"`
46
+ Status string `json:"status" yaml:"status"`
47
+ StartedAt string `json:"started_at" yaml:"started_at"`
48
+ EndedAt string `json:"ended_at,omitempty" yaml:"ended_at,omitempty"`
49
+ ErrorReason string `json:"error_reason,omitempty" yaml:"error_reason,omitempty"`
50
+ FirmwareSize int64 `json:"firmware_size,omitempty"`
51
+ MaxRetries int64 `json:"max_retries,omitempty"`
52
+ RetryAttempt int64 `json:"retry_attempt,omitempty"`
50
53
}
51
54
52
55
State struct {
57
60
}
58
61
59
62
OtaStatusDetail struct {
60
- FirmwareSize * int64 `json:"firmware_size,omitempty"`
63
+ FirmwareSize int64 `json:"firmware_size,omitempty"`
61
64
Ota Ota `json:"ota"`
62
65
Details []State `json:"details,omitempty"`
63
66
}
@@ -160,8 +163,8 @@ func (r OtaStatusDetail) String() string {
160
163
t = table .New ()
161
164
t .SetHeader ("Time" , "Status" , "Detail" )
162
165
fwSize := int64 (0 )
163
- if r .FirmwareSize != nil {
164
- fwSize = * r .FirmwareSize
166
+ if r .FirmwareSize > 0 {
167
+ fwSize = r .FirmwareSize
165
168
}
166
169
for _ , s := range r .Details {
167
170
stateData := formatStateData (s .State , s .StateData , fwSize , hasReachedFlashState (r .Details ))
@@ -186,6 +189,7 @@ func formatStateData(state, data string, firmware_size int64, hasReceivedFlashSt
186
189
if data == "" || data == "Unknown" {
187
190
return ""
188
191
}
192
+ fmt .Println ("State: " , state )
189
193
if state == "fetch" {
190
194
// This is the state 'fetch' of OTA progress. This contains a number that represents the number of bytes fetched
191
195
actualDownloadedData , err := strconv .Atoi (data )
0 commit comments