From 8f725e1ed40d6588c546bbf71b1a2b191364b683 Mon Sep 17 00:00:00 2001 From: areyna1 <157658711+areyna1@users.noreply.github.com> Date: Fri, 26 Jul 2024 14:01:27 -0600 Subject: [PATCH 1/3] Update main.cpp --- src/bennu/executables/bennu-simulink-provider/main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/bennu/executables/bennu-simulink-provider/main.cpp b/src/bennu/executables/bennu-simulink-provider/main.cpp index fbd893e7..c2ee8e2f 100644 --- a/src/bennu/executables/bennu-simulink-provider/main.cpp +++ b/src/bennu/executables/bennu-simulink-provider/main.cpp @@ -121,11 +121,13 @@ struct Dto class BennuSimulinkProvider : public Provider { public: - BennuSimulinkProvider(const Endpoint& serverEndpoint, const Endpoint& publishEndpoint, bool debug) : + double publishRate_setting; + BennuSimulinkProvider(const Endpoint& serverEndpoint, const Endpoint& publishEndpoint, bool debug, double publishRate) : Provider(serverEndpoint, publishEndpoint), mLock(), mDebug(debug) { + publishRate_setting = publishRate; mPublishSemaphore = sem_open(PUBLISH_SEM, O_CREAT, 0644, 0); if(SEM_FAILED == mPublishSemaphore) { @@ -284,7 +286,8 @@ class BennuSimulinkProvider : public Provider { publishData(); std::cout << std::flush; - std::this_thread::sleep_for(std::chrono::seconds(1)); + // std::this_thread::sleep_for(std::chrono::seconds(1)); + std::this_thread::sleep_for(durationToDuration(this->publishRate_setting)); } } @@ -333,6 +336,7 @@ int main(int argc, char** argv) ("debug", po::bool_switch(&debug), "print debugging information") ("server-endpoint", po::value()->default_value("tcp://127.0.0.1:5555"), "server listening endpoint") ("publish-endpoint", po::value()->default_value("udp://239.0.0.1:40000"), "publishing endpoint"); + ("publish-rate", po::value()->default_value(0.1), "rate at which updates published from provider to simulation"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -348,6 +352,8 @@ int main(int argc, char** argv) sEndpoint.str = vm["server-endpoint"].as(); pEndpoint.str = vm["publish-endpoint"].as(); BennuSimulinkProvider bsp(sEndpoint, pEndpoint, debug); + double publishRate = vm["publish-rate"].as(); + BennuSimulinkProvider bsp(sEndpoint, pEndpoint, debug, publishRate); bsp.run(); return 0; } From a11f793e7f1f335c4630909b22dbe0841dc6ef8b Mon Sep 17 00:00:00 2001 From: areyna1 <157658711+areyna1@users.noreply.github.com> Date: Wed, 7 Aug 2024 14:20:45 -0600 Subject: [PATCH 2/3] Add durationToDuration and parameter for changing publish rate --- .../executables/bennu-simulink-provider/main.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/bennu/executables/bennu-simulink-provider/main.cpp b/src/bennu/executables/bennu-simulink-provider/main.cpp index c2ee8e2f..4ae0d94d 100644 --- a/src/bennu/executables/bennu-simulink-provider/main.cpp +++ b/src/bennu/executables/bennu-simulink-provider/main.cpp @@ -117,11 +117,18 @@ struct Dto } }; + constexpr auto durationToDuration(const float time_s) +{ + using namespace std::chrono; + using fsec = duration; + return round(fsec{time_s}); +} class BennuSimulinkProvider : public Provider { public: double publishRate_setting; + BennuSimulinkProvider(const Endpoint& serverEndpoint, const Endpoint& publishEndpoint, bool debug, double publishRate) : Provider(serverEndpoint, publishEndpoint), mLock(), @@ -286,7 +293,6 @@ class BennuSimulinkProvider : public Provider { publishData(); std::cout << std::flush; - // std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(durationToDuration(this->publishRate_setting)); } } @@ -336,7 +342,7 @@ int main(int argc, char** argv) ("debug", po::bool_switch(&debug), "print debugging information") ("server-endpoint", po::value()->default_value("tcp://127.0.0.1:5555"), "server listening endpoint") ("publish-endpoint", po::value()->default_value("udp://239.0.0.1:40000"), "publishing endpoint"); - ("publish-rate", po::value()->default_value(0.1), "rate at which updates published from provider to simulation"); + ("publish-rate", po::value()->default_value(0.1), "rate at which updates are published from the provider to the simulation"); po::variables_map vm; po::store(po::parse_command_line(argc, argv, desc), vm); @@ -351,7 +357,6 @@ int main(int argc, char** argv) Endpoint sEndpoint, pEndpoint; sEndpoint.str = vm["server-endpoint"].as(); pEndpoint.str = vm["publish-endpoint"].as(); - BennuSimulinkProvider bsp(sEndpoint, pEndpoint, debug); double publishRate = vm["publish-rate"].as(); BennuSimulinkProvider bsp(sEndpoint, pEndpoint, debug, publishRate); bsp.run(); From e432c016e23796863a11e15af48e5abc04400d39 Mon Sep 17 00:00:00 2001 From: Chris Goes Date: Fri, 9 Aug 2024 22:38:06 -0600 Subject: [PATCH 3/3] fix whitespace --- src/bennu/executables/bennu-simulink-provider/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bennu/executables/bennu-simulink-provider/main.cpp b/src/bennu/executables/bennu-simulink-provider/main.cpp index 4ae0d94d..fc6ec247 100644 --- a/src/bennu/executables/bennu-simulink-provider/main.cpp +++ b/src/bennu/executables/bennu-simulink-provider/main.cpp @@ -117,7 +117,7 @@ struct Dto } }; - constexpr auto durationToDuration(const float time_s) +constexpr auto durationToDuration(const float time_s) { using namespace std::chrono; using fsec = duration;