Changeset 10918 for fact/tools/FSC
- Timestamp:
- 06/07/11 19:29:15 (14 years ago)
- Location:
- fact/tools/FSC/simple_daq
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
fact/tools/FSC/simple_daq/simple_daq.cpp
r10894 r10918 1 1 /********************************************************************\ 2 2 3 Read SOCKETS_PER_FADChannels from FAD-Board3 Read NUMBER_OF_SOCKETS Channels from FAD-Board 4 4 Write Commands to Socket 0, Commands must be (n * 16) Bit long 5 5 … … 31 31 using namespace std; 32 32 33 FSC_STATUS *answer; 33 34 34 35 35 int main(int argc, char *argv[]) … … 43 43 int max_fd = 0; 44 44 45 FILE* outfile[ SOCKETS_PER_FAD];45 FILE* outfile[NUMBER_OF_SOCKETS]; 46 46 char outfilename[PATH_MAX]; 47 47 48 49 SimpleDaqConfiguration *conf; 48 FSC_STATUS *answer; 49 50 SimpleDaqConfiguration *conf; 50 51 // Get configuration file path from command line 51 52 // Get configurarion from configurationfile. 52 // such as FADIP Adress53 // such as IP Adress 53 54 if (argc > 1) 54 55 { … … 57 58 conf = getConfig(CONFIG_FILE_PATH); 58 59 } 60 if (conf == NULL) { 61 fprintf ( stderr, "Error: Config Error. \n"); 62 exit_program (EXIT_FAILURE); 63 } 59 64 60 65 // Open sockets 61 SocketDescriptor = OpenSockets( SOCKETS_PER_FAD);66 SocketDescriptor = OpenSockets(NUMBER_OF_SOCKETS); 62 67 if (SocketDescriptor == NULL) { 68 fprintf(stderr, "Error: While opening sockets. \n"); 63 69 exit_program (EXIT_FAILURE); 64 70 } 65 max_fd = GetMaxFileDescriptor( SOCKETS_PER_FAD, SocketDescriptor);71 max_fd = GetMaxFileDescriptor(NUMBER_OF_SOCKETS, SocketDescriptor); 66 72 67 73 // Connect to server 68 if( Connect2Server( SocketDescriptor, SOCKETS_PER_FAD, FIRST_DAQPORT, conf->FADIPAddress, 1) != SOCKETS_PER_FAD) {74 if( Connect2Server( SocketDescriptor, NUMBER_OF_SOCKETS, FIRST_DAQPORT, conf->FADIPAddress, 1) != NUMBER_OF_SOCKETS) { 69 75 // Connect2Server prints some error messages in case of exceptions... 70 76 printf ("Error in Connect2Server()\n"); … … 73 79 74 80 // Open files for output 75 for (int i = 0; i < SOCKETS_PER_FAD; i++)81 for (int i = 0; i < NUMBER_OF_SOCKETS; i++) 76 82 { 77 83 sprintf (outfilename, "%s/%s-%d.%s", conf->outfilepath, conf->outfilename, i, conf->outfileext); 78 84 if ((outfile[i] = fopen (outfilename, "w")) == NULL) 79 85 { 80 printf ("Error: Could not open file %s\n", outfilename);86 printf ("Error: Could not open output-file %s\n", outfilename); 81 87 exit_program (EXIT_FAILURE); 82 88 } 83 89 } 84 90 85 //init_fad(); 91 86 92 87 93 //fad_firmware_revision = get_firmware_revision(); … … 94 100 signal (SIGINT, int_handler); // Cleanup after SIGINT (CTRL-C) 95 101 96 // init_fad();97 // fflush (stdin);98 102 // Main loop 99 103 while (true) … … 103 107 FD_ZERO (&ReadFileDescriptor); 104 108 FD_SET(STDIN_FILENO, &ReadFileDescriptor); 105 for (int i = 0; i < SOCKETS_PER_FAD; i++)109 for (int i = 0; i < NUMBER_OF_SOCKETS; i++) 106 110 { 107 111 FD_SET (SocketDescriptor[i], &ReadFileDescriptor); … … 118 122 119 123 120 // init board -- should be switchable121 // with a commandline switch, but ...122 // TODO123 124 125 124 // Data from STDIN 126 125 if (FD_ISSET (STDIN_FILENO, &ReadFileDescriptor)) … … 134 133 { 135 134 // Check all sockets 136 for (int i = 0; i < SOCKETS_PER_FAD; i++)135 for (int i = 0; i < NUMBER_OF_SOCKETS; i++) 137 136 { 138 137 if (FD_ISSET (SocketDescriptor[i], &ReadFileDescriptor)) 139 138 { 140 139 // Only for testing 141 memset (Buffer, 0 xAA, sizeof (Buffer));140 memset (Buffer, 0, sizeof (Buffer)); 142 141 if ((read_return = read (SocketDescriptor[i], Buffer, MAX_COM_SIZE)) == 0) 143 142 { … … 149 148 { 150 149 printf ("Socket [%d]: Read %d Bytes\n", i, read_return); 150 printf ("\n\n%s\n", Buffer); 151 152 //answer = Buffer; 153 151 154 152 155 … … 167 170 { 168 171 printf ("\nClosing Sockets..."); 169 for (int i = 0; i < SOCKETS_PER_FAD; i++)172 for (int i = 0; i < NUMBER_OF_SOCKETS; i++) 170 173 { 171 174 close (SocketDescriptor[i]); … … 192 195 ConfigFile = fopen (path, "r"); 193 196 if (ConfigFile == NULL) { 197 fprintf ( stderr, "Error: Config Error. \n File not found %s", path); 194 198 return NULL; 195 199 } … … 266 270 unsigned short rev; 267 271 268 max_fd = GetMaxFileDescriptor( SOCKETS_PER_FAD, SocketDescriptor);272 max_fd = GetMaxFileDescriptor(NUMBER_OF_SOCKETS, SocketDescriptor); 269 273 270 274 cmd_send ("sra 10\n", SocketDescriptor[0]); … … 274 278 275 279 FD_ZERO (&ReadFileDescriptor); 276 for (int i = 0; i < SOCKETS_PER_FAD; i++)280 for (int i = 0; i < NUMBER_OF_SOCKETS; i++) 277 281 { 278 282 FD_SET (SocketDescriptor[i], &ReadFileDescriptor); … … 288 292 289 293 // Check all sockets 290 for (int i = 0; i < SOCKETS_PER_FAD; i++)294 for (int i = 0; i < NUMBER_OF_SOCKETS; i++) 291 295 { 292 296 if (FD_ISSET (SocketDescriptor[i], &ReadFileDescriptor)) -
fact/tools/FSC/simple_daq/simple_daq.h
r10894 r10918 14 14 #define IP_ADDR_LENGTH 16 15 15 16 #define FIRST_DAQPORT 5000 17 #define SOCKETS_PER_FAD 1 16 #define FIRST_PORT 5000 17 #define NUMBER_OF_SOCKETS 1 18 #define CONFIG_FILE_PATH "./config.txt" 18 19 19 // Commands for FAD 20 #define CMD_Start 0xC000 // Start Run 21 #define CMD_Stop 0x3000 // Stop Run 22 #define CMD_Trigger 0xA000 // single trigger 23 #define CMD_DENABLE 0x0600 // DENABLE line HIGH 24 #define CMD_DDISABLE 0x0700 // DENABLE line LOW 25 #define CMD_DWRITE_RUN 0x0800 // DWRITE possibly HIGH 26 #define CMD_DWRITE_STOP 0x0900 // DWRITE always LOW 27 28 #define CMD_SCLK_ON 0x1000 29 #define CMD_SCLK_OFF 0x1100 30 31 #define CMD_PS_DIRINC 0x1200 32 #define CMD_PS_DIRDEC 0x1300 33 #define CMD_PS_DO 0x1400 34 #define CMD_PS_RESET 0x1700 20 // Commands for Board 21 // to be done 35 22 36 23 37 #define CMD_SRCLK_ON 0x150038 #define CMD_SRCLK_OFF 0x160039 40 #define CMD_Trigger_C 0xB000 // continous trigger41 #define CMD_Trigger_S 0x2000 // stop continous trigger42 #define CMD_Read 0x0A00 // read from Config-RAM43 #define CMD_Write 0x0500 // write to Config-RAM44 45 // Addresses in FAD Config-RAM46 #define MAX_ADDR 0xFF // highest address in Config-RAM47 #define BADDR_ROI 0x00 // Baseaddress ROI-Values48 #define BADDR_DAC 0x24 // Baseaddress DAC-Values49 50 // Max-Values51 #define MAX_VAL 6553552 #define MAX_ROINUM 3553 #define MAX_ROIVAL 102454 #define MAX_DACNUM 755 #define MAX_DACVAL 6553556 57 #define CONFIG_FILE_PATH "config.txt"58 24 59 25 class SimpleDaqConfiguration {
Note:
See TracChangeset
for help on using the changeset viewer.