source: fact/FADctrl/FADctrl.cc@ 10120

Last change on this file since 10120 was 10120, checked in by ogrimm, 12 years ago
Moved OpenOtherSockets() to FADBoard class
File size: 2.0 KB
Line 
1//
2// FADctrl
3//
4
5#include <stdio.h>
6#include <readline/history.h>
7#include <string>
8
9#include "FAD.h"
10
11using namespace std;
12
13const string READLINE_HIST_FILE = string(getenv("HOME"))+"/.history_FADctrl";
14
15// ================
16// Main program
17// ================
18
19int main() {
20
21 // Uses getc() for readline library (allows interruption by signal) and load history buffer
22 rl_getc_function = getc;
23 read_history(READLINE_HIST_FILE.c_str());
24
25 system("clear");
26 printf("\n*** FADctrl (built %s, %s, revision %s) *** \n\n",__DATE__, __TIME__, REVISION);
27
28 // Construct main instance (static ensures destructor is called with exit())
29 static FAD M;
30
31 // Do not kill process if writing to closed socket
32 signal(SIGPIPE,SIG_IGN);
33
34 // Initialise all boards
35 DimClient::sendCommand(SERVER_NAME"/Command", "dwrite off");
36 DimClient::sendCommand(SERVER_NAME"/Command", "domino off");
37 DimClient::sendCommand(SERVER_NAME"/Command", "dac 0 25000");
38 DimClient::sendCommand(SERVER_NAME"/Command", "dac 1-3 0");
39 DimClient::sendCommand(SERVER_NAME"/Command", "dac 4-7 28800");
40 DimClient::sendCommand(SERVER_NAME"/Command", "domino on");
41 DimClient::sendCommand(SERVER_NAME"/Command", "dwrite on");
42 DimClient::sendCommand(SERVER_NAME"/Command", "roi all 1024");
43 DimClient::sendCommand(SERVER_NAME"/Command", "trigger enable");
44 M.PrintMessage("Finished initalizing all boards\n");
45
46 // Command loop
47 char *Command;
48 std::string LastHist;
49
50 while (!M.ExitRequest) {
51 Command = readline("\rFADctrl>");
52
53 // Check for interruption by signal
54 if (Command == NULL) continue;
55
56 // Add command to history
57 if(strlen(Command) > 0 && LastHist != Command) {
58 add_history(Command);
59 LastHist = Command;
60 }
61
62 // Process command
63 DimClient::sendCommand(SERVER_NAME"/Command", Command);
64 free(Command);
65 }
66
67 // Save history buffer
68 int Ret = write_history(READLINE_HIST_FILE.c_str());
69 if (Ret != 0 ) printf("Error writing history file to '%s' (%s)\n", READLINE_HIST_FILE.c_str(), strerror(Ret));
70}
Note: See TracBrowser for help on using the repository browser.