18
18
package otaapi
19
19
20
20
import (
21
- "fmt"
22
21
"strconv"
23
22
"strings"
24
23
"time"
62
61
OtaStatusDetail struct {
63
62
FirmwareSize int64 `json:"firmware_size,omitempty"`
64
63
MaxRetries int64 `json:"max_retries,omitempty"`
65
- RetryAttempt int64 `json:"retry_attempt,omitempty"`
64
+ RetryAttempt int64 `json:"retry_attempt,omitempty"`
66
65
Ota Ota `json:"ota"`
67
66
Details []State `json:"details,omitempty"`
68
67
}
@@ -96,7 +95,7 @@ func (r OtaStatusList) String() string {
96
95
line := []any {r .DeviceID , r .ID , r .MapStatus (), formatHumanReadableTs (r .StartedAt ), formatHumanReadableTs (r .EndedAt )}
97
96
if hasErrorReason {
98
97
line = append (line , r .ErrorReason )
99
- line = append (line , r .RetryAttempt )
98
+ line = append (line , strconv . FormatInt ( r .RetryAttempt , 10 ) )
100
99
}
101
100
t .AddRow (line ... )
102
101
}
@@ -120,7 +119,7 @@ func (r Ota) String() string {
120
119
hasErrorReason := r .ErrorReason != ""
121
120
122
121
if hasErrorReason {
123
- t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" , "Error Reason" )
122
+ t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" , "Error Reason" , "Retry Attempt" )
124
123
} else {
125
124
t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" )
126
125
}
@@ -129,6 +128,7 @@ func (r Ota) String() string {
129
128
line := []any {r .DeviceID , r .ID , r .MapStatus (), formatHumanReadableTs (r .StartedAt ), formatHumanReadableTs (r .EndedAt )}
130
129
if hasErrorReason {
131
130
line = append (line , r .ErrorReason )
131
+ line = append (line , strconv .FormatInt (r .RetryAttempt , 10 ))
132
132
}
133
133
t .AddRow (line ... )
134
134
@@ -147,7 +147,7 @@ func (r OtaStatusDetail) String() string {
147
147
hasErrorReason := r .Ota .ErrorReason != ""
148
148
149
149
if hasErrorReason {
150
- t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" , "Error Reason" )
150
+ t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" , "Error Reason" , "Retry Attempt" )
151
151
} else {
152
152
t .SetHeader ("Device ID" , "Ota ID" , "Status" , "Started At" , "Ended At" )
153
153
}
@@ -156,23 +156,41 @@ func (r OtaStatusDetail) String() string {
156
156
line := []any {r .Ota .DeviceID , r .Ota .ID , r .Ota .MapStatus (), formatHumanReadableTs (r .Ota .StartedAt ), formatHumanReadableTs (r .Ota .EndedAt )}
157
157
if hasErrorReason {
158
158
line = append (line , r .Ota .ErrorReason )
159
+ line = append (line , strconv .FormatInt (r .RetryAttempt , 10 ))
159
160
}
160
161
t .AddRow (line ... )
161
162
162
163
output := t .Render ()
163
164
164
165
// Add details
166
+ containsFlashState := false
167
+ firstTS := ""
165
168
if len (r .Details ) > 0 {
166
169
t = table .New ()
167
170
t .SetHeader ("Time" , "Status" , "Detail" )
168
171
fwSize := int64 (0 )
169
172
if r .FirmwareSize > 0 {
170
173
fwSize = r .FirmwareSize
171
174
}
175
+ for _ , s := range r .Details {
176
+ if upperCaseFirst (s .State ) == "Flash" {
177
+ containsFlashState = true
178
+ }
179
+ if firstTS == "" {
180
+ firstTS = formatHumanReadableTs (s .Timestamp )
181
+ }
182
+ }
183
+ if ! containsFlashState && ! hasErrorReason {
184
+ t .AddRow (firstTS , "Flash" , "" )
185
+ if fwSize > 0 {
186
+ t .AddRow (firstTS , "Fetch" , formatStateData ("fetch" , strconv .Itoa (int (fwSize )), fwSize , true ))
187
+ }
188
+ }
172
189
for _ , s := range r .Details {
173
190
stateData := formatStateData (s .State , s .StateData , fwSize , hasReachedFlashState (r .Details ))
174
191
t .AddRow (formatHumanReadableTs (s .Timestamp ), upperCaseFirst (s .State ), stateData )
175
192
}
193
+
176
194
output += "\n Details:\n " + t .Render ()
177
195
}
178
196
@@ -192,7 +210,6 @@ func formatStateData(state, data string, firmware_size int64, hasReceivedFlashSt
192
210
if data == "" || data == "Unknown" {
193
211
return ""
194
212
}
195
- fmt .Println ("State: " , state )
196
213
if state == "fetch" {
197
214
// This is the state 'fetch' of OTA progress. This contains a number that represents the number of bytes fetched
198
215
actualDownloadedData , err := strconv .Atoi (data )
0 commit comments