Skip to content

Commit

Permalink
Introduce random delays in filter simulators to simulate equipment
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed May 10, 2024
1 parent a74f09b commit 82b03bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/ccd/ccd_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
#include <dirent.h>
#include <sys/stat.h>
#include <algorithm>
#include <chrono>
#include <random>
#include <thread>

static pthread_cond_t cv = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t condMutex = PTHREAD_MUTEX_INITIALIZER;
Expand Down Expand Up @@ -1404,6 +1407,12 @@ bool CCDSim::saveConfigItems(FILE * fp)

bool CCDSim::SelectFilter(int f)
{
// Sleep randomly between 1500 and 2000ms to simulate filter selection
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dist(1500, 2000);
std::this_thread::sleep_for(std::chrono::milliseconds(dist(gen)));

CurrentFilter = f;
SelectFilterDone(f);
return true;
Expand Down
9 changes: 9 additions & 0 deletions drivers/filter_wheel/filter_simulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
#include "filter_simulator.h"

#include <memory>
#include <chrono>
#include <random>
#include <thread>

// We declare an auto pointer to FilterSim.
std::unique_ptr<FilterSim> filter_sim(new FilterSim());
Expand All @@ -43,6 +46,12 @@ bool FilterSim::Disconnect()

bool FilterSim::SelectFilter(int f)
{
// Sleep randomly between 1500 and 2000ms to simulate filter selection
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<> dist(1500, 2000);
std::this_thread::sleep_for(std::chrono::milliseconds(dist(gen)));

CurrentFilter = f;
SetTimer(500);
return true;
Expand Down

0 comments on commit 82b03bd

Please sign in to comment.