Exemplo n.º 1
0
        private static bool validarComando(byte[] pacote, int codigoComandoEsperado)
        {
            if ((Conversor.byteToInt(pacote[Protocol.INDICE_COMANDO_RETORNO]) != codigoComandoEsperado))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public static String bytesCodigoToString(byte[] bytes)
        {
            int qtdBytes = bytes.Length;

            int[] dadosInt = new int[qtdBytes];
            for (int i = 0; (i < qtdBytes); i++)
            {
                dadosInt[i] = Conversor.byteToInt(bytes[i]);
            }

            return(Convert.ToString(((dadosInt[0] * PESO_2)
                                     + ((dadosInt[1] * PESO_1)
                                        + dadosInt[2]))));
        }
Exemplo n.º 3
0
        public override ErrorCommand tratarResposta(int codigoComandoEsperado, byte[] dados, int qdeRecebida, int qdeEsperada)
        {
            ErrorCommand errorCommand = new ErrorCommand(ErrorCommand.SUCESSO);

            try
            {
                // Conversão do Identificador (CNPJ/CPF)
                byte[] bytesIdentificador = new byte[Protocol.TAMANHO_IDENTIFICADOR_EMPREGADOR];
                for (int i = 0, j = Protocol.INDICE_IDENTIFICADOR_EMPREGADOR;
                     i < Protocol.TAMANHO_IDENTIFICADOR_EMPREGADOR &&
                     j < Protocol.INDICE_IDENTIFICADOR_EMPREGADOR + Protocol.TAMANHO_IDENTIFICADOR_EMPREGADOR;
                     i++, j++)
                {
                    bytesIdentificador[i] = dados[j];
                }
                String identificador = Conversor.bytesIdentificadorToString(bytesIdentificador);

                int tipoIdentificador = Conversor.byteToInt(dados[Protocol.INDICE_TIPO_IDENTIFICADOR_EMPREGADOR]);

                company.cnpj = identificador;

                // Conversão do CEI
                byte[] bytesCEI = new byte[Protocol.TAMANHO_CEI_EMPREGADOR];
                for (int i = 0, j = Protocol.INDICE_CEI_EMPREGADOR;
                     i < Protocol.TAMANHO_CEI_EMPREGADOR &&
                     j < Protocol.INDICE_CEI_EMPREGADOR + Protocol.TAMANHO_CEI_EMPREGADOR;
                     i++, j++)
                {
                    bytesCEI[i] = dados[j];
                }
                company.cei = Conversor.bytesCEIToString(bytesCEI);

                // Conversão da Razão Social
                byte[] bytesRazaoSocial = new byte[Protocol.TAMANHO_RAZAO_SOCIAL_EMPREGADOR];
                for (int i = 0, j = Protocol.INDICE_RAZAO_SOCIAL_EMPREGADOR;
                     i < Protocol.TAMANHO_RAZAO_SOCIAL_EMPREGADOR &&
                     j < Protocol.INDICE_RAZAO_SOCIAL_EMPREGADOR + Protocol.TAMANHO_RAZAO_SOCIAL_EMPREGADOR;
                     i++, j++)
                {
                    bytesRazaoSocial[i] = dados[j];
                }
                company.companyName = Conversor.bytesASCIIToString(bytesRazaoSocial);

                // Conversão do Local da Prestação de Serviço
                byte[] bytesLocalPrestacaoServico = new byte[Protocol.TAMANHO_LOCAL_EMPREGADOR];
                for (int i = 0, j = Protocol.INDICE_LOCAL_EMPREGADOR;
                     i < Protocol.TAMANHO_LOCAL_EMPREGADOR &&
                     j < Protocol.INDICE_LOCAL_EMPREGADOR + Protocol.TAMANHO_LOCAL_EMPREGADOR;
                     i++, j++)
                {
                    bytesLocalPrestacaoServico[i] = dados[j];
                }
                company.address = Conversor.bytesASCIIToString(bytesLocalPrestacaoServico);
            }
            catch (Exception e)
            {
                errorCommand.setErro(ErrorCommand.RETORNO_INCONSISTENTE);
            }

            return(errorCommand);
        }