Example #1
0
        static bool PrintUdsErrorDetail(UdsReader udsReader, byte[] data)
        {
            List <string> resultList = udsReader.ErrorDetailBlockToString(null, data);

            if (resultList == null)
            {
                return(false);
            }
            foreach (string line in resultList)
            {
                Console.WriteLine(line);
            }
            Console.WriteLine();

            return(true);
        }
Example #2
0
        static bool PrintSaeErrorDetail(UdsReader udsReader, byte[] data)
        {
            List <string> resultList = udsReader.DataReader.SaeErrorDetailHeadToString(data, udsReader);

            if (resultList == null)
            {
                return(false);
            }
            foreach (string line in resultList)
            {
                Console.WriteLine(line);
            }
            Console.WriteLine();

            return(true);
        }
Example #3
0
        static bool PrintErrorCode(UdsReader udsReader, uint errorCode, uint errorDetail, DataReader.ErrorType errorType)
        {
            List <string> resultList = udsReader.DataReader.ErrorCodeToString(errorCode, errorDetail, errorType, udsReader);

            if (resultList == null || resultList.Count == 0)
            {
                Console.WriteLine("Error code {0} invalid", errorCode);
                return(false);
            }
            foreach (string line in resultList)
            {
                Console.WriteLine(line);
            }
            Console.WriteLine();

            return(true);
        }
Example #4
0
 static bool PrintKwpErrorCode(UdsReader udsReader, uint errorCode, uint errorDetail)
 {
     return(PrintErrorCode(udsReader, errorCode, errorDetail, DataReader.ErrorType.Kwp2000));
 }
Example #5
0
 static bool PrintSaeErrorCode(UdsReader udsReader, uint errorCode, uint errorDetail)
 {
     return(PrintErrorCode(udsReader, errorCode, errorDetail, DataReader.ErrorType.Sae));
 }
