Skip to content

Commit

Permalink
add reboot command
Browse files Browse the repository at this point in the history
  • Loading branch information
dcentelles committed Jan 10, 2025
1 parent 7b5f1d4 commit ddc486d
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions protocol/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ var (
OpcodeSeal [4]byte = [4]byte{'S', 'E', 'A', 'L'}
OpcodeGo [4]byte = [4]byte{'G', 'O', 'G', 'O'}
OpcodeInfo [4]byte = [4]byte{'I', 'N', 'F', 'O'}
OpcodeReboot [4]byte = [4]byte{'B', 'O', 'O', 'T'}
ResponseSync [4]byte = [4]byte{'P', 'I', 'C', 'O'}
ResponseSyncWota [4]byte = [4]byte{'W', 'O', 'T', 'A'}
ResponseOK [4]byte = [4]byte{'O', 'K', 'O', 'K'}
Expand Down Expand Up @@ -317,6 +318,32 @@ func (c *GoCommand) Execute(rw io.ReadWriter) error {
return nil
}

type RebootCommand struct {
Bootloader bool
}

func (c *RebootCommand) Execute(rw io.ReadWriter) error {
buf := make([]byte, len(OpcodeReboot)+4)

copy(buf[0:], OpcodeReboot[:])
var arg0 uint32
if c.Bootloader {
arg0 = 1
}
binary.LittleEndian.PutUint32(buf[4:], arg0)

n, err := rw.Write(buf)
if err != nil {
return err
} else if n != len(buf) {
return fmt.Errorf("unexpected write length: %v", n)
}

// Fire and forget

return nil
}

type InfoCommand struct {
FlashAddr uint32
FlashSize uint32
Expand Down

0 comments on commit ddc486d

Please sign in to comment.