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:
185
status.c
185
status.c
@ -13,6 +13,10 @@
|
||||
Reworked restore to keep parameters from uninitialized devices
|
||||
Mark Koennecke, November 2007
|
||||
|
||||
Reworked to determine the status from the state of the machine rather then
|
||||
from explicit sets on a global variable. Which caused trouble, trouble and more
|
||||
trouble. Mark Koennecke, July 2015
|
||||
|
||||
Copyright:
|
||||
|
||||
Labor fuer Neutronenstreuung
|
||||
@ -52,6 +56,10 @@
|
||||
#include "status.h"
|
||||
#include "interrupt.h"
|
||||
#include "sicshipadaba.h"
|
||||
#include "messagepipe.h"
|
||||
#include "scan.h"
|
||||
#include "exeman.h"
|
||||
#include "nxscript.h"
|
||||
#undef VALUECHANGE
|
||||
#define VALUECHANGE 2
|
||||
|
||||
@ -97,6 +105,8 @@ static char *iText[] = {
|
||||
static pICallBack pCall = NULL;
|
||||
static int fixed = 0;
|
||||
static Status eCode = eEager;
|
||||
static int userWait = 0;
|
||||
static double lastStatus = .0;
|
||||
/*-------------------------------------------------------------------------*/
|
||||
void KillStatus(void *pData)
|
||||
{
|
||||
@ -108,24 +118,35 @@ void KillStatus(void *pData)
|
||||
/*--------------------------------------------------------------------------*/
|
||||
void SetStatus(Status eNew)
|
||||
{
|
||||
if (!fixed) {
|
||||
/* if (!fixed) {
|
||||
if (eCode == eNew) {
|
||||
return;
|
||||
}
|
||||
eCode = eNew;
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
This now only manages the userWait status
|
||||
*/
|
||||
if(eNew == eUserWait){
|
||||
userWait = 1;
|
||||
} else {
|
||||
if(userWait == 1){
|
||||
userWait = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
void SetStatusFixed(Status eNew)
|
||||
{
|
||||
if (eCode == eNew) {
|
||||
return;
|
||||
}
|
||||
eCode = eNew;
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
fixed = 1;
|
||||
// if (eCode == eNew) {
|
||||
// return;
|
||||
// }
|
||||
// eCode = eNew;
|
||||
// InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
// fixed = 1;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
@ -279,7 +300,9 @@ int ResetStatus(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
SCWrite(pCon, "Insufficient authorisation to reset server", eError);
|
||||
return 0;
|
||||
}
|
||||
SetStatus(eEager);
|
||||
// SetStatus(eEager);
|
||||
eCode = eEager;
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
SetInterrupt(eContinue);
|
||||
ClearExecutor(GetExecutor());
|
||||
SCsetMacro(pCon, 0);
|
||||
@ -337,3 +360,149 @@ int RedirectControl(SConnection * pCon, SicsInterp * pSics, void *pData,
|
||||
pOwner->sockHandle = pCon->sockHandle;
|
||||
return 1;
|
||||
}
|
||||
/*----------------------------------------------------------------------------
|
||||
Message pipe based new status calculation code
|
||||
------------------------------------------------------------------------------*/
|
||||
|
||||
static int DevexecStatusFunc(void *message, void *userData)
|
||||
{
|
||||
|
||||
int *status = (int *)message;
|
||||
|
||||
*status = GetDevExecInstStatus(pServ->pExecutor);
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*-----------------------------------------------------------------------------
|
||||
This must be identical to the definition in interface.c As this structure is only
|
||||
required in interface.c and here, I choose not to put it into an header file.
|
||||
-------------------------------------------------------------------------------*/
|
||||
typedef struct {
|
||||
int id;
|
||||
void *obj;
|
||||
pICountable pCount;
|
||||
SConnection *pCon;
|
||||
char *name;
|
||||
}CountTaskData;
|
||||
/*-----------------------------------------------------------------------------*/
|
||||
static int CheckCountStatus(void *message, void *userData)
|
||||
{
|
||||
int *status = (int *)message;
|
||||
int testStatus;
|
||||
pTaskHead it;
|
||||
CountTaskData *countTask = NULL;
|
||||
|
||||
if(*status == eCounting){
|
||||
for(it = TaskIteratorStart(pServ->pTasker); it != NULL; it = TaskIteratorNext(it)){
|
||||
countTask = (CountTaskData *)GetTaskData(it);
|
||||
if(countTask != NULL && countTask->id == COUNTID){
|
||||
testStatus = countTask->pCount->CheckCountStatus(countTask->obj,pServ->dummyCon);
|
||||
if(testStatus == HWNoBeam){
|
||||
*status = eOutOfBeam;
|
||||
}
|
||||
if(testStatus == HWPause){
|
||||
*status = ePaused;
|
||||
}
|
||||
}
|
||||
}
|
||||
return MPSTOP;
|
||||
}
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*---------------------------------------------------------------------------*/
|
||||
static pScanData scan = NULL;
|
||||
static int CheckScan(void *message, void *userData)
|
||||
{
|
||||
char *scannames[] = {"xxxscan","iscan", NULL};
|
||||
unsigned int count = 0;
|
||||
int *status = (int *)message;
|
||||
|
||||
if(*status == eEager){
|
||||
if(scan == NULL){
|
||||
while(scannames[count] != NULL){
|
||||
scan = FindCommandData(pServ->pSics, scannames[count],NULL);
|
||||
if(scan != NULL){
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if(scan != NULL){
|
||||
if(isScanRunning(scan)){
|
||||
*status = eScanning;
|
||||
return MPCONTINUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
|
||||
static int CheckExe(void *message, void *userData)
|
||||
{
|
||||
int *status = (int *)message;
|
||||
|
||||
if(*status == eEager){
|
||||
if(isBatchRunning()){
|
||||
*status = eBatch;
|
||||
}
|
||||
}
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*------------------------------------------------------------------------------*/
|
||||
static int CheckUserWait(void *message, void *userData)
|
||||
{
|
||||
int *status = (int *)message;
|
||||
|
||||
if(*status == eEager){
|
||||
if(isTaskRunning(pServ->pTasker,"wait")){
|
||||
*status = eUserWait;
|
||||
}
|
||||
}
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
static int CheckNXScript(void *message, void *userData)
|
||||
{
|
||||
int *status = (int *)message;
|
||||
|
||||
if(*status == eEager){
|
||||
if(isNXScriptWriting()){
|
||||
*status = eWriting;
|
||||
}
|
||||
}
|
||||
return MPCONTINUE;
|
||||
}
|
||||
/*--------------------------------------------------------------------------------*/
|
||||
static pMP statusPipe = NULL;
|
||||
|
||||
static void BuildStatusChain(void)
|
||||
{
|
||||
statusPipe = MakeMP();
|
||||
AppendMPFilter(statusPipe,DevexecStatusFunc,NULL,NULL);
|
||||
AppendMPFilter(statusPipe,CheckCountStatus,NULL,NULL);
|
||||
AppendMPFilter(statusPipe,CheckScan,NULL,NULL);
|
||||
AppendMPFilter(statusPipe,CheckExe,NULL,NULL);
|
||||
AppendMPFilter(statusPipe,CheckUserWait,NULL,NULL);
|
||||
AppendMPFilter(statusPipe,CheckNXScript,NULL,NULL);
|
||||
}
|
||||
/*-------------------------------------------------------------------------------*/
|
||||
static int StatusTask(void *data)
|
||||
{
|
||||
int status = eEager;
|
||||
|
||||
MPprocess(statusPipe,&status);
|
||||
if(status != eCode && DoubleTime() > lastStatus + .1){
|
||||
eCode = status;
|
||||
lastStatus = DoubleTime();
|
||||
InvokeCallBack(pCall, VALUECHANGE, NULL);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void InitStatus(void)
|
||||
{
|
||||
BuildStatusChain();
|
||||
TaskRegisterN(pServ->pTasker,"statustask",StatusTask, NULL, NULL, NULL,1);
|
||||
}
|
||||
|
Reference in New Issue
Block a user