Пример #1
0
        internal bool FixAavFile18Aug(string fileName, int firstFrame, int lastFrame)
        {
            fileName = m_FileName;
            string newFile = Path.ChangeExtension(fileName, ".new.aav");

            File.Copy(fileName, newFile, true);

            using (FileStream fsr = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                using (BinaryReader reader = new BinaryReader(fsr))
                    using (FileStream fs = new FileStream(newFile, FileMode.Open, FileAccess.Write))
                        using (BinaryWriter writer = new BinaryWriter(fs))
                        {
                            uint numFrames = m_Index.NumberOfFrames;

                            long ZEROTICKS = (new DateTime(2013, 8, 18).Ticks - ADV_ZERO_DATE_REF.Ticks) / 10000;

                            for (int i = 0; i < numFrames; i++)
                            {
                                AdvFramesIndexEntry entry = m_Index.Index[i];

                                uint elapsedMiliseconds = (uint)entry.ElapsedTime.TotalMilliseconds;
                                long offset             = entry.Offset;
                                uint length             = entry.Length;

                                object[]      data       = GetFrameSectionData(i, null);
                                AdvImageData  imageData  = (AdvImageData)data[0];
                                AdvStatusData statusData = (AdvStatusData)data[1];

                                AdvTagDefinition startTS = StatusSection.TagDefinitions[3];
                                AdvTagDefinition endTS   = StatusSection.TagDefinitions[4];
                                AdvTagDefinition gpsFix  = StatusSection.TagDefinitions[7];

                                string startTSString = statusData.TagValues[startTS];
                                string endTSString   = statusData.TagValues[endTS];
                                string gpsFixString  = statusData.TagValues[gpsFix];

                                long ticksStart = FixOSD(ref startTSString, true);
                                long ticksEnd   = FixOSD(ref endTSString, false);

                                long midTicks     = ZEROTICKS + (ticksStart - 20 * 10000 + ticksEnd) / 20000;
                                long exposureMs10 = new TimeSpan(ticksEnd - ticksStart + 20 * 10000).Milliseconds * 10;

                                fsr.Seek(12 + (4 + entry.Offset), SeekOrigin.Begin);
                                int bytesToSkip = reader.ReadInt32();

                                WriteInt16((short)exposureMs10, 8 + (4 + entry.Offset), writer, reader);
                                WriteInt64(midTicks, (4 + entry.Offset), writer, reader);

                                WriteString(startTSString, 16 + (4 + entry.Offset) + bytesToSkip + 0x22, writer, reader);
                                WriteString(endTSString, 16 + (4 + entry.Offset) + bytesToSkip + 0x43, writer, reader);

                                int gspFixByte = int.Parse(gpsFixString);
                                if (gspFixByte >= 1)
                                {
                                    gspFixByte++;
                                }

                                WriteInt8((byte)gspFixByte, 16 + (4 + entry.Offset) + bytesToSkip + 0x1f, writer, reader);
                                //writer.Write(elapsedMiliseconds);
                                //writer.Write(offset);
                                //writer.Write(length);
                            }

                            fs.Flush();
                        }

            return(false);
        }
Пример #2
0
 public void AddTagDefinition(AdvTagDefinition tagDefinition)
 {
     m_TagDefinitions.Add(tagDefinition);
 }
Пример #3
0
        public object GetDataFromDataBytes(byte[] bytes, ushort[,] prevFrame, int size, int startIndex)
        {
            var rv = new AdvStatusData();

            if (size > 0)
            {
                byte tagValuesCount = bytes[startIndex];
                startIndex++;

                for (int i = 0; i < tagValuesCount; i++)
                {
                    int tagId = bytes[startIndex];
                    AdvTagDefinition tagDef = m_TagDefinitions[tagId];

                    if (tagDef.Type == AdvTagType.UInt8)
                    {
                        byte value = bytes[startIndex + 1];
                        rv.TagValues[tagDef] = value.ToString();

                        startIndex += 2;
                    }
                    else if (tagDef.Type == AdvTagType.UInt16)
                    {
                        byte   b1    = bytes[startIndex + 1];
                        byte   b2    = bytes[startIndex + 2];
                        ushort value = (ushort)((b2 << 8) + b1);
                        rv.TagValues[tagDef] = value.ToString();

                        startIndex += 3;
                    }
                    else if (tagDef.Type == AdvTagType.UInt32)
                    {
                        byte b1 = bytes[startIndex + 1];
                        byte b2 = bytes[startIndex + 2];
                        byte b3 = bytes[startIndex + 3];
                        byte b4 = bytes[startIndex + 4];

                        uint value = (uint)((b4 << 24) + (b3 << 16) + (b2 << 8) + b1);
                        rv.TagValues[tagDef] = value.ToString();

                        startIndex += 5;
                    }
                    else if (tagDef.Type == AdvTagType.Real)
                    {
                        byte b1 = bytes[startIndex + 1];
                        byte b2 = bytes[startIndex + 2];
                        byte b3 = bytes[startIndex + 3];
                        byte b4 = bytes[startIndex + 4];

                        uint value = (uint)((b4 << 24) + (b3 << 16) + (b2 << 8) + b1);

                        IntToFloatStruct converter = new IntToFloatStruct();
                        converter.UInt32Value = value;
                        float realValue = converter.RealValue;

                        rv.TagValues[tagDef] = realValue.ToString();

                        startIndex += 5;
                    }
                    else if (tagDef.Type == AdvTagType.ULong64)
                    {
                        byte b1 = bytes[startIndex + 1];
                        byte b2 = bytes[startIndex + 2];
                        byte b3 = bytes[startIndex + 3];
                        byte b4 = bytes[startIndex + 4];
                        byte b5 = bytes[startIndex + 5];
                        byte b6 = bytes[startIndex + 6];
                        byte b7 = bytes[startIndex + 7];
                        byte b8 = bytes[startIndex + 8];

                        uint valLo = (uint)((b4 << 24) + (b3 << 16) + (b2 << 8) + b1);
                        uint valHi = (uint)((b8 << 24) + (b7 << 16) + (b6 << 8) + b5);
                        long value = (((long)valHi) << 32) + (long)valLo;
                        rv.TagValues[tagDef] = value.ToString();

                        startIndex += 9;
                    }
                    else if (tagDef.Type == AdvTagType.AnsiString254)
                    {
                        byte   len           = bytes[startIndex + 1];
                        byte[] tagValuebytes = new byte[len];
                        Array.Copy(bytes, startIndex + 2, tagValuebytes, 0, len);

                        rv.TagValues[tagDef] = Encoding.ASCII.GetString(tagValuebytes);

                        startIndex += 2 + len;
                    }
                    else if (tagDef.Type == AdvTagType.List16AnsiString254)
                    {
                        StringBuilder bld   = new StringBuilder();
                        byte          count = bytes[startIndex + 1];
                        startIndex += 2;
                        for (int j = 0; j < count; j++)
                        {
                            byte   len           = bytes[startIndex];
                            byte[] tagValuebytes = new byte[len];
                            Array.Copy(bytes, startIndex + 1, tagValuebytes, 0, len);

                            bld.AppendLine(Encoding.ASCII.GetString(tagValuebytes));

                            startIndex += 1 + len;
                        }

                        rv.TagValues[tagDef] = bld.ToString();
                    }
                }
            }

            return(rv);
        }
Пример #4
0
 public void AddTagDefinition(AdvTagDefinition tagDefinition)
 {
     m_TagDefinitions.Add(tagDefinition);
 }