receiver loops forever; add errWrap

This commit is contained in:
soypat
2023-05-22 08:12:32 -03:00
parent 06c18d75cd
commit 048f89366f
2 changed files with 15 additions and 10 deletions
+13 -8
View File
@@ -50,15 +50,20 @@ func main() {
var rx [256]byte
// This blocks forever reading messages received.
ctx := context.Background()
err = dev.RxContinuous(ctx, func(r io.Reader) (_ error) {
n, err := r.Read(rx[:])
for {
time.Sleep(10 * time.Second)
err = dev.RxContinuous(ctx, func(r io.Reader) (_ error) {
n, err := r.Read(rx[:])
if err != nil {
return err
}
println("received LoRa:", string(rx[:n]))
return nil
})
if err != nil {
return err
println(err.Error())
} else {
println("RX finished no error")
}
println("received LoRa:", string(rx[:n]))
return nil
})
if err != nil {
panic(err)
}
}
+2 -2
View File
@@ -479,8 +479,8 @@ func (d *DeviceLoRa) RxContinuous(ctx context.Context, fn rxCallback) error {
if err != nil {
return err
} else if op != OpRx {
return errors.New("unexpected op mode change during RxContinuous to " +
op.String() + " with irqs:" + irqFlagsString(irq))
return d.wrapErr(errors.New("unexpected op mode change during RxContinuous to " +
op.String() + " with irqs:" + irqFlagsString(irq)))
}
}
return ctx.Err()