Exemplo n.º 1
0
        public UInt32[] TxDelayCalcualtor(int channel, int steerAngle)
        {
            UInt32[] TxDelay     = new UInt32[channel];
            Int32[]  TxDelayTemp = new Int32[channel];

            double ts = 1 / fs;
            double d0 = c0 * ts;

            double[] txPosition = new double[channel];

            for (int i = 0; i < channel; i++)
            {
                txPosition[i] = elementPitch * ((double)(i + 1) / 2.0 - 0.5);
            }

            double angle = steerAngle * Math.PI / 180.0;

            for (int i = 0; i < channel; i++)
            {
                double txDistance = txPosition[i] * Math.Sin(angle);
                double Temp       = txDistance / d0;
                TxDelayTemp[i] = MathMethod.ROUND(Temp);
            }

            int minTxDelay = MathMethod.MIN(TxDelayTemp);

            for (int i = 0; i < TxDelay.Count(); i++)
            {
                TxDelay[i] = (uint)(1024 - (TxDelayTemp[i] - minTxDelay));
            }

            return(TxDelay);
        }
Exemplo n.º 2
0
        public static void extractFiles(byte[] file, string path)
        {
            MemoryStream     src = new MemoryStream(file);
            BinaryDataReader br  = new BinaryDataReader(src);

            //Read files.
            int number = 0;

            //Map file.
            List <string> mapFile = new List <string>();

            // Map File: Offset; Size; Filename; Add_Name_Here
            mapFile.Add("How the format works: Offset; Size; Filename; Name For Injector To Read");

            string[] magicNumbers    = { "CWSD", "FWSD", "CSEQ", "FSEQ", "CBNK", "FBNK", "CGRP", "FGRP", "CSTM", "FSTM", "CWAV", "FWAV", "CWAR", "FWAR" };
            UInt32[] magicNumbersBin = new UInt32[magicNumbers.Length];
            for (int i = 0; i < magicNumbers.Count(); i++)
            {
                byte[]           h   = Encoding.UTF8.GetBytes(magicNumbers[i]);
                MemoryStream     o2  = new MemoryStream(h);
                BinaryDataReader br2 = new BinaryDataReader(o2);
                br2.ByteOrder      = ByteOrder.BigEndian;
                magicNumbersBin[i] = br2.ReadUInt32();
            }

            br.ReadUInt32();
            while (br.Position <= file.Length - 4)
            {
                br.ByteOrder = ByteOrder.BigEndian;
                UInt32 magic = br.ReadUInt32();
                byte[] f;
                UInt16 t;
                UInt32 l;

                bool found = false;
                for (int i = 0; i < magicNumbersBin.Count(); i++)
                {
                    if (magic.Equals(magicNumbersBin[i]))
                    {
                        t     = br.ReadUInt16();
                        found = true;
                        if (t == 0xFFFE)
                        {
                            br.ByteOrder = ByteOrder.LittleEndian;
                        }
                        else
                        {
                            br.ByteOrder = ByteOrder.BigEndian;
                        }
                        br.ReadUInt16s(3);
                        l = br.ReadUInt32();

                        br.Position -= 16;
                        long position = br.Position;

                        f = br.ReadBytes((int)l);

                        Directory.CreateDirectory(path + "/" + magicNumbers[i]);
                        File.WriteAllBytes(path + "/" + magicNumbers[i] + "/" + number.ToString("D4") + ".b" + magicNumbers[i].ToLower(), f);

                        if (i == 0 || i == 1 || i == 6 || i == 7 || i == 12 || i == 13)
                        {
                            Directory.CreateDirectory(path + "/" + magicNumbers[i] + "/" + number.ToString("D4") + magicNumbers[i]);
                            extractFiles(f, path + "/" + magicNumbers[i] + "/" + number.ToString("D4") + magicNumbers[i]);
                        }

                        mapFile.Add(position + "; " + l + "; " + magicNumbers[i] + "/" + number.ToString("D4") + ".b" + magicNumbers[i].ToLower() + "; " + "ADD_CUSTOM_NAME_HERE!");

                        number += 1;
                    }
                }

                if (!found)
                {
                    br.Position -= 3;
                }
            }

            File.WriteAllLines(path + "/fileMap.txt", mapFile.ToArray());
        }