- Fixed bugs in sinqhttp.c, most notatbly the unknown error on hm init

- Added first slit to amorset
- Added untested code for the POLDI strees machine
This commit is contained in:
koennecke
2006-11-24 15:52:51 +00:00
parent d01758de72
commit 8a1a808fe5
17 changed files with 591 additions and 88 deletions

View File

@ -22,3 +22,4 @@ int AmorDriveAction(SConnection *pCon, SicsInterp *pSics, void *pData,
int argc, char *argv[]); int argc, char *argv[]);
#endif #endif

View File

@ -29,11 +29,16 @@ static int readMotors(pamorSet self, SConnection *pCon){
float val; float val;
result = LLDcreate(sizeof(MotControl)); result = LLDcreate(sizeof(MotControl));
status = addMotorToList(result,"d2t",.0); status = addMotorToList(result,"d1t",.0);
if(status != 1){ if(status != 1){
SCWrite(pCon,"ERROR: configuration error: d2t not found", eError); SCWrite(pCon,"ERROR: configuration error: d1t not found", eError);
return -1; return -1;
} }
status = addMotorToList(result,"d2t",.0);
if(status != 1){
SCWrite(pCon,"ERROR: configuration error: d2t not found", eError);
return -1;
}
status = addMotorToList(result,"d3t",.0); status = addMotorToList(result,"d3t",.0);
if(status != 1){ if(status != 1){
SCWrite(pCon,"ERROR: configuration error: d3t not found", eError); SCWrite(pCon,"ERROR: configuration error: d3t not found", eError);
@ -92,20 +97,36 @@ static int calcAmorSettings(pamorSet self,SConnection *pCon){
addMotorToList(self->driveList,"dbs",val); addMotorToList(self->driveList,"dbs",val);
} }
/* /*
* slit 2 * slit 1 is before the monochromator and does not need to be
*/ * driven when m2t changes. This is here to make sure that d1b is
if(self->D2.activeFlag == 1){ * in a feasible position.
dist = ABS(calcCompPosition(&self->D2) - calcCompPosition(&self->M)); */
mot = getListMotorPosition(readList,"d2t"); if(self->D1.activeFlag == 1){
if(mot < -99999){ mot = getListMotorPosition(readList,"d1t");
SCWrite(pCon,"WARNING: skipping d2 because of bad read on d2t", if(mot < -99999){
eWarning); SCWrite(pCon,"WARNING: skipping d1 because of bad read on d1t",
} else { eWarning);
val = dist*Tand(-self->targetm2t) - .5 * mot; } else {
addMotorToList(self->driveList,"d2b",val); val = - .5 * mot;
} addMotorToList(self->driveList,"d1b",val);
} }
}
/*
* slit 2
*/
if(self->D2.activeFlag == 1){
dist = ABS(calcCompPosition(&self->D2) - calcCompPosition(&self->M));
mot = getListMotorPosition(readList,"d2t");
if(mot < -99999){
SCWrite(pCon,"WARNING: skipping d2 because of bad read on d2t",
eWarning);
} else {
val = dist*Tand(-self->targetm2t) - .5 * mot;
addMotorToList(self->driveList,"d2b",val);
}
}
/* /*
* slit 3 * slit 3
@ -362,7 +383,8 @@ static int amorSetSave(void *data, char *name,FILE *fd){
saveAmorComp(fd,name,"chopper",&self->chopper); saveAmorComp(fd,name,"chopper",&self->chopper);
saveAmorComp(fd,name,"mono",&self->M); saveAmorComp(fd,name,"mono",&self->M);
saveAmorComp(fd,name,"ds",&self->DS); saveAmorComp(fd,name,"ds",&self->DS);
saveAmorComp(fd,name,"slit2",&self->D2); saveAmorComp(fd,name,"slit1",&self->D2);
saveAmorComp(fd,name,"slit2",&self->D2);
saveAmorComp(fd,name,"slit3",&self->D3); saveAmorComp(fd,name,"slit3",&self->D3);
saveAmorComp(fd,name,"sample",&self->S); saveAmorComp(fd,name,"sample",&self->S);
saveAmorComp(fd,name,"slit4",&self->D4); saveAmorComp(fd,name,"slit4",&self->D4);
@ -423,7 +445,9 @@ static void killAmorSet(void *data){
/*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/
static int testRequiredMotors(SConnection *pCon){ static int testRequiredMotors(SConnection *pCon){
char motList[][20] = {"soz", "com", char motList[][20] = {"soz", "com",
"cox","coz","dbs","d2b","d2t", "cox","coz","dbs",
"d1t", "d1b",
"d2b","d2t",
"d3b", "d3t", "d4b","d4t", "d3b", "d3t", "d4b","d4t",
"d5t", "d5b","aoz", "aom"}; "d5t", "d5b","aoz", "aom"};
int i = 0, status = 1; int i = 0, status = 1;
@ -431,7 +455,7 @@ static int testRequiredMotors(SConnection *pCon){
char pBueffel[132]; char pBueffel[132];
for(i = 0; i < 15; i++){ for(i = 0; i < 17; i++){
pMot = NULL; pMot = NULL;
pMot = FindMotor(pServ->pSics,motList[i]); pMot = FindMotor(pServ->pSics,motList[i]);
if(pMot == NULL){ if(pMot == NULL){
@ -507,8 +531,10 @@ static pamorComp locateComponent(pamorSet self, char *name){
return &self->M; return &self->M;
} else if(strcmp(name,"ds") == 0){ } else if(strcmp(name,"ds") == 0){
return &self->DS; return &self->DS;
}else if(strcmp(name,"slit2") == 0){ }else if(strcmp(name,"slit1") == 0){
return &self->D2; return &self->D1;
}else if(strcmp(name,"slit2") == 0){
return &self->D2;
}else if(strcmp(name,"slit3") == 0){ }else if(strcmp(name,"slit3") == 0){
return &self->D3; return &self->D3;
}else if(strcmp(name,"sample") == 0){ }else if(strcmp(name,"sample") == 0){

View File

@ -19,6 +19,7 @@ typedef struct {
amorComp chopper; amorComp chopper;
amorComp M; amorComp M;
amorComp DS; amorComp DS;
amorComp D1;
amorComp D2; amorComp D2;
amorComp D3; amorComp D3;
amorComp S; amorComp S;
@ -50,3 +51,4 @@ double amorGetMotor(pamorSet amor, SConnection *pCon, int type);
#endif #endif

View File

@ -70,6 +70,7 @@ $\langle$amorsetint {\footnotesize ?}$\rangle\equiv$
\mbox{}\verb@ amorComp chopper;@\\ \mbox{}\verb@ amorComp chopper;@\\
\mbox{}\verb@ amorComp M;@\\ \mbox{}\verb@ amorComp M;@\\
\mbox{}\verb@ amorComp DS;@\\ \mbox{}\verb@ amorComp DS;@\\
\mbox{}\verb@ amorComp D1;@\\
\mbox{}\verb@ amorComp D2;@\\ \mbox{}\verb@ amorComp D2;@\\
\mbox{}\verb@ amorComp D3;@\\ \mbox{}\verb@ amorComp D3;@\\
\mbox{}\verb@ amorComp S;@\\ \mbox{}\verb@ amorComp S;@\\

View File

@ -53,6 +53,7 @@ typedef struct {
amorComp chopper; amorComp chopper;
amorComp M; amorComp M;
amorComp DS; amorComp DS;
amorComp D1;
amorComp D2; amorComp D2;
amorComp D3; amorComp D3;
amorComp S; amorComp S;

View File

@ -593,7 +593,11 @@
{ {
snprintf(hmCommand,255,"sum:2:0:%d",iDim[2]); snprintf(hmCommand,255,"sum:2:0:%d",iDim[2]);
data = self->pHM->pDriv->SubSample(self->pHM->pDriv,pCon,0,hmCommand); if(self->pHM->pDriv->SubSample != NULL){
data = self->pHM->pDriv->SubSample(self->pHM->pDriv,pCon,0,hmCommand);
} else {
data = NULL;
}
if(data == NULL) if(data == NULL)
{ {
SCWrite(pCon,"ERROR: failed to retrieve collapsed data from HM", eError); SCWrite(pCon,"ERROR: failed to retrieve collapsed data from HM", eError);

View File

@ -515,11 +515,11 @@
if(strcmp(name,"threshold") == 0) if(strcmp(name,"threshold") == 0)
{ {
sprintf(pCommand,"DL %1.1d %f\r",iCter,fVal); sprintf(pCommand,"DL %1.1d %6.2f\r",iCter,fVal);
iRet = EL737_SendCmnd(&pEL737->pData,pCommand,pReply,79); iRet = EL737_SendCmnd(&pEL737->pData,pCommand,pReply,79);
if(iRet == 1) if(iRet == 1)
{ {
if(pCommand[0] == '?') if(pReply[0] == '?')
{ {
self->iErrorCode = BADCOUNTER; self->iErrorCode = BADCOUNTER;
return HWFault; return HWFault;

View File

@ -412,6 +412,9 @@ static int EL737GetError(struct __COUNTER *self, int *iCode,
case OFFLINE: case OFFLINE:
strncpy(pError,"EL737 is offline",errLen); strncpy(pError,"EL737 is offline",errLen);
break; break;
case OVERFLOW:
strncpy(pError,"EL737 reported overflow, communication problem",errLen);
break;
case BADRANGE: case BADRANGE:
strncpy(pError,"EL737 parameter is out of range",errLen); strncpy(pError,"EL737 parameter is out of range",errLen);
break; break;
@ -468,6 +471,7 @@ static int EL737FixIt(struct __COUNTER *self, int iCode){
case NOPARAM: case NOPARAM:
case BADRANGE: case BADRANGE:
case BADTRANGE: case BADTRANGE:
case OVERFLOW:
return COREDO; return COREDO;
break; break;
case BADREPLY: case BADREPLY:

View File

@ -17,6 +17,7 @@
#include <assert.h> #include <assert.h>
#include <time.h> #include <time.h>
#include <sics.h> #include <sics.h>
#include <unistd.h>
#define CHOCOINTERNAL #define CHOCOINTERNAL
#include <choco.h> #include <choco.h>
#include <SCinter.h> #include <SCinter.h>
@ -41,6 +42,8 @@
/*--------------------- update flags -------------------------------------*/ /*--------------------- update flags -------------------------------------*/
#define ALL 1 #define ALL 1
#define SPEED 2 #define SPEED 2
/*--------------------- wait after set -----------------------------------*/
#define STWAIT 5
/*------------------------- chopper internal names -----------------------*/ /*------------------------- chopper internal names -----------------------*/
#define CH1N "snail" #define CH1N "snail"
#define CH2N "master" #define CH2N "master"
@ -381,6 +384,7 @@ static int ReadJulChoFlags(pJulCho self){
char reply[256]; char reply[256];
status = JulChoTransact(self,"RSC",reply,255); status = JulChoTransact(self,"RSC",reply,255);
/* fprintf(stdout,"Chopper flags = %s\n", reply);*/
if(status < 0){ if(status < 0){
self->errorCode = status; self->errorCode = status;
return 0; return 0;
@ -911,6 +915,12 @@ static int JulChoSetPar2(pCodri pDriv, char *parname, char *pValue){
self->errorCode = status; self->errorCode = status;
return 0; return 0;
} }
/*
* The SicsWait is here to allow the chopper to update his status flags.
* There were occurrences where the chopper was still driving but the
* status flag did not reflect this.
*/
SicsWait(STWAIT);
self->lastUpdate = 0; self->lastUpdate = 0;
return status; return status;
} }
@ -958,6 +968,12 @@ static int JulChoSetPar(pCodri pDriv, char *parname, float fValue){
self->errorCode = status; self->errorCode = status;
return 0; return 0;
} }
/*
* The SicsWait is here to allow the chopper to update his status flags.
* There were occurrences where the chopper was still driving but the
* status flag did not reflect this.
*/
SicsWait(STWAIT);
self->lastUpdate = 0; self->lastUpdate = 0;
return status; return status;
} }
@ -1015,8 +1031,8 @@ static int JulChoGetPar(pCodri pDriv, char *parname,
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static int JulChoCheckPar(pCodri pDriv, char *parname){ static int JulChoCheckPar(pCodri pDriv, char *parname){
pJulCho self = NULL; pJulCho self = NULL;
int i; int i, status;
char path[256]; char path[256], reply[256];
pHdb target = NULL; pHdb target = NULL;
char *chNames[] = {CH1N, char *chNames[] = {CH1N,
CH2N, CH2N,
@ -1052,6 +1068,12 @@ static int JulChoCheckPar(pCodri pDriv, char *parname){
return HWBusy; return HWBusy;
} }
} }
status = JulChoTransact(self,"RSC",reply,255);
if(status < 0){
self->errorCode = status;
return HWFault;
}
/* fprintf(stdout,"Chopper Flags at finish: %s\n", reply);*/
return HWIdle; return HWIdle;
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/

BIN
libpsi.a

Binary file not shown.

View File

@ -18,7 +18,7 @@ OBJ=psi.o buffer.o ruli.o dmc.o nxsans.o nextrics.o sps.o pimotor.o \
el737hpv2driv.o swmotor2.o tricssupport.o amorcomp.o \ el737hpv2driv.o swmotor2.o tricssupport.o amorcomp.o \
$(MZOBJ) amordrive.o amorset.o tcpdornier.o sinqhttp.o\ $(MZOBJ) amordrive.o amorset.o tcpdornier.o sinqhttp.o\
dgrambroadcast.o sinq.o tabledrive.o tcpdocho.o julcho.o \ dgrambroadcast.o sinq.o tabledrive.o tcpdocho.o julcho.o \
ritastorage.o ritastorage.o poldizug.o
MZOBJ=fsm.o logger.o sugar.o pardef.o ease.o strobj.o oxinst.o logreader.o \ MZOBJ=fsm.o logger.o sugar.o pardef.o ease.o strobj.o oxinst.o logreader.o \
ipsdriv.o ilmdriv.o itcdriv.o ighdriv.o euro2kdriv.o modbus.o arrobj.o \ ipsdriv.o ilmdriv.o itcdriv.o ighdriv.o euro2kdriv.o modbus.o arrobj.o \

358
poldizug.c Normal file
View File

@ -0,0 +1,358 @@
/**
* This is the implementation of a SICS access module for the POLDI
* pull machine for testing mechanical samples. This thing is a one
* of a kind; therefore its implementation does not follow the usual
* SICS distinction between hardware object and driver. The thing can
* operate in two modes: either a force is driven or a position.
*
* copyright: see file COPYRIGHT
*
* Mark Koennecke, October 2006
*/
#include <sics.h>
#include <rs232controller.h>
#include <bit.h>
/*===============================================================*/
#define FORCE 0
#define ZUGPOS 1
/*---------------------------------------------------------------*/
typedef struct {
pObjectDescriptor pDes;
pIDrivable pDriv;
prs232 controller;
int iMode;
float maxForce, minForce;
float maxPos, minPos;
}PZR, *pPZR;
/*--------------------------------------------------------------*/
static int PZRCommand(prs232 controller, SConnection *pCon,
char *command,
char *reply, int replyLen){
int status, i;
char buffer[512], error[132];
/*
* try three times to get our message through...
*/
for(i = 0; i < 3; i++){
status = transactRS232(controller,command, strlen(command),
reply, replyLen);
if(status == 1){
return 1;
}
/*
* error processing
*/
memset(error,0,132);
getRS232Error(status,error,131);
status = fixRS232Error(controller,status);
if(pCon != NULL){
if(status == 1){
snprintf(buffer,511,"WARNING: trying to fix: %s",
error);
SCWrite(pCon,buffer,eWarning);
} else {
snprintf(buffer,511,"ERROR: %s",
error);
SCWrite(pCon,buffer,eError);
}
}
if(status == 0){
return HWFault;
}
}
return HWFault;
}
/*===============================================================*/
static void *PZRGetInterface(void *data, int iD){
pPZR self = NULL;
self = (pPZR)data;
if(self != NULL && iD == DRIVEID){
return self->pDriv;
} else {
return NULL;
}
return NULL;
}
/*----------------------------------------------------------------
This routine can return either OKOK or HWFault when thing
go wrong. However, the return value of Halt is usually ignored!
------------------------------------------------------------------*/
static int PZRHalt(void *data) {
pPZR self = NULL;
char buffer[80];
self = (pPZR)data;
PZRCommand(self->controller,NULL,"stop\n",buffer,79);
return OKOK;
}
/*----------------------------------------------------------------
This routine can return either 1 or 0. 1 means the position can
be reached, 0 NOT
If 0, error shall contain up to errlen characters of information
about which limit was violated
------------------------------------------------------------------*/
static int PZRCheckLimits(void *data, float val,
char *error, int errlen){
pPZR self = NULL;
self = (pPZR)data;
if(self->iMode == FORCE){
if(val < self->minForce || val > self->maxForce){
snprintf(error,errlen,"%f is not within limits %f to %f",
val,self->minForce, self->maxForce);
return 0;
}
} else {
if(val < self->minPos || val > self->maxPos){
snprintf(error,errlen,"%f is not within limits %f to %f",
val,self->minPos, self->maxPos);
return 0;
}
}
return 1;
}
/*----------------------------------------------------------------
This routine can return 0 when a limit problem occurred
OKOK when the motor was successfully started
HWFault when a problem occured starting the device
Possible errors shall be printed to pCon
For real motors, this is supposed to try at least three times
to start the motor in question
val is the value to drive the motor too
------------------------------------------------------------------*/
static long PZRSetValue(void *data, SConnection *pCon, float val){
pPZR self = NULL;
char command[80], reply[80];
int status;
self = (pPZR)data;
if(self->iMode == FORCE){
snprintf(command,79,"wr force %f\n", val);
} else {
snprintf(command,79,"wr vel %f\n", val);
}
status = PZRCommand(self->controller, pCon, command, reply, 79);
if(status == 1){
return OKOK;
} else {
return HWFault;
}
return HWFault;
}
/*----------------------------------------------------------------
Checks the status of a running motor. Possible return values
HWBusy The motor is still running
OKOK or HWIdle when the motor finished driving
HWFault when a hardware problem ocurred
HWPosFault when the hardware cannot reach a position
Errors are duly to be printed to pCon
For real motors CheckStatus again shall try hard to fix any
issues with the motor
------------------------------------------------------------------*/
static int PZRCheckStatus(void *data, SConnection *pCon){
pPZR self = NULL;
int status, code;
char command[80], reply[80], bits[1];
self = (pPZR)data;
snprintf(command,79,"rd stat\n");
status = PZRCommand(self->controller, pCon, command, reply, 79);
if(status != 1){
return HWFault;
}
sscanf(reply,"%x", &code);
bits[0] = (char)code;
/*
* check for errors
*/
if(BITSET(bits,3)){
SCWrite(pCon,"ERROR: BANG! Sample broken!",eError);
return HWFault;
}
if(BITSET(bits,4)){
SCWrite(pCon,"ERROR: hit positive limit switch",eError);
return HWFault;
}
if(BITSET(bits,5)){
SCWrite(pCon,"ERROR: hit negative limit switch",eError);
return HWFault;
}
if(BITSET(bits,7)){
SCWrite(pCon,"ERROR: general and overall error",eError);
return HWFault;
}
if(BITSET(bits,2)){
return HWBusy;
} else {
return HWIdle;
}
return HWFault;
}
/*----------------------------------------------------------------
GetValue is supposed to read a motor position
On errors, -99999999.99 is returned and messages printed to pCon
------------------------------------------------------------------*/
static float PZRGetValue(void *data, SConnection *pCon){
pPZR self = NULL;
float val = -99999999.99;
int status;
char command[80], reply[80];
self = (pPZR)data;
if(self->iMode == FORCE){
snprintf(command,79,"rd force\n");
} else {
snprintf(command,79,"rd vel\n");
}
status = PZRCommand(self->controller, pCon, command, reply, 79);
if(status != 1){
return HWFault;
}
sscanf(reply,"%f",&val);
return val;
}
/*----------------------------------------------------------------
returns NULL on failure, a new datastructure else
------------------------------------------------------------------*/
static pPZR PZRMakeObject(char *host, int port){
pPZR self = NULL;
self = malloc(sizeof(PZR));
if(self == NULL){
return NULL;
}
self->pDes = CreateDescriptor("PoldiReiss");
self->pDriv = CreateDrivableInterface();
self->controller = createRS232(host,port);
if(self->pDes == NULL || self->pDriv == NULL || self->controller == NULL){
free(self);
return NULL;
}
initRS232(self->controller);
setRS232SendTerminator(self->controller,"\n");
setRS232ReplyTerminator(self->controller,"\n");
setRS232Timeout(self->controller,1000);
setRS232Debug(self->controller,1);
self->pDes->GetInterface = PZRGetInterface;
self->pDriv->Halt = PZRHalt;
self->pDriv->CheckLimits = PZRCheckLimits;
self->pDriv->SetValue = PZRSetValue;
self->pDriv->CheckStatus = PZRCheckStatus;
self->pDriv->GetValue = PZRGetValue;
return self;
}
/*--------------------------------------------------------------------------*/
static void killPoldiZug(void *data){
pPZR self = (pPZR)data;
if(self == NULL){
return;
}
if(self->pDes != NULL){
DeleteDescriptor(self->pDes);
}
if(self->controller != NULL){
closeRS232(self->controller);
KillRS232(self->controller);
}
free(self);
}
/*============================================================================*/
static int PoldiReissAction(SConnection *pCon, SicsInterp *pSics,
void *pData, int argc, char *argv[]){
pPZR self = NULL;
char command[80], reply[80];
float val;
int status;
self = (pPZR)pData;
assert(self != NULL);
if(argc > 1) {
strtolower(argv[1]);
if(strcmp(argv[1],"mode") == 0) {
if(argc > 2){
if(!SCMatchRights(pCon,usUser)){
return 0;
}
strtolower(argv[2]);
if(strcmp(argv[2],"force") == 0) {
status = PZRCommand(self->controller, pCon,
"wr mode 1\n", reply,79);
if(status == 1){
self->iMode == FORCE;
SCSendOK(pCon);
return 1;
} else {
return 0;
}
} else if(strcmp(argv[2],"pos") == 0) {
status = PZRCommand(self->controller, pCon,
"wr mode 0\n", reply,79);
if(status == 1){
self->iMode == ZUGPOS;
SCSendOK(pCon);
return 1;
} else {
return 0;
}
} else {
SCWrite(pCon,"ERROR: zug mode unknown, allowed force, pos",
eError);
return 0;
}
}
} else {
if(self->iMode == FORCE){
snprintf(command,79,"%s.mode = force",argv[0]);
} else {
snprintf(command,79,"%s.mode = pos",argv[0]);
}
SCWrite(pCon,command,eValue);
return 1;
}
}
val = self->pDriv->GetValue(self,pCon);
snprintf(command,79,"%s = %f", argv[0], val);
SCWrite(pCon,command,eValue);
return 1;
}
/*----------------------------------------------------------------------------
* MakePoldiReiss name host port minForce maxForce minPos maxPos
* ---------------------------------------------------------------------------*/
int MakePoldiReiss(SConnection *pCon, SicsInterp *pSics,
void *pData, int argc, char *argv[]){
pPZR self = NULL;
char reply[80];
if(argc < 8) {
SCWrite(pCon,"ERROR: not enough arguments to MakePoldiReiss",eError);
return 0;
}
self = PZRMakeObject(argv[2],atoi(argv[3]));
if(self == NULL){
SCWrite(pCon,"ERROR: out of memory making PoldiReiss",eError);
return 0;
}
self->minForce = atof(argv[4]);
self->maxForce = atof(argv[5]);
self->minPos = atof(argv[6]);
self->maxPos = atof(argv[7]);
PZRCommand(self->controller, pCon,
"wr mode 1\n", reply,79);
AddCommand(pSics,argv[1],
PoldiReissAction,
killPoldiZug,
self);
return 1;
}

19
poldizug.h Normal file
View File

@ -0,0 +1,19 @@
/**
* This is the implementation of a SICS access module for the POLDI
* pull machine for testing mechanical samples. This thing is a one
* of a kind; therefore its implementation does not follow the usual
* SICS distinction between hardware object and driver. The thing can
* operate in two modes: either a force is driven or a position.
*
* There is only the creation function here, everything else is in poldizug.c
*
* copyright: see file COPYRIGHT
*
* Mark Koennecke, October 2006
*/
#ifndef POLDIZUG_H_
#define POLDIZUG_H_
#include <sics.h>
int MakePoldiReiss(SConnection *pCon, SicsInterp *pSics,
void *pData, int argc, char *argv[]);
#endif /*POLDIZUG_H_*/

3
psi.c
View File

@ -55,6 +55,7 @@
#include "tabledrive.h" #include "tabledrive.h"
#include "amorset.h" #include "amorset.h"
#include "sinqhttp.h" #include "sinqhttp.h"
#include "poldizug.h"
/* /*
from tcpdornier.c from tcpdornier.c
*/ */
@ -121,6 +122,7 @@ static void AddPsiCommands(SicsInterp *pInter){
AddCommand(pInter,"MakeTCPSelector",VelSelTcpFactory,NULL,NULL); AddCommand(pInter,"MakeTCPSelector",VelSelTcpFactory,NULL,NULL);
AddCommand(pInter,"MakeJulCho",JulChoFactory,NULL,NULL); AddCommand(pInter,"MakeJulCho",JulChoFactory,NULL,NULL);
AddCommand(pInter,"MakeRitaFix",MakeRitaFix,NULL,NULL); AddCommand(pInter,"MakeRitaFix",MakeRitaFix,NULL,NULL);
AddCommand(pInter,"MakePoldiReiss",MakePoldiReiss,NULL,NULL);
/* /*
AddCommand(pInter,"MakeDifrac",MakeDifrac,NULL,NULL); AddCommand(pInter,"MakeDifrac",MakeDifrac,NULL,NULL);
*/ */
@ -143,6 +145,7 @@ static void RemovePsiCommands(SicsInterp *pSics){
RemoveCommand(pSics,"MakeTCPSelector"); RemoveCommand(pSics,"MakeTCPSelector");
RemoveCommand(pSics,"MakeJulCho"); RemoveCommand(pSics,"MakeJulCho");
RemoveCommand(pSics,"MakeRitaFix"); RemoveCommand(pSics,"MakeRitaFix");
RemoveCommand(pSics,"MakePoldiReiss");
/* /*
RemoveCommand(pSics,"MakeDifrac"); RemoveCommand(pSics,"MakeDifrac");
*/ */

View File

@ -131,7 +131,7 @@ static int sinqHttpGet(pSinqHttp self, char *request){
if(httpStatus != ghttp_done){ if(httpStatus != ghttp_done){
ghttp_close(self->syncRequest); ghttp_close(self->syncRequest);
sinqHttpGetPrepare(self,request); sinqHttpGetPrepare(self,request);
ghttp_prepare(self->syncRequest); ghttp_prepare(self->syncRequest);
httpStatus = ghttp_process(self->syncRequest); httpStatus = ghttp_process(self->syncRequest);
} }
if(httpStatus != ghttp_done){ if(httpStatus != ghttp_done){
@ -151,6 +151,7 @@ static int SinqHttpConfigure(pHistDriver self, SConnection *pCon,
pSinqHttp pPriv = NULL; pSinqHttp pPriv = NULL;
int status, iInit; int status, iInit;
float fVal; float fVal;
int i;
char *confData = NULL; char *confData = NULL;
ghttp_status httpStatus; ghttp_status httpStatus;
@ -199,58 +200,69 @@ static int SinqHttpConfigure(pHistDriver self, SConnection *pCon,
actually do configure actually do configure
*/ */
if(iInit == 1){ if(iInit == 1){
memset(confCommand,0,512*sizeof(char)); for(i = 0; i < 2; i++){
if(StringDictGet(pOpt,"hmconfigscript",confCommand,511) != 1){ memset(confCommand,0,512*sizeof(char));
SCWrite(pCon, if(StringDictGet(pOpt,"hmconfigscript",confCommand,511) != 1){
"ERROR: required parameter hmconfigscript not found!", SCWrite(pCon,
eError); "ERROR: required parameter hmconfigscript not found!",
return 0; eError);
}
status = Tcl_Eval(pSics->pTcl,confCommand);
if(status != TCL_OK){
snprintf(confCommand,511,
"ERROR: Tcl reported %s while evaluating hmconfigscript",
Tcl_GetStringResult(pSics->pTcl));
SCWrite(pCon,confCommand,eError);
return 0;
} else {
/*
uplod new configuration to HM
*/
ghttp_clean(pPriv->syncRequest);
snprintf(url,511,"%s%s",pPriv->hmAddress,configure);
status = ghttp_set_uri(pPriv->syncRequest,url);
if(status < 0){
SCWrite(pCon,"ERROR: invalid URI for HM request",eError);
return 0; return 0;
} }
status = ghttp_set_type(pPriv->syncRequest,ghttp_type_post); status = Tcl_Eval(pSics->pTcl,confCommand);
confData = (char *)Tcl_GetStringResult(pSics->pTcl); if(status != TCL_OK){
/* puts(confData); */ snprintf(confCommand,511,
status = ghttp_set_body(pPriv->syncRequest,confData, "ERROR: Tcl reported %s while evaluating hmconfigscript",
strlen(confData)); Tcl_GetStringResult(pSics->pTcl));
ghttp_set_authinfo(pPriv->syncRequest, pPriv->userName,
pPriv->passWord);
ghttp_set_sync(pPriv->syncRequest,ghttp_sync);
status = ghttp_prepare(pPriv->syncRequest);
httpStatus = ghttp_process(pPriv->syncRequest);
confData = (char *)ghttp_get_body(pPriv->syncRequest);
if(httpStatus != ghttp_done){
confData = (char *)ghttp_get_error(pPriv->syncRequest);
snprintf(confCommand,511,"ERROR: http error %s occurred",
confData);
SCWrite(pCon,confCommand,eError); SCWrite(pCon,confCommand,eError);
return 0; return 0;
} else if(confData != NULL){ } else {
if(strstr(confData,"ERROR") != NULL){ /*
snprintf(confCommand,511,"%s",confData); uplod new configuration to HM
SCWrite(pCon,confCommand,eError); */
ghttp_clean(pPriv->syncRequest);
snprintf(url,511,"%s%s",pPriv->hmAddress,configure);
status = ghttp_set_uri(pPriv->syncRequest,url);
if(status < 0){
SCWrite(pCon,"ERROR: invalid URI for HM request",eError);
return 0; return 0;
} }
if(strstr(confData,"Authentication Error") != NULL){ status = ghttp_set_type(pPriv->syncRequest,ghttp_type_post);
snprintf(confCommand,511,"%s",confData); confData = (char *)Tcl_GetStringResult(pSics->pTcl);
/* puts(confData); */
status = ghttp_set_body(pPriv->syncRequest,confData,
strlen(confData));
ghttp_set_authinfo(pPriv->syncRequest, pPriv->userName,
pPriv->passWord);
ghttp_set_sync(pPriv->syncRequest,ghttp_sync);
status = ghttp_prepare(pPriv->syncRequest);
httpStatus = ghttp_process(pPriv->syncRequest);
confData = (char *)ghttp_get_body(pPriv->syncRequest);
if(httpStatus != ghttp_done){
/* we may need to reconnect.....
*/
if(i == 0){
ghttp_close(pPriv->syncRequest);
continue;
}
/*
* no we have a real error
*/
confData = (char *)ghttp_get_error(pPriv->syncRequest);
snprintf(confCommand,511,"ERROR: http error %s occurred",
confData);
SCWrite(pCon,confCommand,eError); SCWrite(pCon,confCommand,eError);
return 0; return 0;
} else if(confData != NULL){
if(strstr(confData,"ERROR") != NULL){
snprintf(confCommand,511,"%s",confData);
SCWrite(pCon,confCommand,eError);
return 0;
}
if(strstr(confData,"Authentication Error") != NULL){
snprintf(confCommand,511,"%s",confData);
SCWrite(pCon,confCommand,eError);
return 0;
}
} }
} }
} }

View File

@ -758,6 +758,12 @@ static void slsdspCodeToText(int code, char *text, int textlen){
int iRet, ival; int iRet, ival;
char msg[6], reply[6]; char msg[6], reply[6];
assert(self);
pMe = (pSLSDriv )self->pPrivate;
assert(pMe);
msg[0] = DSPWRITE; msg[0] = DSPWRITE;
msg[1] = 0x3c; msg[1] = 0x3c;
if(strcmp(pCommand,"off") == 0){ if(strcmp(pCommand,"off") == 0){
@ -825,9 +831,6 @@ static void slsdspCodeToText(int code, char *text, int textlen){
try to switch device on try to switch device on
*/ */
msg[0] = DSPWRITE; msg[0] = DSPWRITE;
/* old device on
msg[1] = 0x31;
*/
msg[1] = 0x3c; msg[1] = 0x3c;
/* /*
* ival = 0: ausschalten * ival = 0: ausschalten
@ -869,7 +872,6 @@ static void slsdspCodeToText(int code, char *text, int textlen){
memcpy(msg+2, &ival,4); memcpy(msg+2, &ival,4);
iRet = communicateSLS(pMe->pSock,msg,reply); iRet = communicateSLS(pMe->pSock,msg,reply);
*/ */
NETClosePort(pMe->pSock); NETClosePort(pMe->pSock);
pMe->pSock = NULL; pMe->pSock = NULL;
return 1; return 1;

View File

@ -10,11 +10,13 @@
#include "../lld.h" #include "../lld.h"
#include "tabledrive.h" #include "tabledrive.h"
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
#define OUTOFSYNC 100 #define OUTOFSYNC 100
#define STARTING 101 #define STARTING 101
#define STEPPING 102 #define STEPPING 102
#define WAITING 103 #define WAITING 103
#define WAITFINISH 104 #define WAITFINISH 104
#define IDLE 105
#define ABS(x) (x < 0 ? -(x) : (x)) #define ABS(x) (x < 0 ? -(x) : (x))
#define SIGN(x) (x < .0 ? (-1) : (1)) #define SIGN(x) (x < .0 ? (-1) : (1))
extern char *trim(char *txt); extern char *trim(char *txt);
@ -183,6 +185,10 @@ static void checkSync(pTableDrive self, SConnection *pCon, float value){
tdMotor moti; tdMotor moti;
char pBueffel[256]; char pBueffel[256];
if(self->state != IDLE){
return;
}
status = LLDnodePtr2First(self->motorTable); status = LLDnodePtr2First(self->motorTable);
while(status != 0){ while(status != 0){
LLDnodeDataTo(self->motorTable,&moti); LLDnodeDataTo(self->motorTable,&moti);
@ -224,6 +230,36 @@ static float TableDriveGetValue(void *pData, SConnection *pCon){
self->currentPosition = value; self->currentPosition = value;
return value; return value;
} }
/*-------------------------------------------------------------------------*/
static void tableInfo(pTableDrive self, SConnection *pCon){
int status, test;
float motorPosition, targetPosition, tolerance, diff, value;
tdMotor moti;
char pBueffel[256];
value = TableDriveGetValue(self,pCon);
snprintf(pBueffel,255," Triffid Position: %8.2f", value);
SCWrite(pCon,pBueffel,eValue);
status = LLDnodePtr2First(self->motorTable);
while(status != 0){
LLDnodeDataTo(self->motorTable,&moti);
test = MotorGetSoftPosition(moti.pMot,pCon,&motorPosition);
if(!test){
snprintf(pBueffel,255,"ERROR: failed to read motor %s",
moti.motorName);
SCWrite(pCon,pBueffel,eError);
} else {
MotorGetPar(moti.pMot,"precision",&tolerance);
targetPosition = findTarget(moti,value);
snprintf(pBueffel,256,"Motor %10s, should: %8.2f, is %8.2f, diff = %8.2f",
moti.motorName, motorPosition, targetPosition,
ABS(targetPosition - motorPosition));
SCWrite(pCon,pBueffel,eValue);
}
status = LLDnodePtr2Next(self->motorTable);
}
}
/*------------------------------------------------------------------------*/ /*------------------------------------------------------------------------*/
static void tableSetPar(pMotor pMot, char *name, float value){ static void tableSetPar(pMotor pMot, char *name, float value){
ObPar *ob = NULL; ObPar *ob = NULL;
@ -401,6 +437,7 @@ static int TableDriveCheckStatus(void *pData, SConnection *pCon){
if(status != HWBusy){ if(status != HWBusy){
TableDriveGetValue(self,pCon); TableDriveGetValue(self,pCon);
closeMotors(self,pCon); closeMotors(self,pCon);
self->state = IDLE;
return status; return status;
} else { } else {
return HWBusy; return HWBusy;
@ -408,6 +445,7 @@ static int TableDriveCheckStatus(void *pData, SConnection *pCon){
break; break;
case OUTOFSYNC: case OUTOFSYNC:
SCWrite(pCon,"WARNING: tabledrive out of sync",eWarning); SCWrite(pCon,"WARNING: tabledrive out of sync",eWarning);
self->state = IDLE;
return HWFault; return HWFault;
break; break;
default: default:
@ -579,6 +617,7 @@ int TableDriveFactory(SConnection *pCon, SicsInterp *pSics, void *pData,
killTableDrive(pNew); killTableDrive(pNew);
return 0; return 0;
} }
pNew->state = IDLE;
status = AddCommand(pSics,argv[1], status = AddCommand(pSics,argv[1],
TableDriveAction, TableDriveAction,
@ -600,6 +639,7 @@ int TableDriveAction(SConnection *pCon, SicsInterp *pSics, void *pData,
int status; int status;
char pBueffel[1024]; char pBueffel[1024];
float value; float value;
pDynString print = NULL;
if(argc < 2){ if(argc < 2){
value = TableDriveGetValue(self,pCon); value = TableDriveGetValue(self,pCon);
@ -626,10 +666,18 @@ int TableDriveAction(SConnection *pCon, SicsInterp *pSics, void *pData,
SCSendOK(pCon); SCSendOK(pCon);
} }
return status; return status;
}else if(strcmp(argv[1],"show") == 0){ }else if(strcmp(argv[1],"show") == 0){
showPositions(self,pCon,pBueffel,1023); showPositions(self,pCon,pBueffel,1023);
SCWrite(pCon,pBueffel,eValue); SCWrite(pCon,pBueffel,eValue);
return 1; return 1;
}else if(strcmp(argv[1],"info") == 0){
SCStartBuffering(pCon);
tableInfo(self,pCon);
print = SCEndBuffering(pCon);
if(print != NULL){
SCWrite(pCon,GetCharArray(print), eValue);
}
return 1;
}else if(strcmp(argv[1],"orient") == 0){ }else if(strcmp(argv[1],"orient") == 0){
if(argc > 2){ if(argc > 2){
if(!SCMatchRights(pCon,usMugger)){ if(!SCMatchRights(pCon,usMugger)){