Cleaned up ANSTO code to merge with sinqdev.sics

This is our new RELEASE-4_0 branch which was taken from ansto/93d9a7c
Conflicts:
	.gitignore
	SICSmain.c
	asynnet.c
	confvirtualmot.c
	counter.c
	devexec.c
	drive.c
	event.h
	exebuf.c
	exeman.c
	histmem.c
	interface.h
	motor.c
	motorlist.c
	motorsec.c
	multicounter.c
	napi.c
	napi.h
	napi4.c
	network.c
	nwatch.c
	nxscript.c
	nxxml.c
	nxxml.h
	ofac.c
	reflist.c
	scan.c
	sicshipadaba.c
	sicsobj.c
	site_ansto/docs/Copyright.txt
	site_ansto/instrument/lyrebird/config/tasmad/sicscommon/nxsupport.tcl
	site_ansto/instrument/lyrebird/config/tasmad/taspub_sics/tasscript.tcl
	statusfile.c
	tasdrive.c
	tasub.c
	tasub.h
	tasublib.c
	tasublib.h
This commit is contained in:
Ferdi Franceschini
2015-04-23 20:49:26 +10:00
parent c650788a2c
commit 10d29d597c
1336 changed files with 9430 additions and 226646 deletions

117
histmem.c
View File

