bug fixes and enhancements related to evcontroller
This commit is contained in:
40
ipsdriv.c
40
ipsdriv.c
@ -33,6 +33,7 @@ typedef struct {
|
||||
float current; /* current (in Tesla) */
|
||||
float persfield; /* persistent field from IPS (in Tesla) */
|
||||
float lastfield; /* persistent field from last drive */
|
||||
float confirmfield; /* field confirmed in 1st step */
|
||||
float ramp; /* actual ramp rate (Telsa/min) */
|
||||
int persmode; /* 0: leave switch on, 1: go to persistant mode */
|
||||
int perswitch; /* state of switch */
|
||||
@ -43,22 +44,18 @@ typedef struct {
|
||||
time_t tim;
|
||||
} IpsDriv;
|
||||
|
||||
int IpsConfirm(SConnection *pCon, pEVControl evc, int argc, char *argv[]);
|
||||
/*----------------------------------------------------------------------------*/
|
||||
static int IpsOk(IpsDriv *me, SConnection *pCon) {
|
||||
float dif;
|
||||
Eve *eve=&me->eve;
|
||||
|
||||
if (!pCon) pCon = SCLoad(&eve->evc->conn);
|
||||
if (me->eve.version[0]=='\0') return 1; /* connection not yet confirmed */
|
||||
if (me->perswitch) return 1;
|
||||
if (fabs(me->persfield - me->lastfield) < 1e-5) {
|
||||
return 1;
|
||||
}
|
||||
if (me->force == 2) {
|
||||
return 1;
|
||||
}
|
||||
if (fabs(me->persfield - me->lastfield) < 1e-5
|
||||
|| me->force == 2) return 1;
|
||||
if (fabs(me->persfield - me->lastfield) < 1e-5) return 1;
|
||||
if (me->force != 0) return 1;
|
||||
eve->errCode = EVE_FAULT;
|
||||
if (!pCon) pCon = SCLoad(&eve->evc->conn);
|
||||
SCPrintf(pCon, eWarning,
|
||||
"\nit is not sure which field is in the magnet\n"
|
||||
"value stored in power supply: %f\n"
|
||||
@ -75,12 +72,17 @@ static int IpsOk(IpsDriv *me, SConnection *pCon) {
|
||||
#define S EVE_SAVEPAR
|
||||
|
||||
void IpsPars(IpsDriv *me, EveParArg *arg) {
|
||||
IpsOk(me, EveArgConn(arg));
|
||||
EveIntPar(arg, "persmode", &me->persmode, usUser, A+S);
|
||||
EveIntPar(arg, "perswitch", &me->perswitch, usInternal, A);
|
||||
EveObPar(arg, UPLIMIT, "%.5g\tT", A+S);
|
||||
EveFloatPar(arg, "ramp", &me->ramp, "%.5g\tT/min", usUser, A+S);
|
||||
EveStdParEnd(arg, "%.5g\tT", A+L+S);
|
||||
EveObPar(arg, UPLIMIT, "%.5g\tTesla", A+S);
|
||||
EveFloatPar(arg, "ramp", &me->ramp, "%.5g\tTesla/min", usUser, A+S);
|
||||
EveFloatPar(arg, "current", &me->current, "%.5g\tTesla", usInternal, A+L);
|
||||
EveFloatPar(arg, "lastfield", &me->lastfield, "%.5g\tTesla", usInternal, S);
|
||||
EveCmd(arg, "confirm", IpsConfirm, usUser);
|
||||
EveStdParEnd(arg, "%.5g\tTesla", A+L+S);
|
||||
if (EveUserAction(arg)) {
|
||||
IpsOk(me, EveArgConn(arg));
|
||||
}
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void IpsStatus(IpsDriv *me) {
|
||||
@ -158,11 +160,12 @@ static int IpsRead(long pc, IpsDriv *me) {
|
||||
EveWrite(eve, "X");
|
||||
FSM_NEXT
|
||||
IpsStatus(me); /* check for errors and get perswitch */
|
||||
/*
|
||||
if (!me->remote) goto rd;
|
||||
EveWrite(eve, "C0");
|
||||
me->remote = 0;
|
||||
FSM_NEXT
|
||||
|
||||
*/
|
||||
rd:
|
||||
EveWrite(eve, "R7"); /* read current (in Tesla) */
|
||||
FSM_NEXT
|
||||
@ -176,6 +179,7 @@ static int IpsRead(long pc, IpsDriv *me) {
|
||||
IpsSetField(me, OiGetFlt(eve, 3, NULL));
|
||||
|
||||
quit:
|
||||
EveLog(eve);
|
||||
FSM_END
|
||||
}
|
||||
/*----------------------------------------------------------------------------*/
|
||||
@ -245,6 +249,7 @@ static int IpsChangeField(long pc, IpsDriv *me) {
|
||||
EveWrite(eve, "R7"); /* read current (in Tesla) */
|
||||
FSM_NEXT
|
||||
me->current = OiGetFlt(eve, 3, NULL);
|
||||
EveLog(eve);
|
||||
if (fabs(me->current - me->lastfield) > 1e-5) goto stab1;
|
||||
|
||||
stab2:
|
||||
@ -316,6 +321,7 @@ static int IpsChangeField(long pc, IpsDriv *me) {
|
||||
}
|
||||
OiSet(eve, "J", fld, 3);
|
||||
FSM_NEXT
|
||||
EveLog(eve);
|
||||
goto ramping;
|
||||
|
||||
target_reached:
|
||||
@ -388,7 +394,7 @@ int IpsConfirm(SConnection *pCon, pEVControl evc, int argc, char *argv[]) {
|
||||
return -1;
|
||||
}
|
||||
fld=atof(argv[1]);
|
||||
if (fld < ObVal(evc->pParam, UPLIMIT)) {
|
||||
if (fld > ObVal(evc->pParam, UPLIMIT)) {
|
||||
SCPrintf(pCon, eError, "Field outside limit");
|
||||
return -1;
|
||||
}
|
||||
@ -399,12 +405,12 @@ int IpsConfirm(SConnection *pCon, pEVControl evc, int argc, char *argv[]) {
|
||||
if (fabs(fld - me->persfield) > 1e-5 && fabs(fld - me->lastfield) > 1e-5) {
|
||||
SCPrintf(pCon, eWarning, "Be aware that this does neither match the field"
|
||||
" stored in software\nnor the field stored in power supply.");
|
||||
me->force = 0;
|
||||
}
|
||||
if (me->force && fld != me->confirmfield) me->force = 0;
|
||||
if (me->force == 0) {
|
||||
SCPrintf(pCon, eWarning, "Please repeat this command, to confirm again"
|
||||
" the persistent field of\n %f Tesla.", fld);
|
||||
IpsSetField(me, fld);
|
||||
me->confirmfield = fld;
|
||||
me->force=1;
|
||||
} else {
|
||||
me->force=2;
|
||||
|
Reference in New Issue
Block a user