Commit da3a3ef9 authored by koennecke's avatar koennecke
Browse files

-Added a collect protocol which reads until a timeout has been reached. For

the radial collimator controller at HRPT which has no proper termination
- Fixed a bug which caused the mode not being properly switched at TASP. This
is triggered by chnages to the MN ot TI parameters. Which did not call the
callback doing the switch when the value was identical to the one stored. The
fix sets the value of the other preset to 0.
- Added a testmongo script which tests if all instruments still have the
connection to the MongoDb open
parent e6679c0a
/*
* This is yet another protocol handler for scriptcontext. This one collects response
* data until the timeout has expired. And then suppresses the timeout error. It if for
* the radial collimator at HRPT which does not have a proper terminator.
* Mark Koennecke, July 2017
*/
#include <errno.h>
#include <ascon.h>
#include <ascon.i>
#include <dynstring.h>
int CollectProtHandler(Ascon *a)
{
int ret;
char chr;
switch(a->state){
case AsconReading:
ret = AsconReadChar(a->fd, &chr);
if (ret <= 0) {
if (ret < 0) {
AsconError(a, "ASC5", errno);
return 0;
}
if (a->timeout > 0) {
if (DoubleTime() - a->start > a->timeout) {
a->state = AsconReadDone;
return 1;
}
}
return 0;
}
a->lastChar = chr;
a->start = DoubleTime();
if (DynStringConcatChar(a->rdBuffer, chr) == 0) {
AsconError(a, "ASC6", errno);
return 0;
}
break;
default:
return AsconStdHandler(a);
}
return 1;
}
/*----------------------------------------------------------------------------------------------*/
void AddCollectProtocoll()
{
AsconProtocol *prot = NULL;
prot = calloc(sizeof(AsconProtocol), 1);
prot->name = strdup("collect");
prot->init = AsconStdInit;
prot->handler = CollectProtHandler;
AsconInsertProtocol(prot);
}
......@@ -23,7 +23,7 @@ OBJ=psi.o buffer.o ruli.o sps.o \
ritastorage.o el737hpdrivsps.o \
rebin.o sanslirebin.o lmd200.o slsvme.o julprot.o sinqhttpprot.o \
pfeifferprot.o termprot.o phytron.o autowin.o eigera2.o \
jvlprot.o \
jvlprot.o collectprot.o \
eigermono.o sputterprot.o zwickroll.o astriumnet.o poldifold.o \
epicsadapter.o zebraswap.o
......
......@@ -27,12 +27,7 @@
#include "sinqhmdriv.i"
#include "tdchm.h"
#include "itc4.h"
#include "bruker.h"
#include "ltc11.h"
#include "eurodriv.h"
#include "el755driv.h"
#include <evdriver.i>
#include "serial.h"
#include "sinqhttp.h"
/*--------------------------------------------------------------------------*/
......@@ -63,6 +58,7 @@ void SiteInit(void)
INIT(AddHttpOptProtocoll);
INIT(AddPfeifferProtocoll);
INIT(AddTermProtocoll);
INIT(AddCollectProtocoll);
INIT(AddPhytronProtocoll);
INIT(AddSLSEchoProtocoll);
INIT(AddSeaClientProtocol);
......@@ -105,7 +101,6 @@ static void AddPsiCommands(SicsInterp * pInter)
SCMD("MakeECB", MakeECB);
SCMD("MakeFocusAverager", MakeFA);
SCMD("MakeLMD200", MakeLMD200);
SCMD("MakePIMotor", PIMotorFactory);
SCMD("MakePoldiFold", MakePoldiFold);
SCMD("MakePSDFrame", MakeFrameFunc);
SCMD("MakeRitaFix", MakeRitaFix);
......@@ -121,7 +116,6 @@ static void AddPsiCommands(SicsInterp * pInter)
SCMD("MakeTAS", TASFactory);
SCMD("MakeTRICSSupport", MakeTricsSupport);
SCMD("PolterInstall", PolterInstall);
SCMD("SerialInit", SerialInit);
SCMD("MakeEiger", InitEiger);
SCMD("MakeEigerMono", InitEigerMono);
PCMD("cnvrt", CnvrtAction);
......@@ -225,24 +219,12 @@ static pCounterDriver CreatePsiCounterDriver(SConnection * pCon,
/*
our caller has already checked for enough arguments
*/
if (strcmp(argv[2], "el737") == 0) {
pNew = CreateEL737Counter(pCon, argv[1], argc - 3, &argv[3]);
} else if (strcmp(argv[2], "el737hp") == 0) {
if (strcmp(argv[2], "el737hp") == 0) {
pNew = MakeEL737HP(pCon, argv[1], argc - 3, &argv[3]);
} else if (strcmp(argv[2], "el737hpsps") == 0) {
pNew = MakeEL737hpsps(pCon, argv[1], argc - 3, &argv[3]);
} else if (strcmp(argv[2], "el737hpv2") == 0) {
pNew = MakeEL737HPV2(pCon, argv[1], argc - 3, &argv[3]);
/*
} else if (strcmp(argv[2], "epics") == 0) {
if (argc < 4) {
SCWrite(pCon,
"ERROR: insufficient no of arguments to create epics counter",
eError);
return NULL;
}
pNew = MakeEPICSCounter(argv[3]);
*/
}
return pNew;
}
......@@ -253,49 +235,18 @@ static HistDriver *CreatePsiHistMem(char *name, pStringDict pOptions)
if (strcmp(name, "sinqhm") == 0) {
pNew = CreateSINQDriver(pOptions);
} else if (strcmp(name, "tdc") == 0) {
pNew = MakeTDCHM(pOptions);
} else if (strcmp(name, "sinqhttp") == 0) {
pNew = CreateSinqHttpDriver(pOptions);
}
return pNew;
}
/*------------------------------------------------------------------*/
extern pCodri MakeCookerDriver(char *pHost, int iPort, int iChannel);
/*-------------------------------------------------------------------*/
static pCodri CreatePsiController(SConnection * pCon, int argc,
char *argv[])
{
pCodri pNew = NULL;
Tcl_Interp *pTcl = InterpGetTcl(pServ->pSics);
int iPort, iChannel, iRet, iSingle = 0;
char pBueffel[512];
if (strcmp(argv[0], "sanscook") == 0) {
if (argc < 4) {
SCWrite(pCon,
"ERROR: Insufficient number of arguments to install SANS Cooker driver",
eError);
return NULL;
}
iRet = Tcl_GetInt(pTcl, argv[2], &iPort);
if (iRet != TCL_OK) {
snprintf(pBueffel, 511, "ERROR: expected integer as port number, got %s",
argv[2]);
SCWrite(pCon, pBueffel, eError);
return NULL;
}
iRet = Tcl_GetInt(pTcl, argv[3], &iChannel);
if (iRet != TCL_OK) {
sprintf(pBueffel,
"ERROR: expected integer as channel number, got %s",
argv[3]);
SCWrite(pCon, pBueffel, eError);
return NULL;
}
pNew = MakeCookerDriver(argv[1], iPort, iChannel);
}
return pNew;
}
......@@ -308,19 +259,6 @@ static void ConfigureController(char *name, pEVControl pNew,
{
EVCSetPar(pNew, "upperlimit", 300.0, pCon);
EVCSetPar(pNew, "lowerlimit", 1.0, pCon);
if (strcmp(name, "euro") == 0) {
EVCSetPar(pNew, "upperlimit", 750.0, pCon);
EVCSetPar(pNew, "lowerlimit", 15.0, pCon);
} else if (strcmp(name, "el755") == 0) {
EVCSetPar(pNew, "upperlimit", 10., pCon);
EVCSetPar(pNew, "lowerlimit", -10., pCon);
} else if (strcmp(name, "bruker") == 0) {
EVCSetPar(pNew, "upperlimit", 45., pCon);
EVCSetPar(pNew, "lowerlimit", 0., pCon);
} else if (strcmp(name, "ltc11") == 0) {
EVCSetPar(pNew, "upperlimit", 500., pCon);
EVCSetPar(pNew, "lowerlimit", 1.5, pCon);
}
}
/*-------------------------------------------------------------------*/
......@@ -354,44 +292,12 @@ static pEVControl InstallPsiEnvironmentController(SicsInterp * pSics,
commandInstalled = 1;
}
}
} else if (strcmp(argv[3], "bruker") == 0) {
checkError = 1;
pDriv = CreateBrukerDriver(argc - 4, &argv[4]);
if (pDriv != NULL) {
pNew = CreateEVController(pDriv, argv[2], &status);
if (pNew != NULL) {
AddCommand(pSics, argv[2], BrukerAction, DeleteEVController, pNew);
commandInstalled = 1;
}
}
} else if (strcmp(argv[2], "ltc11") == 0) {
checkError = 1;
pDriv = CreateLTC11Driver(argc - 4, &argv[4]);
if (pDriv != NULL) {
pNew = CreateEVController(pDriv, argv[2], &status);
if (pNew != NULL) {
AddCommand(pSics, argv[2], LTC11Action, DeleteEVController, pNew);
commandInstalled = 1;
}
}
} else if (strcmp(argv[3], "euro") == 0) {
checkError = 1;
pDriv = CreateEURODriv(argc - 4, &argv[4]);
if (pDriv != NULL) {
pNew = CreateEVController(pDriv, argv[2], &status);
}
} else if (strcmp(argv[3], "vme-dsp") == 0) {
checkError = 1;
pDriv = CreateSLSVMEDriv(argc - 4, &argv[4]);
if (pDriv != NULL) {
pNew = CreateEVController(pDriv, argv[2], &status);
}
} else if (strcmp(argv[3], "el755") == 0) {
checkError = 1;
pDriv = CreateEL755Driv(argc - 4, &argv[4]);
if (pDriv != NULL) {
pNew = CreateEVController(pDriv, argv[2], &status);
}
} else {
snprintf(pBueffel,511, "ERROR: %s not recognized as a valid driver type",
argv[3]);
......
......@@ -297,6 +297,7 @@ static int MonitorCallback(int iEvent, void *pEvent, void *pUser)
SetCounterMode(self->pScan->pCounterData, ePreset);
SetCounterPreset(self->pScan->pCounterData,
(float) self->tasPar[MN]->iVal);
self->tasPar[TI]->fVal = .0;
return 1;
}
......@@ -311,6 +312,8 @@ static int TimerCallback(int iEvent, void *pEvent, void *pUser)
SetCounterMode(self->pScan->pCounterData, eTimer);
SetCounterPreset(self->pScan->pCounterData, self->tasPar[TI]->fVal);
self->tasPar[MN]->iVal = 0;
return 1;
}
......
......@@ -2420,7 +2420,7 @@ static int RS__MAX_ASYNCH = 20; /* Asynch "ports" 0 - 19 will be allowed */
Next_tmo_secs = 1.0; /* Time-out is 1 sec by default. It can be
** shorter if client requests need it to be. */
for (;;) {
fflush (NULL);
/* fflush (NULL); */
#ifdef LINUX
#define fds_bits __fds_bits
......
#!/usr/bin/python
from sics.sics.sics import Sics
import paramiko
dblist = ['amor', 'boa', 'dmc', 'eiger', 'focus', 'hrpt', 'morpheus',
'narziss', 'orion', 'poldi', 'rita2', 'sans', 'sans2', 'tasp', 'zebra']
for inst in dblist:
try:
con = Sics(inst,2911)
con.connect()
con.login('Spy','007')
result = con.transact('mongoconfig status')
if result.find('disconnected') >= 0:
print('%s lost connection to MongoDB server, reconnecting...' %(inst))
con.transact('mongoconfig reopen')
command = 'find log -name "*.log" | xargs grep "mongo server"\''
cl = paramiko.SSHClient()
cl.set_missing_host_key_policy(paramiko.AutoAddPolicy())
pw = '%slns' % (inst)
pw = pw.upper()
cl.connect(inst,username=inst,password=pw)
stdin, stdout, stderr = cl.exec_command('find log -name "*.log"|xargs grep "mongo server"')
reply = stdout.read()
lines = reply.split('\n')
print(lines[len(lines)-1])
cl.close()
else:
print('%s mongo connection OK' % (inst))
con.disconnect()
except:
print('Failed to connect to %s' %(inst))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment