Fix .hex file handling to read as binary instead of text

- Changed .hex file processing from text-based hex string parsing to direct binary reading
- Updated usage example and header format for clarity

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-09-07 19:47:15 +09:00
parent fdfab0c666
commit 4f2f6a99d7

View File

@@ -42,8 +42,9 @@ namespace V2GProtocol
if (showHeader) if (showHeader)
{ {
Console.WriteLine("=== V2G Transfer Protocol Decoder/Encoder ==="); Console.WriteLine("=== V2G Transfer Protocol Decoder/Encoder");
Console.WriteLine("ISO 15118-2 / DIN SPEC 70121 / SAP Protocol"); Console.WriteLine("=== ISO 15118-2 / DIN SPEC 70121 / SAP Protocol");
Console.WriteLine("=== made by [tindevil82@gmail.com]");
Console.WriteLine(); Console.WriteLine();
} }
@@ -136,7 +137,7 @@ namespace V2GProtocol
else else
{ {
Console.WriteLine($"Error: Unknown option or file not found: {args[0]}"); Console.WriteLine($"Error: Unknown option or file not found: {args[0]}");
ShowUsage(); //ShowUsage();
} }
} }
catch (Exception ex) catch (Exception ex)
@@ -166,16 +167,9 @@ namespace V2GProtocol
Console.WriteLine("Pipe Usage:"); Console.WriteLine("Pipe Usage:");
Console.WriteLine(" type file.xml | V2GDecoder.exe --encode # Pipe XML file to encode"); Console.WriteLine(" type file.xml | V2GDecoder.exe --encode # Pipe XML file to encode");
Console.WriteLine(" echo \"hex_string\" | V2GDecoder.exe --decode # Pipe hex string to decode"); Console.WriteLine(" echo \"hex_string\" | V2GDecoder.exe --decode # Pipe hex string to decode");
Console.WriteLine("Example:");
Console.WriteLine("V2GDecoder.exe 01FE80010000001E809802104142423030303831908C0C0C0E0C51E020256968C0C0C0C0C080 --decode");
Console.WriteLine(); Console.WriteLine();
Console.WriteLine("Examples:");
Console.WriteLine(" V2GDecoder.exe data/dump2.dump # Full analysis of hex dump");
Console.WriteLine(" V2GDecoder.exe data/test.hex # Auto-decode hex to XML");
Console.WriteLine(" V2GDecoder.exe data/encode0.xml # Auto-encode XML to EXI");
Console.WriteLine(" V2GDecoder.exe -d \"8098021050908C0C0C0E0C5211003200\" # Decode hex string");
Console.WriteLine(" V2GDecoder.exe data/test.dat --decode # Decode unknown file type");
Console.WriteLine(" V2GDecoder.exe data/data0.xml -out data0.hex # Encode to binary file");
Console.WriteLine(" V2GDecoder.exe --decode data.hex -out out.xml # Decode to XML file");
Console.WriteLine(" type data\\encode0.xml | V2GDecoder.exe -e # Pipe XML to encode");
} }
static string? GetOutputFilename(string[] args) static string? GetOutputFilename(string[] args)
@@ -245,10 +239,8 @@ namespace V2GProtocol
} }
else if (extension == ".hex") else if (extension == ".hex")
{ {
// Plain hex file (pure hex string) // Binary hex file
string fileContent = File.ReadAllText(input).Trim(); exiBytes = File.ReadAllBytes(input);
fileContent = fileContent.Replace(" ", "").Replace("-", "").Replace("0x", "").Replace("\n", "").Replace("\r", "");
exiBytes = Convert.FromHexString(fileContent);
} }
else if (extension == ".txt") else if (extension == ".txt")
{ {