public BlueteraManager()
        {
            var status = NativeSdkWrapper.Initialize();

            if (status != NativeSdkWrapper.StatusCode.Success)
            {
                throw new BlueteraException("Native SDK initialization failed");
            }

            NativeSdkWrapper.SetOnDeviceDiscovered(_onDeviceDiscoveredDelegate);
            NativeSdkWrapper.SetOnDeviceConnected(_onDeviceConnectedDelegate);
            NativeSdkWrapper.SetOnDeviceDisconnected(_onDeviceDisconnectedDelegate);
            NativeSdkWrapper.SetOnUartTx(_onUartTx);
        }
        public async Task <IBlueteraDevice> Connect(ulong addr, bool autopair = false)
        {
            // ignore duplicate requests
            TaskCompletionSource <BlueteraDevice> tcs = new TaskCompletionSource <BlueteraDevice>();

            if (!_connectTcs.TryAdd(addr, tcs))
            {
                return(null);
            }

            // send command
            NativeSdkWrapper.Connect(addr);

            // _connectedTcs will fire when _onDeviceConnectedDelegate() is called
            return(await tcs.Task.ContinueWith(t => (IBlueteraDevice)t.Result));
        }
        public Task <bool> SendMessage(UplinkMessage msg)
        {
            var stream = new MemoryStream();

            msg.WriteDelimitedTo(stream);

            if (stream.Position > 0)
            {
                byte[] buf = stream.ToArray();
                return(Task.Factory.StartNew(() =>
                {
                    NativeSdkWrapper.StatusCode status = NativeSdkWrapper.Write(Address, buf, (ushort)buf.Length);
                    return (status == NativeSdkWrapper.StatusCode.Success);
                }));
            }
            else
            {
                throw new ArgumentException("Invalid UplinkMessage");
            }
        }
 public void StopScan()
 {
     NativeSdkWrapper.StopScan();
 }
 public void Disconnect()
 {
     NativeSdkWrapper.Disconnect(Address);
 }