1 | /**************************************************************\
|
---|
2 |
|
---|
3 | Control program for the FACT G-APD bias supply
|
---|
4 |
|
---|
5 | Oliver Grimm
|
---|
6 |
|
---|
7 | \**************************************************************/
|
---|
8 |
|
---|
9 | #include <stdio.h>
|
---|
10 |
|
---|
11 | #include "User.h"
|
---|
12 |
|
---|
13 | #include <readline/readline.h>
|
---|
14 | #include <readline/history.h>
|
---|
15 |
|
---|
16 | const char READLINE_HIST_FILE[] = "/tmp/.history.BIASctrl";
|
---|
17 |
|
---|
18 | // Main program
|
---|
19 | int main() {
|
---|
20 |
|
---|
21 | char *Command;
|
---|
22 | std::string LastHist;
|
---|
23 |
|
---|
24 | // Uses getc() for readline library (allows interruption by signal) and load history buffer
|
---|
25 | rl_getc_function = getc;
|
---|
26 | read_history(READLINE_HIST_FILE);
|
---|
27 |
|
---|
28 | // Set signal SIGTERM to interrupt blocking system calls
|
---|
29 | siginterrupt(SIGTERM, true);
|
---|
30 |
|
---|
31 | if (system("clear") == -1) printf("Error with system() call\n");
|
---|
32 |
|
---|
33 | printf("\n*** BIASctrl (compiled %s, %s) ***\n\n", __DATE__, __TIME__);
|
---|
34 |
|
---|
35 | // Construct main instance
|
---|
36 | static User M;
|
---|
37 |
|
---|
38 | // Handle command-line input
|
---|
39 | while (!M.ExitRequest) {
|
---|
40 | Command = readline("\rBias> ");
|
---|
41 |
|
---|
42 | // NULL returned if interrupted by signal
|
---|
43 | if (Command == NULL) continue;
|
---|
44 |
|
---|
45 | // Add command to history
|
---|
46 | if(strlen(Command) > 0 && LastHist != Command) {
|
---|
47 | add_history(Command);
|
---|
48 | LastHist = Command;
|
---|
49 | }
|
---|
50 |
|
---|
51 | // Process command (via DIM gives automatic thread serialisation)
|
---|
52 | DimClient::sendCommand("Bias/Command", Command);
|
---|
53 | free(Command);
|
---|
54 | }
|
---|
55 |
|
---|
56 | // Save history buffer
|
---|
57 | int Ret = write_history(READLINE_HIST_FILE);
|
---|
58 | if (Ret != 0 ) printf("Error writing history file to '%s' (%s)\n", READLINE_HIST_FILE, strerror(Ret));
|
---|
59 | }
|
---|