Commit 7ca27dd0 authored by koennecke's avatar koennecke
Browse files

Merge branch 'master' into maverick

parents 22d28d9f 0c8b6518
add_library(site
psi.c
buffer.c
ruli.c
sps.c
pipiezo.c
sanswave.c
faverage.c
spss7.c
amorstat.c
tasinit.c
ptasdrive.c
tasutil.c
tasscan.c
swmotor.c
polterwrite.c
ecb.c
frame.c
sqlitelog.c
mongolog.c
sicslogquery.c
approxidate.c
sinqhmdriv.c
tdchm.c
sanscook.c
itc4driv.c
itc4.c
serial.c
scontroller.c
t_update.c
t_rlp.c
t_conv.c
el737hpdriv.c
el734hp.c
el737hpv2driv.c
swmotor2.c
tricssupport.c
amorcomp.c
amordrive.c
amorset.c
sinqhttp.c
slsecho.c
tabledrive.c
sinqhttpopt.c
ritastorage.c
el737hpdrivsps.c
rebin.c
sanslirebin.c
lmd200.c
slsvme.c
julprot.c
sinqhttpprot.c
pfeifferprot.c
termprot.c
phytron.c
autowin.c
eigera2.c
eigermono.c
sputterprot.c
zwickroll.c
astriumnet.c
poldifold.c
epicsadapter.c
zebraswap.c
fsm.c
sugar.c
pardef.c
ease.c
strobj.c
oxinst.c
ipsdriv.c
ilmdriv.c
itcdriv.c
ighdriv.c
euro2kdriv.c
modbus.c
arrobj.c
linadriv.c
haakedriv.c
seaclientprot.c
dumprot.c
collectprot.c
mpaprot.c
zebracounter.c
)
set_property(SOURCE epicsadapter.c PROPERTY COMPILE_FLAGS "-I{PROJECT_SOURCE_DIR} -I${EPICS_BASE}/include -I${EPICS_BASE}/include/os/Darwin")
include_directories("." ".." "../sics" "hardsup")
......@@ -4,6 +4,8 @@ amilevel.c
Driver for the AMI 135/136 level meter
Markus Zolliker, May 2007
OBSOLETE, replaced by scriptcontext driver, May 2016
----------------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
......@@ -22,7 +24,6 @@ Markus Zolliker, May 2007
#include <emon.h>
#include <evcontroller.h>
#include <evcontroller.i>
#include <servlog.h>
#include <sicsvar.h>
#include <evdriver.i>
#include <rs232controller.h>
......
This diff is collapsed.
#ifndef APPROXIDATE_H
#define APPROXIDATE_H
#include <sys/time.h>
/**
* @param date The date string
* @param tv Where the time will be placed.
*
* @return 0 on success
* @return 1 on error
*/
int approxidate(const char *date, struct timeval *tv);
#endif
\ No newline at end of file
......@@ -138,7 +138,7 @@ static int ArrayItems(void *object, void *arg, int argc, char *argv[])
if (p > result)
p--;
*p = '\0';
ParPrintf(object, eValue, result);
ParPrintf(object, eValue, "%s", result);
free(result);
}
return 1;
......
This diff is collapsed.
/*-------------------------------------------------------------------------
B r u k e r
An environment control driver and an additonal wrapper function for
controlling a Bruker B-EC-1 magnet controller. This controller can
either control a current or control the current through an external hall
sensor mesuring the magnetic field. In both cases both values: the field
and the current must be readable.
copyright: see copyright.h
Mark Koennecke, October 1998
---------------------------------------------------------------------------*/
#ifndef BRUKERMAGNET
#define BRUKERMAGNET
pEVDriver CreateBrukerDriver(int argc, char *argv[]);
int BrukerReadField(pEVControl self, float *fField);
int BrukerReadCurrent(pEVControl self, float *fCurrent);
int BrukerAction(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[]);
#endif
\subsubsection{Bruker Magnet Controller B-EC-1}
SANS is using a Bruker magnet controller. This controller is integrated
into SICS as a derivate of an environment controller. The Bruker controller
can be operated in two modes: in the first the current is controlled,
in the second the current
is controlled by an external hall sensor giving the magnetic field. Whatever
is the controlling sensor, the magnetic field and the current need to be
read. Furthermore this device supports switching the polarity. All this is
achieved with a special driver and an additional wrapper function for
handling extra commands. All this is implemented in the file bruker.h
and bruker.c. The functions defined are:
\begin{verbatim}
pEVDriver CreateBrukerDriver(int argc, char *argv[]);
int BrukerReadField(pEVControl self, float *fField);
int BrukerReadCurrent(pEVControl self, float *fCurrent);
int BrukerAction(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]);
\end{verbatim}
\begin{description}
\item[CreateBrukerDriver] creates a driver for the bruker magnet
controller.
\item[BrukerReadField] reads the current magnetic field.
\item[BrukerReadCurrent] reads the current current in Ampere.
\item[BrukerAction] a special SICS interpreter wrapper function for
the Bruker Magnet. This function handles the few special Bruker
commands and passes everything else to the standard environment
controller handler function.
\end{description}
/*
* 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);
}
......@@ -120,6 +120,7 @@ void EaseWrite(EaseBase * eab, char *cmd)
int l;
if (eab->errCode) {
FsmStop(eab->task, eab->idle);
eab->state = EASE_abort;
return;
}
......@@ -396,6 +397,9 @@ static long EaseIdle(long pc, void *object)
switch (pc) {
default: /* FSM BEGIN ****************************** */
EasePchk(eab);
if (eab->state == EASE_abort) {
eab->state = EASE_idle;
}
idle:
if (!EaseCheckDoit(eab))
......@@ -408,10 +412,8 @@ static long EaseIdle(long pc, void *object)
case __LINE__: /**********************************/
eab->startOk = 1;
if (eab->state == EASE_abort) {
eab->state = EASE_idle;
}
rd:
/* rd: */
/*
if (eab->state == EASE_lost) {
snprintf(eab->msg, sizeof eab->msg, "no response from %s",
......@@ -464,7 +466,7 @@ int EaseUpdate(int flag)
if (ParActionIs(PAR_SET) > 0) {
assert(flag >= 0);
assert(flag <= eab->maxflag);
eab->updateFlags[flag / EASE_FLAGBITS] |= 1 << (flag % EASE_FLAGBITS);
eab->updateFlags[flag / EASE_FLAGBITS] |= (unsigned long)1 << (flag % EASE_FLAGBITS);
if (eab->task)
FsmSpeed(eab->task);
return 1;
......@@ -485,7 +487,7 @@ int EaseNextUpdate(void *object)
p = 1;
flag = 0;
/* find first */
while (flag < 32) {
while (flag < EASE_FLAGBITS) {
if (mask & p) {
eab->updateFlags[i] &= ~p;
return flag + i * EASE_FLAGBITS;
......@@ -506,7 +508,7 @@ int EaseGetUpdate(void *object, int flag)
assert(flag >= 0);
assert(flag <= eab->maxflag);
i = flag / EASE_FLAGBITS;
if ((1 << (flag % EASE_FLAGBITS)) & eab->updateFlags[i]) {
if (((unsigned long)1 << (flag % EASE_FLAGBITS)) & eab->updateFlags[i]) {
return 1;
}
return 0;
......@@ -521,10 +523,10 @@ void EaseSetUpdate(void *object, int flag, int state)
assert(flag <= eab->maxflag);
if (state) {
eab->updateFlags[flag / EASE_FLAGBITS] |= 1 << (flag % EASE_FLAGBITS);
eab->updateFlags[flag / EASE_FLAGBITS] |= (unsigned long)1 << (flag % EASE_FLAGBITS);
} else {
eab->updateFlags[flag / EASE_FLAGBITS] &=
~(1 << (flag % EASE_FLAGBITS));
~((unsigned long)1 << (flag % EASE_FLAGBITS));
}
}
......@@ -838,7 +840,7 @@ static int EaseInit(SConnection * pCon, EaseBase * eab, int argc,
eab->task = FsmStartTask(eab, eab->handler, eab->idle, eab->p.name);
TaskRegisterN(pServ->pTasker,"ease", (TaskFunc) FsmTaskHandler, NULL, FsmKill,
eab->task, 0);
eab->task, TASK_PRIO_LOW);
return 1;
}
......
......@@ -316,33 +316,36 @@ static void startMono(pSICSOBJ self, SConnection *pCon)
/*
the translation
There used to be a test here to run the tranlsation only when mcv succeded. This test caused
issues when mcv already was at the correct position in that the translation was not driven.
Thus the test was removed on request of the IC. The current state of the code can have the consequence
that mt is driven even when mcv fails. This then can throw the focus point completely off, resulting
in a loss of intensity, resolution and even move peaks.
*/
if(status > 0){
/*
only run mt when mcv started
*/
SICSHdbGetPar(self,pCon,"MTA",&mta);
SICSHdbGetPar(self,pCon,"MTB",&mtb);
mtx = mta.v.doubleValue + mtb.v.doubleValue*pow(curve,.75);
MotorGetPar((pMotor)mono->motData[MTX],"softupperlim",&lim);
if(mtx > lim){
SCPrintf(pCon,eLog,"WARNING: correcting mt target %f to %f within upper limit", mtx, lim-.1);
mtx = lim - .1;
}
MotorGetPar((pMotor)mono->motData[MTX],"softlowerlim",&lim);
if(mtx < lim){
SCPrintf(pCon,eLog,"WARNING: correcting mt target %f to %f within lower limit", mtx, lim +.1);
mtx = lim + .1;
}
status = startTASMotor((pMotor)mono->motData[MTX], pCon, "mt",
mtx, silent,stopFixed);
if (status < 0 && status != NOTSTARTED) {
SCWrite(pCon,"WARNING: monochromator translation motor failed to start", eLog);
SCSetInterrupt(pCon,eContinue);
} else {
AddTaskToGroup(pServ->pTasker,status, mono->waitID);
}
SICSHdbGetPar(self,pCon,"MTA",&mta);
SICSHdbGetPar(self,pCon,"MTB",&mtb);
mtx = mta.v.doubleValue + mtb.v.doubleValue*pow(curve,.75);
MotorGetPar((pMotor)mono->motData[MTX],"softupperlim",&lim);
if(mtx > lim){
SCPrintf(pCon,eLog,"WARNING: correcting mt target %f to %f within upper limit", mtx, lim-.1);
mtx = lim - .1;
}
MotorGetPar((pMotor)mono->motData[MTX],"softlowerlim",&lim);
if(mtx < lim){
SCPrintf(pCon,eLog,"WARNING: correcting mt target %f to %f within lower limit", mtx, lim +.1);
mtx = lim + .1;
}
status = startTASMotor((pMotor)mono->motData[MTX], pCon, "mt",
mtx, silent,stopFixed);
if (status < 0 && status != NOTSTARTED) {
SCWrite(pCon,"WARNING: monochromator translation motor failed to start", eLog);
SCSetInterrupt(pCon,eContinue);
} else {
AddTaskToGroup(pServ->pTasker,status, mono->waitID);
}
}
/*--------------------------------------------------------------*/
......
/*----------------------------------------------------------------------
This is driver for a standard PSI EL737 counter box as used at
SINQ
copyright: see file COPYRIGHT
extracted from countdriv.c. Mark Koennecke, June 2003
-----------------------------------------------------------------------*/
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <fortify.h>
#include <string.h>
#include <sics.h>
#include <countdriv.h>
#include <splitter.h>
#include "hardsup/sinq_prototypes.h"
#include "hardsup/el737_def.h"
#include "hardsup/el737fix.h"
#define BADTRANGE -117766
/*----------------------------- EL737 ------------------------------------*/
typedef struct {
char *host;
int iPort;
int iChannel;
void *pData;
int finishCount;
} EL737st;
/*------------------------------------------------------------------------*/
static int EL737GetStatus(struct __COUNTER *self, float *fControl)
{
int iRet;
int iC1, iC2, iC3, iC4, iRS;
float fTime;
EL737st *pEL737;
assert(self);
pEL737 = (EL737st *) self->pData;
assert(pEL737);
iRet =
EL737_GetStatus(&pEL737->pData, &iC1, &iC2, &iC3, &iC4, &fTime,
&iRS);
if (self->eMode == eTimer) {
*fControl = fTime;
} else {
*fControl = iC1;
}
/* store time */
self->fTime = fTime;
if (iRet != 1) {
return HWFault;
}
self->lCounts[0] = iC2;
self->lCounts[1] = iC1;
self->lCounts[2] = iC3;
self->lCounts[3] = iC4;
/* get extra counters for 8-fold counter boxes */
iRet = EL737_GetStatusExtra(&pEL737->pData, &iC1, &iC2, &iC3, &iC4);
self->lCounts[4] = iC1;
self->lCounts[5] = iC2;
self->lCounts[6] = iC3;
self->lCounts[7] = iC4;
if (iRS == 0) {
pEL737->finishCount++;
if (pEL737->finishCount >= 2) {
return HWIdle;
} else {
return HWBusy;
}
} else if ((iRS == 1) || (iRS == 2)) {
pEL737->finishCount = 0;
return HWBusy;
} else if ((iRS == 5) || (iRS == 6)) {
pEL737->finishCount = 0;
return HWNoBeam;
} else {
pEL737->finishCount = 0;
return HWPause;
}
}
#ifdef NONINTF
extern float nintf(float f);
#endif
/*-------------------------------------------------------------------------*/
static int EL737Start(struct __COUNTER *self)
{
int iRet, iRS;
EL737st *pEL737;
assert(self);
pEL737 = (EL737st *) self->pData;
assert(pEL737);
self->fTime = 0.;
if (self->eMode == ePreset) {
iRet =
EL737_StartCnt(&pEL737->pData, (int) nintf(self->fPreset), &iRS);
if (iRet == 1) {
pEL737->finishCount = 0;
return OKOK;
} else {
return HWFault;
}
} else if (self->eMode == eTimer) {
if (self->fPreset < .1 || self->fPreset > 200000) {
self->iErrorCode = BADTRANGE;
return HWFault;
}
iRet = EL737_StartTime(&pEL737->pData, self->fPreset, &iRS);
if (iRet == 1) {
pEL737->finishCount = 0;
return OKOK;
} else {
return HWFault;
}
}
return 0;
}
/*-------------------------------------------------------------------------*/
static int EL737Pause(struct __COUNTER *self)
{
int iRet, iRS;
EL737st *pEL737;
assert(self);
pEL737 = (EL737st *) self->pData;
assert(pEL737);
iRet = EL737_Pause(&pEL737->pData, &iRS);
if (iRet == 1) {
return OKOK;
} else {
return HWFault;
}
return 0;
}
/*-------------------------------------------------------------------------*/
static int EL737Continue(struct __COUNTER *self)
{
int iRet, iRS;
EL737st *pEL737;
assert(self);
pEL737 = (EL737st *) self->pData;
assert(pEL737);
iRet = EL737_Continue(&pEL737->pData, &iRS);
if (iRet == 1) {
return OKOK;
} else {
return HWFault;
}
return 0;
}
/*--------------------------------------------------------------------------*/
static int EL737Halt(struct __COUNTER *self)
{
int iRet, iC1, iC2, iC3, iC4, iRS;
float fPreset;
EL737st *pEL737;
assert(self);
pEL737 = (EL737st *) self->pData;
assert(pEL737);
iRet =
EL737_Stop(&pEL737->pData, &iC1, &iC2, &iC3, &iC4, &fPreset, &iRS);
if (iRet == 1) {
self->lCounts[0] = iC2;
self->lCounts[1] = iC1;
self->lCounts[2] = iC3;
self->lCounts[3] = iC4;
return OKOK;
}
return HWFault;
}
/*--------------------------------------------------------------------------*/
static int EL737ReadValues(struct __COUNTER *self)
{
int iRet;
int iC1, iC2, iC3, iC4, iRS;
float fTime;
EL737st *pEL737;
assert(self);
pEL737 = (EL737st *) self->pData;
assert(pEL737);
iRet =
EL737_GetStatus(&pEL737->pData, &iC1, &iC2, &iC3, &iC4, &fTime,
&iRS);
if (iRet != 1) {
return HWFault;
}
self