- Adapted indenation to new agreed upon system
- Added support for second generation scriptcontext based counter
This commit is contained in:
308
hmcontrol.c
308
hmcontrol.c
@ -25,188 +25,184 @@ static void *HMCGetInterface(void *pData, int ID)
|
||||
{
|
||||
pHMcontrol self = NULL;
|
||||
|
||||
self = (pHMcontrol)pData;
|
||||
self = (pHMcontrol) pData;
|
||||
assert(self);
|
||||
|
||||
if(ID == COUNTID)
|
||||
if (ID == COUNTID)
|
||||
return self->pCount;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int HMCHalt(void *pData)
|
||||
{
|
||||
int i, retVal = OKOK, status;
|
||||
pHMcontrol self = NULL;
|
||||
|
||||
self = (pHMcontrol)pData;
|
||||
self = (pHMcontrol) pData;
|
||||
assert(self);
|
||||
|
||||
for(i = 0; i < self->nSlaves; i++)
|
||||
{
|
||||
for (i = 0; i < self->nSlaves; i++) {
|
||||
status = self->slaves[i]->Halt(self->slaveData[i]);
|
||||
ReleaseCountLock(self->slaves[i]);
|
||||
if(status != OKOK)
|
||||
if (status != OKOK)
|
||||
retVal = status;
|
||||
}
|
||||
ReleaseCountLock(self->pCount);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static int HMCStart(void *pData, SConnection *pCon)
|
||||
static int HMCStart(void *pData, SConnection * pCon)
|
||||
{
|
||||
int i, status;
|
||||
pHMcontrol self = NULL;
|
||||
|
||||
self = (pHMcontrol)pData;
|
||||
self = (pHMcontrol) pData;
|
||||
assert(self);
|
||||
|
||||
if(!GetCountLock(self->pCount, pCon)){
|
||||
return HWFault;
|
||||
|
||||
if (!GetCountLock(self->pCount, pCon)) {
|
||||
return HWFault;
|
||||
}
|
||||
|
||||
for(i = 0; i < self->nSlaves; i++)
|
||||
{
|
||||
ReleaseCountLock(self->slaves[i]);
|
||||
status = self->slaves[i]->StartCount(self->slaveData[i],pCon);
|
||||
if(status != OKOK)
|
||||
{
|
||||
|
||||
for (i = 0; i < self->nSlaves; i++) {
|
||||
ReleaseCountLock(self->slaves[i]);
|
||||
status = self->slaves[i]->StartCount(self->slaveData[i], pCon);
|
||||
if (status != OKOK) {
|
||||
HMCHalt(self);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
static int HMCStatus(void *pData, SConnection *pCon)
|
||||
static int HMCStatus(void *pData, SConnection * pCon)
|
||||
{
|
||||
int status,i;
|
||||
int status, i;
|
||||
pHMcontrol self = NULL;
|
||||
|
||||
self = (pHMcontrol)pData;
|
||||
self = (pHMcontrol) pData;
|
||||
assert(self);
|
||||
|
||||
status = self->slaves[0]->CheckCountStatus(self->slaveData[0],pCon);
|
||||
if(status == HWIdle || status == HWFault)
|
||||
{
|
||||
status = self->slaves[0]->CheckCountStatus(self->slaveData[0], pCon);
|
||||
if (status == HWIdle || status == HWFault) {
|
||||
/*
|
||||
stop counting on slaves when finished or when an error
|
||||
occurred.
|
||||
*/
|
||||
InvokeCallBack(self->pCall,COUNTEND,pCon);
|
||||
stop counting on slaves when finished or when an error
|
||||
occurred.
|
||||
*/
|
||||
InvokeCallBack(self->pCall, COUNTEND, pCon);
|
||||
HMCHalt(self);
|
||||
}
|
||||
/*
|
||||
Warning: this assumes that salves 1 - MAXSLAVE are histogram memories.
|
||||
If this assumption does not hold, change this code to check if this
|
||||
is really a histogram memory.
|
||||
*/
|
||||
for(i = 1; i < MAXSLAVE; i++)
|
||||
{
|
||||
if(self->slaves[i] != NULL)
|
||||
{
|
||||
HistDirty((pHistMem)self->slaveData[i]);
|
||||
Warning: this assumes that salves 1 - MAXSLAVE are histogram memories.
|
||||
If this assumption does not hold, change this code to check if this
|
||||
is really a histogram memory.
|
||||
*/
|
||||
for (i = 1; i < MAXSLAVE; i++) {
|
||||
if (self->slaves[i] != NULL) {
|
||||
HistDirty((pHistMem) self->slaveData[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------*/
|
||||
static int HMCPause(void *pData, SConnection *pCon)
|
||||
static int HMCPause(void *pData, SConnection * pCon)
|
||||
{
|
||||
int i, status;
|
||||
pHMcontrol self = NULL;
|
||||
|
||||
self = (pHMcontrol)pData;
|
||||
self = (pHMcontrol) pData;
|
||||
assert(self);
|
||||
|
||||
for(i = 0; i < self->nSlaves; i++)
|
||||
{
|
||||
status = self->slaves[i]->Pause(self->slaveData[i],pCon);
|
||||
if(status != OKOK)
|
||||
{
|
||||
for (i = 0; i < self->nSlaves; i++) {
|
||||
status = self->slaves[i]->Pause(self->slaveData[i], pCon);
|
||||
if (status != OKOK) {
|
||||
HMCHalt(self);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------*/
|
||||
static int HMCContinue(void *pData, SConnection *pCon)
|
||||
static int HMCContinue(void *pData, SConnection * pCon)
|
||||
{
|
||||
int i, status;
|
||||
pHMcontrol self = NULL;
|
||||
|
||||
self = (pHMcontrol)pData;
|
||||
self = (pHMcontrol) pData;
|
||||
assert(self);
|
||||
|
||||
for(i = 0; i < self->nSlaves; i++)
|
||||
{
|
||||
status = self->slaves[i]->Continue(self->slaveData[i],pCon);
|
||||
if(status != OKOK)
|
||||
{
|
||||
for (i = 0; i < self->nSlaves; i++) {
|
||||
status = self->slaves[i]->Continue(self->slaveData[i], pCon);
|
||||
if (status != OKOK) {
|
||||
HMCHalt(self);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return OKOK;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
static int HMCTransfer(void *pData, SConnection *pCon)
|
||||
static int HMCTransfer(void *pData, SConnection * pCon)
|
||||
{
|
||||
int i, retVal = OKOK, status;
|
||||
pHMcontrol self = NULL;
|
||||
char pBueffel[132];
|
||||
|
||||
self = (pHMcontrol)pData;
|
||||
self = (pHMcontrol) pData;
|
||||
assert(self);
|
||||
|
||||
for(i = 0; i < self->nSlaves; i++)
|
||||
{
|
||||
for (i = 0; i < self->nSlaves; i++) {
|
||||
status = self->slaves[i]->TransferData(self->slaveData[i], pCon);
|
||||
if(status != OKOK)
|
||||
{
|
||||
if (status != OKOK) {
|
||||
retVal = status;
|
||||
sprintf(pBueffel,"WARNING: slave histogram %d failed to transfer data",
|
||||
i);
|
||||
SCWrite(pCon,pBueffel,eWarning);
|
||||
sprintf(pBueffel,
|
||||
"WARNING: slave histogram %d failed to transfer data", i);
|
||||
SCWrite(pCon, pBueffel, eWarning);
|
||||
}
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
static void HMCParameter(void *pData, float fPreset, CounterMode eMode )
|
||||
static void HMCParameter(void *pData, float fPreset, CounterMode eMode)
|
||||
{
|
||||
int i;
|
||||
pHMcontrol self = NULL;
|
||||
|
||||
self = (pHMcontrol)pData;
|
||||
self = (pHMcontrol) pData;
|
||||
assert(self);
|
||||
|
||||
for(i = 0; i < self->nSlaves; i++)
|
||||
{
|
||||
for (i = 0; i < self->nSlaves; i++) {
|
||||
self->slaves[i]->SetCountParameters(self->slaveData[i], fPreset,
|
||||
eMode);
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
static void KillHMcontrol(void *pData)
|
||||
{
|
||||
pHMcontrol self;
|
||||
|
||||
self = (pHMcontrol)pData;
|
||||
if(!self)
|
||||
self = (pHMcontrol) pData;
|
||||
if (!self)
|
||||
return;
|
||||
|
||||
if(self->pDes)
|
||||
if (self->pDes)
|
||||
DeleteDescriptor(self->pDes);
|
||||
if(self->pCount)
|
||||
if (self->pCount)
|
||||
free(self->pCount);
|
||||
free(self);
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------*/
|
||||
int MakeHMControl(SConnection *pCon, SicsInterp *pSics,
|
||||
void *pData, int argc, char *argv[])
|
||||
int MakeHMControl(SConnection * pCon, SicsInterp * pSics,
|
||||
void *pData, int argc, char *argv[])
|
||||
{
|
||||
int i, status;
|
||||
pHMcontrol pNew = NULL;
|
||||
@ -215,38 +211,36 @@ int MakeHMControl(SConnection *pCon, SicsInterp *pSics,
|
||||
pICountable pCount;
|
||||
|
||||
/*
|
||||
need at least two parameters
|
||||
*/
|
||||
if(argc < 3)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: insufficient number of arguments to MakeHMControl",
|
||||
eError);
|
||||
need at least two parameters
|
||||
*/
|
||||
if (argc < 3) {
|
||||
SCWrite(pCon,
|
||||
"ERROR: insufficient number of arguments to MakeHMControl",
|
||||
eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
allocate our data structure
|
||||
*/
|
||||
pNew = (pHMcontrol)malloc(sizeof(HMcontrol));
|
||||
if(!pNew)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory in MakeHMControl",eError);
|
||||
*/
|
||||
pNew = (pHMcontrol) malloc(sizeof(HMcontrol));
|
||||
if (!pNew) {
|
||||
SCWrite(pCon, "ERROR: out of memory in MakeHMControl", eError);
|
||||
return 0;
|
||||
}
|
||||
memset(pNew,0,sizeof(HMcontrol));
|
||||
memset(pNew, 0, sizeof(HMcontrol));
|
||||
pNew->pDes = CreateDescriptor("HMcontrol");
|
||||
pNew->pCount = CreateCountableInterface();
|
||||
pNew->pCall = CreateCallBackInterface();
|
||||
if(!pNew->pDes || ! pNew->pCount)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: out of memory in MakeHMControl",eError);
|
||||
if (!pNew->pDes || !pNew->pCount) {
|
||||
SCWrite(pCon, "ERROR: out of memory in MakeHMControl", eError);
|
||||
KillHMcontrol(pNew);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
assign interface functions
|
||||
*/
|
||||
assign interface functions
|
||||
*/
|
||||
pNew->pDes->GetInterface = HMCGetInterface;
|
||||
pNew->pCount->Halt = HMCHalt;
|
||||
pNew->pCount->StartCount = HMCStart;
|
||||
@ -257,25 +251,21 @@ int MakeHMControl(SConnection *pCon, SicsInterp *pSics,
|
||||
pNew->pCount->SetCountParameters = HMCParameter;
|
||||
|
||||
/*
|
||||
now loop through the remaining arguments, thereby entering them into
|
||||
the slave list.
|
||||
*/
|
||||
for(i = 2; i < argc; i++)
|
||||
{
|
||||
pCom = FindCommand(pSics,argv[i]);
|
||||
if(!pCom)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: object %s not found in MakeHMcontrol",
|
||||
now loop through the remaining arguments, thereby entering them into
|
||||
the slave list.
|
||||
*/
|
||||
for (i = 2; i < argc; i++) {
|
||||
pCom = FindCommand(pSics, argv[i]);
|
||||
if (!pCom) {
|
||||
sprintf(pBueffel, "ERROR: object %s not found in MakeHMcontrol",
|
||||
argv[i]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
continue;
|
||||
}
|
||||
pCount = GetCountableInterface(pCom->pData);
|
||||
if(!pCount)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: object %s is NOT countable",
|
||||
argv[i]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
if (!pCount) {
|
||||
sprintf(pBueffel, "ERROR: object %s is NOT countable", argv[i]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
continue;
|
||||
}
|
||||
pNew->slaves[pNew->nSlaves] = pCount;
|
||||
@ -284,25 +274,25 @@ int MakeHMControl(SConnection *pCon, SicsInterp *pSics,
|
||||
}
|
||||
|
||||
/*
|
||||
now install our action command and we are done
|
||||
*/
|
||||
status = AddCommand(pSics,argv[1],HMControlAction,KillHMcontrol,
|
||||
pNew);
|
||||
if(!status)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: duplicate command %s not created",argv[1]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
now install our action command and we are done
|
||||
*/
|
||||
status = AddCommand(pSics, argv[1], HMControlAction, KillHMcontrol,
|
||||
pNew);
|
||||
if (!status) {
|
||||
sprintf(pBueffel, "ERROR: duplicate command %s not created", argv[1]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
KillHMcontrol(pNew);
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------
|
||||
Syntax: whatever start preset mode
|
||||
------------------------------------------------------------------------*/
|
||||
int HMControlAction(SConnection *pCon, SicsInterp *pSics,
|
||||
void *pData, int argc, char *argv[])
|
||||
int HMControlAction(SConnection * pCon, SicsInterp * pSics,
|
||||
void *pData, int argc, char *argv[])
|
||||
{
|
||||
pHMcontrol self;
|
||||
char pBueffel[132];
|
||||
@ -311,63 +301,53 @@ int HMControlAction(SConnection *pCon, SicsInterp *pSics,
|
||||
int status;
|
||||
|
||||
/*
|
||||
checks
|
||||
*/
|
||||
self = (pHMcontrol)pData;
|
||||
checks
|
||||
*/
|
||||
self = (pHMcontrol) pData;
|
||||
assert(self);
|
||||
if(argc < 4)
|
||||
{
|
||||
snprintf(pBueffel,131,"ERROR: Usage %s start preset mode", argv[0]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
if (argc < 4) {
|
||||
snprintf(pBueffel, 131, "ERROR: Usage %s start preset mode", argv[0]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
strtolower(argv[1]);
|
||||
if(strcmp(argv[1],"start") == 0)
|
||||
{
|
||||
/*
|
||||
if (strcmp(argv[1], "start") == 0) {
|
||||
/*
|
||||
interpret count parameters
|
||||
*/
|
||||
status = Tcl_GetDouble(pSics->pTcl,argv[2],&dPreset);
|
||||
if(status != TCL_OK)
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: failed to convert %s to number",
|
||||
argv[2]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
strtolower(argv[3]);
|
||||
if(strcmp(argv[3],"timer") == 0)
|
||||
eMode = eTimer;
|
||||
else if(strcmp(argv[3],"monitor") == 0)
|
||||
eMode = ePreset;
|
||||
else
|
||||
{
|
||||
sprintf(pBueffel,"ERROR: %s is no recognized count mode",argv[3]);
|
||||
SCWrite(pCon,pBueffel,eError);
|
||||
return 0;
|
||||
}
|
||||
status = Tcl_GetDouble(pSics->pTcl, argv[2], &dPreset);
|
||||
if (status != TCL_OK) {
|
||||
sprintf(pBueffel, "ERROR: failed to convert %s to number", argv[2]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
strtolower(argv[3]);
|
||||
if (strcmp(argv[3], "timer") == 0)
|
||||
eMode = eTimer;
|
||||
else if (strcmp(argv[3], "monitor") == 0)
|
||||
eMode = ePreset;
|
||||
else {
|
||||
sprintf(pBueffel, "ERROR: %s is no recognized count mode", argv[3]);
|
||||
SCWrite(pCon, pBueffel, eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
set count parameters and go
|
||||
*/
|
||||
self->pCount->SetCountParameters(self,(float)dPreset,eMode);
|
||||
status = StartDevice(pServ->pExecutor,"hmcontrol",self->pDes,
|
||||
self,pCon,99);
|
||||
if(!status)
|
||||
{
|
||||
SCWrite(pCon,"ERROR: failed to start counting",eError);
|
||||
return 0;
|
||||
}
|
||||
InvokeCallBack(self->pCall,COUNTSTART,pCon);
|
||||
SCSendOK(pCon);
|
||||
}
|
||||
else
|
||||
{
|
||||
SCWrite(pCon,"ERROR: subcommand not recognized",eError);
|
||||
return 0;
|
||||
self->pCount->SetCountParameters(self, (float) dPreset, eMode);
|
||||
status = StartDevice(pServ->pExecutor, "hmcontrol", self->pDes,
|
||||
self, pCon, 99);
|
||||
if (!status) {
|
||||
SCWrite(pCon, "ERROR: failed to start counting", eError);
|
||||
return 0;
|
||||
}
|
||||
InvokeCallBack(self->pCall, COUNTSTART, pCon);
|
||||
SCSendOK(pCon);
|
||||
} else {
|
||||
SCWrite(pCon, "ERROR: subcommand not recognized", eError);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user