2022-04-23 00:12:30 +00:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
2022-05-01 22:22:28 +00:00
|
|
|
"context"
|
|
|
|
|
2023-04-21 02:54:58 +00:00
|
|
|
"go.elara.ws/itd/internal/rpc"
|
2022-04-23 00:12:30 +00:00
|
|
|
)
|
|
|
|
|
2023-01-03 06:30:17 +00:00
|
|
|
type DFUProgress struct {
|
|
|
|
Sent int64
|
|
|
|
Received int64
|
|
|
|
Total int64
|
|
|
|
Err error
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) FirmwareUpgrade(ctx context.Context, upgType UpgradeType, files ...string) (chan DFUProgress, error) {
|
|
|
|
progressCh := make(chan DFUProgress, 5)
|
|
|
|
fc, err := c.client.FirmwareUpgrade(ctx, &rpc.FirmwareUpgradeRequest{
|
|
|
|
Type: rpc.FirmwareUpgradeRequest_Type(upgType),
|
|
|
|
Files: files,
|
|
|
|
})
|
2022-04-23 00:12:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2023-01-03 06:30:17 +00:00
|
|
|
go fsRecvToChannel[rpc.DFUProgress](fc, progressCh, func(evt *rpc.DFUProgress, err error) DFUProgress {
|
|
|
|
return DFUProgress{
|
|
|
|
Sent: evt.Sent,
|
|
|
|
Received: evt.Recieved,
|
|
|
|
Total: evt.Total,
|
|
|
|
Err: err,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2022-04-23 00:12:30 +00:00
|
|
|
return progressCh, nil
|
|
|
|
}
|