Пример #1
0
        public void ProcessLogResponse(Logger logger, IQcdmCommandResponse response)
        {
            if (response != null && logger != null)
            {
                var command = response.Command;
                switch (command)
                {
                case QcdmCommand.Log:
                    LogResponse(logger, (LogCommandResponse)response);
                    LogDelimeter(logger);
                    break;

                case QcdmCommand.Msg:
                    LogResponse(logger, (MsgCommandResponse)response);
                    LogDelimeter(logger);
                    break;

                case QcdmCommand.ExtMsg:
                    LogResponse(logger, (ExtMsgCommandResponse)response);
                    LogDelimeter(logger);
                    break;

                case QcdmCommand.EventReport:
                    LogResponse(logger, (EventReportCommandResponse)response);
                    LogDelimeter(logger);
                    break;
                }
            }
        }
Пример #2
0
        private IQcdmCommandResponse WriteCommandAndReadResponse(IQcdmCommandRequest request, byte[] data, bool logCommands)
        {
            IQcdmCommandResponse response = null;
            var counter = 10;

            while (!TryWriteCommandAndReadResponse(request, data, logCommands, ref response))
            {
                --counter;
                if (counter <= 0)
                {
                    throw new QcdmManagerException(Strings.InvalidResponseCrc);
                }
            }
            return(response);
        }
        public static IQcdmCommandResponse CommandResponse(QcdmCommand command, byte[] data)
        {
            IQcdmCommandResponse result = null;

            switch (command)
            {
            case QcdmCommand.SubsysCmd:
                result = CreateSubsysCommandResponse(data);
                break;

            default:
                result = CreateCommandResponse(command, data);
                break;
            }

            return(result);
        }
Пример #4
0
        public IQcdmCommandResponse ExecuteQcdmCommandRequest(IQcdmCommandRequest request)
        {
            if (!IsOpen)
            {
                throw new QcdmManagerException(Strings.QcdmSerialPortIsNotOpen);
            }

            var logCommands = false; //Debugger.IsAttached;
            var data        = request.GetData();

            if (logCommands)
            {
                LogCommandRequestDebug(request.Command, data);
            }

            _port.Write(data);

            var doRead = true;
            IQcdmCommandResponse response = null;
            var counter = 0;

            while (doRead)
            {
                var responseData = _port.Read();
                if (logCommands)
                {
                    LogCommandResponseDebug(request.Command, responseData);
                }

                response = CreateResponse(responseData);
                doRead   = response.Command != request.Command;
                ++counter;
                if (counter > 15)
                {
                    throw new QcdmManagerException(Strings.QcdmManyLogLines);
                }
            }

            return(response);
        }
Пример #5
0
        private bool TryWriteCommandAndReadResponse(IQcdmCommandRequest request, byte[] data, bool logCommands, ref IQcdmCommandResponse response)
        {
            try
            {
                _port.Write(data);

                var doRead  = true;
                var counter = 30;
                while (doRead)
                {
                    var responseData = _port.Read();
                    if (logCommands)
                    {
                        LogCommandResponseDebug(request.Command, responseData);
                    }

                    response = CreateResponse(responseData);
                    doRead   = response.Command != request.Command &&
                               response.Command != QcdmCommand.BadCmd &&
                               response.Command != QcdmCommand.BadLen &&
                               response.Command != QcdmCommand.BadParm;
                    if (doRead)
                    {
                        ProcessLogResponse(_logger, response);
                    }

                    --counter;
                    if (counter <= 0)
                    {
                        throw new QcdmManagerException(Strings.QcdmManyLogLines);
                    }
                }
                return(true);
            }
            catch (HdlcEncoderException ex)
            {
                if (ex.IsInvalidCrc)
                {
                    return(false);
                }
                throw ex;
            }
        }