Exemplo n.º 1
0
Arquivo: QDL.cs Projeto: EnJens/QDLLib
        private bool transmitCommand(PreloaderCommand command, int timeout, out PreloaderCommand response)
        {
            int actual;

            byte[] respBytes = new byte[4096];

            byte[] cmdData = null;

            log.DebugFormat("Transmitting command {0}", command.payload.ToString());
            cmdData = command.Serialize();
            if (!transmitCommand(cmdData, timeout, ref respBytes, out actual))
            {
                throw new Exception("Failed transmitting Preloader command");
            }

            response = PreloaderCommand.Deserialize(respBytes, actual);
            if (response.payload is ErrorPayload || response.payload is MessagePayload)
            {
                log.ErrorFormat("Got Error/Msg response to command of type {0}", command.payload.CommandType);
                if (response.payload is MessagePayload)
                {
                    var msg = (MessagePayload)response.payload;
                    log.ErrorFormat("Message: {0}", msg.Message);
                }
                return(false);
            }
            log.DebugFormat("Received response {0}", response.payload.ToString());
            return(true);
        }
Exemplo n.º 2
0
Arquivo: QDL.cs Projeto: EnJens/QDLLib
        public void WriteFile(uint flashOffset, BufferedStream file)
        {
            byte[] buffer      = new byte[1024];
            uint   localOffset = flashOffset;
            int    read        = 0;

            log.DebugFormat("Writing file to offset {0:X8}", flashOffset);

            while ((read = file.Read(buffer, 0, 1024)) > 0)
            {
                PreloaderCommand response;
                PreloaderCommand cmd  = new PreloaderCommand(new WriteFlashPayload(localOffset, buffer));
                byte[]           data = cmd.Serialize();
                if (!transmitCommand(cmd, 1000, out response))
                {
                    throw new Exception("Failure during transmitting writeflash command");
                }
                if (response.payload is WriteFlashPayload)
                {
                    localOffset += (uint)read;
                }
                else if (response.payload is ErrorPayload)
                {
                    ErrorPayload errorpl = (ErrorPayload)response.payload;
                    log.ErrorFormat("Error received from device: {0} with Message: {1}", errorpl.ErrorCode, errorpl.Message);
                    throw new Exception(String.Format("Error received from device: {0} with Message: {1}", errorpl.ErrorCode, errorpl.Message));
                }
                else if (response.payload is MessagePayload)
                {
                    MessagePayload msgpl = (MessagePayload)response.payload;
                    log.ErrorFormat("Message received from device: {0}", msgpl.Message);
                    throw new Exception(String.Format("Message received from device: {0}", msgpl.Message));
                }
            }
        }