Example #6
0
        static bool ParseUdsFile(UdsReader udsReader, string fileName, StreamWriter outStream)
        {
            try
            {
                List <string> includeFiles = udsReader.GetFileList(fileName);
                if (includeFiles == null)
                {
                    outStream.WriteLine("Get file list failed");
                    return(false);
                }

                outStream.WriteLine("Includes:");
                foreach (string includeFile in includeFiles)
                {
                    outStream.WriteLine(includeFile);
                }

                foreach (UdsReader.SegmentType segmentType in Enum.GetValues(typeof(UdsReader.SegmentType)))
                {
                    UdsReader.SegmentInfo segmentInfo = udsReader.GetSegmentInfo(segmentType);
                    if (segmentInfo == null || segmentInfo.Ignored)
                    {
                        outStream.WriteLine();
                        outStream.WriteLine("*** Ignoring segment: {0}", segmentType.ToString());
                        continue;
                    }
                    List <UdsReader.ParseInfoBase> resultList = udsReader.ExtractFileSegment(includeFiles, segmentType);
                    if (resultList == null)
                    {
                        outStream.WriteLine("Parsing failed");
                        return(false);
                    }
                    if (resultList.Count == 0)
                    {
                        continue;
                    }

                    outStream.WriteLine();
                    outStream.WriteLine("Segment Type: {0}", segmentType.ToString());
                    outStream.WriteLine("-----------------------------------");
                    foreach (UdsReader.ParseInfoBase parseInfo in resultList)
                    {
                        outStream.WriteLine("");

                        StringBuilder sb = new StringBuilder();
                        if (parseInfo.LineArray != null)
                        {
                            foreach (string entry in parseInfo.LineArray)
                            {
                                if (sb.Length > 0)
                                {
                                    sb.Append("; ");
                                }
                                sb.Append("\"");
                                sb.Append(entry);
                                sb.Append("\"");
                            }
                            sb.Insert(0, "Raw: ");
                            outStream.WriteLine(sb.ToString());
                        }

                        if (parseInfo is UdsReader.ParseInfoMwb parseInfoMwb)
                        {
                            sb.Clear();
                            foreach (string entry in parseInfoMwb.NameArray)
                            {
                                if (sb.Length > 0)
                                {
                                    sb.Append("; ");
                                }
                                sb.Append("\"");
                                sb.Append(entry);
                                sb.Append("\"");
                            }
                            sb.Insert(0, "Name: ");
                            outStream.WriteLine(sb.ToString());
                            outStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "Service ID: {0:X04}", parseInfoMwb.ServiceId));
                            outStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "Data ID Name: {0}", parseInfoMwb.DataIdString));

                            if (!PrintDataTypeEntry(outStream, parseInfoMwb.DataTypeEntry))
                            {
                                return(false);
                            }

                            outStream.WriteLine(TestDataType(fileName, parseInfoMwb));
                        }

                        if (parseInfo is UdsReader.ParseInfoDtc parseInfoDtc)
                        {
                            sb.Clear();
                            outStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "Error Code: {0} (0x{0:X06}), {1}", parseInfoDtc.ErrorCode, parseInfoDtc.PcodeText));
                            outStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "Error Text: {0}", parseInfoDtc.ErrorText));
                            if (parseInfoDtc.DetailCode.HasValue && parseInfoDtc.DetailCode.Value > 0)
                            {
                                outStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "Detail Code: {0:X02}", parseInfoDtc.DetailCode));
                            }
                            if (!string.IsNullOrEmpty(parseInfoDtc.ErrorDetail))
                            {
                                outStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "Error Detail: {0}", parseInfoDtc.ErrorDetail));
                            }
                        }

                        if (parseInfo is UdsReader.ParseInfoSlv parseInfoSlv)
                        {
                            sb.Clear();
                            if (parseInfoSlv.TableKey.HasValue)
                            {
                                outStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "Slave Table Key: {0}", parseInfoSlv.TableKey));
                                if (parseInfoSlv.SlaveList != null)
                                {
                                    foreach (UdsReader.ParseInfoSlv.SlaveInfo slaveInfo in parseInfoSlv.SlaveList)
                                    {
                                        outStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "Min Addr: {0}, Max Addr: {1}, Name: {2}",
                                                                          slaveInfo.MinAddr, slaveInfo.MaxAddr, slaveInfo.Name));
                                    }
                                }
                            }
                        }
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                try
                {
                    outStream.WriteLine("Exception: {0}", ex.Message);
                }
                catch (Exception)
                {
                    // ignored
                }
                return(false);
            }
        }
Example #7
0
 static bool PrintIsoErrorCode(UdsReader udsReader, uint errorCode, uint errorDetail)
 {
     return(PrintErrorCode(udsReader, errorCode, errorDetail, DataReader.ErrorType.Iso9141));
 }
Example #8
0
        public List <string> ErrorCodeToString(uint errorCode, uint errorDetail, ErrorType errorType, UdsReader udsReader = null)
        {
            List <string> resultList   = new List <string>();
            string        errorText    = string.Empty;
            uint          errorCodeMap = errorCode;
            int           errorCodeKey = (int)(errorCode + 100000);
            bool          useFullCode  = errorCode >= 0x4000 && errorCode <= 0xBFFF;

            if (errorType != ErrorType.Sae)
            {
                useFullCode = false;
                if (errorCode < 0x4000 || errorCode > 0x7FFF)
                {
                    errorCodeKey = (int)errorCode;
                }
                else
                {
                    if (string.IsNullOrEmpty(PcodeToString(errorCode, out uint convertedValue)))
                    {
                        errorCodeKey = -1;
                    }
                    else
                    {
                        errorCodeMap = convertedValue;
                        errorCodeKey = (int)(convertedValue + 100000);
                    }
                }
Example #9
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);
            }
        }
Example #10
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;
                _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);
            }
        }
