Esempio n. 1
0
        public static void WriteCharacteristic(string identifier,
                                               string serviceUUID, string characteristicUUID,
                                               byte[] data, int length, bool withResponse,
                                               Action <string, string> didWriteCharacteristicAction)
        {
            if (!s_isInitialized)
            {
                return;
            }
            //Debug.Log("WriteCharacteristic " + identifier);
            var addr = DeviceAddressDatabase.GetAddressValue(identifier);

            var serviceHandle        = UuidDatabase.GetUuid(serviceUUID);
            var characteristicHandle = UuidDatabase.GetUuid(characteristicUUID);
            var writeRequest         = DllInterface.WriteCharastristicRequest(addr, serviceHandle, characteristicHandle, data, 0, length);

            if (withResponse && didWriteCharacteristicAction == null)
            {
                var charastricsItem = new BleCharastericsKeyInfo(identifier, serviceUUID, characteristicUUID);
                var requestData     = new BleWriteRequestData(charastricsItem, writeRequest, didWriteCharacteristicAction);
                s_writeRequests.Add(requestData);
            }
            else
            {
                DllInterface.ReleaseWriteRequest(addr, writeRequest);
            }
        }
Esempio n. 2
0
        public static void SubscribeCharacteristic(string identifier,
                                                   string serviceUUID, string characteristicUUID,
                                                   Action <string, string, byte[]> notifiedCharacteristicAction)
        {
            //Debug.Log("SubscribeCharacteristic " + identifier + ":" + serviceUUID + ":" + characteristicUUID);
            var addr                 = DeviceAddressDatabase.GetAddressValue(identifier);
            var serviceHandle        = UuidDatabase.GetUuid(serviceUUID);
            var characteristicHandle = UuidDatabase.GetUuid(characteristicUUID);
            var charastricsItem      = new BleCharastericsKeyInfo(identifier, serviceUUID, characteristicUUID);

            s_notifyEvents[charastricsItem] = new BleNotifyData(notifiedCharacteristicAction);
            DllInterface.SetNotificationRequest(addr, serviceHandle, characteristicHandle, true);
        }
Esempio n. 3
0
        public static void UnSubscribeCharacteristic(string identifier,
                                                     string serviceUUID, string characteristicUUID,
                                                     Action <string> action)
        {
            if (!s_isInitialized)
            {
                return;
            }
            //Debug.Log("UnSubscribeCharacteristic " + identifier + ":" + serviceUUID + ":" + characteristicUUID);
            var addr                 = DeviceAddressDatabase.GetAddressValue(identifier);
            var serviceHandle        = UuidDatabase.GetUuid(serviceUUID);
            var characteristicHandle = UuidDatabase.GetUuid(characteristicUUID);
            var charastricsItem      = new BleCharastericsKeyInfo(identifier, serviceUUID, characteristicUUID);

            DllInterface.SetNotificationRequest(addr, serviceHandle, characteristicHandle, false);
            s_notifyEvents.Remove(charastricsItem);
        }
Esempio n. 4
0
 public static void StartScan(string[] serviceUUIDs,
                              Action <string, string, int, byte[]> discoveredAction = null)
 {
     if (!s_isInitialized)
     {
         return;
     }
     s_discoverAction = discoveredAction;
     DllInterface.ClearScanFilter();
     if (serviceUUIDs != null)
     {
         foreach (var uuid in serviceUUIDs)
         {
             var uuidHandle = UuidDatabase.GetUuid(uuid);
             DllInterface.AddScanServiceUuid(uuidHandle);
         }
     }
     DllInterface.StartScan();
 }
Esempio n. 5
0
        public static void ReadCharacteristic(string identifier,
                                              string serviceUUID,
                                              string characteristicUUID,
                                              Action <string, string, byte[]> didReadChracteristicAction)
        {
            if (!s_isInitialized)
            {
                return;
            }
            //Debug.Log("ReadCharacteristic " + identifier);
            var addr                 = DeviceAddressDatabase.GetAddressValue(identifier);
            var serviceHandle        = UuidDatabase.GetUuid(serviceUUID);
            var characteristicHandle = UuidDatabase.GetUuid(characteristicUUID);
            var charastricsItem      = new BleCharastericsKeyInfo(identifier, serviceUUID, characteristicUUID);

            var readRequestHandle = DllInterface.ReadCharastristicRequest(addr, serviceHandle, characteristicHandle);
            var requestData       = new BleReadRequestData(charastricsItem, readRequestHandle, didReadChracteristicAction);

            s_readRequests.Add(requestData);
        }