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); }
private static void UpdateReadRequests() { if (!s_isInitialized) { return; } s_removeIdxBuffer.Clear(); int count = s_readRequests.Count; for (int i = 0; i < count; ++i) { var request = s_readRequests[i]; if (DllInterface.IsReadRequestComplete(request.handle)) { if (request.didReadChracteristicAction != null) { var data = DllInterface.GetReadRequestData(request.handle, 32); request.didReadChracteristicAction(request.charastericsInfo.serviceUUID, request.charastericsInfo.characteristicUUID, data); } s_removeIdxBuffer.Add(i); } else if (DllInterface.IsReadRequestError(request.handle)) { s_removeIdxBuffer.Add(i); } } // remove done request s_removeIdxBuffer.Reverse(); foreach (var idx in s_removeIdxBuffer) { var request = s_readRequests[idx]; var addr = DeviceAddressDatabase.GetAddressValue(request.charastericsInfo.address); DllInterface.ReleaseReadRequest(addr, request.handle); s_readRequests.RemoveAt(idx); } }