@@ -18,6 +18,10 @@
Mark Koennecke, March 2009
Added an error field in the options stringdict
Mark Koennecke, June 2013
Copyright:
Labor fuer Neutronenstreuung
@@ -70,6 +74,7 @@
#include "event.h"
#include "status.h"
#include "site.h"
#include "histmemsec.h"
#define ABS(x) (x < 0 ? -(x) : (x))
/*
@@ -84,6 +89,27 @@ extern pHistDriver CreateRegressHM(pStringDict pOpt);
*/
extern pHistDriver MakeHMSlaveHM(pStringDict pOpt);
/*------------------------------------------------------------------------*/
int isSecondGen(pHistMem self)
{
pDummy test = (pDummy)self;
if(strcmp(test->pDescriptor->name,"HistMemSec") == 0) {
return 1;
} else {
return 0;
}
}
/*-----------------------------------------------------------------------*/
pHistMem FindHM(SicsInterp *pSics, char *name)
{
pHistMem result = NULL;
result = (pHistMem)FindCommandData(pSics,name,"HistMem");
if(result == NULL){
result = (pHistMem)FindCommandData(pSics,name,"HistMemSec");
}
return result;
}
/*------------------------------------------------------------------------*/
static int HistHalt(void *pData)
{
pHistMem self = NULL;
@@ -182,12 +208,13 @@ static int HistStartCount(void *pData, SConnection * pCon)
}
/* try at least three times to do it */
StringDictUpdate(self->pDriv->pOption, "error", "None");
for (i = 0; i < 3; i++) {
iRet = self->pDriv->Start(self->pDriv, pCon);
if (iRet == OKOK) {
/* send a COUNTSTART event */
clearHMData(self->pDriv->data);
InvokeCallBack(self->pCall, COUNTSTART, pCon);
updateHMData(self->pDriv->data);
return iRet;
} else {
iRet = self->pDriv->GetError(self->pDriv, &iErr, pError, 79);
@@ -199,6 +226,7 @@ static int HistStartCount(void *pData, SConnection * pCon)
eLogError);
SCSetInterrupt(pCon, eAbortBatch);
ReleaseCountLock(self->pCountInt);
StringDictUpdate(self->pDriv->pOption, "error", pError);
return HWFault;
}
}
@@ -322,15 +350,16 @@ static int HistCountStatus(void *pData, SConnection * pCon)
SCSetInterrupt(pCon, eAbortBatch);
InvokeCallBack(self->pCall, COUNTEND, NULL);
ReleaseCountLock(self->pCountInt);
StringDictUpdate(self->pDriv->pOption, "error", pError);
return eCt;
} else {
updateHMData(self->pDriv->data);
return HWBusy;
}
}
if (eCt == HWBusy){
updateHMData(self->pDriv->data);
}
/* if (eCt == HWBusy){ */
/* updateHMData(self->pDriv->data); */
/* } */
if (eCt == HWIdle) {
/* force an update of local histogram data with next
@@ -377,6 +406,7 @@ static int HistTransfer(void *pData, SConnection * pCon)
SCWrite(pCon, "ERROR: failed to fix histogram memory problem",
eError);
SCSetInterrupt(pCon, eAbortBatch);
StringDictUpdate(self->pDriv->pOption, "error", pError);
iStatus = HWFault;
}
}
@@ -443,6 +473,7 @@ pHistMem CreateHistMemory(char *driver)
}
StringDictAddPair(pOption, "driver", driver);
StringDictAddPair(pOption, "update", "0");
StringDictAddPair(pOption, "error", "None");
/* initialise driver */
if (strcmp(driver, "sim") == 0) {
@@ -715,6 +746,12 @@ long GetHistMonitor(pHistMem self, int i, SConnection * pCon)
void HistDirty(pHistMem self)
{
assert(self);
if(isSecondGen(self)){
SecHistDirty(self);
return;
}
if(self->pDriv != NULL){
updateHMData(self->pDriv->data);
}
@@ -724,6 +761,11 @@ void HistDirty(pHistMem self)
const float *GetHistTimeBin(pHistMem self, int *iLength)
{
assert(self);
if(isSecondGen(self)){
return GetSecHistTimeBin(self,iLength);
}
*iLength = getNoOfTimebins(self->pDriv->data);
return getTimeBinning(self->pDriv->data);
}
@@ -733,6 +775,10 @@ int GetHistLength(pHistMem self)
{
assert(self);
if(isSecondGen(self)){
return GetSecHistLength(self);
}
return getHMDataLength(self->pDriv->data);
}
@@ -827,6 +873,11 @@ int GetHistogram(pHistMem self, SConnection * pCon,
{
assert(self);
if(isSecondGen(self)){
return GetSecHistogram(self,pCon,i,iStart,iEnd,lData,iDataLen);
}
if (!self->iInit) {
SCWrite(pCon, "ERROR: histogram memory not initialised", eError);
return 0;
@@ -837,7 +888,7 @@ int GetHistogram(pHistMem self, SConnection * pCon,
eWarning);
iEnd = (iDataLen / sizeof(HistInt)) - 1;
}
return getHMDataHistogram(self, pCon, i, iStart, iEnd, lData);
return getHMDataHistogram(self, pCon, i, iStart, iEnd-iStart, lData);
}
/*-------------------------------------------------------------------------*/
@@ -870,6 +921,7 @@ int GetHistogramDirect(pHistMem self, SConnection * pCon,
SCWrite(pCon, pBueffel, eError);
iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr);
if (iRet == COTERM) {
StringDictUpdate(self->pDriv->pOption, "error", pError);
return 0;
}
}
@@ -883,6 +935,11 @@ HistInt *GetHistogramPointer(pHistMem self, SConnection * pCon)
{
assert(self);
if(isSecondGen(self)){
return GetSecHistogramPointer(self,pCon);
}
if (!self->iInit) {
SCWrite(pCon, "ERROR: histogram memory not initialised", eError);
return NULL;
@@ -916,6 +973,7 @@ int PresetHistogram(pHistMem self, SConnection * pCon, HistInt lVal)
SCWrite(pCon, pBueffel, eError);
iRet = self->pDriv->TryAndFixIt(self->pDriv, iErr);
if (iRet == COTERM) {
StringDictUpdate(self->pDriv->pOption, "error", pError);
return 0;
}
}
@@ -1185,7 +1243,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
/* do it */
Arg2Text(argc - 3, &argv[3], pBueffel, 511);
/* authorise */
if (!SCMatchRights(pCon, usUser)) { /* FIXME ffr stupid hack */
if (!SCMatchRights(pCon, usMugger)) {
snprintf(pBueffel,sizeof(pBueffel)-1,
"ERROR: you need to be manager in order to configure %s",
argv[0]);
@@ -1271,11 +1329,7 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
}
} else if (strcmp(argv[1], "init") == 0) {
if (GetStatus() != eEager) {
SCWrite(pCon, "ERROR: cannot initialize HM while running", eError);
return 0;
}
if (SCMatchRights(pCon, usUser)) { /* FIXME ffr stupid hack */
if (SCMatchRights(pCon, usMugger)) {
iRet = HistConfigure(self, pCon, pSics);
if (iRet) {
self->iInit = 1;
@@ -1288,6 +1342,22 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
} else {
return 0;
}
} else if (strcmp(argv[1], "clearhm") == 0) {
/*
clear the local copy of the HM. Assumes that the HM
clears itself on start. Which it does.
*/
if (SCMatchRights(pCon, usUser)) {
if(self->pDriv->data != NULL){
clearHMData(self->pDriv->data);
SCSendOK(pCon);
return 1;
} else {
return 0;
}
} else {
return 0;
}
} else if (strcmp(argv[1], "list") == 0) {
HMListOption(self, pCon);
return 1;
@@ -1301,14 +1371,6 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
SCSendOK(pCon);
return 1;
}
else if (strcmp(argv[1], "astop") == 0) {
if (!SCMatchRights(pCon, usUser)) {
return 0;
}
self->pDriv->Halt(self->pDriv);
SCSendOK(pCon);
return 1;
}
/* pause */
else if (strcmp(argv[1], "pause") == 0) {
if (!SCMatchRights(pCon, usUser)) {
@@ -1318,6 +1380,16 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
SCSendOK(pCon);
return 1;
}
/* state */
else if (strcmp(argv[1], "status") == 0) {
HistCountStatus(self,pCon);
if(isRunning(self->pCountInt)){
SCPrintf(pCon,eValue,"%s.status = run",argv[0]);
} else {
SCPrintf(pCon,eValue,"%s.status = idle",argv[0]);
}
return 1;
}
/* normal counting */
else if (strcmp(argv[1], "count") == 0) {
if (SCMatchRights(pCon, self->iAccess)) {
@@ -1725,6 +1797,12 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
SCSendOK(pCon);
return 1;
}
/* error */
else if (strcmp(argv[1], "error") == 0) {
StringDictGet(self->pDriv->pOption, "error", pBueffel, sizeof(pBueffel));
SCPrintf(pCon,eValue,"%s.error = %s", argv[0], pBueffel);
return 1;
}
/*-------- sum */
else if (strcmp(argv[1], "sum") == 0) {
/* read following arguments as ints and put them
@@ -1759,4 +1837,5 @@ int HistAction(SConnection * pCon, SicsInterp * pSics, void *pData,
SCWrite(pCon, pBueffel, eError);
return 0;
}
return 0;
}