예제 #1
0
        private static object GetSerializableObjects(CurdayHeader header)
        {
            string unknownFlagsString = $"{FormatHelpers.BooleanToYNFlag(header.UnknownFlag1)}{FormatHelpers.BooleanToYNFlag(header.UnknownFlag2)}{FormatHelpers.BooleanToYNFlag(header.UnknownFlag3)}{FormatHelpers.BooleanToYNFlag(header.UnknownFlag4)}{FormatHelpers.BooleanToYNFlag(header.UnknownFlag5)}{FormatHelpers.BooleanToYNFlag(header.UnknownFlag6)}{FormatHelpers.BooleanToYNFlag(header.UnknownFlag7)}{FormatHelpers.BooleanToYNFlag(header.UnknownFlag8)}";

            return(new
            {
                diagnosticsBCK = header.DiagnosticsBCK,
                diagnosticsFWD = header.DiagnosticsFWD,
                scrollSpeed = header.ScrollSpeed,
                numberOfTextAdsAllowedA = header.NumberOfTextAdsAllowedA,
                numberOfTextAdsAllowedB = header.NumberOfTextAdsAllowedB,
                numberOfLinesInTextAd = header.NumberOfLinesInTextAd,
                grphDST = header.GrphDST,
                timezone = header.Timezone,
                unknownFlags = unknownFlagsString,
                diagnosticsVIN = header.DiagnosticsVIN,
                unknownValue1 = header.UnknownValue1,
                dataRevisionNumber = header.DataRevisionValue,
                weatherAirportCode = header.WeatherAirportCode,
                weatherDisplayCityName = header.WeatherCityDisplayName,
                julianDate = header.JulianDate,
                numberOfChannels = header.NumberOfChannels,
                unknownValue2 = header.UnknownValue2,
                unknownValue3 = header.UnknownValue3
            });
        }
예제 #2
0
        private static CurdayHeader Deserialize(JToken token)
        {
            CurdayHeader result = new CurdayHeader();

            string unknownFlags = (string)token["unknownFlags"];

            result.DiagnosticsBCK          = (char)token["diagnosticsBCK"];
            result.DiagnosticsFWD          = (char)token["diagnosticsFWD"];
            result.ScrollSpeed             = (int)token["scrollSpeed"];
            result.NumberOfTextAdsAllowedA = (int)token["numberOfTextAdsAllowedA"];
            result.NumberOfTextAdsAllowedB = (int)token["numberOfTextAdsAllowedB"];
            result.NumberOfLinesInTextAd   = (int)token["numberOfLinesInTextAd"];
            result.GrphDST                = (bool)token["grphDST"];
            result.Timezone               = (int)token["timezone"];
            result.UnknownFlag1           = (unknownFlags[0] == 'Y');
            result.UnknownFlag2           = (unknownFlags[1] == 'Y');
            result.UnknownFlag3           = (unknownFlags[2] == 'Y');
            result.UnknownFlag4           = (unknownFlags[3] == 'Y');
            result.UnknownFlag5           = (unknownFlags[4] == 'Y');
            result.UnknownFlag6           = (unknownFlags[5] == 'Y');
            result.UnknownFlag7           = (unknownFlags[6] == 'Y');
            result.UnknownFlag8           = (unknownFlags[7] == 'Y');
            result.DiagnosticsVIN         = (char)token["diagnosticsVIN"];
            result.UnknownValue1          = (char)token["unknownValue1"];
            result.DataRevisionValue      = (int)token["dataRevisionNumber"];
            result.WeatherAirportCode     = (string)token["weatherAirportCode"];
            result.WeatherCityDisplayName = (string)token["weatherDisplayCityName"];
            result.NumberOfChannels       = (int)token["numberOfChannels"];
            result.UnknownValue2          = (int)token["unknownValue2"];
            result.UnknownValue3          = (int)token["unknownValue3"];

            return(result);
        }
