diff --git a/V2GApi.cs b/V2GApi.cs new file mode 100644 index 0000000..3008642 --- /dev/null +++ b/V2GApi.cs @@ -0,0 +1,124 @@ +using System; +using System.Text; + +namespace V2GProtocol +{ + /// + /// V2G 프로토콜 API - 외부 프로그램에서 사용하기 위한 간단한 인터페이스 + /// + public static class V2GApi + { + /// + /// EXI 헥스 문자열을 XML로 디코드 + /// + /// EXI 형식의 헥스 문자열 + /// 디코드된 XML 문자열 + public static string DecodeHexToXml(string exiHexString) + { + try + { + // 헥스 문자열 정리 + exiHexString = exiHexString.Replace(" ", "").Replace("-", "").Replace("0x", ""); + + // 헥스를 바이트 배열로 변환 + byte[] exiBytes = Helper.FromHexString(exiHexString); + + // EXI를 XML로 디코드 + return V2GDecoder.DecodeEXIToXML(exiBytes); + } + catch (Exception ex) + { + throw new Exception($"Failed to decode EXI: {ex.Message}", ex); + } + } + + /// + /// EXI 바이트 배열을 XML로 디코드 + /// + /// EXI 형식의 바이트 배열 + /// 디코드된 XML 문자열 + public static string DecodeBytesToXml(byte[] exiBytes) + { + try + { + return V2GDecoder.DecodeEXIToXML(exiBytes); + } + catch (Exception ex) + { + throw new Exception($"Failed to decode EXI: {ex.Message}", ex); + } + } + + /// + /// XML을 EXI 헥스 문자열로 인코드 + /// + /// XML 내용 + /// 인코드된 EXI 헥스 문자열 + public static string EncodeXmlToHex(string xmlContent) + { + try + { + // XML을 EXI로 인코드 + byte[] exiBytes = V2GDecoder.EncodeXMLToEXI(xmlContent); + + // 바이트 배열을 헥스 문자열로 변환 + return Helper.ToHexString(exiBytes); + } + catch (Exception ex) + { + throw new Exception($"Failed to encode XML: {ex.Message}", ex); + } + } + + /// + /// XML을 EXI 바이트 배열로 인코드 + /// + /// XML 내용 + /// 인코드된 EXI 바이트 배열 + public static byte[] EncodeXmlToBytes(string xmlContent) + { + try + { + return V2GDecoder.EncodeXMLToEXI(xmlContent); + } + catch (Exception ex) + { + throw new Exception($"Failed to encode XML: {ex.Message}", ex); + } + } + + /// + /// V2G 메시지 분석 (헥스 덤프에서 V2G 메시지 추출) + /// + /// 헥스 덤프 데이터 + /// V2G 메시지 정보 + public static V2GDecoder.V2GMessage AnalyzeV2GMessage(byte[] hexDumpData) + { + try + { + return V2GDecoder.DecodeMessage(hexDumpData); + } + catch (Exception ex) + { + throw new Exception($"Failed to analyze V2G message: {ex.Message}", ex); + } + } + + /// + /// 헥스 파일 파싱 + /// + /// 헥스 파일 경로 + /// 파싱된 바이트 배열 + public static byte[] ParseHexFile(string filePath) + { + try + { + return V2GDecoder.ParseHexFile(filePath); + } + catch (Exception ex) + { + throw new Exception($"Failed to parse hex file: {ex.Message}", ex); + } + } + } +} \ No newline at end of file diff --git a/V2GProtocol.Library.csproj b/V2GProtocol.Library.csproj new file mode 100644 index 0000000..373025a --- /dev/null +++ b/V2GProtocol.Library.csproj @@ -0,0 +1,15 @@ + + + + Library + net48 + 9.0 + V2GDecoder.Library + true + + + + + + + \ No newline at end of file diff --git a/V2GProtocol.csproj b/V2GProtocol.csproj index c204ba5..163cdec 100644 --- a/V2GProtocol.csproj +++ b/V2GProtocol.csproj @@ -5,6 +5,7 @@ net48 9.0 V2GDecoder + true