Example #1
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 #2
0
	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))
	})

	It("gets the digital values", func() {
		vals, err := x.GetDigital()
		Expect(err).To(BeNil())
		Expect(vals).To(HaveLen(2))
		v, ok := vals["dio3"]
		Expect(ok).To(BeTrue())
		Expect(v).To(BeFalse())
		Expect(vals["dio4"]).To(BeTrue())
	})
})