func discAllChrs()

in nmxact/nmble/ble_act.go [313:363]


func discAllChrs(x *BleXport, bl *Listener, r *BleDiscAllChrsReq) (
	[]*BleDiscChr, error) {

	const rspType = MSG_TYPE_DISC_ALL_CHRS
	const evtType = MSG_TYPE_DISC_CHR_EVT

	j, err := json.Marshal(r)
	if err != nil {
		return nil, err
	}

	if err := x.Tx(j); err != nil {
		return nil, err
	}

	bhdTmoChan := bl.AfterTimeout(x.RspTimeout())
	chrs := []*BleDiscChr{}
	for {
		select {
		case err := <-bl.ErrChan:
			return nil, err

		case bm := <-bl.MsgChan:
			switch msg := bm.(type) {
			case *BleDiscAllChrsRsp:
				bl.Acked = true
				if msg.Status != 0 {
					return nil, StatusError(MSG_OP_RSP, rspType, msg.Status)
				}

			case *BleDiscChrEvt:
				switch msg.Status {
				case 0:
					chrs = append(chrs, &msg.Chr)
				case ERR_CODE_EDONE:
					return chrs, nil
				default:
					return nil, StatusError(MSG_OP_EVT, evtType, msg.Status)
				}

			default:
			}

		case _, ok := <-bhdTmoChan:
			if ok {
				x.Restart("Blehostd timeout: " + MsgTypeToString(rspType))
			}
			bhdTmoChan = nil
		}
	}
}