- Enhanced and debugged histogram memory for AMOR
* added PROJECT both in HM and driver code * added single detector support. - Removed several bugs in the AMOR data bit. - Updated documentation
This commit is contained in:
130
hardsup/sinqhm.c
130
hardsup/sinqhm.c
@@ -6,6 +6,8 @@
|
||||
David Maden, Mark Koennecke, April 1997
|
||||
|
||||
Updated for TOF support: Mark Koennecke, December 1998
|
||||
|
||||
Added Project for AMOR: Mark Koennecke, August 2001
|
||||
|
||||
Copyright:
|
||||
|
||||
@@ -1098,6 +1100,134 @@ extern int close(int fp);
|
||||
}
|
||||
}
|
||||
|
||||
/* swap bytes if necessary */
|
||||
if ((self->iBinWidth > 0) && (Rply_buff.bigend != 0x12345678))
|
||||
{
|
||||
switch (self->iBinWidth)
|
||||
{ /* Byte swapping is necessary */
|
||||
case 2:
|
||||
/* Not sure how to do this - this might be wrong! */
|
||||
p16 = (SQint16 *) pData;
|
||||
for (i = 0; i < iNoBins; i++)
|
||||
{
|
||||
p16[i] = ntohs (p16[i]);
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
p32 = (SQint32 *) pData;
|
||||
for (i = 0; i < iNoBins; i++)
|
||||
{
|
||||
p32[i] = ntohl(p32[i]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
/* done */
|
||||
return 1;
|
||||
}
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int SINQHMProject(pSINQHM self, int code, int xStart, int nx,
|
||||
int yStart, int ny,
|
||||
void *pData, int iDataLen)
|
||||
{
|
||||
long lBins2Get, lSpace,iNoBins, i;
|
||||
int status, iRet;
|
||||
struct req_buff_struct Req_buff;
|
||||
struct rply_buff_struct Rply_buff;
|
||||
SQint16 *p16;
|
||||
SQint32 *p32;
|
||||
char *pPtr;
|
||||
char pBuffer[8192];
|
||||
|
||||
assert(self);
|
||||
|
||||
/* initialize the Request data */
|
||||
Req_buff.bigend = htonl (0x12345678);
|
||||
Req_buff.cmnd = htonl (SQHM_PROJECT);
|
||||
Req_buff.u.project.sub_code = htonl (code);
|
||||
|
||||
Req_buff.u.project.x_lo = htonl (xStart);
|
||||
Req_buff.u.project.nx = htonl (nx);
|
||||
Req_buff.u.project.y_lo = htonl (yStart);
|
||||
Req_buff.u.project.ny = htonl (ny);
|
||||
Req_buff.u.project.nhist = htonl (1);
|
||||
|
||||
/* send the message */
|
||||
status = send (self->iClientSocket, (char *) &Req_buff,
|
||||
sizeof (Req_buff), 0);
|
||||
if (status == -1)
|
||||
{
|
||||
return SEND_ERROR;
|
||||
}
|
||||
if (status != sizeof (Req_buff))
|
||||
{
|
||||
return SEND_ERROR;
|
||||
}
|
||||
|
||||
/* wait for an answer */
|
||||
status = recv (self->iClientSocket, (char *) &Rply_buff,
|
||||
sizeof (Rply_buff), MSG_WAITALL);
|
||||
|
||||
/* check various error conditions */
|
||||
if (status == -1)
|
||||
{
|
||||
return RECEIVE_ERROR;
|
||||
}
|
||||
if (status != sizeof (Rply_buff))
|
||||
{
|
||||
return INSUFFICIENT_DATA;
|
||||
}
|
||||
if(ntohl (Rply_buff.bigend) != 0x12345678)
|
||||
{
|
||||
return BYTE_ORDER_CHAOS;
|
||||
}
|
||||
iRet = ntohl(Rply_buff.status);
|
||||
if(iRet != KER__SUCCESS)
|
||||
{
|
||||
return HIST_BAD_CODE;
|
||||
}
|
||||
|
||||
/* calculate the size of things to come */
|
||||
lBins2Get = ntohl(Rply_buff.u.project.n_bins) *
|
||||
ntohl(Rply_buff.u.project.bytes_per_bin);
|
||||
|
||||
/* read data */
|
||||
pPtr = (char *)pData;
|
||||
lSpace = iDataLen;
|
||||
iNoBins = ntohl(Rply_buff.u.project.n_bins);
|
||||
while (lBins2Get > 0)
|
||||
{
|
||||
if(lBins2Get > self->iPacket)
|
||||
{
|
||||
i = self->iPacket;
|
||||
}
|
||||
else
|
||||
{
|
||||
i = lBins2Get;
|
||||
}
|
||||
status = recv (self->iClientSocket, pBuffer,
|
||||
i, 0);
|
||||
if (status == -1)
|
||||
{
|
||||
return SEND_ERROR;
|
||||
}
|
||||
lBins2Get -= status;
|
||||
if((lSpace - status) > 0)
|
||||
{
|
||||
memcpy(pPtr,pBuffer,status);
|
||||
lSpace -= status;
|
||||
pPtr += status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(lSpace > 0)
|
||||
{
|
||||
memcpy(pPtr,pBuffer,lSpace);
|
||||
lSpace = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* swap bytes if necessary */
|
||||
if ((self->iBinWidth > 0) && (Rply_buff.bigend != 0x12345678))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user