Esempio n. 1
0
void cam24o_r(const int c, const int n, const int a, const int f, DWORD * d, const int r)
{
   INT status, size, x, q;

   size = sizeof(DWORD) * r;
   status = rpc_client_call(hConn, RPC_CNAF24, CNAF, 0, c, n, a, f, d, &size, &x, &q);
   if (status != RPC_SUCCESS)
      printf("RPC error %d\n", status);
}
Esempio n. 2
0
void camo(const int c, const int n, const int a, const int f, WORD d)
{
   INT status, size, x, q;

   size = sizeof(WORD);
   status = rpc_client_call(hConn, RPC_CNAF16, CNAF, 0, c, n, a, f, &d, &size, &x, &q);
   if (status != RPC_SUCCESS)
      printf("RPC error %d\n", status);
}
Esempio n. 3
0
void cam24o_q(const int c, const int n, const int a, const int f, DWORD d, int *x, int *q)
{
   INT status, size;

   size = sizeof(DWORD);
   status = rpc_client_call(hConn, RPC_CNAF24, CNAF, 0, c, n, a, f, &d, &size, x, q);
   if (status != RPC_SUCCESS)
      printf("RPC error %d\n", status);
}
Esempio n. 4
0
void cam_crate_zinit(const int c)
{
   INT status, size, dummy;

   dummy = 0;
   size = sizeof(INT);
   status = rpc_client_call(hConn, RPC_CNAF16, CNAF_CRATE_ZINIT, 0, c, 0, 0, 0,
                            &dummy, &size, &dummy, &dummy);
   if (status != RPC_SUCCESS)
      printf("RPC error %d\n", status);
}
Esempio n. 5
0
void cam_inhibit_clear(const int c)
{
   INT status, size, dummy;

   dummy = 0;
   size = sizeof(INT);
   status = rpc_client_call(hConn, RPC_CNAF16, CNAF_INHIBIT_CLEAR, 0, c, 0, 0, 0,
                            &dummy, &size, &dummy, &dummy);
   if (status != RPC_SUCCESS)
      printf("RPC error %d\n", status);
}
Esempio n. 6
0
void cam16i_rq(const int c, const int n, const int a, const int f, WORD ** d, const int r)
{
   INT status, size, x, q;

   size = sizeof(WORD) * r;
   status = rpc_client_call(hConn, RPC_CNAF16, CNAF_nQ, 0, c, n, a, f, *d, &size, &x, &q);
   if (status != RPC_SUCCESS)
      printf("RPC error %d\n", status);
   else
      *d += r;
}
Esempio n. 7
0
/* ********************************************************************* */
INT send_ready_for_cycle()
{
  // Send "ready to go"
  struct timeval tv1, tv2;
  gettimeofday(&tv1, NULL);
  rpc_client_call(rpc_conn_master_crate, RPC_READY_FOR_CYCLE, crate_number, 0); 
  gettimeofday(&tv2, NULL);

  diag_print(2, "Waited %f microseconds for RPC_READY_FOR_CYCLE.\n",
    (tv2.tv_sec-tv1.tv_sec)*1e6 + (tv2.tv_usec-tv1.tv_usec));
   
  return SUCCESS;
}
Esempio n. 8
0
void cam16i_sn(const int c, const int n, const int a, const int f, WORD ** d, const int r)
{
   INT status, size, i, x, q;

   for (i = 0; i < r; i++) {
      size = sizeof(WORD);
      status =
          rpc_client_call(hConn, RPC_CNAF16, CNAF, 0, c, n + i, a, f, *d, &size, &x, &q);

      if (status != RPC_SUCCESS)
         printf("RPC error %d\n", status);
      else
         *d += 1;
   }
}
Esempio n. 9
0
/* ********************************************************************* */
INT rpc_slave_stop_block()
{
  if(!enable_rpc_slave) {
    return SUCCESS;
  }

  int event_number = last_event_number + 1;

  // Send a request to the master crate for the block to end.
  if(sent_stop_request < event_number) {
    rpc_client_call(rpc_conn_master_crate, RPC_REQUEST_STOP, crate_number, 
      event_number);
    sent_stop_request = event_number;
  }

  return SUCCESS;
}
Esempio n. 10
0
int main(int argc , char ** argv){
	printf("test client begin!\n");	
	rpc_client *client = rpc_client_new();
	rpc_client_connect(client,"127.0.0.1",8778);
	printf("test client started success!");
	
	pointer output;
	size_t len;
	char input[256];
	int i, result;

	rpc_code code;

	for (i = 0; i < 10000; i++) {
		len = sprintf(input, "%d %d", i, i + 1);
		printf("call!\n");
		code = rpc_client_call(client, "TestService", "add", input, strlen(
				input) + 1, &output, &len);
		if (code != RPC_OK) {
			printf("call error %s\n", rpc_code_format(code));
			exit(1);
		}
		result = *(int*) output;
		if (result != (2 * i + 1)) {
			printf("i is %d,result:%d should %d\n", i, result, 2 * i + 1);
			exit(1);
		}
		printf("result:%d\n", result);
	}
	int j;
	for (j = 0; j < 10; j++) {
		for (i = 0; i < 10000; i++) {
			len = sprintf(input, "%d %d", i, i + 1);
			rpc_client_call_async(client, "TestService", "add", strdup(input),
					strlen(input) + 1, cb_add, INT_TO_POINTER(i));
		}
    rpc_sleep(1000);
	}

	printf("test ok\n");
	for (;;) {
		rpc_sleep(1000);
	}
	return EXIT_SUCCESS;
}
Esempio n. 11
0
int main()
{
   char host_name[80];
   HNDLE hConn;
   INT status;
   BYTE b;
   WORD w;
   INT i;
   float f;
   double d;

   printf("Remote host name: ");
   ss_gets(host_name, sizeof(host_name));

   /* register this as an RPC client with rpc_list */
   rpc_register_client("MYCLIENT", rpc_list);

   /* connect to RPC server */
   status = rpc_client_connect(host_name, 1750, "", &hConn);
   if (status != RPC_SUCCESS) {
      printf("Cannot connect to RPC server running on %s at port 1750.\n", host_name);
      return 0;
   }

   f = 3.5f;
   d = 4.5;

   /* rpc_mytest just doubles numbers */
   rpc_client_call(hConn, RPC_MYTEST, 1, 2, 3l, f, d, &b, &w, &i, &f, &d);

   printf("\nResult should be:  2 4 6 7.0 9.0\n");
   printf("Result is:         %d %d %d %1.1f %1.1lf\n", b, w, i, f, d);

   printf("\nhit return...");
   b = getchar();

   /* disconnect this client from server */
   rpc_client_disconnect(hConn, FALSE);
   return 1;
}
Esempio n. 12
0
INT rpc_master_read(char *pevent)
{
  if(!enable_rpc_master) {
    return SUCCESS;
  }

  int ram = cycle_ram();

  // Send a message to other crates that the cycle is now over
  for(int i = 0; i < MAX_CRATES; i++) {
    if(i != crate_number && crate[i].enabled) {
      if(crate[i].synchronous || crate[i].participating) {
        diag_print(2, "Sending RPC_END_OF_CYCLE to crate %d RAM %d event %d\n",
            i, ram, event_number);
        rpc_client_call(crate[i].conn, RPC_END_OF_CYCLE, ram, event_number);
      }
    }
   }
 
  // Increment event number
  event_number++;

  return SUCCESS;
}
Esempio n. 13
0
int cam_init_rpc(char *host_name, char *exp_name, char *fe_name,
                 char *client_name, char *rpc_server)
{
   INT status, i, size;
   char str[256];
   HNDLE hDB, hKey, hRootKey, hSubkey;

   if (rpc_server[0]) {
      /* connect directly to RPC server, not to MIDAS experiment */
      midas_connect = FALSE;

#ifdef OS_WINNT
      {
         WSADATA WSAData;

         /* Start windows sockets */
         if (WSAStartup(MAKEWORD(1, 1), &WSAData) != 0)
            return RPC_NET_ERROR;
      }
#endif

      rpc_set_name(client_name);
      rpc_register_functions(rpc_get_internal_list(0), NULL);
      rpc_register_functions(rpc_get_internal_list(1), NULL);

      status = rpc_client_connect(rpc_server, 1750, client_name, &hConn);
      if (status != RPC_SUCCESS) {
         printf("Cannot connect to RPC server running on %s at port 1750.\n", rpc_server);
         return status;
      }
   } else {
      /* connect to MIDAS experiment */
      midas_connect = TRUE;

      /* turn off message display, turn on message logging */
      cm_set_msg_print(MT_ALL, 0, NULL);

      /* connect to experiment */
      status = cm_connect_experiment(host_name, exp_name, client_name, 0);
      if (status != CM_SUCCESS)
         return CM_UNDEF_EXP;

      /* connect to the database */
      cm_get_experiment_database(&hDB, &hKey);

      /* find CNAF server if not specified */
      strcpy(str, fe_name);
      if (fe_name[0] == '\0') {
         /* find client which exports CNAF function */
         status = db_find_key(hDB, 0, "System/Clients", &hRootKey);
         if (status == DB_SUCCESS) {
            for (i = 0, status = 0;; i++) {
               status = db_enum_key(hDB, hRootKey, i, &hSubkey);
               if (status == DB_NO_MORE_SUBKEYS) {
                  printf("No client currently exports the CNAF functionality.\n");
                  cm_disconnect_experiment();
                  return CM_UNDEF_EXP;
               }

               sprintf(str, "RPC/%d", RPC_CNAF16);
               status = db_find_key(hDB, hSubkey, str, &hKey);
               if (status == DB_SUCCESS) {
                  size = sizeof(str);
                  db_get_value(hDB, hSubkey, "Name", str, &size, TID_STRING, TRUE);
                  break;
               }
            }
         }
      }

      /* register CNAF_RPC call */
      if (cm_connect_client(str, &hConn) == CM_SUCCESS) {
         DWORD data, size, q, x;

         /* test if CNAF function implemented */
         size = sizeof(WORD);
         status =
             rpc_client_call(hConn, RPC_CNAF16, CNAF_TEST, 0, 0, 0, 0, 0, &data, &size,
                             &q, &x);

         if (status != RPC_SUCCESS) {
            printf("CNAF functionality not implemented by frontend %s\n", fe_name);
            cm_disconnect_client(hConn, FALSE);
            return CM_NO_CLIENT;
         }
      } else {
         printf("Cannot connect to frontend %s\n", fe_name);
         return CM_NO_CLIENT;
      }
   }

   return SUCCESS;
}
Esempio n. 14
0
INT rpc_g2_end_of_fill(INT index, void *prpc_param[])
{
  int status;

  struct timeval tv_rpc, tv_amc;

  status = gettimeofday( &tv_rpc, NULL);
  if ( status != 0)
    {
      printf("ERROR! gettimeofday() failed\n");
      tv_rpc.tv_sec = 0;
      tv_rpc.tv_usec = 0;
    }
  trigger_info.time_slave_got_eof_s = tv_rpc.tv_sec;
  trigger_info.time_slave_got_eof_us = tv_rpc.tv_usec;


  //trigger_nr,trigger_mask,time_s,time_us);
  trigger_info.trigger_nr   = CDWORD(0);
  trigger_info.trigger_mask = CDWORD(1);
  trigger_info.time_master_got_eof_s = CDWORD(2);
  trigger_info.time_master_got_eof_us = CDWORD(3);

  long int dt_s = trigger_info.time_slave_got_eof_s;
  dt_s -= trigger_info.time_master_got_eof_s;
  long int dt_us =  trigger_info.time_slave_got_eof_us;
  dt_us -= trigger_info.time_master_got_eof_us;
  if ( dt_us < 0 )
    {
      dt_s -= 1;
      dt_us += 1000000;
    }

  printf("rpc_g2_eof: end of spill #%i, master-slave interval dt = %li s %li us\n", trigger_info.trigger_nr, dt_s, dt_us);

  /*
  status = gettimeofday( &tv_rpc, NULL);
  if ( status != 0)
    {
      printf("ERROR! gettimeofday() failed\n");
      tv_rpc.tv_sec = 0;
      tv_rpc.tv_usec = 0;
    }

  dt_s = tv_rpc.tv_sec;
  dt_s -= trigger_info.time_slave_got_eof_s;
  dt_us = tv_rpc.tv_usec;
  dt_us -= trigger_info.time_slave_got_eof_us;
  if ( dt_us < 0 )
    {
      dt_s -= 1;
      dt_us += 1000000;
    }

  printf("rpc_g2_eof: end of spill #%i, rpc_ready delay dt = %li s %li us\n", trigger_info.trigger_nr, dt_s, dt_us);
  */

  /* disabled for AMC13 based readout
  // send data to the tcp readout frontend
  status = tcp_write();
  if ( status != 0 )
    {
      cm_msg(MERROR, __FILE__, "TCP send data failed, err = %i", status);
      return FE_ERR_HW;
    }
  */

  // makes amc13 send event
  printf(" before amc13 write\n");
  //int nSubEvents = 54 * 30; // no. of sub-events in each fill, ~ nsegments x ( 2bytes*6e5ns*0.8samples/ns / 32kB payload ) 
  //int nSubEvents = 54; // testing
  int nSubEvents = 1; // testing
  int iSubEvents;
  int write_stat;
  if (amc13_amc13_odb.enableSoftwareTrigger){
    for (iSubEvents = 0; iSubEvents < nSubEvents; iSubEvents++){
      printf(" software trigger enabled, writing AMC event %i\n",iSubEvents);
      write_stat = amc13lib.AMC13_Write(amc13);
      printf(" software trigger enabled, wrote AMC event %i\n",iSubEvents);
      if (write_stat==0) printf("STOP!  Write to AMC13 failed!\n");
    }
  }
    
    status = gettimeofday( &tv_amc, NULL);
  if ( status != 0)
    {
      printf("ERROR! gettimeofday() failed\n");
      tv_amc.tv_sec = 0;
      tv_amc.tv_usec = 0;
    }

  dt_s = tv_amc.tv_sec;
  dt_s -= trigger_info.time_master_got_eof_s;
  dt_us = tv_amc.tv_usec;
  dt_us -= trigger_info.time_master_got_eof_us;
  if ( dt_us < 0 )
    {
      dt_s -= 1;
      dt_us += 1000000;
    }

  printf("rpc_g2_eof: end of spill #%i, amc write - slave interval dt = %li s %li us\n", trigger_info.trigger_nr, dt_s, dt_us);

  // have EOF set data available so poll will succeed 
  data_avail = TRUE;

  // 14 August 2014
  // try quick fix to send ready on tcp_client_send()
  // and remove data_avail so wont make any events
  //rpc_g2_ready( frontend_index + frontend_index_offset );
  // Finally figured out that Fast TCP  communications
  // via rpc_call_client() return after send, i.e. dont 
  // block until "success" from remote routine

  //send_event(0,0); /** equipment id: 0, manual trigger: 0 */
  // *** unlock VME thread which will start data readout ***

  /* do quick stuff here */

  /* get control over vme interface */
  //pthread_mutex_lock( &vme_thread_info.mutex_vme  );

#if 0
  // Arm sampling logic
  status = sis3350_ArmSamplingOnAlternateBank();
  if ( status != 0 )
  {
    /** \todo handle errors */
    /* must not send RPC from this function */
    //cm_msg(MERROR, "read_trigger_event", "Error arming sampling on alternate bank, err = %i", status);
  }
#endif
  

#if 0
  // send back
  extern HNDLE rpc_master_hndle;
  #define RPC_READY 2202

  status = rpc_client_call(rpc_master_hndle, RPC_READY, frontend_index);

  if(status != RPC_SUCCESS ) 
    {
      cm_msg(MERROR, "rpc_call", "No RPC to master");
    }
#endif  

#if 0
  rpc_g2_ready();
#endif
  
#ifdef USE_GPU
  pthread_mutex_unlock( &(gpu_thread_1_info.mutex)  );
#endif


  return SUCCESS;
}