Beispiel #1
0
        public async Task <T> Send <T>(SendBaseCommand cmd, int nTimeout = 2000)
            where T : RecieveBaseCommand
        {
            T ret = default(T);

            if (await Send(cmd))
            {
                ret = await Recieve <T>(nTimeout);

                if (ret == null)
                {
                    Connection.Update(new NukiCommandTimeout(cmd, nTimeout));
                }
                else if (ret is RecieveStatusCommand)
                {
                    var status = ((RecieveStatusCommand)(object)ret).StatusCode;
                    if (status != API.NukiErrorCode.COMPLETE && status != API.NukiErrorCode.ACCEPTED)
                    {
                        this.Connection.Update(new NukiCommandFailed(cmd.CommandType, status));
                    }
                    else
                    {
                    }        //OK
                }
                else
                {
                }
            }
            else
            {
                Connection.Update(new NukiCommandTimeout(cmd, nTimeout));
            }
            return(ret);
        }
Beispiel #2
0
 internal NukiCommandTimeout(SendBaseCommand bleCommand, int nTimeoutTime)
     : this(bleCommand.CommandType, nTimeoutTime)
 {
     if (bleCommand is SendRequestDataCommand)
     {
         Message = $"Requested Command {((SendRequestDataCommand)bleCommand).ReqestedCommand }";
     }
     else
     {
         Message = string.Empty;
     }
 }
Beispiel #3
0
        protected override Task <bool> Send(SendBaseCommand cmd, DataWriter writer)
        {
            bool blnRet = false;

            lock (Syncroot)
                m_RecieveBuffer = null;

            byte[] byNonce = Sodium.Core.GetRandomBytes(24);
            writer.WriteBytes(byNonce);
            writer.WriteUInt32(Connection.UniqueClientID.Value);

            byte[] byDecryptedMessage = cmd.Serialize(BitConverter.GetBytes(Connection.UniqueClientID.Value)).ToArray();
            byte[] byEncryptedMessage = Sodium.SecretBox.Create(byDecryptedMessage, byNonce, Connection.SharedKey);

            writer.WriteUInt16((UInt16)byEncryptedMessage.Length);
            writer.WriteBytes(byEncryptedMessage);
            blnRet = true;

            return(Task.FromResult(blnRet));
        }
Beispiel #4
0
        public async Task <bool> Send(SendBaseCommand cmd, int nTimeout)
        {
            bool blnRet = false;

            Reset();
            Log.Info($"Send Command {cmd}...");
            var writer = new DataWriter();

            writer.ByteOrder = ByteOrder.LittleEndian;
            if (await Send(cmd, writer))
            {
                var result = await m_GattCharacteristic.WriteValueAsync(writer.DetachBuffer());

                blnRet = result == GattCommunicationStatus.Success;
            }
            else
            {
            }
            return(blnRet);
        }
Beispiel #5
0
 protected abstract Task <bool> Send(SendBaseCommand cmd, DataWriter writer);
Beispiel #6
0
 public Task <bool> Send(SendBaseCommand cmd)
 {
     return(Send(cmd, 2000));
 }
        protected override Task <bool> Send(SendBaseCommand cmd, DataWriter writer)
        {
            writer.WriteBytes(cmd.Serialize().ToArray());

            return(Task.FromResult(true));
        }