/**************************************************************\ Main program for the CTX G-APD HV supply, sends commands, reads and monitors status of the G-APD HV supply Name: hvcontrol.cpp Actions: Do global initialization, start threads Created by: Sebastian Commichau, November 2008 commichau@phys.ethz.ch \**************************************************************/ #include #include #include #include #include #include "ConsoleCommand.h" #include "CCCommand.h" #include "ProcessIO.h" #include "HVMonitor.h" #include "Types.h" #define Sleep(x) usleep(x*1000) #define DEFAULT_CONFIG "HV.conf" // Default configuration file #define LOCKFILE "/tmp/CTX_HV_LOCK" int main(int argc, char *argv[]) { char config_file[] = DEFAULT_CONFIG, str[MAX_COM_SIZE]; pthread_t thread_ConsoleCommand; // Read commands from console pthread_t thread_HVMonitor; // Reads continuously from HV board(s) pthread_t thread_CCCommand; // Thread listening to commands from Central Control int LockDescriptor; // Assure only one instance of the HV control program runs // The flag O_EXCL together with O_CREAT assure that the lock // file cannot be opened by another instance, i.e. there are no parallel write accesses if ((LockDescriptor = open(LOCKFILE,O_RDONLY|O_CREAT|O_EXCL)) == -1) { sprintf(str, "Could not create lock file %s", LOCKFILE); perror(str); exit(EXIT_FAILURE); } close(LockDescriptor); for (int i=1; i] default file is \"%s\"\n", argv[0], config_file); exit(1); } if (argv[i][1] == 'c') { if (argcHVMonitor = thread_HVMonitor; pio.status->SocketThread = thread_CCCommand; // Wait for threads to quit pthread_join(thread_CCCommand, NULL); pthread_join(thread_ConsoleCommand, NULL); pthread_join(thread_HVMonitor, NULL); // Remove lockfile if (remove(LOCKFILE)==-1) { sprintf(str, "Could not remove lock file %s", LOCKFILE); perror(str); exit(EXIT_FAILURE); } return 0; }