Ejemplo n.º 1
0
        public void BleClientWriteConfig(BleGattCharacteristic character, byte config)
        {
            if (!character.Service.GattDevice.Connected)
            {
                Error("[CSR]:BleClientWriteConfig when device is not connect!");
                return;
            }

            if (!CsrBleDll.CsrBleClientWriteConfiguration(character.Service.GattDevice.Handle, character.DescriptorHandle,
                                                          character.Handle, config))
            {
                Error("[CSR]:BleClientWriteConfig Fail!");
            }
        }
Ejemplo n.º 2
0
        private void OnDatabaseDiscoveryResult(CSR_BLE_DATABASE_DISCOVERY_RESULT database)
        {
            int servicePtrPos = GetServicePtrPos((ushort)_curServiceUuid, ref database);

            if (servicePtrPos != 0xFF)
            {
                CSR_BLE_SERVICE service =
                    (CSR_BLE_SERVICE)Marshal.PtrToStructure(
                        database.services + servicePtrPos * Marshal.SizeOf(typeof(CSR_BLE_SERVICE)),
                        typeof(CSR_BLE_SERVICE));

                //if (_curServiceUuid != XIM_BATTERY_SERVICE)
                {
                    var nCharacter = service.nCharacteristics;
                    CSR_BLE_CHARACTERISTIC readCharcter =
                        (CSR_BLE_CHARACTERISTIC)
                        Marshal.PtrToStructure(service.characteristics, typeof(CSR_BLE_CHARACTERISTIC));

                    CSR_BLE_CHARACTERISTIC writeCharcter =
                        (CSR_BLE_CHARACTERISTIC)
                        Marshal.PtrToStructure(
                            service.characteristics + 1 * Marshal.SizeOf(typeof(CSR_BLE_CHARACTERISTIC)),
                            typeof(CSR_BLE_CHARACTERISTIC));

                    CurDevInfo.ReadHandle  = readCharcter.handle;
                    CurDevInfo.WriteHandle = writeCharcter.handle;

                    if (readCharcter.nDescriptors > 0)
                    {
                        var descHandle =
                            (CSR_BLE_CHARACTERISTIC_DSC)Marshal.PtrToStructure(readCharcter.descriptors,
                                                                               typeof(CSR_BLE_CHARACTERISTIC_DSC));
                        CsrBleDll.CsrBleClientWriteConfiguration(CurDevInfo.ConnHandle, descHandle.handle,
                                                                 readCharcter.handle, 0x01);
                    }
                }
                _dbDiscoverEvent.Set();
            }
        }