예제 #3
0
        private static CurdayHeader ReadHeader(BinaryReader reader)
        {
            CurdayHeader result = new CurdayHeader();

            // Read Diagnostics BCK (ASCII char, one byte)
            result.DiagnosticsBCK = reader.ReadChar();

            // Read Diagnostics FWD (ASCII char, one byte)
            result.DiagnosticsFWD = reader.ReadChar();

            // Read Scroll Speed (ASCII char, one byte, number in range 0..7 inclusive)
            char scrollSpeed = reader.ReadChar();

            if (!(new char[] { '0', '1', '2', '3', '4', '5', '6', '7' }).Contains(scrollSpeed))
            {
                throw new IOException($"Read invalid scroll speed value {scrollSpeed}. Expected number between 0 and 7.");
            }
            result.ScrollSpeed = int.Parse(scrollSpeed.ToString());

            // Read Number of Text Ads Allowed A (ASCII char, one byte, number in range 0..9 inclusive)
            char numberOfTextAdsAllowedA = reader.ReadChar();

            if (!char.IsNumber(numberOfTextAdsAllowedA))
            {
                throw new IOException($"Read invalid number of text ads allowed A value {numberOfTextAdsAllowedA}. Expected number between 0 and 9.");
            }
            result.NumberOfTextAdsAllowedA = int.Parse(numberOfTextAdsAllowedA.ToString());

            // Read Number of Text Ads Allowed B (ASCII char, one byte, number in range 0..9 inclusive)
            char numberOfTextAdsAllowedB = reader.ReadChar();

            if (!char.IsNumber(numberOfTextAdsAllowedB))
            {
                throw new IOException($"Read invalid number of text ads allowed B value {numberOfTextAdsAllowedB}. Expected number between 0 and 9.");
            }
            result.NumberOfTextAdsAllowedB = int.Parse(numberOfTextAdsAllowedB.ToString());

            // Read Number of Lines in Text Ad (ASCII char, one byte, number in range 0..9 inclusive)
            char numberOfLinesInTextAd = reader.ReadChar();

            if (!char.IsNumber(numberOfLinesInTextAd))
            {
                throw new IOException($"Read invalid number of lines in text ad {numberOfLinesInTextAd}. Expected number between 0 and 9.");
            }
            result.NumberOfLinesInTextAd = int.Parse(numberOfLinesInTextAd.ToString());

            // Read GRPH DST (ASCII char, one byte, either Y or N)
            char grphDST = reader.ReadChar();

            result.GrphDST = ReadYNFlag(grphDST, "GRPH DST");

            // Skip ETX SOH (two bytes).
            reader.BaseStream.Position += 2;

            // Read timezone (ASCII char, one byte)
            result.Timezone = int.Parse(reader.ReadChar().ToString());

            // Read flags (8 ASCII chars, eight bytes, all Y or N)
            result.UnknownFlag1 = ReadYNFlag(reader.ReadChar(), "unknown flag 1");
            result.UnknownFlag2 = ReadYNFlag(reader.ReadChar(), "unknown flag 2");
            result.UnknownFlag3 = ReadYNFlag(reader.ReadChar(), "unknown flag 3");
            result.UnknownFlag4 = ReadYNFlag(reader.ReadChar(), "unknown flag 4");
            result.UnknownFlag5 = ReadYNFlag(reader.ReadChar(), "unknown flag 5");
            result.UnknownFlag6 = ReadYNFlag(reader.ReadChar(), "unknown flag 6");
            result.UnknownFlag7 = ReadYNFlag(reader.ReadChar(), "unknown flag 7");
            result.UnknownFlag8 = ReadYNFlag(reader.ReadChar(), "unknown flag 8");

            // Read Diagnostics VIN (ASCII char, one byte)
            result.DiagnosticsVIN = reader.ReadChar();

            // Skip two null bytes
            reader.BaseStream.Position += 2;

            // Read the unknown value (ASCII char, one bytes)
            result.UnknownValue1 = reader.ReadChar();

            // Skip null byte
            reader.BaseStream.Position += 1;

            // Read data revision number (null-terminated string, takes the form "DREV #").
            string dataRevisionText         = reader.ReadNTString();
            string dataRevisionNumberString = dataRevisionText.Split(' ')[1];
            int    dataRevisionNumber;

            if (!int.TryParse(dataRevisionNumberString, out dataRevisionNumber))
            {
                throw new IOException($"Invalid data revision number value {dataRevisionNumberString}. Expected number.");
            }
            result.DataRevisionValue = dataRevisionNumber;

            // Read weather airport code (null-terminated string).
            result.WeatherAirportCode = reader.ReadNTString();

            // Read weather city display name (null-terminated string).
            result.WeatherCityDisplayName = reader.ReadNTString();

            // Read julian date
            string julianDateString = reader.ReadNTString();
            byte   julianDate;

            if (!byte.TryParse(julianDateString, out julianDate))
            {
                throw new IOException($"Invalid Julian date value {julianDateString}. Expected number between 0 and 255.");
            }
            result.JulianDate = julianDate;

            // Read number of channels (null-terminated string).
            result.NumberOfChannels = int.Parse(reader.ReadNTString());

            // Read two unknown values
            result.UnknownValue2 = int.Parse(reader.ReadNTString());
            result.UnknownValue3 = int.Parse(reader.ReadNTString());

            return(result);
        }
