Пример #1
0
INT master_ODB_set()
{
  INT   status;
  HNDLE hKey;
  char  str[MAX_ODB_PATH];
  char  str_aux[MAX_ODB_PATH];
//  int   i;

  sprintf(str_aux,"/Equipment/MasterGM2/Settings/Globals");
  sprintf(str, str_aux);

  // create ODB structure /Equipment/%s/Settings if it doesn't exist
  status = db_check_record(hDB, 0, str, MASTER_SETTINGS_ODB_STR, TRUE);
  if (status != DB_SUCCESS) 
    {
      cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status);
      ss_sleep(3000);
    }
  
  // returns key handle "hDB" to ODB name "str" for fast access 
  status = db_find_key(hDB, 0, str, &hKey);
  if ( status != DB_SUCCESS ) 
    {
      cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status);               
      return FE_ERR_ODB;
    }

  // Copy a set of keys from local memory to the database
  db_set_record(hDB, hKey, &master_settings_odb, sizeof(MASTER_SETTINGS_ODB), 0);

  print(str);

  return SUCCESS;
}
Пример #2
0
int null_read(NULL_INFO * info, char *data, int size, int timeout)
{
    int i, l;

    /* somethng like

       memset(data, 0, size);
       for (l=0 ; l<size ; l++)
       {
       status = read(info->fd, data+l, 1, &i);
       if (!status || i == 0)
       break;
       }
     */

    /* simulate reading */
    ss_sleep(10);
    l = 0;

    if (debug_flag && l > 0) {
        FILE *f;

        f = fopen("null.log", "a");
        fprintf(f, "read: ");
        for (i = 0; i < l; i++)
            fprintf(f, "%X ", data[i]);
        fprintf(f, "\n");
        fclose(f);
    }

    return l;
}
Пример #3
0
void process_event(HNDLE hBuf, HNDLE request_id, EVENT_HEADER * pheader, void *pevent)
{
   static INT ser[10], count, start_time, jam = 0;

   INT stop_time;
   INT size, *pdata, id;
   BUFFER_HEADER buffer_header;
   double rate;

   /* accumulate received event size */
   size = pheader->data_size;
   id = pheader->event_id;
   if (id > 9)
      id = 9;
   count += size;

   /* check if first and last word inside event is equal
      to size to check that nothing was overwritten... */

   if (!jam) {
      /* only test once */
      pdata = (INT *) (pheader + 1);
      if (pdata[0] != size || pdata[size / 4 - 1] != size)
         cm_msg(MERROR, "process_event", "--> data jam <--");
      jam = 1;
   }

   /* if only some events are requested, sleep a little bit
      to simulate a random event consumer */
   if (!all_flag)
      ss_sleep(10);

   /* if all events are requested, now check the serial number
      if no events are missing */
   if (all_flag && (INT) pheader->serial_number != ser[id] + 1)
      cm_msg(MERROR, "process_event",
             "Serial number mismatch: Ser: %ld, OldSer: %ld, ID: %d, size: %ld\n",
             pheader->serial_number, ser[id], pheader->event_id, pheader->data_size);

   ser[id] = pheader->serial_number;

   /* calculate rates each second */
   if (ss_millitime() - start_time > 1000) {
      stop_time = ss_millitime();
      rate = count / 1024.0 / 1024.0 / ((stop_time - start_time) / 1000.0);

      /* get information about filling level of the buffer */
      bm_get_buffer_info(hBufEvent, &buffer_header);
      size = buffer_header.read_pointer - buffer_header.write_pointer;
      if (size <= 0)
         size += buffer_header.size;
      printf("Level: %4.1lf %%, ", 100 - 100.0 * size / buffer_header.size);

      printf("Rate: %1.2lf MB/sec\n", rate);
      start_time = stop_time;
      count = 0;
   }
}
Пример #4
0
INT frontend_loop()
{
   /* don't eat up all CPU time in main thread */
//printf("in the fe loop\n");
   //fillBank();
   ss_sleep(100);

   return CM_SUCCESS;
}
Пример #5
0
void receive_message(HNDLE hBuf, HNDLE id, EVENT_HEADER * header, void *message)
{
   char str[256], *pc, *sp;
   static DWORD last_beep = 0;

   /* print message */
   printf("%s\n", (char *) (message));

   if (fp == NULL) {
      fputs("Speech synthesizer not enabled - terminating\n", stderr);
      cm_disconnect_experiment();
      exit(2);
   }

   /* skip none talking message */
   if (header->trigger_mask == MT_TALK || header->trigger_mask == MT_USER) {
      pc = strchr((char *) (message), ']') + 2;
      sp = pc + strlen(pc) - 1;
      while (*sp == ' ' || *sp == '\t')
         sp--;
      *(++sp) = '\0';

      /* Send beep first */
      // "play --volume=0.3 /etc/mt_talk.wav"
      if ((ss_time() - last_beep) > shutupTime) {
         switch (header->trigger_mask) {
         case MT_TALK:
            if (mtTalkStr[0])
               sprintf(str, "%s", mtTalkStr);
            break;
         case MT_USER:
            if (mtUserStr[0])
               sprintf(str, "%s", mtUserStr);
            break;
         }
         ss_system(str);
         last_beep = ss_time();
         ss_sleep(1000);
      }

#ifdef OS_DARWIN      
      sprintf(str, "say %s.", pc);
      ss_system(str);
#else
      fprintf(fp, "%s.\n", pc);
      fflush(fp);
#endif      
   }

   return;
}
Пример #6
0
int rb_get_rp(int handle, void **p, int millisec)
/********************************************************************\

  Routine: rb_get_rp

  Purpose: Obtain the current read pointer at which new data is
           available with optional timeout

  Input:
    int handle               Ring buffer handle
    int millisec             Optional timeout in milliseconds if
                             buffer is full. Zero to not wait at
                             all (non-blocking)

  Output:
    char **p                 Address of pointer pointing to newly
                             available data. If p == NULL, only
                             return status.

  Function value:
    RB_SUCCESS       Successful completion

\********************************************************************/
{
   int i, h;

   if (handle < 1 || handle > MAX_RING_BUFFER || rb[handle - 1].buffer == NULL)
      return RB_INVALID_HANDLE;

   h = handle - 1;

   for (i = 0; i <= millisec / 10; i++) {

      if (rb[h].wp != rb[h].rp) {
         if (p != NULL)
            *p = rb[handle - 1].rp;
         return RB_SUCCESS;
      }

      if (millisec == 0)
         return RB_TIMEOUT;

      if (_rb_nonblocking)
         return RB_TIMEOUT;

      /* wait one time slice */
      ss_sleep(10);
   }

   return RB_TIMEOUT;
}
Пример #7
0
static void *se_worker(void *arg)
{
	seworker *self = arg;
	se *o = self->arg;
	for (;;)
	{
		int rc = se_active(o);
		if (ssunlikely(rc == 0))
			break;
		rc = se_scheduler(&o->sched, self);
		if (ssunlikely(rc == -1))
			break;
		if (ssunlikely(rc == 0))
			ss_sleep(10000000); /* 10ms */
	}
	return NULL;
}
Пример #8
0
int ps7106_set(int crate, int slot, double thresh_value)
/********************************************************************\
  Sets the threshold of a Phillips 7106 discriminator to the given
  <thresh_value> in millivolts.
\********************************************************************/
{
   INT q;
   WORD data, threshold;

   // Convert threshold value to register value
   if (thresh_value > 1033)
      thresh_value = 1033;
   if (thresh_value < 10)
      thresh_value = 10;
   threshold = (unsigned int) (thresh_value - 10);

   /* Set remote mode */
   camo(crate, slot, 0, SET_REMOTE_7106, 0);

   /* Verify Remote mode */
   camc_q(crate, slot, 0, TEST_REMOTE_7106, &q);
   if (!q) {
      cm_msg(MERROR, "ps7106_set", "Error setting remote mode on crate %d, slot %d.\n",
             crate, slot);
//    printf("Error setting remote mode on crate %d, slot %d.\n", crate, slot);
      return -1;
   }

   /* unmask all channels */
   camo(crate, slot, 0, 16, 0xFFFF);

   /* Write threshold */
   camo(crate, slot, 0, WRITE_THRESH_7106, threshold);
   ss_sleep(10);

   /* Verify threshold */
   cami(crate, slot, 0, READ_THRESH_7106, &data);
   data = data & 0x3FF;
   if (data != threshold) {
      cm_msg(MERROR, "ps7106_set", "Error setting threshold:\
 requested %d (%4.0f mV), read %d", threshold, thresh_value, data);
//    printf("Error setting threshold:\
// requested %d (%4.0f mV), read %d", threshold, thresh_value, data);
      return -1;
   }
Пример #9
0
static void *se_worker(void *arg)
{
	ssthread *self = arg;
	se *e = self->arg;
	seworker *worker = se_workerpool_pop(&e->sched.workers, &e->r);
	if (ssunlikely(worker == NULL))
		return NULL;
	for (;;)
	{
		int rc = se_active(e);
		if (ssunlikely(rc == 0))
			break;
		rc = se_scheduler(&e->sched, worker);
		if (ssunlikely(rc == -1))
			break;
		if (ssunlikely(rc == 0))
			ss_sleep(10000000); /* 10ms */
	}
	se_workerpool_push(&e->sched.workers, worker);
	return NULL;
}
Пример #10
0
int null_gets(NULL_INFO * info, char *str, int size, char *pattern, int timeout)
{
    int l;

    /* something like

       memset(str, 0, size);
       for (l=0 ; l<size-1 ; l++)
       {
       status = read(info->fd, str+l, 1, &i);
       if (!status || i == 0)
       {
       if (pattern && pattern[0])
       return 0;
       break;
       }

       if (pattern && pattern[0])
       if (strstr(str, pattern) != NULL)
       break;
       }
     */

    /* simulate reading */
    ss_sleep(10);
    l = 0;
    str[0] = 0;

    if (debug_flag && l > 0) {
        FILE *f;

        f = fopen("null.log", "a");
        fprintf(f, "gets %s: %s\n", pattern, str);
        fclose(f);
    }

    return l;
}
Пример #11
0
static void*
se_worker(void *arg)
{
	ssthread *self = arg;
	se *e = self->arg;
	ss_thread_setname(self, "worker");
	ss_vfsioprio_low(&e->vfs);
	scworker *w = sc_workerpool_pop(&e->scheduler.wp, &e->r);
	if (ssunlikely(w == NULL))
		return NULL;
	for (;;)
	{
		int rc = se_active(e);
		if (ssunlikely(rc == 0))
			break;
		rc = sc_step(&e->scheduler, w, sx_vlsn(&e->xm));
		if (ssunlikely(rc == -1))
			break;
		if (ssunlikely(rc == 0))
			ss_sleep(10000000); /* 10ms */
	}
	sc_workerpool_push(&e->scheduler.wp, w);
	return NULL;
}
Пример #12
0
int rb_get_wp(int handle, void **p, int millisec)
/********************************************************************\

Routine: rb_get_wp

  Purpose: Retrieve write pointer where new data can be written

  Input:
     int handle               Ring buffer handle
     int millisec             Optional timeout in milliseconds if
                              buffer is full. Zero to not wait at
                              all (non-blocking)

  Output:
    char **p                  Write pointer

  Function value:
    DB_SUCCESS       Successful completion

\********************************************************************/
{
   int h, i;
   unsigned char *rp;

   if (handle < 1 || handle > MAX_RING_BUFFER || rb[handle - 1].buffer == NULL)
      return RB_INVALID_HANDLE;

   h = handle - 1;

   for (i = 0; i <= millisec / 10; i++) {

      rp = rb[h].rp;            // keep local copy, rb[h].rp might be changed by other thread

      /* check if enough size for wp >= rp without wrap-around */
      if (rb[h].wp >= rp
          && rb[h].wp + rb[h].max_event_size <= rb[h].buffer + rb[h].size - rb[h].max_event_size) {
         *p = rb[h].wp;
         return RB_SUCCESS;
      }

      /* check if enough size for wp >= rp with wrap-around */
      if (rb[h].wp >= rp && rb[h].wp + rb[h].max_event_size > rb[h].buffer + rb[h].size - rb[h].max_event_size && rb[h].rp > rb[h].buffer) {    // next increment of wp wraps around, so need space at beginning
         *p = rb[h].wp;
         return RB_SUCCESS;
      }

      /* check if enough size for wp < rp */
      if (rb[h].wp < rp && rb[h].wp + rb[h].max_event_size < rp) {
         *p = rb[h].wp;
         return RB_SUCCESS;
      }

      if (millisec == 0)
         return RB_TIMEOUT;

      if (_rb_nonblocking)
         return RB_TIMEOUT;

      /* wait one time slice */
      ss_sleep(10);
   }

   return RB_TIMEOUT;
}
Пример #13
0
INT amc13simulator_ODB_set()
{
  INT   status;
  HNDLE hKey;
  char  str[MAX_ODB_PATH];
  char  str_aux[MAX_ODB_PATH];
  int   i;

  sprintf(str_aux,"/Equipment/AMC13Simulator%02d/Settings/Globals",frontend_index);
  sprintf(str, str_aux, frontend_index);

  // create ODB structure /Equipment/%s/Settings/Globals if doesn't exist
  status = db_check_record(hDB, 0, str, AMC13SIMULATOR_SETTINGS_ODB_STR, TRUE);
  if (status != DB_SUCCESS) 
    {
      cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status);
      ss_sleep(3000);
    }
  
  // returns key handle "hDB" to ODB name "str" for fast access 
  status = db_find_key(hDB, 0, str, &hKey);
  if ( status != DB_SUCCESS ) 
    {
      cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status);		  
      return FE_ERR_ODB;
    }
  
  // Copy a set of keys from local memory to the database
  db_set_record(hDB, hKey, &amc13simulator_settings_odb, sizeof(AMC13SIMULATOR_SETTINGS_ODB), 0);
  
  dbprintf("%s(%d): %s sync %d\n",  __func__, __LINE__, str, amc13simulator_settings_odb.sync );

  for (i=0; i<AMC13SIMULATOR_NUM; i++)
    {
      sprintf(str,"/Equipment/AMC13Simulator%02d/Settings/Channel%02d",frontend_index,i+1);
 
      // create ODB structure /Equipment/%s/Settings/Channel%02d if doesn't exist
      status = db_check_record(hDB, 0, str, AMC13SIMULATOR_CHANNEL_ODB_STR, TRUE);
      if (status != DB_SUCCESS) 
        {
          cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status);
          ss_sleep(3000);
        }

      // returns key handle "hDB" to ODB name "str" for fast access
      status = db_find_key(hDB, 0, str, &hKey);
      if ( status != DB_SUCCESS )
        {
          cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status);
          return FE_ERR_ODB; 
        }
 
      // Copy a set of keys from local memory to the database 
      db_set_record(hDB, hKey, &amc13simulator_channel_odb[i], sizeof(AMC13SIMULATOR_CHANNEL_ODB), 0);

      dbprintf("%s(%d): %s enabled %d\n",  __func__, __LINE__, str, amc13simulator_channel_odb[i].enabled );
      dbprintf("%s(%d): %s port no %d\n",  __func__, __LINE__, str, amc13simulator_channel_odb[i].port_no );
      dbprintf("%s(%d): %s ip addr %s\n",  __func__, __LINE__, str, amc13simulator_channel_odb[i].ip_addr );
      
    }
  
  return SUCCESS;

}
Пример #14
0
/*--------------------------------------------------------------------*/
INT cnafsub(BOOL cmd_mode, char *cmd)
{
  char str[128], line[128];
  INT status, j;
  CAMAC *P, *p = NULL, *job;

  /* Loop return label */
  if (jobflag) {
    jobflag = FALSE;
  }

  /* Load default CAMAC */
  P = Prompt;
  while (1) {
    if (!cmd_mode) {
      make_display_string(MAIN, P, addr);
      /* prompt */
      printf("mCNAF> [%s] :", addr);
      ss_gets(str, 128);
    } else {
      strcpy(str, cmd);
    }

    /* decode line */
    status = decode_line(P, str);
    if (status == QUIT)
      return status;
    else if (status == MCSTD) {
      mcstd_func(P);
      status = decode_line(P, str);
    } else if (status == HELP)
      help_page(MAIN);
    else if (status == JOB) {
      if (!cmd_mode) {
        /* interactive session, display default job name */
        printf("\nmCNAF> Job file name [%s]:", job_name);
        ss_gets(line, 128);
        if (strlen(line) == 0)
          strcpy(line, job_name);  // Use default
        else {
          strcpy(job_name, line);
        }
      } else {
        /* from command line, skip @ */
        strcpy(line, &str[1]);
      }
      /* Check if file exists */
      status = read_job_file(pF, CHECK, &job, line);
      if (status == JOB)
        status = read_job_file(pF, READ, &job, line);
    }

    if (status == LOOP || status == JOB) {
      for (j = 0; j < P->r; j++) {
        if (status == LOOP)
          p = P;
        if (status == JOB)
          p = job;
        while (p->m) {
          if (p->n == 28 || p->n == 29 || p->n == 30)
            cc_services(p);
          else if (p->m == 24) {    /* Actual 24 bits CAMAC operation */
            if (p->f < 8)
              cam24i_q(p->c, p->n, p->a, p->f, &p->d24, &p->x, &p->q);
            else if (p->f < 16)
              camc_q(p->c, p->n, p->a, p->f, &p->q);
            else if (p->f < 24)
              cam24o_q(p->c, p->n, p->a, p->f, p->d24, &p->x, &p->q);
            else 
              camc_q(p->c, p->n, p->a, p->f, &p->q);
          }
          else {
            if (p->f < 16)  /* Actual 16 bits CAMAC operation */ 
              cam16i_q(p->c, p->n, p->a, p->f, &p->d16, &p->x, &p->q);
            else if (p->f < 24)
              cam16o_q(p->c, p->n, p->a, p->f, (WORD)p->d24, &p->x, &p->q);
            else 
              camc_q(p->c, p->n, p->a, p->f, &p->q);
          }
          make_display_string(MAIN, p, addr);

          /* Result display */
          if (p->r > 1) {
            /* repeat mode */
            if (status == JOB) {
              if (!cmd_mode)
                printf("\nmCNAF> [%s]", addr);
              if (p->w != 0)
                ss_sleep(p->w);
            } else {
              if (!cmd_mode)
                printf("mCNAF> [%s] <-%03i\n", addr, j + 1);
              if (p->w != 0)
                ss_sleep(p->w);
              if (j > p->r - 1)
                break;
            }
          } else {
            /* single command */
            if (status == JOB) {
              if (!cmd_mode)
                printf("mCNAF> [%s]\n", addr);
              if (p->w != 0)
                ss_sleep(p->w);
            }
          }
          p++;
        }
      };
      if (status == JOB) {
        free(job);
        if (!cmd_mode)
          printf("\n");
      }
    }
    if (cmd_mode)
      break;
  }
  return status;
}
Пример #15
0
INT frontend_loop()
{
   ss_sleep(100);
   return CM_SUCCESS;
}
Пример #16
0
INT amc13simulator_ODB_get()
{
  INT   status;
  HNDLE hKey;
  char  str[MAX_ODB_PATH];
  char  str_aux[MAX_ODB_PATH];
  int   size;

  sprintf(str_aux,"/Equipment/AMC13Simulator%02d/Settings/Globals",frontend_index);
  sprintf(str, str_aux, frontend_index);

  // create ODB structure /Equipment/%s/Settings/Globals if doesn't exist
  status = db_check_record(hDB, 0, str, AMC13SIMULATOR_SETTINGS_ODB_STR, TRUE);
  if (status != DB_SUCCESS) 
    {
      cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status);
      ss_sleep(3000);
    }
  
      // returns key handle "hDB" to ODB name "str" for fast access 
  status = db_find_key(hDB, 0, str, &hKey);
  if ( status != DB_SUCCESS ) 
    {
      cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status);		  
      return FE_ERR_ODB;
    }
  
  // Copy a set of keys from local memory to the database
  size = sizeof(AMC13SIMULATOR_SETTINGS_ODB);
  db_get_record(hDB, hKey, &amc13simulator_settings_odb, &size, 0);
  
  
  dbprintf("%s(%d): %s sync %d\n",  __func__, __LINE__, str, amc13simulator_settings_odb.sync );
  dbprintf("%s(%d): %s write_root %d\n",  __func__, __LINE__, str, amc13simulator_settings_odb.write_root );
  dbprintf("%s(%d): %s rider_header %d\n",  __func__, __LINE__, str, amc13simulator_settings_odb.rider_header );
  dbprintf("%s(%d): %s n_seg_x %d\n",  __func__, __LINE__, str, amc13simulator_settings_odb.n_seg_x );
  dbprintf("%s(%d): %s n_seg_y %d\n",  __func__, __LINE__, str, amc13simulator_settings_odb.n_seg_y );
  dbprintf("%s(%d): %s seg_size %d\n",  __func__, __LINE__, str, amc13simulator_settings_odb.seg_size );
  dbprintf("%s(%d): %s waveform length %d\n",  __func__, __LINE__, str, amc13simulator_settings_odb.waveform_length );
  dbprintf("%s(%d): %s n_muons_mean %d\n",  __func__, __LINE__, str, amc13simulator_settings_odb.n_muons_mean );
  dbprintf("%s(%d): %s Emax %f\n",  __func__, __LINE__, str, amc13simulator_settings_odb.Emax );
  dbprintf("%s(%d): %s Elab_max %f\n",  __func__, __LINE__, str, amc13simulator_settings_odb.Elab_max );
  dbprintf("%s(%d): %s omega_a %f\n",  __func__, __LINE__, str, amc13simulator_settings_odb.omega_a );
  dbprintf("%s(%d): %s repeat_first_event %d\n",__func__,__LINE__,str,amc13simulator_settings_odb.repeat_first_event);
  dbprintf("%s(%d): %s laser_pulse %d\n",__func__,__LINE__,str,amc13simulator_settings_odb.laser_pulse);

  /*
  int   i;                                                                                                     
  for (i=0; i<AMC13SIMULATOR_NUM; i++)
    {
      sprintf(str,"/Equipment/AMC13Simulator%02d/Settings/Channel%02d",frontend_index,i+1);

      // create ODB structure /Equipment/%s/Settings/Channel%02d if doesn't exist 
      status = db_check_record(hDB, 0, str, AMC13SIMULATOR_CHANNEL_ODB_STR, TRUE);
      if (status != DB_SUCCESS)
        {
          cm_msg(MERROR, __FILE__, "Cannot create [%s] entry in ODB, err = %i",str,status);
          ss_sleep(3000);
        }
 
      // returns key handle "hDB" to ODB name "str" for fast access
      status = db_find_key(hDB, 0, str, &hKey); 
      if ( status != DB_SUCCESS )
	{
          cm_msg(MERROR, __FILE__, "Cannot find [%s] key in ODB, err = %i",str,status);
          return FE_ERR_ODB;
        }

      // Copy a set of keys from local memory to the database                                                  
      size = sizeof(AMC13SIMULATOR_CHANNEL_ODB);
      db_get_record(hDB, hKey, &amc13simulator_channel_odb[i], &size, 0);
 
      dbprintf("%s(%d): %s enabled %d\n",  __func__, __LINE__, str, amc13simulator_channel_odb[i].enabled );
      dbprintf("%s(%d): %s port no %d\n",  __func__, __LINE__, str, amc13simulator_channel_odb[i].port_no );
      dbprintf("%s(%d): %s ip addr %s\n",  __func__, __LINE__, str, amc13simulator_channel_odb[i].ip_addr );
    }
  */
  return SUCCESS;

}
Пример #17
0
INT register_equipment(void)
{
   INT index, size, status;
   char str[256];
   EQUIPMENT_INFO *eq_info;
   EQUIPMENT_STATS *eq_stats;
   HNDLE hKey;

   /* get current ODB run state */
   size = sizeof(run_state);
   run_state = STATE_STOPPED;
   db_get_value(hDB, 0, "/Runinfo/State", &run_state, &size, TID_INT, TRUE);
   size = sizeof(run_number);
   run_number = 1;
   status = db_get_value(hDB, 0, "/Runinfo/Run number", &run_number, &size, TID_INT, TRUE);
   assert(status == SUCCESS);

   /* scan EQUIPMENT table from mevb.C */
   for (index = 0; equipment[index].name[0]; index++) {
      eq_info = &equipment[index].info;
      eq_stats = &equipment[index].stats;

      if (eq_info->event_id == 0) {
         printf("\nEvent ID 0 for %s not allowed\n", equipment[index].name);
         cm_disconnect_experiment();
         ss_sleep(5000);
         exit(0);
      }

      /* init status */
      equipment[index].status = EB_SUCCESS;

      sprintf(str, "/Equipment/%s/Common", equipment[index].name);

      /* get last event limit from ODB */
      if (eq_info->eq_type != EQ_SLOW) {
         db_find_key(hDB, 0, str, &hKey);
         size = sizeof(double);
         if (hKey)
            db_get_value(hDB, hKey, "Event limit", &eq_info->event_limit, &size, TID_DOUBLE, TRUE);
      }

      /* Create common subtree */
      status = db_check_record(hDB, 0, str, EQUIPMENT_COMMON_STR, TRUE);
      if (status != DB_SUCCESS) {
         printf("Cannot check equipment record, status = %d\n", status);
         ss_sleep(3000);
      }
      db_find_key(hDB, 0, str, &hKey);

      if (equal_ustring(eq_info->format, "FIXED"))
         equipment[index].format = FORMAT_FIXED;
      else                      /* default format is MIDAS */
         equipment[index].format = FORMAT_MIDAS;

      gethostname(eq_info->frontend_host, sizeof(eq_info->frontend_host));
      strcpy(eq_info->frontend_name, frontend_name);
      strcpy(eq_info->frontend_file_name, frontend_file_name);

      /* set record from equipment[] table in frontend.c */
      db_set_record(hDB, hKey, eq_info, sizeof(EQUIPMENT_INFO), 0);

      /* get record once at the start equipment info */
      size = sizeof(EQUIPMENT_INFO);
      db_get_record(hDB, hKey, eq_info, &size, 0);

    /*---- Create just the key , leave it empty ---------------------------------*/
      sprintf(str, "/Equipment/%s/Variables", equipment[index].name);
      db_create_key(hDB, 0, str, TID_KEY);
      db_find_key(hDB, 0, str, &hKey);
      equipment[index].hkey_variables = hKey;

    /*---- Create and initialize statistics tree -------------------*/
      sprintf(str, "/Equipment/%s/Statistics", equipment[index].name);

      status = db_check_record(hDB, 0, str, EQUIPMENT_STATISTICS_STR, TRUE);
      if (status != DB_SUCCESS) {
         printf("Cannot create/check statistics record, error %d\n", status);
         ss_sleep(3000);
      }

      status = db_find_key(hDB, 0, str, &hKey);
      if (status != DB_SUCCESS) {
         printf("Cannot find statistics record, error %d\n", status);
         ss_sleep(3000);
      }

      eq_stats->events_sent = 0;
      eq_stats->events_per_sec = 0;
      eq_stats->kbytes_per_sec = 0;

      /* open hot link to statistics tree */
      status = db_open_record(hDB, hKey, eq_stats, sizeof(EQUIPMENT_STATS)
                              , MODE_WRITE, NULL, NULL);
      if (status != DB_SUCCESS) {
         cm_msg(MERROR, "register_equipment",
                "Cannot open statistics record, error %d. Probably other FE is using it", status);
         ss_sleep(3000);
      }

    /*---- open event buffer ---------------------------------------*/
      if (eq_info->buffer[0]) {
         status = bm_open_buffer(eq_info->buffer, 2 * max_event_size, &equipment[index].buffer_handle);
         if (status != BM_SUCCESS && status != BM_CREATED) {
            cm_msg(MERROR, "register_equipment",
                   "Cannot open event buffer. Try to reduce EVENT_BUFFER_SIZE in midas.h \
          and rebuild the system.");
            return 0;
         }

	 if (1)
	   {
	     int level = 0;
	     bm_get_buffer_level(equipment[index].buffer_handle, &level);
	     printf("Buffer %s, level %d, info: \n", eq_info->buffer, level);
	   }

         /* set the default buffer cache size */
         bm_set_cache_size(equipment[index].buffer_handle, 0, SERVER_CACHE_SIZE);
      } else {
Пример #18
0
INT read_trigger_event(char *pevent, INT off)
{
   WORD *pdata, a;
   INT q, timeout;

   /* init bank structure */
   bk_init(pevent);

   /* create structured ADC0 bank */
   bk_create(pevent, "ADC0", TID_WORD, &pdata);

   /* wait for ADC conversion */
   for (timeout = 100; timeout > 0; timeout--) {
      camc_q(CRATE, SLOT_ADC, 0, 8, &q);
      if (q)
         break;
   }
   if (timeout == 0)
      ss_printf(0, 10, "No ADC gate!");

   /* use following code to read out real CAMAC ADC */
   /*
      for (a=0 ; a<N_ADC ; a++)
      cami(CRATE, SLOT_ADC, a, 0, pdata++);
    */

   /* Use following code to "simulate" data */
   for (a = 0; a < N_ADC; a++)
      *pdata++ = rand() % 1024;

   /* clear ADC */
   camc(CRATE, SLOT_ADC, 0, 9);

   bk_close(pevent, pdata);

   /* create variable length TDC bank */
   bk_create(pevent, "TDC0", TID_WORD, &pdata);

   /* use following code to read out real CAMAC TDC */
   /*
      for (a=0 ; a<N_TDC ; a++)
      cami(CRATE, SLOT_TDC, a, 0, pdata++);
    */

   /* Use following code to "simulate" data */
   for (a = 0; a < N_TDC; a++)
      *pdata++ = rand() % 1024;

   /* clear TDC */
   camc(CRATE, SLOT_TDC, 0, 9);

   bk_close(pevent, pdata);

   /* clear IO unit LAM */
   camc(CRATE, SLOT_IO, 0, 10);

   /* clear LAM in crate controller */
   cam_lam_clear(CRATE, SLOT_IO);

   /* reset external LAM Flip-Flop */
   camo(CRATE, SLOT_IO, 1, 16, 0xFF);
   camo(CRATE, SLOT_IO, 1, 16, 0);

   ss_sleep(10);

   return bk_size(pevent);
}