From c3c32860c3440ecb1597c91a9866a7943a6284fe Mon Sep 17 00:00:00 2001 From: Oliver Glandberger Date: Thu, 30 Jan 2025 14:47:30 +0100 Subject: [PATCH 1/2] Added 'SetGeneralSettings' function. --- RTProtocol.cpp | 2 +- Tinyxml2Serializer.cpp | 182 +++++++++++++++++++++++------------------ Tinyxml2Serializer.h | 4 +- 3 files changed, 106 insertions(+), 82 deletions(-) diff --git a/RTProtocol.cpp b/RTProtocol.cpp index 23d90da..224490e 100644 --- a/RTProtocol.cpp +++ b/RTProtocol.cpp @@ -2655,7 +2655,7 @@ bool CRTProtocol::SetGeneralSettings( const bool* pbStartOnExtTrig, const bool* startOnTrigNO, const bool* startOnTrigNC, const bool* startOnTrigSoftware, const EProcessingActions* peProcessingActions, const EProcessingActions* peRtProcessingActions, const EProcessingActions* peReprocessingActions) { - auto serializer = CMarkupSerializer(mnMajorVersion, mnMinorVersion); + CTinyxml2Serializer serializer(mnMajorVersion, mnMinorVersion); auto message = serializer.SetGeneralSettings(pnCaptureFrequency, pfCaptureTime, pbStartOnExtTrig,startOnTrigNO, startOnTrigNC, startOnTrigSoftware, peProcessingActions, peRtProcessingActions, peReprocessingActions); if (SendXML(message.data())) diff --git a/Tinyxml2Serializer.cpp b/Tinyxml2Serializer.cpp index b32a6e8..022be88 100644 --- a/Tinyxml2Serializer.cpp +++ b/Tinyxml2Serializer.cpp @@ -13,17 +13,21 @@ using namespace CRTProtocolNs; -void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLDocument* oXML, const char* tTag, const bool* pbValue, const char* tTrue, const char* tFalse) +void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool* pbValue, tinyxml2::XMLDocument& oXML) { - //if (pbValue) - //{ - // oXML->AddElem(tTag, *pbValue ? tTrue : tFalse); - //} + if (pbValue) + { + tinyxml2::XMLElement* pElement = oXML.NewElement(tTag); + pElement->SetText(*pbValue ? "True" : "False"); + parent.InsertEndChild(pElement); + } } -void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLDocument* oXML, const char* tTag, const bool pbValue, const char* tTrue, const char* tFalse) +void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool pbValue, tinyxml2::XMLDocument& oXML) { - //oXML->AddElem(tTag, pbValue ? tTrue : tFalse); + tinyxml2::XMLElement* pElement = oXML.NewElement(tTag); + pElement->SetText(pbValue ? "True" : "False"); + parent.InsertEndChild(pElement); } void CTinyxml2Serializer::AddXMLElementInt(tinyxml2::XMLDocument* oXML, const char* tTag, const int* pnValue) @@ -3041,88 +3045,108 @@ CTinyxml2Serializer::CTinyxml2Serializer(std::uint32_t pMajorVersion, std::uint3 } std::string CTinyxml2Serializer::SetGeneralSettings(const unsigned int* pnCaptureFrequency, - const float* pfCaptureTime, const bool* pbStartOnExtTrig, const bool* pStartOnTrigNO, const bool* pStartOnTrigNC, + const float* pfCaptureTime, const bool* pbStartOnExtTrig, + const bool* pStartOnTrigNO, const bool* pStartOnTrigNC, const bool* pStartOnTrigSoftware, const EProcessingActions* peProcessingActions, const EProcessingActions* peRtProcessingActions, const EProcessingActions* peReprocessingActions) { - //CTinyxml2 oXML; + tinyxml2::XMLDocument oXML; - //oXML.AddElem("QTM_Settings"); - //oXML.IntoElem(); - //oXML.AddElem("General"); - //oXML.IntoElem(); + // Root element + tinyxml2::XMLElement* pRoot = oXML.NewElement("QTM_Settings"); + oXML.InsertFirstChild(pRoot); - //if (pnCaptureFrequency) - //{ - // AddXMLElementUnsignedInt(&oXML, "Frequency", pnCaptureFrequency); - //} - //if (pfCaptureTime) - //{ - // AddXMLElementFloat(&oXML, "Capture_Time", pfCaptureTime, 3); - //} - //if (pbStartOnExtTrig) - //{ - // AddXMLElementBool(&oXML, "Start_On_External_Trigger", pbStartOnExtTrig); - // if (mnMajorVersion > 1 || mnMinorVersion > 14) - // { - // AddXMLElementBool(&oXML, "Start_On_Trigger_NO", pStartOnTrigNO); - // AddXMLElementBool(&oXML, "Start_On_Trigger_NC", pStartOnTrigNC); - // AddXMLElementBool(&oXML, "Start_On_Trigger_Software", pStartOnTrigSoftware); - // } - //} + // General element + tinyxml2::XMLElement* pGeneral = oXML.NewElement("General"); + pRoot->InsertEndChild(pGeneral); - //const char* processings[3] = { "Processing_Actions", "RealTime_Processing_Actions", "Reprocessing_Actions" }; - //const EProcessingActions* processingActions[3] = { peProcessingActions, peRtProcessingActions, peReprocessingActions }; + // Capture Frequency + if (pnCaptureFrequency) + { + AddXMLElementUnsignedInt(*pGeneral, "Frequency", pnCaptureFrequency, oXML); + } - //auto actionsCount = (mnMajorVersion > 1 || mnMinorVersion > 13) ? 3 : 1; + // Capture Time + if (pfCaptureTime) + { + AddXMLElementFloat(*pGeneral, "Capture_Time", pfCaptureTime, 3, oXML); + } - //for (auto i = 0; i < actionsCount; i++) - //{ - // if (processingActions[i]) - // { - // oXML.AddElem(processings[i]); - // oXML.IntoElem(); + // External Trigger and additional triggers + if (pbStartOnExtTrig) + { + AddXMLElementBool(*pGeneral, "Start_On_External_Trigger", pbStartOnExtTrig, oXML); - // if (mnMajorVersion > 1 || mnMinorVersion > 13) - // { - // AddXMLElementBool(&oXML, "PreProcessing2D", (*processingActions[i] & ProcessingPreProcess2D) != 0); - // } - // if (*processingActions[i] & ProcessingTracking2D && i != 1) // i != 1 => Not RtProcessingSettings - // { - // oXML.AddElem("Tracking", "2D"); - // } - // else if (*processingActions[i] & ProcessingTracking3D) - // { - // oXML.AddElem("Tracking", "3D"); - // } - // else - // { - // oXML.AddElem("Tracking", "False"); - // } - // if (i != 1) //Not RtProcessingSettings - // { - // AddXMLElementBool(&oXML, "TwinSystemMerge", (*processingActions[i] & ProcessingTwinSystemMerge) != 0); - // AddXMLElementBool(&oXML, "SplineFill", (*processingActions[i] & ProcessingSplineFill) != 0); - // } - // AddXMLElementBool(&oXML, "AIM", (*processingActions[i] & ProcessingAIM) != 0); - // AddXMLElementBool(&oXML, "Track6DOF", (*processingActions[i] & Processing6DOFTracking) != 0); - // AddXMLElementBool(&oXML, "ForceData", (*processingActions[i] & ProcessingForceData) != 0); - // AddXMLElementBool(&oXML, "GazeVector", (*processingActions[i] & ProcessingGazeVector) != 0); - // if (i != 1) //Not RtProcessingSettings - // { - // AddXMLElementBool(&oXML, "ExportTSV", (*processingActions[i] & ProcessingExportTSV) != 0); - // AddXMLElementBool(&oXML, "ExportC3D", (*processingActions[i] & ProcessingExportC3D) != 0); - // AddXMLElementBool(&oXML, "ExportMatlabFile", (*processingActions[i] & ProcessingExportMatlabFile) != 0); - // AddXMLElementBool(&oXML, "ExportAviFile", (*processingActions[i] & ProcessingExportAviFile) != 0); - // } - // oXML.OutOfElem(); // Processing_Actions - // } - //} - //oXML.OutOfElem(); // General - //oXML.OutOfElem(); // QTM_Settings + if (mnMajorVersion > 1 || mnMinorVersion > 14) + { + AddXMLElementBool(*pGeneral, "Start_On_Trigger_NO", pStartOnTrigNO, oXML); + AddXMLElementBool(*pGeneral, "Start_On_Trigger_NC", pStartOnTrigNC, oXML); + AddXMLElementBool(*pGeneral, "Start_On_Trigger_Software", pStartOnTrigSoftware, oXML); + } + } - //return oXML.GetDoc(); - return ""; + // Processing Actions + const char* processings[3] = { "Processing_Actions", "RealTime_Processing_Actions", "Reprocessing_Actions" }; + const EProcessingActions* processingActions[3] = { peProcessingActions, peRtProcessingActions, peReprocessingActions }; + + auto actionsCount = (mnMajorVersion > 1 || mnMinorVersion > 13) ? 3 : 1; + + for (auto i = 0; i < actionsCount; i++) + { + if (processingActions[i]) + { + tinyxml2::XMLElement* pProcessing = oXML.NewElement(processings[i]); + pGeneral->InsertEndChild(pProcessing); + + if (mnMajorVersion > 1 || mnMinorVersion > 13) + { + AddXMLElementBool(*pProcessing, "PreProcessing2D", (*processingActions[i] & ProcessingPreProcess2D) != 0, oXML); + } + + if (*processingActions[i] & ProcessingTracking2D && i != 1) // i != 1 => Not RtProcessingSettings + { + tinyxml2::XMLElement* pTracking = oXML.NewElement("Tracking"); + pTracking->SetText("2D"); + pProcessing->InsertEndChild(pTracking); + } + else if (*processingActions[i] & ProcessingTracking3D) + { + tinyxml2::XMLElement* pTracking = oXML.NewElement("Tracking"); + pTracking->SetText("3D"); + pProcessing->InsertEndChild(pTracking); + } + else + { + tinyxml2::XMLElement* pTracking = oXML.NewElement("Tracking"); + pTracking->SetText("False"); + pProcessing->InsertEndChild(pTracking); + } + + if (i != 1) // Not RtProcessingSettings + { + AddXMLElementBool(*pProcessing, "TwinSystemMerge", (*processingActions[i] & ProcessingTwinSystemMerge) != 0, oXML); + AddXMLElementBool(*pProcessing, "SplineFill", (*processingActions[i] & ProcessingSplineFill) != 0, oXML); + } + + AddXMLElementBool(*pProcessing, "AIM", (*processingActions[i] & ProcessingAIM) != 0, oXML); + AddXMLElementBool(*pProcessing, "Track6DOF", (*processingActions[i] & Processing6DOFTracking) != 0, oXML); + AddXMLElementBool(*pProcessing, "ForceData", (*processingActions[i] & ProcessingForceData) != 0, oXML); + AddXMLElementBool(*pProcessing, "GazeVector", (*processingActions[i] & ProcessingGazeVector) != 0, oXML); + + if (i != 1) // Not RtProcessingSettings + { + AddXMLElementBool(*pProcessing, "ExportTSV", (*processingActions[i] & ProcessingExportTSV) != 0, oXML); + AddXMLElementBool(*pProcessing, "ExportC3D", (*processingActions[i] & ProcessingExportC3D) != 0, oXML); + AddXMLElementBool(*pProcessing, "ExportMatlabFile", (*processingActions[i] & ProcessingExportMatlabFile) != 0, oXML); + AddXMLElementBool(*pProcessing, "ExportAviFile", (*processingActions[i] & ProcessingExportAviFile) != 0, oXML); + } + } + } + + // Convert to string + tinyxml2::XMLPrinter printer; + oXML.Print(&printer); + return printer.CStr(); } std::string CTinyxml2Serializer::SetExtTimeBaseSettings(const bool* pbEnabled, const ESignalSource* peSignalSource, diff --git a/Tinyxml2Serializer.h b/Tinyxml2Serializer.h index 768e51a..6eb9352 100644 --- a/Tinyxml2Serializer.h +++ b/Tinyxml2Serializer.h @@ -88,8 +88,8 @@ namespace CRTProtocolNs { private: std::uint32_t mnMajorVersion; std::uint32_t mnMinorVersion; - void AddXMLElementBool(tinyxml2::XMLDocument* oXML, const char* tTag, const bool* pbValue, const char* tTrue = "True", const char* tFalse = "False"); - void AddXMLElementBool(tinyxml2::XMLDocument* oXML, const char* tTag, const bool bValue, const char* tTrue = "True", const char* tFalse = "False"); + void AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool* pbValue, tinyxml2::XMLDocument& oXML); + void AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool pbValue, tinyxml2::XMLDocument& oXML); void AddXMLElementInt(tinyxml2::XMLDocument* oXML, const char* tTag, const int* pnValue); void AddXMLElementUnsignedInt(tinyxml2::XMLElement& parent, const char* tTag, const unsigned int nValue, tinyxml2::XMLDocument& oXML); void AddXMLElementUnsignedInt(tinyxml2::XMLElement& parent, const char* tTag, const unsigned int* pnValue, tinyxml2::XMLDocument& oXML); From 962cc6cb6b7979f5fcac9c792f8453cbdc560a49 Mon Sep 17 00:00:00 2001 From: Oliver Glandberger Date: Mon, 3 Feb 2025 11:27:14 +0100 Subject: [PATCH 2/2] Reverted 'AddXMLElementBool' functions to contain default-specified texts for 'True' and 'False' alternatives, since there are commented out functions that need to specify these texts. --- Tinyxml2Serializer.cpp | 8 ++++---- Tinyxml2Serializer.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Tinyxml2Serializer.cpp b/Tinyxml2Serializer.cpp index 384a263..d4022a0 100644 --- a/Tinyxml2Serializer.cpp +++ b/Tinyxml2Serializer.cpp @@ -13,20 +13,20 @@ using namespace qualisys_cpp_sdk; -void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool* pbValue, tinyxml2::XMLDocument& oXML) +void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool* pbValue, tinyxml2::XMLDocument& oXML, const char* tTrue, const char* tFalse) { if (pbValue) { tinyxml2::XMLElement* pElement = oXML.NewElement(tTag); - pElement->SetText(*pbValue ? "True" : "False"); + pElement->SetText(*pbValue ? tTrue : tFalse); parent.InsertEndChild(pElement); } } -void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool pbValue, tinyxml2::XMLDocument& oXML) +void CTinyxml2Serializer::AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool pbValue, tinyxml2::XMLDocument& oXML, const char* tTrue, const char* tFalse) { tinyxml2::XMLElement* pElement = oXML.NewElement(tTag); - pElement->SetText(pbValue ? "True" : "False"); + pElement->SetText(pbValue ? tTrue : tFalse); parent.InsertEndChild(pElement); } diff --git a/Tinyxml2Serializer.h b/Tinyxml2Serializer.h index cf016f8..b6d33d7 100644 --- a/Tinyxml2Serializer.h +++ b/Tinyxml2Serializer.h @@ -88,8 +88,8 @@ namespace qualisys_cpp_sdk { private: std::uint32_t mnMajorVersion; std::uint32_t mnMinorVersion; - void AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool* pbValue, tinyxml2::XMLDocument& oXML); - void AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool pbValue, tinyxml2::XMLDocument& oXML); + void AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool* pbValue, tinyxml2::XMLDocument& oXML, const char* tTrue = "True", const char* tFalse = "False"); + void AddXMLElementBool(tinyxml2::XMLElement& parent, const char* tTag, const bool pbValue, tinyxml2::XMLDocument& oXML, const char* tTrue = "True", const char* tFalse = "False"); void AddXMLElementInt(tinyxml2::XMLDocument* oXML, const char* tTag, const int* pnValue); void AddXMLElementUnsignedInt(tinyxml2::XMLElement& parent, const char* tTag, const unsigned int nValue, tinyxml2::XMLDocument& oXML); void AddXMLElementUnsignedInt(tinyxml2::XMLElement& parent, const char* tTag, const unsigned int* pnValue, tinyxml2::XMLDocument& oXML);