Example #1
0
func (x *XBee) getAnalog(msg xbee.Message, ch chan<- Value) {
	m, ok := x.adc[msg.GetAddr()]
	if !ok {
		log.Println("ignoring message from unknown xbee:", msg.GetAddr())
		return
	}

	a, err := msg.GetAnalog()
	if err != nil {
		return
	}

	for k, v := range a {
		go func(k string, v float64) {
			f, ok := m[k]
			if !ok {
				log.Println("ignoring message from unknown xbee pin:", k, x)
			} else {
				val, u, loc := f(v)
				ch <- Value{
					Value:    val,
					Units:    u,
					location: loc.location,
					name:     loc.name,
				}
			}
		}(k, v)
	}
}
Example #2
0
func (x *XBee) getDigital(msg xbee.Message, ch chan<- Value) {
	m, ok := x.dio[msg.GetAddr()]
	if !ok {
		log.Println("ignoring message from unknown xbee:", msg.GetAddr())
		return
	}

	d, err := msg.GetDigital()
	if err != nil {
		return
	}
	for k, v := range d {
		go func(k string, v bool) {
			loc, ok := m[k]
			if !ok {
				log.Println("ignoring message from unknown xbee pin:", k, x)
			} else {
				ch <- Value{
					Value:    v,
					location: loc.location,
					name:     loc.name,
				}
			}
		}(k, v)
	}
}
Example #3
0
	"github.com/cswank/xbee"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"

	"testing"
)

func TestXbee(t *testing.T) {
	RegisterFailHandler(Fail)
	RunSpecs(t, "Xbee Suite")
}

var _ = Describe("xbee message", func() {

	var (
		x xbee.Message
	)

	BeforeEach(func() {
		var err error
		d := []byte{0x92, 0x00, 0x13, 0xA2, 0x00, 0x40, 0x4C, 0x0E, 0xBE, 0x61, 0x59, 0x01, 0x01, 0x00, 0x18, 0x03, 0x00, 0x10, 0x02, 0x2F, 0x01, 0xFE, 0x49}
		x, err = xbee.NewMessage(d)
		Expect(err).To(BeNil())
	})

	It("gets the analog values", func() {
		vals, err := x.GetAnalog()
		Expect(err).To(BeNil())
		Expect(vals).To(HaveLen(2))
		Expect(vals["adc0"]).To(BeNumerically("~", 655.7, 0.1))
		Expect(vals["adc1"]).To(BeNumerically("~", 598.2, 0.1))