mirror of
https://github.com/soypat/lora.git
synced 2026-07-26 07:28:38 +00:00
receiver loops forever; add errWrap
This commit is contained in:
@@ -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
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user