source: fact/BIASctrl/BIASctrl.cc@ 10719

Last change on this file since 10719 was 10153, checked in by ogrimm, 14 years ago
New command 'crate', changed signalling of program exit
File size: 1.5 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
16const char READLINE_HIST_FILE[] = "/tmp/.history.BIASctrl";
17
18// Main program
19int 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 system("clear");
32 printf("\n*** BIASctrl (compiled %s, %s) ***\n\n", __DATE__, __TIME__);
33
34 // Construct main instance
35 static User M;
36
37 // Handle command-line input
38 while (!M.ExitRequest) {
39 Command = readline("\rBias> ");
40
41 // NULL returned if interrupted by signal
42 if (Command == NULL) continue;
43
44 // Add command to history
45 if(strlen(Command) > 0 && LastHist != Command) {
46 add_history(Command);
47 LastHist = Command;
48 }
49
50 // Process command (via DIM gives automatic thread serialisation)
51 DimClient::sendCommand("Bias/Command", Command);
52 free(Command);
53 }
54
55 // Save history buffer
56 int Ret = write_history(READLINE_HIST_FILE);
57 if (Ret != 0 ) printf("Error writing history file to '%s' (%s)\n", READLINE_HIST_FILE, strerror(Ret));
58}
Note: See TracBrowser for help on using the repository browser.