From 57a157fc2628e83b0642c585c91c2d567b334ed6 Mon Sep 17 00:00:00 2001 From: Friedl Ulrich Date: Fri, 6 Feb 2015 22:30:33 +0100 Subject: [PATCH] Read FiFo implemented --- rfm69d/rfm69d.go | 2 +- rfm69device.go | 34 +++++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/rfm69d/rfm69d.go b/rfm69d/rfm69d.go index 4423db8..6f186bd 100644 --- a/rfm69d/rfm69d.go +++ b/rfm69d/rfm69d.go @@ -38,7 +38,7 @@ func main() { if err != nil { log.Fatal(err) } - t.Print(rfm) + log.Print(rfm) rfm.Loop() } diff --git a/rfm69device.go b/rfm69device.go index 48af00f..0999327 100644 --- a/rfm69device.go +++ b/rfm69device.go @@ -26,10 +26,11 @@ const ( // Data is the data structure for the protocol type Data struct { - ToAddress byte - Data []byte - RequestAck bool - SendAck bool + ToAddress byte + FromAddress byte + Data []byte + RequestAck bool + SendAck bool } // NewDevice creates a new device @@ -369,5 +370,28 @@ func (r *Device) writeFifo(data *Data) error { } func (r *Device) readFifo() (Data, error) { - return Data{}, nil + data := Data{} + tx := new([67]byte) + tx[0] = REG_FIFO & 0x7f + rx, err := r.SpiDevice.Xfer(tx[:3]) + if err != nil { + return data, err + } + + data.ToAddress = rx[2] + length := rx[1] - 3 + if length > 66 { + length = 66 + } + + rx, err = r.SpiDevice.Xfer(tx[:length+3]) + if err != nil { + return data, err + } + + data.FromAddress = rx[1] + data.SendAck = bool(rx[2]&0x80 > 0) + data.RequestAck = bool(rx[2]&0x40 > 0) + data.Data = rx[3:] + return data, nil }