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"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/davecheney/gpio"
|
"github.com/davecheney/gpio"
|
||||||
"github.com/fulr/rfm69"
|
"github.com/fulr/rfm69"
|
||||||
|
@ -35,7 +36,7 @@ func main() {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
rxChan, quit := rfm.Loop()
|
rxChan, txChan, quit := rfm.Loop()
|
||||||
|
|
||||||
sigint := make(chan os.Signal, 1)
|
sigint := make(chan os.Signal, 1)
|
||||||
signal.Notify(sigint, os.Interrupt, os.Kill)
|
signal.Notify(sigint, os.Interrupt, os.Kill)
|
||||||
|
@ -49,6 +50,13 @@ func main() {
|
||||||
quit <- 1
|
quit <- 1
|
||||||
<-quit
|
<-quit
|
||||||
return
|
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
|
// 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)
|
quit := make(chan int)
|
||||||
txChan := make(chan Data, 5)
|
txChan := make(chan Data, 5)
|
||||||
rxChan := make(chan Data, 5)
|
rxChan := make(chan Data, 5)
|
||||||
|
@ -106,6 +106,7 @@ func (r *Device) Loop() (chan Data, chan int) {
|
||||||
resp := Data{
|
resp := Data{
|
||||||
FromAddress: r.address,
|
FromAddress: r.address,
|
||||||
ToAddress: data.FromAddress,
|
ToAddress: data.FromAddress,
|
||||||
|
Data: data.Data,
|
||||||
SendAck: true,
|
SendAck: true,
|
||||||
}
|
}
|
||||||
txChan <- resp
|
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