diff --git a/Port/vc2022/V2GDecoder.c b/Port/vc2022/V2GDecoder.c index c4d3af2..826908d 100644 --- a/Port/vc2022/V2GDecoder.c +++ b/Port/vc2022/V2GDecoder.c @@ -831,7 +831,7 @@ void dump_iso1_document_to_file(const struct iso1EXIDocument* doc, const char* f } fclose(fp); - printf("✓ Structure dump saved to %s\n", filename); + DEBUG_PRINTF(("✓ Structure dump saved to %s\n", filename)); } // Helper function to convert hex string to binary @@ -1146,7 +1146,7 @@ void print_iso1_message(struct iso1EXIDocument* doc) { } int main(int argc, char *argv[]) { - printf("DEBUG: argc=%d\n", argc); + DEBUG_PRINTF(("DEBUG: argc=%d\n", argc)); int xml_mode = 0; int encode_mode = 0; char *filename = NULL; @@ -1179,16 +1179,17 @@ int main(int argc, char *argv[]) { encode_mode = 1; filename = argv[arg_index + 1]; } else { - printf("Usage: %s [-debug] [-decode|-encode] input_file\\n", argv[0]); - printf(" %s [-debug] -encode (read XML from stdin)\\n", argv[0]); - printf(" %s [-debug] -decode (read hex string from stdin)\\n", argv[0]); + printf("Usage: V2GDecoder [-debug] [-decode|-encode] input_file\\n"); + printf(" V2GDecoder [-debug] -encode (read XML from stdin)\\n"); + printf(" V2GDecoder [-debug] -decode (read hex string from stdin)\\n"); printf("Enhanced EXI viewer with XML conversion capabilities\\n"); printf(" -debug Enable detailed bit-level encoding/decoding output\\n"); printf(" -decode Convert EXI to Wireshark-style XML format\\n"); - printf(" -decode Read hex string from stdin (echo hex | %s -decode)\\n", argv[0]); + printf(" -decode Read hex string from stdin (echo hex | V2GDecoder -decode)\\n"); printf(" -encode Convert XML to EXI format\\n"); - printf(" -encode Read XML from stdin (type file.xml | %s -encode)\\n", argv[0]); + printf(" -encode Read XML from stdin (type file.xml | V2GDecoder -encode)\\n"); printf(" (default) Analyze EXI with detailed output\\n"); + printf("\\nContact: tindevil82@gmail.com\\n"); return -1; } @@ -1208,7 +1209,7 @@ int main(int argc, char *argv[]) { // Handle encode mode (XML to EXI) if (encode_mode) { - fprintf(stderr, "DEBUG: Entering encode mode\n"); + DEBUG_PRINTF(("DEBUG: Entering encode mode\n")); FILE* xml_file; char* xml_content; long xml_size; @@ -1266,9 +1267,9 @@ int main(int argc, char *argv[]) { } // Parse XML to ISO1 document structure - fprintf(stderr, "DEBUG: About to parse XML content\n"); + DEBUG_PRINTF(("DEBUG: About to parse XML content\n")); int parse_result = parse_xml_to_iso1(xml_content, &iso1Doc); - fprintf(stderr, "DEBUG: XML parse result: %d\n", parse_result); + DEBUG_PRINTF(("DEBUG: XML parse result: %d\n", parse_result)); if (parse_result != 0) { printf("Error parsing XML file - no supported message type found\\n"); free(xml_content); @@ -1284,17 +1285,17 @@ int main(int argc, char *argv[]) { // Debug output disabled for clean hex-only output if (iso1Doc.V2G_Message.Body.CurrentDemandReq_isUsed) { - fprintf(stderr, "EVReady: %s\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVReady ? "true" : "false"); - fprintf(stderr, "EVErrorCode: %d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVErrorCode); - fprintf(stderr, "EVRESSSOC: %d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVRESSSOC); - fprintf(stderr, "EVTargetCurrent: M=%d, U=%d, V=%d\\n", + DEBUG_PRINTF(("EVReady: %s\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVReady ? "true" : "false")); + DEBUG_PRINTF(("EVErrorCode: %d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVErrorCode)); + DEBUG_PRINTF(("EVRESSSOC: %d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVRESSSOC)); + DEBUG_PRINTF(("EVTargetCurrent: M=%d, U=%d, V=%d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetCurrent.Multiplier, iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetCurrent.Unit, - iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetCurrent.Value); - fprintf(stderr, "EVTargetVoltage: M=%d, U=%d, V=%d\\n", + iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetCurrent.Value)); + DEBUG_PRINTF(("EVTargetVoltage: M=%d, U=%d, V=%d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetVoltage.Multiplier, iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetVoltage.Unit, - iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetVoltage.Value); + iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetVoltage.Value)); } @@ -1309,9 +1310,11 @@ int main(int argc, char *argv[]) { stream.capacity = 0; // 구조체 덤프 (디버그용, 필요시 활성화) - fprintf(stderr, "DEBUG: About to dump structure to temp/struct_xml.txt\n"); - dump_iso1_document_to_file(&iso1Doc, "temp/struct_xml.txt"); - fprintf(stderr, "DEBUG: Structure dump completed\n"); + DEBUG_PRINTF(("DEBUG: About to dump structure to temp/struct_xml.txt\n")); + if (EXI_DEBUG_MODE) { + dump_iso1_document_to_file(&iso1Doc, "temp/struct_xml.txt"); + } + DEBUG_PRINTF(("DEBUG: Structure dump completed\n")); errn = encode_iso1ExiDocument(&stream, &iso1Doc); @@ -1422,31 +1425,31 @@ int main(int argc, char *argv[]) { print_iso1_message(&iso1Doc); // Compare with expected structure - printf("\\n=== Original EXI Structure Debug ===\\n"); - printf("V2G_Message_isUsed: %s\\n", iso1Doc.V2G_Message_isUsed ? "true" : "false"); - printf("SessionID length: %d\\n", iso1Doc.V2G_Message.Header.SessionID.bytesLen); - printf("CurrentDemandReq_isUsed: %s\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq_isUsed ? "true" : "false"); + DEBUG_PRINTF(("\\n=== Original EXI Structure Debug ===\\n")); + DEBUG_PRINTF(("V2G_Message_isUsed: %s\\n", iso1Doc.V2G_Message_isUsed ? "true" : "false")); + DEBUG_PRINTF(("SessionID length: %d\\n", iso1Doc.V2G_Message.Header.SessionID.bytesLen)); + DEBUG_PRINTF(("CurrentDemandReq_isUsed: %s\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq_isUsed ? "true" : "false")); if (iso1Doc.V2G_Message.Body.CurrentDemandReq_isUsed) { - printf("EVReady: %s\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVReady ? "true" : "false"); - printf("EVErrorCode: %d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVErrorCode); - printf("EVRESSSOC: %d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVRESSSOC); - printf("EVTargetCurrent: M=%d, U=%d, V=%d\\n", + DEBUG_PRINTF(("EVReady: %s\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVReady ? "true" : "false")); + DEBUG_PRINTF(("EVErrorCode: %d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVErrorCode)); + DEBUG_PRINTF(("EVRESSSOC: %d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.DC_EVStatus.EVRESSSOC)); + DEBUG_PRINTF(("EVTargetCurrent: M=%d, U=%d, V=%d\\n", iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetCurrent.Multiplier, iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetCurrent.Unit, - iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetCurrent.Value); - printf("EVMaximumVoltageLimit_isUsed: %s\\n", - iso1Doc.V2G_Message.Body.CurrentDemandReq.EVMaximumVoltageLimit_isUsed ? "true" : "false"); - printf("EVMaximumCurrentLimit_isUsed: %s\\n", - iso1Doc.V2G_Message.Body.CurrentDemandReq.EVMaximumCurrentLimit_isUsed ? "true" : "false"); - printf("EVMaximumPowerLimit_isUsed: %s\\n", - iso1Doc.V2G_Message.Body.CurrentDemandReq.EVMaximumPowerLimit_isUsed ? "true" : "false"); - printf("BulkChargingComplete_isUsed: %s\\n", - iso1Doc.V2G_Message.Body.CurrentDemandReq.BulkChargingComplete_isUsed ? "true" : "false"); - printf("RemainingTimeToFullSoC_isUsed: %s\\n", - iso1Doc.V2G_Message.Body.CurrentDemandReq.RemainingTimeToFullSoC_isUsed ? "true" : "false"); - printf("RemainingTimeToBulkSoC_isUsed: %s\\n", - iso1Doc.V2G_Message.Body.CurrentDemandReq.RemainingTimeToBulkSoC_isUsed ? "true" : "false"); + iso1Doc.V2G_Message.Body.CurrentDemandReq.EVTargetCurrent.Value)); + DEBUG_PRINTF(("EVMaximumVoltageLimit_isUsed: %s\\n", + iso1Doc.V2G_Message.Body.CurrentDemandReq.EVMaximumVoltageLimit_isUsed ? "true" : "false")); + DEBUG_PRINTF(("EVMaximumCurrentLimit_isUsed: %s\\n", + iso1Doc.V2G_Message.Body.CurrentDemandReq.EVMaximumCurrentLimit_isUsed ? "true" : "false")); + DEBUG_PRINTF(("EVMaximumPowerLimit_isUsed: %s\\n", + iso1Doc.V2G_Message.Body.CurrentDemandReq.EVMaximumPowerLimit_isUsed ? "true" : "false")); + DEBUG_PRINTF(("BulkChargingComplete_isUsed: %s\\n", + iso1Doc.V2G_Message.Body.CurrentDemandReq.BulkChargingComplete_isUsed ? "true" : "false")); + DEBUG_PRINTF(("RemainingTimeToFullSoC_isUsed: %s\\n", + iso1Doc.V2G_Message.Body.CurrentDemandReq.RemainingTimeToFullSoC_isUsed ? "true" : "false")); + DEBUG_PRINTF(("RemainingTimeToBulkSoC_isUsed: %s\\n", + iso1Doc.V2G_Message.Body.CurrentDemandReq.RemainingTimeToBulkSoC_isUsed ? "true" : "false")); } }