forked from Elara6331/infinitime
Add debug logging
This commit is contained in:
10
dfu.go
10
dfu.go
@@ -313,6 +313,7 @@ func (dfu *DFU) Reset() {
|
||||
// on waits for the given command to be received on
|
||||
// the control point characteristic, then runs the callback.
|
||||
func (dfu *DFU) on(cmd []byte, onCmdCb func(data []byte) error) error {
|
||||
log.Debug().Hex("expecting", cmd).Msg("Waiting for command")
|
||||
// Use for loop in case of invalid property
|
||||
for {
|
||||
select {
|
||||
@@ -324,6 +325,10 @@ func (dfu *DFU) on(cmd []byte, onCmdCb func(data []byte) error) error {
|
||||
}
|
||||
// Assert propery value as byte slice
|
||||
data := propChanged.Value.([]byte)
|
||||
log.Debug().
|
||||
Hex("expecting", cmd).
|
||||
Hex("received", data).
|
||||
Msg("Received command")
|
||||
// If command has prefix of given command
|
||||
if bytes.HasPrefix(data, cmd) {
|
||||
// Return callback with data after command
|
||||
@@ -408,6 +413,7 @@ func (dfu *DFU) stepSeven() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Debug().Msg("Sent firmware image segment")
|
||||
// Increment bytes sent by amount read
|
||||
dfu.bytesSent += len(segment)
|
||||
}
|
||||
@@ -415,6 +421,10 @@ func (dfu *DFU) stepSeven() error {
|
||||
err := dfu.on(DFUNotifPktRecvd, func(data []byte) error {
|
||||
// Set bytes received to data returned by InfiniTime
|
||||
dfu.bytesRecvd = int(binary.LittleEndian.Uint32(data))
|
||||
log.Debug().
|
||||
Int("sent", dfu.bytesSent).
|
||||
Int("rcvd", dfu.bytesRecvd).
|
||||
Msg("Received packet receipt notification")
|
||||
if dfu.bytesRecvd != dfu.bytesSent {
|
||||
return ErrDFUSizeMismatch
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user