- Added code to read SANS TOF frames from a) files and b) from HM

- Fixed an bug causing core dumps on bad Tcl scripts
- Started on a syntax checker for SICS
This commit is contained in:
cvs
2003-03-14 16:14:31 +00:00
parent a858f25522
commit 1969980f0f
19 changed files with 700 additions and 27 deletions

View File

@@ -2203,6 +2203,80 @@ extern PART_ID sysHighMemPart;
exit (KER__BAD_VALUE);
}
}
/**
* --------------------------------------------------------------------------
* project_frame reads one time frame of a TOF or PSD histogram
*/
static int project_frame(int rw_skt, int pkt_size, int nx){
struct rply_buff_struct rply;
uint *buffer = NULL;
uchar *bufPtr;
int i, bytesToSend, nSend, bytesSent;
register union {
void *base;
uchar *ch;
usint *i2;
uint *i4;
} hm_pntr;
printf("PROJECT: Trying to retrieve time frame: %d\n", nx);
/*
check arguments
*/
if(nx < 0 || nx >= N_bins){
printf("PROJECT FRAME: bad time frame requested: 0 < %d < %d\n",
nx,N_bins);
rply_status_setup (&rply, KER__BAD_VALUE, 0, "Bad argument");
rply_status_send (rw_skt, &rply);
return OK;
}
/*
allocate space
*/
buffer = (uint *)malloc(N_hists*sizeof(uint));
if(!buffer){
printf ("\n\007 -- SQHM_PROJECT-FRAME: failed to get buffer!\n");
rply_status_setup_and_send (rw_skt, &rply, KER__BAD_ALLOC, 0,
"Failed to get buffer for projecting data");
return OK;
}
/*
fill buffer
FIX: This works only OK with 4 byte HM data.
*/
hm_pntr.i4 = Hist_base_addr;
for(i = 0; i < N_hists;i++){
buffer[i] = htonl(*(hm_pntr.i4 + (i*N_bins) + nx));
}
/*
build reply and send data
*/
rply.bigend = 0x12345678;
rply.u.project.n_bins = htonl(N_hists);
rply.u.project.bytes_per_bin = htonl(4);
rply.u.project.cnts_lo = 0;
rply.u.project.cnts_hi = 0;
rply_status_setup_and_send (rw_skt, &rply, KER__SUCCESS, 0, NULL);
bufPtr = (uchar *)buffer;
bytesToSend = N_hists*4;
while(bytesToSend > 0){
nSend = (bytesToSend > pkt_size) ? pkt_size : bytesToSend;
bytesSent = send(rw_skt,bufPtr,nSend,0);
if(bytesSent > 0){
bytesToSend -= bytesSent;
bufPtr += bytesSent;
} else {
return ERROR;
}
}
free(buffer);
return OK;
}
/*
**--------------------------------------------------------------------------*/
int do_project (
@@ -2322,6 +2396,9 @@ extern PART_ID sysHighMemPart;
break;
/*-----------------------------------------------------------*/
case SQHM__TOF: /* Time-of-Flight Mode */
if( (sub_code & PROJECT__FRAME) == 0){
return project_frame(rw_skt,pkt_size,nx);
}
if ((sub_code & PROJECT__1_DIM) != 0) {
printf ("\n\007%s -- SQHM_PROJECT: SQHM__TOF+PROJECT__1_DIM not yet "
@@ -2389,6 +2466,10 @@ extern PART_ID sysHighMemPart;
/*
** code for TRICS, AMOR PSD
*/
if( (sub_code & PROJECT__FRAME) == 0){
return project_frame(rw_skt,pkt_size,nx);
}
if(sub_code == PROJECT__COLL){
my_nbins = psdXSize * psdYSize;
nTime = Tof_edges[0]->n_bins;