source: fact/BIASctrl/BIASctrl.cc@ 14342

Last change on this file since 14342 was 11915, checked in by ogrimm, 13 years ago
Ramping also for decreasing voltage
File size: 1.6 KB
Line 
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
16using namespace std;
17
18const string READLINE_HIST_FILE = string(getenv("HOME"))+"/.history_BIASctrl";
19
20// Main program
21int main(int argc, char *argv[]) {
22
23 char *Command;
24 std::string LastHist;
25
26 // Uses getc() for readline library (allows interruption by signal) and load history buffer
27 rl_getc_function = getc;
28 read_history(READLINE_HIST_FILE.c_str());
29
30 // Set signal SIGTERM to interrupt blocking system calls
31 siginterrupt(SIGTERM, true);
32
33 if (system("clear") == -1) printf("Error with system() call\n");
34
35 printf("\n*** BIASctrl (compiled %s, %s) ***\n\n", __DATE__, __TIME__);
36
37 // Construct main instance
38 static User M(argc == 2 ? argv[1] : string());
39
40 // Handle command-line input
41 while (!M.ExitRequest) {
42 Command = readline("Bias> ");
43
44 // NULL returned if interrupted by signal
45 if (Command == NULL) continue;
46
47 // Add command to history
48 if(strlen(Command) > 0 && LastHist != Command) {
49 add_history(Command);
50 LastHist = Command;
51 }
52
53 // Process command (via DIM gives automatic thread serialisation)
54 DimClient::sendCommand("Bias/Command", Command);
55 free(Command);
56 }
57
58 // Save history buffer
59 int Ret = write_history(READLINE_HIST_FILE.c_str());
60 if (Ret != 0 ) printf("Error writing history file to '%s' (%s)\n", READLINE_HIST_FILE.c_str(), strerror(Ret));
61}
Note: See TracBrowser for help on using the repository browser.