Example #11
0
        static bool ParseFile(UdsReader udsReader, string fileName, StreamWriter outStream)
        {
            try
            {
                List <string> includeFiles = udsReader.GetFileList(fileName);
                if (includeFiles == null)
                {
                    outStream.WriteLine("Get file list failed");
                    return(false);
                }

                outStream.WriteLine("Includes:");
                foreach (string includeFile in includeFiles)
                {
                    outStream.WriteLine(includeFile);
                }

                List <UdsReader.ParseInfoBase> resultList = udsReader.ExtractFileSegment(includeFiles, UdsReader.SegmentType.Mwb);
                if (resultList == null)
                {
                    outStream.WriteLine("Parsing failed");
                    return(false);
                }

                outStream.WriteLine("MWB:");
                foreach (UdsReader.ParseInfoBase parseInfo in resultList)
                {
                    outStream.WriteLine("");

                    StringBuilder sb = new StringBuilder();
                    foreach (string entry in parseInfo.LineArray)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Append("; ");
                        }
                        sb.Append("\"");
                        sb.Append(entry);
                        sb.Append("\"");
                    }

                    sb.Insert(0, "Raw: ");
                    outStream.WriteLine(sb.ToString());

                    if (parseInfo is UdsReader.ParseInfoMwb parseInfoMwb)
                    {
                        sb.Clear();
                        foreach (string entry in parseInfoMwb.NameArray)
                        {
                            if (sb.Length > 0)
                            {
                                sb.Append("; ");
                            }
                            sb.Append("\"");
                            sb.Append(entry);
                            sb.Append("\"");
                        }
                        sb.Insert(0, "Name: ");
                        outStream.WriteLine(sb.ToString());
                        outStream.WriteLine(string.Format(CultureInfo.InvariantCulture, "Service ID: {0:X04}", parseInfoMwb.ServiceId));

                        if (!PrintDataTypeEntry(outStream, parseInfoMwb.DataTypeEntry))
                        {
                            return(false);
                        }

                        outStream.WriteLine(TestDataType(fileName, parseInfoMwb));
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                try
                {
                    outStream.WriteLine("Exception: {0}", ex.Message);
                }
                catch (Exception)
                {
                    // ignored
                }
                return(false);
            }
        }
Example #12
0
            public ValueName(UdsReader udsReader, string[] lineArray)
            {
                LineArray = lineArray;

                if (lineArray.Length >= 5)
                {
                    try
                    {
                        string textMin = lineArray[1];
                        if (textMin.Length >= 2 && textMin.Length % 2 == 0 && !textMin.StartsWith("0x") && textMin.StartsWith("0"))
                        {
                            if (Int64.TryParse(textMin, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out Int64 minValue))
                            {
                                MinValue = minValue;
                            }
                        }
                        else
                        {
                            if (textMin.Length < 34)
                            {
                                object valueObjMin = new Int64Converter().ConvertFromInvariantString(textMin);
                                if (valueObjMin != null)
                                {
                                    MinValue = (Int64)valueObjMin;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }

                    try
                    {
                        string textMax = lineArray[2];
                        if (textMax.Length >= 2 && textMax.Length % 2 == 0 && !textMax.StartsWith("0x") && textMax.StartsWith("0"))
                        {
                            if (Int64.TryParse(textMax, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out Int64 maxValue))
                            {
                                MaxValue = maxValue;
                            }
                        }
                        else
                        {
                            if (textMax.Length < 34)
                            {
                                object valueObjMax = new Int64Converter().ConvertFromInvariantString(textMax);
                                if (valueObjMax != null)
                                {
                                    MaxValue = (Int64)valueObjMax;
                                }
                            }
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }

                    if (UInt32.TryParse(lineArray[3], NumberStyles.Integer, CultureInfo.InvariantCulture, out UInt32 valueNameKey))
                    {
                        if (udsReader._textMap.TryGetValue(valueNameKey, out string[] nameValueArray))
Example #13
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);
            }
        }
Example #14
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);
                }

                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);
                    }
                }

                return(0);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(1);
            }
        }