itd/api/firmware.go
Arsen Musayelyan b757af7fed
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
Switch to autogenerated DRPC framework
2023-01-02 22:30:17 -08:00

37 lines
760 B
Go

package api
import (
"context"
"go.arsenm.dev/itd/internal/rpc"
)
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,
})
if err != nil {
return nil, err
}
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,
}
})
return progressCh, nil
}