예제 #4
0
        private static void WriteHeader(CurdayHeader header, BinaryWriter file)
        {
            // Write Diagnostics BCK (ASCII char, one byte)
            file.Write((byte)header.DiagnosticsBCK);

            // Write Diagnostics FWD (ASCII char, one byte)
            file.Write((byte)header.DiagnosticsFWD);

            // Write Scroll Speed (ASCII char, one byte, number in range 0..7 inclusive)
            file.Write((byte)(header.ScrollSpeed + 0x30));

            // Write Number of Text Ads Allowed A (ASCII char, one byte, number in range 0..9
            // inclusive)
            file.Write((byte)(header.NumberOfTextAdsAllowedA + 0x30));

            // Write Number of Text Ads Allowed B (ASCII char, one byte, number in range 0..9
            // inclusive)
            file.Write((byte)(header.NumberOfTextAdsAllowedB + 0x30));

            // Write Number of Lines in Text Ad (ASCII char, one byte, number in range 0..9
            // inclusive)
            file.Write((byte)(header.NumberOfLinesInTextAd + 0x30));

            // Write GRPH DST (ASCII char, one byte, either Y or N)
            file.Write((header.GrphDST) ? 'Y' : 'N');

            // Write ETX SOH (two bytes)
            file.Write((byte)0x03);
            file.Write((byte)0x01);

            // Write timezone (ASCII char, one byte)
            file.Write((byte)(header.Timezone + 0x30));

            // Write flags (8 ASCII chars, eight bytes, all Y or N)
            file.Write((header.UnknownFlag1) ? 'Y' : 'N');
            file.Write((header.UnknownFlag2) ? 'Y' : 'N');
            file.Write((header.UnknownFlag3) ? 'Y' : 'N');
            file.Write((header.UnknownFlag4) ? 'Y' : 'N');
            file.Write((header.UnknownFlag5) ? 'Y' : 'N');
            file.Write((header.UnknownFlag6) ? 'Y' : 'N');
            file.Write((header.UnknownFlag7) ? 'Y' : 'N');
            file.Write((header.UnknownFlag8) ? 'Y' : 'N');

            // Write Diagnostics VIN (ASCII char, one byte)
            file.Write(header.DiagnosticsVIN);

            // Write two null bytes
            file.Write((byte)0x00);
            file.Write((byte)0x00);

            // Write the unknown value (ASCII char, one byte)
            file.Write(header.UnknownValue1);

            // Write null byte
            file.Write((byte)0x00);

            // Write data revision number (null-terminated string, takes the form "DREV #")
            string dataRevisionNumber = $"DREV {header.DataRevisionValue}";

            file.WriteNTString(dataRevisionNumber);

            // Write weather airport code (null-terminated string).
            file.WriteNTString(header.WeatherAirportCode);

            // Write weather city display name (null-terminated string).
            file.WriteNTString(header.WeatherCityDisplayName);

            // Write julian date
            file.Write(header.JulianDate);

            // Write number of channels
            file.WriteNTString(header.NumberOfChannels.ToString());

            // Write unknown values
            file.WriteNTString(header.UnknownValue2.ToString());
            file.WriteNTString(header.UnknownValue3.ToString());
        }