itd/api/upgrade.go

38 lines
802 B
Go
Raw Normal View History

package api
import (
"encoding/json"
"go.arsenm.dev/itd/internal/types"
)
2021-10-23 04:01:18 +00:00
// DFUProgress stores the progress of a DFU upfate
type DFUProgress types.DFUProgress
2021-10-23 04:01:18 +00:00
// UpgradeType indicates the type of upgrade to be performed
type UpgradeType uint8
2021-10-23 04:01:18 +00:00
// Type of DFU upgrade
const (
UpgradeTypeArchive UpgradeType = iota
UpgradeTypeFiles
)
2021-10-23 04:01:18 +00:00
// FirmwareUpgrade initiates a DFU update and returns the progress channel
func (c *Client) FirmwareUpgrade(upgType UpgradeType, files ...string) (<-chan DFUProgress, error) {
err := json.NewEncoder(c.conn).Encode(types.Request{
Type: types.ReqTypeFwUpgrade,
Data: types.ReqDataFwUpgrade{
Type: int(upgType),
Files: files,
},
})
if err != nil {
return nil, err
}
c.dfuProgressCh = make(chan DFUProgress, 5)
return c.dfuProgressCh, nil
}