示例#1
0
        static int Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            if (args.Length < 1)
            {
                Console.WriteLine("No input file specified");
                return(1);
            }

            string        fileSpec      = args[0];
            string        dir           = Path.GetDirectoryName(fileSpec);
            DirectoryInfo dirInfoParent = Directory.GetParent(dir);

            if (dirInfoParent == null)
            {
                Console.WriteLine("Invalid directory");
                return(1);
            }
            string rootDir       = dirInfoParent.FullName;
            string searchPattern = Path.GetFileName(fileSpec);

            if (dir == null || searchPattern == null)
            {
                Console.WriteLine("Invalid file name");
                return(1);
            }

            try
            {
                UdsReader udsReader = new UdsReader();
                if (!udsReader.Init(rootDir
                                    //, new HashSet<UdsReader.SegmentType>{ UdsReader.SegmentType.Mwb, UdsReader.SegmentType.Dtc }
                                    ))
                {
                    Console.WriteLine("Init failed");
                    return(1);
                }

                //Console.WriteLine(udsReader.TestFixedTypes());
                //return 0;
#if false
                StringBuilder sbVin = new StringBuilder();;
                sbVin.Append(@"WVWFA71F77V");
                for (char code = '0'; code <= 'Z'; code++)
                {
                    sbVin[9] = code;
                    int modelYear = DataReader.GetModelYear(sbVin.ToString());
                    Console.WriteLine("'{0}': {1}", code, modelYear);
                }
                return(0);
#endif
#if false
                PrintSaeErrorCode(udsReader, 0x161D, 0x71);
                PrintSaeErrorCode(udsReader, 0x161D, 0x03);
                PrintSaeErrorCode(udsReader, 0x161D, 0xF5);
                PrintSaeErrorCode(udsReader, 0x2634, 0xF5);
                PrintSaeErrorCode(udsReader, 0x4003, 0x96);
                PrintSaeErrorCode(udsReader, 0x900E, 0x96);
                PrintSaeErrorCode(udsReader, 0xD156, 0x75);
                PrintSaeErrorCode(udsReader, 0xD156, 0xF5);
                PrintSaeErrorCode(udsReader, 0xD156, 0x25);
                PrintSaeErrorCode(udsReader, 0x514E, 0xF0);
                PrintKwpErrorCode(udsReader, 0x036C, 0x6B);
                PrintKwpErrorCode(udsReader, 0x036D, 0x6B);
                PrintKwpErrorCode(udsReader, 0x05DF, 0x29);
                PrintKwpErrorCode(udsReader, 0x03A0, 0x28);
                PrintKwpErrorCode(udsReader, 0x045D, 0x68);
                PrintKwpErrorCode(udsReader, 0x038B, 0x60);
                PrintKwpErrorCode(udsReader, 0x0466, 0x28);
                PrintKwpErrorCode(udsReader, 0x4123, 0x28);
                PrintKwpErrorCode(udsReader, 0x4123, 0xA8);
                PrintKwpErrorCode(udsReader, 0x4523, 0x29);
                PrintKwpErrorCode(udsReader, 0x4923, 0x2A);
                PrintKwpErrorCode(udsReader, 0x4D23, 0x2B);
                PrintKwpErrorCode(udsReader, 0x7123, 0x2C);
                PrintKwpErrorCode(udsReader, 0x7523, 0x2D);
                PrintKwpErrorCode(udsReader, 0x6523, 0x2E);

                PrintIsoErrorCode(udsReader, 0x455B, 0x23);
                PrintIsoErrorCode(udsReader, 0x4474, 0xA3);
                PrintIsoErrorCode(udsReader, 0x0074, 0xA3);
                PrintSaeErrorDetail(udsReader, new byte[] { 0x6C, 0x01, 0x71, 0x11, 0x12, 0x13, 0x02, 0xFB, 0xC4, 0x00, 0x00, 0x49, 0x04, 0x51, 0x03 });
                PrintSaeErrorDetail(udsReader, new byte[] { 0x6C, 0x01, 0x71, 0x11, 0x12, 0x13, 0x02, 0xFB, 0xC4, 0x01, 0x00, 0x00, 0x00, 0x01, 0x02 });
                PrintUdsErrorDetail(udsReader, new byte[] { 0x59, 0x06, 0x00, 0x40, 0x11, 0x08, 0x01, 0x02, 0x01, 0x02, 0x1F, 0x00, 0x93, 0x13, 0x00,
                                                            0x00, 0x49, 0x56, 0xB0, 0xA3, 0x71, 0x00, 0x00, 0x80, 0x18, 0x12, 0x00, 0x00, 0x00, 0xCA, 0x84, 0x00, 0x00, 0xFF, 0x00, 0x00,
                                                            0x61, 0x02, 0x40, 0x00, 0x00, 0x00, 0x00, 0x10 });
                PrintUdsErrorDetail(udsReader, new byte[] { 0x59, 0x06, 0x10, 0x01, 0x06, 0x08, 0x01, 0x06, 0x01, 0x02, 0x94, 0x00, 0xA4, 0xFA, 0x00, 0x00, 0x49, 0xF8, 0xF7, 0x95, 0x71, 0x02, 0x86, 0x5B, 0x27, 0xBE, 0xBF, 0x01 });
                return(0);
#endif
#if false
                UdsReader.FileNameResolver fileNameResolver = new UdsReader.FileNameResolver(udsReader, "WVGZZZ1TZBW000000", "EV_ECM20TDI01103L906018DQ", "003003", "03L906018DQ", "1K0907951");
                //UdsReader.FileNameResolver fileNameResolver = new UdsReader.FileNameResolver(udsReader, "WVGZZZ1TZBW000000", "EV_Kombi_UDS_VDD_RM09", "A04089", "0920881A", "1K0907951");
                List <string> fileList = fileNameResolver.GetFileList(dir);
                foreach (string fileName in fileList)
                {
                    Console.WriteLine(fileName);
                }
                return(0);
#endif
#if false
                DataReader dataReader = new DataReader();
                DataReader.FileNameResolver fileNameResolver = new DataReader.FileNameResolver(dataReader, "03L906018DQ", string.Empty, 1);
                string fileName = fileNameResolver.GetFileName(Path.Combine(rootDir, DataReader.DataDir));
                if (!string.IsNullOrEmpty(fileName))
                {
                    List <DataReader.DataInfo> info = dataReader.ExtractDataType(fileName, DataReader.DataType.LongCoding);
                    foreach (DataReader.DataInfo dataInfo in info)
                    {
                        foreach (string text in dataInfo.TextArray)
                        {
                            Console.WriteLine(text);
                        }
                    }
                }
                return(0);
#endif
                _unknownIdDict = new Dictionary <UInt32, UInt32>();

                string[] files = Directory.GetFiles(dir, searchPattern, SearchOption.AllDirectories);
                foreach (string file in files)
                {
                    try
                    {
                        string fileExt = Path.GetExtension(file);
                        if (string.Compare(fileExt, DataReader.FileExtension, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            Console.WriteLine("Parsing: {0}", file);
                            string outFileData = Path.ChangeExtension(file, ".txt");
                            if (outFileData == null)
                            {
                                Console.WriteLine("*** Invalid output file");
                            }
                            else
                            {
                                using (StreamWriter outputStream = new StreamWriter(outFileData, false, new UTF8Encoding(true)))
                                {
                                    if (!ParseDataFile(udsReader.DataReader, file, outputStream))
                                    {
                                        Console.WriteLine("*** Parsing failed: {0}", file);
                                    }
                                }
                            }
                        }
                        else if (string.Compare(fileExt, UdsReader.FileExtension, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            string baseFile = Path.GetFileNameWithoutExtension(file);
                            if (baseFile == null || InvalidFileRegex.IsMatch(baseFile))
                            {
                                Console.WriteLine("Ignoring: {0}", file);
                                continue;
                            }
                            Console.WriteLine("Parsing: {0}", file);
                            string outFileUds = Path.ChangeExtension(file, ".txt");
                            if (outFileUds == null)
                            {
                                Console.WriteLine("*** Invalid output file");
                            }
                            else
                            {
                                using (StreamWriter outputStream = new StreamWriter(outFileUds, false, new UTF8Encoding(true)))
                                {
                                    if (!ParseUdsFile(udsReader, file, outputStream))
                                    {
                                        Console.WriteLine("*** Parsing failed: {0}", file);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("*** Exception {0}", e.Message);
                    }
                }

                if (_unknownIdDict.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    Console.WriteLine();
                    Console.WriteLine("Unknown IDs:");
                    foreach (UInt32 key in _unknownIdDict.Keys.OrderBy(x => x))
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(", ");
                        }
                        sb.Append($"{key}({_unknownIdDict[key]})");
                    }
                    sb.Insert(0, "Index: ");
                    Console.WriteLine(sb.ToString());
                    Console.WriteLine();

                    sb.Clear();
                    foreach (UInt32 key in _unknownIdDict.Keys.OrderByDescending(x => _unknownIdDict[x]))
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(", ");
                        }
                        sb.Append($"{key}({_unknownIdDict[key]})");
                    }
                    sb.Insert(0, "Value: ");
                    Console.WriteLine(sb.ToString());
                }
                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(1);
            }
        }
示例#2
0
        static int Main(string[] args)
        {
            Console.OutputEncoding = Encoding.UTF8;

            if (args.Length < 1)
            {
                Console.WriteLine("No input file specified");
                return(1);
            }

            string fileSpec      = args[0];
            string dir           = Path.GetDirectoryName(fileSpec);
            string searchPattern = Path.GetFileName(fileSpec);

            if (dir == null || searchPattern == null)
            {
                Console.WriteLine("Invalid file name");
                return(1);
            }

            try
            {
                UdsReader udsReader = new UdsReader();
                if (!udsReader.Init(dir))
                {
                    Console.WriteLine("Init failed");
                    return(1);
                }

                //Console.WriteLine(udsReader.TestFixedTypes());
                //return 0;
#if false
                UdsReader.FileNameResolver fileNameResolver = new UdsReader.FileNameResolver(udsReader, "EV_ECM20TDI01103L906018DQ", "003003", "03L906018DQ", "1K0907951");
                //UdsReader.FileNameResolver fileNameResolver = new UdsReader.FileNameResolver(udsReader, "EV_Kombi_UDS_VDD_RM09", "A04089", "0920881A", "1K0907951");
                List <string> fileList = fileNameResolver.GetFileList(dir);
                return(0);
#endif
#if false
                DataReader dataReader = new DataReader();
                DataReader.FileNameResolver fileNameResolver = new DataReader.FileNameResolver(dataReader, "03L906018DQ", 1);
                DirectoryInfo dirInfoParent = Directory.GetParent(dir);
                if (dirInfoParent != null)
                {
                    string fileName = fileNameResolver.GetFileName(Path.Combine(dirInfoParent.FullName, "Labels"));
                    if (!string.IsNullOrEmpty(fileName))
                    {
                        List <DataReader.DataInfo> info = dataReader.ExtractDataType(fileName, DataReader.DataType.Settings);
                    }
                }
                return(0);
#endif
                _unknownIdDict = new Dictionary <UInt32, UInt32>();

                string[] files = Directory.GetFiles(dir, searchPattern, SearchOption.AllDirectories);
                foreach (string file in files)
                {
                    try
                    {
                        string fileExt = Path.GetExtension(file);
                        if (string.Compare(fileExt, UdsReader.FileExtension, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            continue;
                        }

                        string baseFile = Path.GetFileNameWithoutExtension(file);
                        if (baseFile == null || InvalidFileRegex.IsMatch(baseFile))
                        {
                            Console.WriteLine("Ignoring: {0}", file);
                            continue;
                        }
                        Console.WriteLine("Parsing: {0}", file);
                        string outFile = Path.ChangeExtension(file, ".txt");
                        if (outFile == null)
                        {
                            Console.WriteLine("*** Invalid output file");
                        }
                        else
                        {
                            using (StreamWriter outputStream = new StreamWriter(outFile, false, new UTF8Encoding(true)))
                            {
                                if (!ParseFile(udsReader, file, outputStream))
                                {
                                    Console.WriteLine("*** Parsing failed: {0}", file);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("*** Exception {0}", e.Message);
                    }
                }

                if (_unknownIdDict.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    Console.WriteLine();
                    Console.WriteLine("Unknown IDs:");
                    foreach (UInt32 key in _unknownIdDict.Keys.OrderBy(x => x))
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(", ");
                        }
                        sb.Append($"{key}({_unknownIdDict[key]})");
                    }
                    sb.Insert(0, "Index: ");
                    Console.WriteLine(sb.ToString());
                    Console.WriteLine();

                    sb.Clear();
                    foreach (UInt32 key in _unknownIdDict.Keys.OrderByDescending(x => _unknownIdDict[x]))
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append(", ");
                        }
                        sb.Append($"{key}({_unknownIdDict[key]})");
                    }
                    sb.Insert(0, "Value: ");
                    Console.WriteLine(sb.ToString());
                }
                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(1);
            }
        }