Skip to content

Commit 60935ce

Browse files
committed
Configurable arm delay
1 parent 4879bbc commit 60935ce

1 file changed

Lines changed: 20 additions & 18 deletions

File tree

main.cc

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,15 @@ void UpdateStatus(std::string suri, std::string dbname, std::unique_ptr<DAQContr
4343
}
4444

4545
int PrintUsage() {
46-
std::cout<<"Welcome to REDAX readout\nAccepted command-line arguments:"
46+
std::cout<<"Welcome to REDAX readout\nAccepted command-line arguments:\n"
4747
<< "--id <id number>: id number of this readout instance, required\n"
4848
<< "--uri <mongo uri>: full MongoDB URI, required\n"
4949
<< "--db <database name>: name of the database to use, default \"daq\"\n"
5050
<< "--logdir <directory>: where to write the logs, default pwd\n"
5151
<< "--reader: this instance is a reader\n"
5252
<< "--cc: this instance is a crate controller\n"
53+
<< "--arm-delay <delay>: ms to wait between the ARM command and the arming sequence, default 15000\n"
54+
<< "--log-retention <value>: how many days to keep logfiles, default 7\n"
5355
<< "--help: print this message\n"
5456
<< "\n";
5557
return 1;
@@ -67,15 +69,17 @@ int main(int argc, char** argv){
6769
std::string dbname = "daq", suri = "", sid = "";
6870
bool reader = false, cc = false;
6971
int log_retention = 7; // days
70-
int c, opt_index;
72+
int c(0), opt_index, delay(15000);
7173
struct option longopts[] = {
72-
{"id", required_argument, 0, 0},
73-
{"uri", required_argument, 0, 1},
74-
{"db", required_argument, 0, 2},
75-
{"logdir", required_argument, 0, 3},
76-
{"reader", no_argument, 0, 4},
77-
{"cc", no_argument, 0, 5},
78-
{"help", no_argument, 0, 6}
74+
{"id", required_argument, 0, c++},
75+
{"uri", required_argument, 0, c++},
76+
{"db", required_argument, 0, c++},
77+
{"logdir", required_argument, 0, c++},
78+
{"reader", no_argument, 0, c++},
79+
{"cc", no_argument, 0, c++},
80+
{"arm-delay", required_argument, 0, c++},
81+
{"log-retention", required_argument, 0, c++},
82+
{"help", no_argument, 0, c++}
7983
};
8084
while ((c = getopt_long(argc, argv, "", longopts, &opt_index)) != -1) {
8185
switch(c) {
@@ -92,14 +96,18 @@ int main(int argc, char** argv){
9296
case 5:
9397
cc = true; break;
9498
case 6:
99+
delay = std::stoi(optarg); break;
100+
case 7:
101+
log_retention = std::stoi(optarg); break;
102+
case 8:
95103
default:
96104
std::cout<<"Received unknown arg\n";
97105
return PrintUsage();
98106
}
99107
}
100108
if (suri == "" || sid == "") return PrintUsage();
101109
if (reader == cc) {
102-
std::cout<<"Specify --reader OR --cc\n";
110+
std::cout<<"Specify --reader XOR --cc\n";
103111
return 1;
104112
}
105113

@@ -224,14 +232,8 @@ int main(int argc, char** argv){
224232
fOptions = std::make_shared<Options>(fLog, mode,
225233
hostname, suri, dbname, override_json);
226234
int dt = duration_cast<milliseconds>(system_clock::now()-ack_time).count();
227-
if (dt < 15000) std::this_thread::sleep_for(milliseconds(15000-dt));
228-
//if (dt > 3000){
229-
// fLog->Entry(MongoLog::Warning,
230-
// "Took too long to pull the config docs, try again");
231-
// continue;
232-
//} else {
233-
fLog->Entry(MongoLog::Local, "Took %i ms to load config", dt);
234-
//}
235+
fLog->Entry(MongoLog::Local, "Took %i ms to load config", dt);
236+
if (dt < delay) std::this_thread::sleep_for(milliseconds(delay-dt));
235237
if(controller->Arm(fOptions) != 0){
236238
fLog->Entry(MongoLog::Error, "Failed to initialize electronics");
237239
controller->Stop();

0 commit comments

Comments
 (0)