Ejemplo n.º 1
0
func (cs *ConnUDP) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration) error {
	addr, err := net.ResolveUDPAddr("udp", cp.ConnString())
	if err != nil {
		return util.NewNewtError(fmt.Sprintf("Name not resolving: %s",
			err.Error()))
	}
	cs.dst = addr

	// bind local endpoint to wait for response afterwards
	s, err := net.ListenUDP("udp", nil)
	if err != nil {
		return util.NewNewtError(fmt.Sprintf("UDP conn failed: %s\n",
			err.Error()))
	}
	cs.conn = s
	return nil
}
Ejemplo n.º 2
0
func (cs *ConnSerial) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration) error {

	c, err := newSerialConfig(cp.ConnString(), readTimeout)
	if err != nil {
		return err
	}

	cs.serialChannel, err = serial.OpenPort(c)
	if err != nil {
		return util.ChildNewtError(err)
	}
	//defer cs.serialChannel.Close()

	// Most of the reading will be done line by line, use the
	// bufio.Scanner to do this
	cs.scanner = bufio.NewScanner(cs.serialChannel)

	return nil
}
Ejemplo n.º 3
0
func (cb *ConnBLE) Open(cp config.NewtmgrConnProfile, readTimeout time.Duration) error {
	var err error

	var DefaultClientOptions = BleOptions

	deviceName = cp.ConnString()
	deviceAddress = reverseBytes(cp.DeviceAddress())
	log.Debugf("BLE Connection devaddr:%+v", deviceAddress)
	deviceAddressType = cp.DeviceAddressType()
	cb.bleDevice, err = gatt.NewDevice(DefaultClientOptions...)
	if err != nil {
		return util.NewNewtError(err.Error())
	}

	cb.bleDevice.Handle(
		gatt.PeripheralDiscovered(onPeriphDiscovered),
		gatt.PeripheralConnected(onPeriphConnected),
		gatt.PeripheralDisconnected(onPeriphDisconnected),
	)
	cb.bleDevice.Init(onStateChanged)
	CharDisc <- true

	return nil
}