gobot.io/x/gobot/v2@v2.1.0/platforms/sphero/bb8/helpers_test.go (about) 1 package bb8 2 3 import ( 4 "sync" 5 6 "gobot.io/x/gobot/v2/platforms/ble" 7 ) 8 9 var _ ble.BLEConnector = (*bleTestClientAdaptor)(nil) 10 11 type bleTestClientAdaptor struct { 12 name string 13 address string 14 mtx sync.Mutex 15 withoutResponses bool 16 17 testReadCharacteristic func(string) ([]byte, error) 18 testWriteCharacteristic func(string, []byte) error 19 } 20 21 func (t *bleTestClientAdaptor) Connect() (err error) { return } 22 func (t *bleTestClientAdaptor) Reconnect() (err error) { return } 23 func (t *bleTestClientAdaptor) Disconnect() (err error) { return } 24 func (t *bleTestClientAdaptor) Finalize() (err error) { return } 25 func (t *bleTestClientAdaptor) Name() string { return t.name } 26 func (t *bleTestClientAdaptor) SetName(n string) { t.name = n } 27 func (t *bleTestClientAdaptor) Address() string { return t.address } 28 func (t *bleTestClientAdaptor) WithoutResponses(use bool) { t.withoutResponses = use } 29 30 func (t *bleTestClientAdaptor) ReadCharacteristic(cUUID string) (data []byte, err error) { 31 t.mtx.Lock() 32 defer t.mtx.Unlock() 33 return t.testReadCharacteristic(cUUID) 34 } 35 36 func (t *bleTestClientAdaptor) WriteCharacteristic(cUUID string, data []byte) (err error) { 37 t.mtx.Lock() 38 defer t.mtx.Unlock() 39 return t.testWriteCharacteristic(cUUID, data) 40 } 41 42 func (t *bleTestClientAdaptor) Subscribe(cUUID string, f func([]byte, error)) (err error) { 43 // TODO: implement this... 44 return 45 } 46 47 func (t *bleTestClientAdaptor) TestReadCharacteristic(f func(cUUID string) (data []byte, err error)) { 48 t.mtx.Lock() 49 defer t.mtx.Unlock() 50 t.testReadCharacteristic = f 51 } 52 53 func (t *bleTestClientAdaptor) TestWriteCharacteristic(f func(cUUID string, data []byte) (err error)) { 54 t.mtx.Lock() 55 defer t.mtx.Unlock() 56 t.testWriteCharacteristic = f 57 } 58 59 func NewBleTestAdaptor() *bleTestClientAdaptor { 60 return &bleTestClientAdaptor{ 61 address: "01:02:03:04:05:06", 62 testReadCharacteristic: func(cUUID string) (data []byte, e error) { 63 return 64 }, 65 testWriteCharacteristic: func(cUUID string, data []byte) (e error) { 66 return 67 }, 68 } 69 }