Send example
This commit is contained in:
parent
15b9202bc6
commit
39c46ca5e2
2 changed files with 12 additions and 3 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/davecheney/gpio"
|
||||
"github.com/fulr/rfm69"
|
||||
|
@ -35,7 +36,7 @@ func main() {
|
|||
log.Fatal(err)
|
||||
}
|
||||
|
||||
rxChan, quit := rfm.Loop()
|
||||
rxChan, txChan, quit := rfm.Loop()
|
||||
|
||||
sigint := make(chan os.Signal, 1)
|
||||
signal.Notify(sigint, os.Interrupt, os.Kill)
|
||||
|
@ -49,6 +50,13 @@ func main() {
|
|||
quit <- 1
|
||||
<-quit
|
||||
return
|
||||
case <-time.After(10 * time.Second):
|
||||
txChan <- rfm69.Data{
|
||||
ToAddress: 99,
|
||||
FromAddress: 1,
|
||||
Data: []byte{1, 2, 3},
|
||||
RequestAck: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
)
|
||||
|
||||
// Loop is the main receive and transmit handling loop
|
||||
func (r *Device) Loop() (chan Data, chan int) {
|
||||
func (r *Device) Loop() (chan Data, chan Data, chan int) {
|
||||
quit := make(chan int)
|
||||
txChan := make(chan Data, 5)
|
||||
rxChan := make(chan Data, 5)
|
||||
|
@ -106,6 +106,7 @@ func (r *Device) Loop() (chan Data, chan int) {
|
|||
resp := Data{
|
||||
FromAddress: r.address,
|
||||
ToAddress: data.FromAddress,
|
||||
Data: data.Data,
|
||||
SendAck: true,
|
||||
}
|
||||
txChan <- resp
|
||||
|
@ -125,5 +126,5 @@ func (r *Device) Loop() (chan Data, chan int) {
|
|||
}
|
||||
}()
|
||||
|
||||
return rxChan, quit
|
||||
return rxChan, txChan, quit
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue