示例#1
0
        /*
         * public void Salvar(string diretorio_fonte, String diretorio_saida ,ControladorPontos.Controlador Ctrdl)
         * {
         *  List<string> rots = Directory.EnumerateFiles(diretorio_fonte, "*.rot").ToList();
         *
         *  for (int painel = 0; painel < Ctrdl.QuantidadePaineis; painel++)
         *  {
         *      foreach (String s in rots)
         *      {
         *          Arquivo_RPT arpt = new Arquivo_RPT();
         *
         *          arpt.CriarRoteirosPathPadrao();
         *
         *          //criar um arquivo de vídeo para cada entidade.
         *          arpt.pathExibicaoIda = "videos/" + painel.ToString("d3") + ".v01";
         *          arpt.pathExibicaoVolta = "videos/" + painel.ToString("d3") + ".v01";
         *          arpt.pathNumeroRoteiro = "videos/" + painel.ToString("d3") + ".v01";
         *
         *          arpt.Salvar(diretorio_saida + @"\" + painel.ToString("d2") + @"\roteiros\" +
         *                      s.Substring(s.Length - 7, 3) + ".rpt");
         *      }
         *  }
         * }
         */
        private byte[] toByteArray()
        {
            unsafe
            {
                Byte[] resultado = new Byte[sizeof(FormatoRoteiroPaths)];

                fixed(byte *pSrc = resultado)
                {
                    FormatoRoteiroPaths *roteiroPaths = (FormatoRoteiroPaths *)pSrc;

                    roteiroPaths->versao    = this.versao;
                    roteiroPaths->reservado = this.reservado;
                    roteiroPaths->idRoteiro = this.idRoteiro;
                    for (int i = 0; i < 58; i++)
                    {
                        roteiroPaths->reservado2[i] = this.reservado2[i];
                    }
                    roteiroPaths->crc = this.crc;
                    ArrayLDX2.StringToByteArray(roteiroPaths->pathExibicaoIda, this.pathExibicaoIda, 64);
                    ArrayLDX2.StringToByteArray(roteiroPaths->pathExibicaoVolta, this.pathExibicaoVolta, 64);
                    ArrayLDX2.StringToByteArray(roteiroPaths->pathNumeroRoteiro, this.pathNumeroRoteiro, 64);

                    return(resultado);
                }
            }
        }
示例#2
0
        public unsafe void AtualizarCRC()
        {
            Byte[] dados = toByteArray();

            fixed(byte *pSrc = dados)
            {
                FormatoRoteiroPaths *roteiroPath = (FormatoRoteiroPaths *)pSrc;

                this.crc = CalcularCRC(dados);
            }
        }
示例#3
0
        public bool VerificarCRC(byte[] dados)
        {
            unsafe
            {
                fixed(byte *pSrc = dados)
                {
                    FormatoRoteiroPaths *roteiros = (FormatoRoteiroPaths *)pSrc;

                    return(roteiros->crc == CalcularCRC(dados));
                }
            }
        }
示例#4
0
        private unsafe UInt16 CalcularCRC(Byte[] dados)
        {
            int tamanho;

            Byte[] dadosCRC = new byte[dados.Length - sizeof(UInt16)];

            fixed(byte *pSrc = dados)
            {
                FormatoRoteiroPaths *roteiros = (FormatoRoteiroPaths *)pSrc;

                Array.Copy(dados, 0, dadosCRC, 0, (int)&roteiros->crc - (int)pSrc);
                Array.Copy(dados,
                           ((int)&roteiros->crc - (int)pSrc + sizeof(UInt16)),
                           dadosCRC,
                           (int)&roteiros->crc - (int)pSrc,
                           dados.Length - ((int)&roteiros->crc - (int)pSrc + sizeof(UInt16)));

                return(CRC16CCITT.Calcular(dadosCRC));
            }
        }
示例#5
0
        private void FromBytesToFormatoPainelCfg(byte[] dados)
        {
            unsafe
            {
                fixed(byte *pSrc = dados)
                {
                    FormatoRoteiroPaths *roteiroPaths = (FormatoRoteiroPaths *)pSrc;

                    this.versao    = roteiroPaths->versao;
                    this.reservado = roteiroPaths->reservado;
                    this.idRoteiro = roteiroPaths->idRoteiro;

                    for (int i = 0; i < 58; i++)
                    {
                        this.reservado2[i] = roteiroPaths->reservado2[i];
                    }
                    this.crc = roteiroPaths->crc;

                    this.pathExibicaoIda   = ArrayLDX2.ByteArrayToString(roteiroPaths->pathExibicaoIda, 64);
                    this.pathExibicaoVolta = ArrayLDX2.ByteArrayToString(roteiroPaths->pathExibicaoVolta, 64);
                    this.pathNumeroRoteiro = ArrayLDX2.ByteArrayToString(roteiroPaths->pathNumeroRoteiro, 64);
                }
            }
        }
