Esempio n. 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)
	}
}
Esempio n. 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)
	}
}