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; }
/*--------------------------------------------------------------------*/ void mcstd_func(CAMAC * PP) { char paddr[128], pstr[128]; int i, status, pstatus = 0; WORD dd16[100]; WORD *pdd16; DWORD dd24[100]; DWORD *pdd24; DWORD lam; CAMAC *p; /* Load default CAMAC */ // PP = &Prompt[1]; while (1) { make_display_string(MCSTD, PP, paddr); /* prompt */ printf("MCStd> [%s] :", paddr); ss_gets(pstr, 128); /* decode line */ status = decode_line(PP, pstr); p = PP; if (status == LOOP) status = pstatus; if (status != SKIP && status != HELP) pstatus = status; i = 0; pdd16 = dd16; pdd24 = dd24; switch (status) { /* system */ case CAMST: printf("cam_op\n"); cam_op(); break; case CAM_LAM_ENABLE: cam_lam_enable(p->c, p->n); printf("cam_lam_enable:C%i-N%i\n", p->c, p->n); break; case CAM_LAM_DISABLE: cam_lam_disable(p->c, p->n); printf("cam_lam_disable:C%i-N%i\n", p->c, p->n); break; case CAM_LAM_READ: cam_lam_read(p->c, &lam); printf("cam_lam_read:C%i-> 0x%x\n", p->c, lam); break; case CAM_LAM_CLEAR: cam_lam_clear(p->c, p->n); printf("cam_lam_clear:C%i \n", p->c); break; case CAM_INHIBIT_SET: cam_inhibit_set(p->c); printf("cam_inhibit_set:C%i\n", p->c); break; case CAM_INHIBIT_CLEAR: cam_inhibit_clear(p->c); printf("cam_inhibit_clear:C%i\n", p->c); break; case CAM_CRATE_CLEAR: cam_crate_clear(p->c); printf("cam_crate_clear:C%i\n", p->c); break; case CAM_CRATE_ZINIT: cam_crate_zinit(p->c); printf("cam_crate_zinit:C%i\n", p->c); break; /* command */ case CAMC: do { camc(p->c, p->n, p->a, p->f); printf("camc:[R%i]-C%i-N%i-A%i-F%i\n", ++i, p->c, p->n, p->a, p->f); } while (i < p->r); break; case CAMC_Q: do { camc_q(p->c, p->n, p->a, p->f, &p->q); printf("camc_q:[R%i]-C%i-N%i-A%i-F%i -Q:%i\n", ++i, p->c, p->n, p->a, p->f, p->q); } while (i < p->r); break; case CAMC_SA: camc(p->c, p->n, p->a, p->f); printf("camc_sa:C%i-N%i-A%i-F%i\n", p->c, p->n, p->a, p->f); break; case CAMC_SN: camc(p->c, p->n, p->a, p->f); printf("camc_sn:C%i-N%i-A%i-F%i\n", p->c, p->n, p->a, p->f); break; /* output */ case CAM16O: do { cam16o(p->c, p->n, p->a, p->f, p->d16); printf("cam16o:[R%i]-C%i-N%i-A%i-F%i <- 0x%x\n", ++i, p->c, p->n, p->a, p->f, p->d16); } while (i < p->r); break; case CAM24O: do { cam24o(p->c, p->n, p->a, p->f, p->d24); printf("cam24o:[R%i]-C%i-N%i-A%i-F%i <- 0x%x\n", ++i, p->c, p->n, p->a, p->f, p->d24); } while (i < p->r); break; case CAM16O_Q: do { cam16o_q(p->c, p->n, p->a, p->f, p->d16, &p->x, &p->q); printf("cam16o_q:[R%i]-C%i-N%i-A%i-F%i <- 0x%x X:%i-Q:%i\n", ++i, p->c, p->n, p->a, p->f, p->d16, p->x, p->q); } while (i < p->r); break; case CAM24O_Q: do { cam24o_q(p->c, p->n, p->a, p->f, p->d24, &p->x, &p->q); printf("cam24o_q:[R%i]-C%i-N%i-A%i-F%i <- 0x%x X:%i-Q:%i\n", ++i, p->c, p->n, p->a, p->f, p->d24, p->x, p->q); } while (i < p->r); break; case CAM16O_R: cam16o_r(p->c, p->n, p->a, p->f, pdd16, p->r); printf("cam16o_r:C%i-N%i-A%i-F%i <- 0x%x\n", p->c, p->n, p->a, p->f, p->d16); break; case CAM24O_R: cam24o_r(p->c, p->n, p->a, p->f, pdd24, p->r); printf("cam24o_r:C%i-N%i-A%i-F%i <- 0x%x\n", p->c, p->n, p->a, p->f, p->d24); break; /* inputs */ case CAM16I: do { cam16i(p->c, p->n, p->a, p->f, &p->d16); printf("cam16i:[R%i]-C%i-N%i-A%i-F%i-> 0x%4.4x\n", ++i, p->c, p->n, p->a, p->f, p->d16); } while (i < p->r); break; case CAM24I: do { cam24i(p->c, p->n, p->a, p->f, &p->d24); printf("cam24i:[R%i]-C%i-N%i-A%i-F%i-> 0x%6.6x\n", ++i, p->c, p->n, p->a, p->f, p->d24); } while (i < p->r); break; case CAM16I_Q: do { cam16i_q(p->c, p->n, p->a, p->f, &p->d16, &p->x, &p->q); printf("cam16i_q:[R%i]-C%i-N%i-A%i-F%i-> 0x%4.4x X:%i-Q:%i\n", ++i, p->c, p->n, p->a, p->f, p->d16, p->x, p->q); } while (i < p->r); break; case CAM24I_Q: do { cam24i_q(p->c, p->n, p->a, p->f, &p->d24, &p->x, &p->q); printf("cam24i_q:[R%i]-C%i-N%i-A%i-F%i-> 0x%6.6x X:%i-Q:%i\n", ++i, p->c, p->n, p->a, p->f, p->d24, p->x, p->q); } while (i < p->r); break; case CAM16I_R: memset(pdd16, 0, sizeof(dd16)); cam16i_r(p->c, p->n, p->a, p->f, &pdd16, p->r); for (i = 0; i < p->r; i++) printf("cam16i_r:[R%i]-C%i-N%i-A%i-F%i-> 0x%4.4x\n", i + 1, p->c, p->n, p->a, p->f, dd16[i]); break; case CAM24I_R: memset(pdd24, 0, sizeof(dd24)); cam24i_r(p->c, p->n, p->a, p->f, &pdd24, p->r); for (i = 0; i < p->r; i++) printf("cam24i_r:[R%i]-C%i-N%i-A%i-F%i-> 0x%6.6x\n", i + 1, p->c, p->n, p->a, p->f, dd24[i]); break; case CAM16I_RQ: memset(pdd16, 0, sizeof(dd16)); cam16i_rq(p->c, p->n, p->a, p->f, &pdd16, p->r); for (i = 0; i < p->r; i++) printf("cam16i_rq:[R%i]-C%i-N%i-A%i-F%i-> 0x%4.4x\n", i + 1, p->c, p->n, p->a, p->f, dd16[i]); break; case CAM24I_RQ: memset(pdd24, 0, sizeof(dd24)); cam24i_rq(p->c, p->n, p->a, p->f, &pdd24, p->r); for (i = 0; i < p->r; i++) printf("cam24i_rq:[R%i]-C%i-N%i-A%i-F%i-> 0x%6.6x\n", i + 1, p->c, p->n, p->a, p->f, dd24[i]); break; case CAM16I_SA: memset(pdd16, 0, sizeof(dd16)); cam16i_sa(p->c, p->n, p->a, p->f, &pdd16, p->r); for (i = 0; i < p->r; i++) printf("cam16i_sa:[R%i]-C%i-N%i-A%i-F%i-> 0x%4.4x\n", i + 1, p->c, p->n, p->a + i, p->f, dd16[i]); break; case CAM24I_SA: memset(pdd24, 0, sizeof(dd24)); cam24i_sa(p->c, p->n, p->a, p->f, &pdd24, p->r); for (i = 0; i < p->r; i++) printf("cam24i_sa:[R%i]-C%i-N%i-A%i-F%i-> 0x%6.6x\n", i + 1, p->c, p->n, p->a + i, p->f, dd24[i]); break; case CAM16I_SN: memset(pdd16, 0, sizeof(dd16)); cam16i_sa(p->c, p->n, p->a, p->f, &pdd16, p->r); for (i = 0; i < p->r; i++) printf("cam16i_sn:[R%i]-C%i-N%i-A%i-F%i-> 0x%x\n", i + 1, p->c, p->n + i, p->a, p->f, dd16[i]); break; case CAM24I_SN: memset(pdd24, 0, sizeof(dd24)); cam24i_sn(p->c, p->n, p->a, p->f, &pdd24, p->r); for (i = 0; i < p->r; i++) printf("cam24i_sn:[R%i]-C%i-N%i-A%i-F%i-> 0x%x\n", i + 1, p->c, p->n + i, p->a, p->f, dd24[i]); break; case QUIT: p->r = 1; return; case HELP: help_page(MCSTD); break; case SKIP: break; default: status = SKIP; break; } } }
/*--------------------------------------------------------------------*/ 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; }
main() { INT status, size, trans, run_number; char host_name[256], str[32]; INT event_id, request_id; DWORD last_time; BOOL via_callback; /* get parameters */ printf("ID of event to request: "); ss_gets(str, 32); event_id = atoi(str); printf("Host to connect: "); ss_gets(host_name, 256); printf("Get all events (0/1): "); ss_gets(str, 32); all_flag = atoi(str); printf("Receive via callback ([y]/n): "); ss_gets(str, 32); via_callback = str[0] != 'n'; /* connect to experiment */ status = cm_connect_experiment(host_name, "", all_flag ? "Power Consumer" : "Consumer", NULL); if (status != CM_SUCCESS) return 1; /* open the "system" buffer, 1M size */ bm_open_buffer("SYSTEM", EVENT_BUFFER_SIZE, &hBufEvent); /* set the buffer cache size */ bm_set_cache_size(hBufEvent, 100000, 0); /* place a request for a specific event id */ bm_request_event(hBufEvent, (WORD) event_id, TRIGGER_ALL, all_flag ? GET_ALL : GET_SOME, &request_id, via_callback ? process_event : NULL); /* place a request for system messages */ cm_msg_register(process_message); /* place a request for transition notification */ cm_register_transition(TR_START, via_callback? transition : NULL); last_time = 0; do { if (via_callback) status = cm_yield(1000); else { /* receive event "manually" and call receive_event */ size = sizeof(event_buffer); status = bm_receive_event(hBufEvent, event_buffer, &size, ASYNC); if (status == BM_SUCCESS) process_event(hBufEvent, request_id, (EVENT_HEADER *) event_buffer, (void *) (((EVENT_HEADER *) event_buffer) + 1)); /* receive transitions "manually" */ if (cm_query_transition(&trans, &run_number, NULL)) transition(run_number, NULL); /* call yield once every 100 ms */ if (ss_millitime() - last_time > 100) { last_time = ss_millitime(); status = cm_yield(0); } } } while (status != RPC_SHUTDOWN && status != SS_ABORT); cm_disconnect_experiment(); return 1; }