示例#6
0
        public void GerarFormatoNovo(string arquivoNome, string diretorioRaiz)
        {
            UInt32     offsetIda    = 0;
            UInt32     offsetVolta  = 0;
            UInt32     offsetNumero = 0;
            FileStream fs           = File.OpenRead(arquivoNome + Util.Util.sequencial_arquivo_roteiros.ToString("X8") + Util.Util.ARQUIVO_EXT_RPT);

            byte[] dados = new byte[(int)fs.Length];
            fs.Read(dados, 0, dados.Length);
            fs.Close();

            unsafe
            {
                fixed(byte *pSrc = dados)
                {
                    FormatoRoteiroPaths *roteiroPaths = (FormatoRoteiroPaths *)pSrc;

                    this.versao    = roteiroPaths->versao;
                    this.reservado = roteiroPaths->reservado;
                    this.idRoteiro = roteiroPaths->idRoteiro;
                    for (int i = 0; i < 58; i++)
                    {
                        this.reservado2[i] = roteiroPaths->reservado2[i];
                    }
                    this.crc = roteiroPaths->crc;

                    this.pathExibicaoIda   = Util.Util.TrataDiretorio(ArrayLDX2.ByteArrayToString(roteiroPaths->pathExibicaoIda, 64));
                    this.pathExibicaoVolta = Util.Util.TrataDiretorio(ArrayLDX2.ByteArrayToString(roteiroPaths->pathExibicaoVolta, 64));
                    this.pathNumeroRoteiro = Util.Util.TrataDiretorio(ArrayLDX2.ByteArrayToString(roteiroPaths->pathNumeroRoteiro, 64));
                }

                if (this.pathExibicaoIda.Contains(":"))
                {
                    fs = File.OpenRead(this.pathExibicaoIda);
                }
                else
                {
                    fs = File.OpenRead(diretorioRaiz + this.pathExibicaoIda);
                }

                byte[] dadosVideoIda = new byte[(int)fs.Length];
                fs.Read(dadosVideoIda, 0, dadosVideoIda.Length);
                fs.Close();

                offsetIda = 64;
                Array.Resize(ref dados, (dados.Length - (3 * 64)) + dadosVideoIda.Length);
                Array.Copy(dadosVideoIda, 0, dados, offsetIda, dadosVideoIda.Length);

                if (this.pathExibicaoVolta.Contains(":"))
                {
                    fs = File.OpenRead(this.pathExibicaoVolta);
                }
                else
                {
                    fs = File.OpenRead(diretorioRaiz + this.pathExibicaoVolta);
                }

                byte[] dadosVideoVolta = new byte[(int)fs.Length];
                fs.Read(dadosVideoVolta, 0, dadosVideoVolta.Length);
                fs.Close();

                offsetVolta = (UInt32)(offsetIda + dadosVideoIda.Length);
                Array.Resize(ref dados, dados.Length + dadosVideoVolta.Length);
                Array.Copy(dadosVideoVolta, 0, dados, offsetVolta, dadosVideoVolta.Length);

                if (this.pathNumeroRoteiro.Contains(":"))
                {
                    fs = File.OpenRead(this.pathNumeroRoteiro);
                }
                else
                {
                    fs = File.OpenRead(diretorioRaiz + this.pathNumeroRoteiro);
                }
                byte[] dadosVideoNumero = new byte[(int)fs.Length];
                fs.Read(dadosVideoNumero, 0, dadosVideoNumero.Length);
                fs.Close();

                offsetNumero = (UInt32)(offsetVolta + dadosVideoVolta.Length);
                Array.Resize(ref dados, dados.Length + dadosVideoNumero.Length);
                Array.Copy(dadosVideoNumero, 0, dados, offsetNumero, dadosVideoNumero.Length);

                BitConverter.GetBytes(offsetIda).CopyTo(dados, 4);
                BitConverter.GetBytes(offsetVolta).CopyTo(dados, 8);
                BitConverter.GetBytes(offsetNumero).CopyTo(dados, 12);

                fixed(byte *pSrc = dados)
                {
                    FormatoRoteiroPaths *roteiroPaths = (FormatoRoteiroPaths *)pSrc;

                    roteiroPaths->crc = CalcularCRC(dados);

                    BitConverter.GetBytes(roteiroPaths->crc).CopyTo(dados, Util.Util.CRCPosition1);
                }

                fs = File.Create(arquivoNome + Util.Util.sequencial_arquivo_roteiros.ToString("X8") + Util.Util.ARQUIVO_EXT_RPT);
                fs.Write(dados, 0, dados.Length);
                fs.Close();
            }
        }