Skip to content

Commit

Permalink
Merge pull request #25 from areyna1/patch-1
Browse files Browse the repository at this point in the history
Add publish rate parameter
  • Loading branch information
GhostofGoes authored Aug 14, 2024
2 parents 32cc1b8 + e432c01 commit 9380575
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/bennu/executables/bennu-simulink-provider/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,24 @@ struct Dto
}
};

constexpr auto durationToDuration(const float time_s)
{
using namespace std::chrono;
using fsec = duration<float>;
return round<nanoseconds>(fsec{time_s});
}

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)
{
Expand Down Expand Up @@ -284,7 +293,7 @@ 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));
}
}

Expand Down Expand Up @@ -333,6 +342,7 @@ int main(int argc, char** argv)
("debug", po::bool_switch(&debug), "print debugging information")
("server-endpoint", po::value<std::string>()->default_value("tcp://127.0.0.1:5555"), "server listening endpoint")
("publish-endpoint", po::value<std::string>()->default_value("udp://239.0.0.1:40000"), "publishing endpoint");
("publish-rate", po::value<double>()->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);
Expand All @@ -347,7 +357,8 @@ int main(int argc, char** argv)
Endpoint sEndpoint, pEndpoint;
sEndpoint.str = vm["server-endpoint"].as<std::string>();
pEndpoint.str = vm["publish-endpoint"].as<std::string>();
BennuSimulinkProvider bsp(sEndpoint, pEndpoint, debug);
double publishRate = vm["publish-rate"].as<double>();
BennuSimulinkProvider bsp(sEndpoint, pEndpoint, debug, publishRate);
bsp.run();
return 0;
}

0 comments on commit 9380575

Please sign in to comment.