예제 #1
0
        internal async Task WriteFileAsyncInternal(byte[] data, string devicePath)
        {
            const int chunkSize = 960;

            Command commandBegin = new Command(CommandType.SystemReply);

            commandBegin.AddOpcode(SystemOpcode.BeginDownload);
            commandBegin.AddRawParameter((uint)data.Length);
            commandBegin.AddRawParameter(devicePath);

            await _brick.SendCommandAsyncInternal(commandBegin);

            if (commandBegin.Response.SystemReplyStatus != SystemReplyStatus.Success)
            {
                throw new Exception("Could not begin file save: " + commandBegin.Response.SystemReplyStatus);
            }

            byte handle   = commandBegin.Response.Data[0];
            int  sizeSent = 0;

            while (sizeSent < data.Length)
            {
                Command commandContinue = new Command(CommandType.SystemReply);
                commandContinue.AddOpcode(SystemOpcode.ContinueDownload);
                commandContinue.AddRawParameter(handle);
                int sizeToSend = Math.Min(chunkSize, data.Length - sizeSent);
                commandContinue.AddRawParameter(data, sizeSent, sizeToSend);
                sizeSent += sizeToSend;

                await _brick.SendCommandAsyncInternal(commandContinue);

                if (commandContinue.Response.SystemReplyStatus != SystemReplyStatus.Success &&
                    (commandContinue.Response.SystemReplyStatus != SystemReplyStatus.EndOfFile && sizeSent == data.Length))
                {
                    throw new Exception("Error saving file: " + commandContinue.Response.SystemReplyStatus);
                }
            }

            //Command commandClose = new Command(CommandType.SystemReply);
            //commandClose.AddOpcode(SystemOpcode.CloseFileHandle);
            //commandClose.AddRawParameter(handle);
            //await _brick.SendCommandAsyncInternal(commandClose);
            //if(commandClose.Response.SystemReplyStatus != SystemReplyStatus.Success)
            //	throw new Exception("Could not close handle: " + commandClose.Response.SystemReplyStatus);
        }
예제 #2
0
		internal async Task WriteFileAsyncInternal(byte[] data, string devicePath)
		{
			const int chunkSize = 960;

			Command commandBegin = new Command(CommandType.SystemReply);
			commandBegin.AddOpcode(SystemOpcode.BeginDownload);
			commandBegin.AddRawParameter((uint)data.Length);
			commandBegin.AddRawParameter(devicePath);

			await _brick.SendCommandAsyncInternal(commandBegin);
			if(commandBegin.Response.SystemReplyStatus != SystemReplyStatus.Success)
				throw new Exception("Could not begin file save: " + commandBegin.Response.SystemReplyStatus);

			byte handle = commandBegin.Response.Data[0];
			int sizeSent = 0;

			while(sizeSent < data.Length)
			{
				Command commandContinue = new Command(CommandType.SystemReply);
				commandContinue.AddOpcode(SystemOpcode.ContinueDownload);
				commandContinue.AddRawParameter(handle);
				int sizeToSend = Math.Min(chunkSize, data.Length - sizeSent);
				commandContinue.AddRawParameter(data, sizeSent, sizeToSend);
				sizeSent += sizeToSend;

				await _brick.SendCommandAsyncInternal(commandContinue);
				if(commandContinue.Response.SystemReplyStatus != SystemReplyStatus.Success &&
					(commandContinue.Response.SystemReplyStatus != SystemReplyStatus.EndOfFile && sizeSent == data.Length))
					throw new Exception("Error saving file: " + commandContinue.Response.SystemReplyStatus);
			}

			//Command commandClose = new Command(CommandType.SystemReply);
			//commandClose.AddOpcode(SystemOpcode.CloseFileHandle);
			//commandClose.AddRawParameter(handle);
			//await _brick.SendCommandAsyncInternal(commandClose);
			//if(commandClose.Response.SystemReplyStatus != SystemReplyStatus.Success)
			//	throw new Exception("Could not close handle: " + commandClose.Response.SystemReplyStatus);
		}