From ff9dd7c4089d631348cb86e712b838998fa3c22a Mon Sep 17 00:00:00 2001 From: dan-du-car <62157949+dan-du-car@users.noreply.github.com> Date: Wed, 17 Apr 2024 09:29:26 -0400 Subject: [PATCH] Fix tcm intermittent reception (#604) # PR Details ## Description Fix the TCM intermittent reception issue where carma cloud sends TCMs in an http request and v2xhub CARMACloudPlugin sometimes does not receive the TCMs. Replace the OpenAI generated code with QhttpEngine recommended functional call, refer to: https://ci.quickmediasolutions.com/job/qhttpengine-documentation/doxygen/classQHttpEngine_1_1QObjectHandler.html. ## Related Issue https://github.com/usdot-fhwa-OPS/V2X-Hub/issues/601 https://github.com/usdot-fhwa-OPS/V2X-Hub/issues/603 ## Motivation and Context CARMA cloud integration testing ## How Has This Been Tested? Local integration test ## Types of changes - [x] Defect fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that cause existing functionality to change) ## Checklist: - [ ] I have added any new packages to the sonar-scanner.properties file - [ ] My change requires a change to the documentation. - [ ] I have updated the documentation accordingly. - [x] I have read the **CONTRIBUTING** document. [V2XHUB Contributing Guide](https://github.com/usdot-fhwa-OPS/V2X-Hub/blob/develop/Contributing.md) - [ ] I have added tests to cover my changes. - [ ] All new and existing tests passed. --- .../CARMACloudPlugin/src/CARMACloudPlugin.cpp | 27 ++++++------------- .../CARMACloudPlugin/src/CARMACloudPlugin.h | 5 +++- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp index 651384e09..d2110c575 100644 --- a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp +++ b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.cpp @@ -463,25 +463,14 @@ int CARMACloudPlugin::StartWebService() QHostAddress address = QHostAddress(QString::fromStdString (webip)); quint16 port = static_cast(webport); - QSharedPointer handler(new OpenAPI::OAIApiRequestHandler()); - handler = QSharedPointer (new OpenAPI::OAIApiRequestHandler()); - - auto router = QSharedPointer::create(); - router->setUpRoutes(); - - QObject::connect(handler.data(), &OpenAPI::OAIApiRequestHandler::requestReceived, [&](QHttpEngine::Socket *socket) { - - CARMAResponseHandler(socket); - }); - - QObject::connect(handler.data(), &OpenAPI::OAIApiRequestHandler::requestReceived, [&](QHttpEngine::Socket *socket) { - - router->processRequest(socket); - }); - - QHttpEngine::Server server(handler.data()); - - if (!server.listen(address, port)) { + QHttpEngine::QObjectHandler apiHandler; + apiHandler.registerMethod(TCM_REPLY, [this](QHttpEngine::Socket *socket) + { + this->CARMAResponseHandler(socket); + socket->close(); }); + QHttpEngine::Server server(&apiHandler); + + if (!server.listen(address, port)) { qCritical("Unable to listen on the specified port."); return 1; } diff --git a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h index 066e65756..9a9d85061 100644 --- a/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h +++ b/src/v2i-hub/CARMACloudPlugin/src/CARMACloudPlugin.h @@ -67,6 +67,7 @@ #include #endif #include +#include #include @@ -99,6 +100,7 @@ class CARMACloudPlugin: public PluginClient { uint16_t webport; std::string webip; uint16_t fetchtime; + void CARMAResponseHandler(QHttpEngine::Socket *socket); protected: void UpdateConfigSettings(); @@ -109,7 +111,6 @@ class CARMACloudPlugin: public PluginClient { void OnStateChange(IvpPluginState state); int StartWebService(); - void CARMAResponseHandler(QHttpEngine::Socket *socket); int CloudSend(const string& msg,const string& url, const string& base, const string& method); //Send HTTP request async void CloudSendAsync(const string& msg,const string& url, const string& base, const string& method); @@ -210,6 +211,8 @@ class CARMACloudPlugin: public PluginClient { const char *CONTENT_ENCODING_KEY = "Content-Encoding"; const char *CONTENT_ENCODING_VALUE = "gzip"; std::string list_tcm = "true"; + //API URL to accept TCM response + const QString TCM_REPLY="tcmreply"; }; std::mutex _cfgLock;