mirror of
https://github.com/soypat/lora.git
synced 2026-08-17 03:03:22 +00:00
receiver loops forever; add errWrap
This commit is contained in:
@@ -50,15 +50,20 @@ func main() {
|
|||||||
var rx [256]byte
|
var rx [256]byte
|
||||||
// This blocks forever reading messages received.
|
// This blocks forever reading messages received.
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
err = dev.RxContinuous(ctx, func(r io.Reader) (_ error) {
|
for {
|
||||||
n, err := r.Read(rx[:])
|
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 {
|
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
@@ -479,8 +479,8 @@ func (d *DeviceLoRa) RxContinuous(ctx context.Context, fn rxCallback) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if op != OpRx {
|
} else if op != OpRx {
|
||||||
return errors.New("unexpected op mode change during RxContinuous to " +
|
return d.wrapErr(errors.New("unexpected op mode change during RxContinuous to " +
|
||||||
op.String() + " with irqs:" + irqFlagsString(irq))
|
op.String() + " with irqs:" + irqFlagsString(irq)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
|
|||||||
Reference in New Issue
Block a user