- Removed slit 5 from amorset.c

- poldizug now sends all codes all the time
- polterwrite writes the filename again
- sanswave has been modifed to support the new second generation velocity
  selector
- sinqhttprot has been mdified to copy data to nodes, this for the second
  generation HM object
- tasscan suppressed some output
This commit is contained in:
koennecke
2009-05-15 13:24:02 +00:00
parent 5d30c7b5b9
commit caf59ef8eb
12 changed files with 225 additions and 87 deletions

View File

@ -416,7 +416,7 @@ 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, "slit1", &self->D2); saveAmorComp(fd, name, "slit1", &self->D1);
saveAmorComp(fd, name, "slit2", &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);

View File

@ -23,6 +23,10 @@
Support for new HTTP HM added Support for new HTTP HM added
Mark Koennecke, July 2006 Mark Koennecke, July 2006
Lightly ammended for the new second generation HM module.
Mark koennecke, May 2009
--------------------------------------------------------------------------*/ --------------------------------------------------------------------------*/
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
@ -41,6 +45,7 @@
#include "lld.h" #include "lld.h"
#include "amorstat.i" #include "amorstat.i"
#include "amorstat.h" #include "amorstat.h"
#include "sicshipadaba.h"
/*------------------------------------------------------------------- /*-------------------------------------------------------------------
Manually from SinqHM_def.h Manually from SinqHM_def.h
--------------------------------------------------------------------*/ --------------------------------------------------------------------*/
@ -60,6 +65,7 @@ static int HMCountStartCallback(int iEvent, void *pEvent, void *pUser)
const float *fTime = NULL; const float *fTime = NULL;
int *iTime = NULL; int *iTime = NULL;
int iLength, iRet, i; int iLength, iRet, i;
pHdb tbin = NULL;
/* check kill condition */ /* check kill condition */
if (pCon == NULL || !SCisConnected(pCon)) { if (pCon == NULL || !SCisConnected(pCon)) {
@ -69,6 +75,19 @@ static int HMCountStartCallback(int iEvent, void *pEvent, void *pUser)
if (iEvent == COUNTSTART) { if (iEvent == COUNTSTART) {
/* send current time binning */ /* send current time binning */
iTOF = 1; iTOF = 1;
if(pHMHM->pDes->parNode != NULL){
tbin = GetHipadabaNode(pHMHM->pDes->parNode,"time_binning");
assert(tbin != NULL);
iLength = tbin->value.arrayLength;
iTime = (int *) malloc((iLength + 1) * sizeof(int));
if ((!iTime)) {
return 0;
}
iTime[0] = htonl(iLength);
for (i = 0; i < iLength; i++) {
iTime[i + 1] = htonl( (int) ( (tbin->value.v.floatArray[i]) / 10.) * 65536.) ;
}
} else {
fTime = GetHistTimeBin(pHMHM, &iLength); fTime = GetHistTimeBin(pHMHM, &iLength);
iTime = (int *) malloc((iLength + 1) * sizeof(int)); iTime = (int *) malloc((iLength + 1) * sizeof(int));
if ((!fTime) || (!iTime)) { if ((!fTime) || (!iTime)) {
@ -78,6 +97,7 @@ static int HMCountStartCallback(int iEvent, void *pEvent, void *pUser)
for (i = 0; i < iLength; i++) { for (i = 0; i < iLength; i++) {
iTime[i + 1] = htonl((int) ((fTime[i] / 10.) * 65536.)); iTime[i + 1] = htonl((int) ((fTime[i] / 10.) * 65536.));
} }
}
/* send new time binning to all clients */ /* send new time binning to all clients */
SCWrite(pCon, "TOFClear", eError); SCWrite(pCon, "TOFClear", eError);
SCWriteUUencoded(pCon, "arrowaxis_time", iTime, SCWriteUUencoded(pCon, "arrowaxis_time", iTime,
@ -681,7 +701,7 @@ static int projectYTOF(pAmorStat self, SConnection * pCon)
/*----------------------------------------------------------------- /*-----------------------------------------------------------------
SendSingleTOF sends single detector data for TOF mode SendSingleTOF sends single detector data for TOF mode
*/ --------------------------------------------------------------------*/
static int SendSingleTOF(pAmorStat self, SConnection * pCon) static int SendSingleTOF(pAmorStat self, SConnection * pCon)
{ {
@ -753,7 +773,7 @@ static int SendSingleTOF(pAmorStat self, SConnection * pCon)
/*------------------------------------------------------------------- /*-------------------------------------------------------------------
SubSample sums histogram data in the area defined by the rectangle SubSample sums histogram data in the area defined by the rectangle
x1,y1 x2, y2. Summing is along the time axis. x1,y1 x2, y2. Summing is along the time axis.
*/ ----------------------------------------------------------------------*/
static int SubSample(pAmorStat self, SConnection * pCon, static int SubSample(pAmorStat self, SConnection * pCon,
char *name, int x1, int x2, int y1, int y2) char *name, int x1, int x2, int y1, int y2)
{ {

View File

@ -23,7 +23,7 @@ OBJ=psi.o buffer.o ruli.o dmc.o nxsans.o nextrics.o sps.o pimotor.o \
dgrambroadcast.o sinq.o tabledrive.o tcpdocho.o julcho.o \ dgrambroadcast.o sinq.o tabledrive.o tcpdocho.o julcho.o \
ritastorage.o poldizug.o audinelib.o delcam.o el737hpdrivsps.o \ ritastorage.o poldizug.o audinelib.o delcam.o el737hpdrivsps.o \
rebin.o sanslirebin.o lmd200.o slsvme.o julprot.o sinqhttpprot.o \ rebin.o sanslirebin.o lmd200.o slsvme.o julprot.o sinqhttpprot.o \
pmacprot.o pfeifferprot.o pmacprot.o pfeifferprot.o termprot.o
.SECONDARY.: sanslirebin.c .SECONDARY.: sanslirebin.c

View File

@ -23,7 +23,6 @@ typedef struct {
pIDrivable pDriv; pIDrivable pDriv;
prs232 controller; prs232 controller;
int iMode; int iMode;
int state;
float maxForce, minForce; float maxForce, minForce;
float maxPos, minPos; float maxPos, minPos;
int velocity; int velocity;
@ -149,7 +148,6 @@ static long PZRSetValue(void *data, SConnection * pCon, float val)
switch (self->iMode) { switch (self->iMode) {
case FORCE: case FORCE:
if (self->state == OFF) {
snprintf(command, 79, "wr vel %d\r\n", self->velocity); snprintf(command, 79, "wr vel %d\r\n", self->velocity);
status = PZRCommand(self->controller, pCon, command, reply, 79); status = PZRCommand(self->controller, pCon, command, reply, 79);
if (status != 1) { if (status != 1) {
@ -165,19 +163,9 @@ static long PZRSetValue(void *data, SConnection * pCon, float val)
if (status != 1) { if (status != 1) {
return HWFault; return HWFault;
} }
self->state = REGEL;
return OKOK; return OKOK;
} else {
snprintf(command, 79, "wr force %f\r\n", val);
status = PZRCommand(self->controller, pCon, command, reply, 79);
if (status != 1) {
return HWFault;
}
return OKOK;
}
break; break;
case ZUGPOS: case ZUGPOS:
self->state = OFF;
snprintf(command, 79, "wr vel %d\r\n", self->velocity); snprintf(command, 79, "wr vel %d\r\n", self->velocity);
status = PZRCommand(self->controller, pCon, command, reply, 79); status = PZRCommand(self->controller, pCon, command, reply, 79);
if (status != 1) { if (status != 1) {
@ -325,7 +313,6 @@ static int PZRConnect(pPZR self, SConnection * pCon)
int status; int status;
closeRS232(self->controller); closeRS232(self->controller);
self->state = OFF;
status = initRS232(self->controller); status = initRS232(self->controller);
if (status < 0) { if (status < 0) {
getRS232Error(status, error, 131); getRS232Error(status, error, 131);
@ -451,7 +438,6 @@ static int PoldiReissAction(SConnection * pCon, SicsInterp * pSics,
} else if (strcmp(argv[1], "off") == 0) { } else if (strcmp(argv[1], "off") == 0) {
status = status =
PZRCommand(self->controller, pCon, "wr mode 0\r\n", reply, 79); PZRCommand(self->controller, pCon, "wr mode 0\r\n", reply, 79);
self->state = OFF;
if (status == 1) { if (status == 1) {
SCSendOK(pCon); SCSendOK(pCon);
return 1; return 1;
@ -519,7 +505,6 @@ int MakePoldiReiss(SConnection * pCon, SicsInterp * pSics,
self->minPos = atof(argv[6]); self->minPos = atof(argv[6]);
self->maxPos = atof(argv[7]); self->maxPos = atof(argv[7]);
self->iMode = FORCE; self->iMode = FORCE;
self->state = OFF;
self->velocity = 2; self->velocity = 2;
PZRCommand(self->controller, pCon, "wr mode 0\r\n", reply, 79); PZRCommand(self->controller, pCon, "wr mode 0\r\n", reply, 79);

View File

@ -230,6 +230,7 @@ static void PoldiStart(pPolterdi self, SConnection * pCon)
pMotor sa; pMotor sa;
HistInt *lData = NULL; HistInt *lData = NULL;
long lVal; long lVal;
pCounter pCount;
/* create filename */ /* create filename */
self->pFile = SNXMakeFileName(pServ->pSics, pCon); self->pFile = SNXMakeFileName(pServ->pSics, pCon);
@ -255,7 +256,7 @@ static void PoldiStart(pPolterdi self, SConnection * pCon)
} }
if (scancheck == 0) { if (scancheck == 0) {
sprintf(pBueffel, "Writing %s ......", self->pFile); sprintf(pBueffel, "Writing %s ......", self->pFile);
SCWrite(pCon, pBueffel, eWarning); SCWrite(pCon, pBueffel, eLog);
} }
@ -406,19 +407,24 @@ static void PoldiStart(pPolterdi self, SConnection * pCon)
/* /*
write counting data write counting data
*/ */
fVal = GetHistCountTime(self->pHist, pCon); pCount = (pCounter)FindCommandData(pServ->pSics,"counter","SingleCounter");
if(pCount){
fVal = GetCountTime(pCount, pCon);
NXDputalias(hfil, hdict, "cntime", &fVal); NXDputalias(hfil, hdict, "cntime", &fVal);
lVal = GetHistMonitor(self->pHist, 1, pCon); lVal = GetMonitor(pCount, 1, pCon);
NXDputalias(hfil, hdict, "cnmon1", &lVal); NXDputalias(hfil, hdict, "cnmon1", &lVal);
eMode = GetHistCountMode(self->pHist); eMode = GetCounterMode(pCount);
if (eMode == eTimer) { if (eMode == eTimer) {
strcpy(pBueffel, "timer"); strcpy(pBueffel, "timer");
} else { } else {
strcpy(pBueffel, "monitor"); strcpy(pBueffel, "monitor");
} }
NXDputalias(hfil, hdict, "cnmode", pBueffel); NXDputalias(hfil, hdict, "cnmode", pBueffel);
fVal = GetHistPreset(self->pHist); fVal = GetCounterPreset(pCount);
NXDputalias(hfil, hdict, "cnpreset", &fVal); NXDputalias(hfil, hdict, "cnpreset", &fVal);
} else {
SCWrite(pCon,"ERROR: counter not found writing data file", eLogError);
}
/* close everything */ /* close everything */
NXclose(&hfil); NXclose(&hfil);
@ -446,6 +452,7 @@ static void PoldiUpdate(pPolterdi self, SConnection * pCon)
HistInt *lData = NULL; HistInt *lData = NULL;
long lVal; long lVal;
time_t zeit; time_t zeit;
pCounter pCount = NULL;
/* open everything again */ /* open everything again */
status = NXopen(self->pFile, NXACC_RDWR, &hfil); status = NXopen(self->pFile, NXACC_RDWR, &hfil);
@ -513,21 +520,24 @@ static void PoldiUpdate(pPolterdi self, SConnection * pCon)
/* /*
write counting data write counting data
*/ */
fVal = GetHistCountTime(self->pHist, pCon); pCount = (pCounter)FindCommandData(pServ->pSics,"counter","SingleCounter");
if(pCount){
fVal = GetCountTime(pCount, pCon);
NXDputalias(hfil, hdict, "cntime", &fVal); NXDputalias(hfil, hdict, "cntime", &fVal);
lVal = GetHistMonitor(self->pHist, 1, pCon); lVal = GetMonitor(pCount, 1, pCon);
NXDputalias(hfil, hdict, "cnmon1", &lVal); NXDputalias(hfil, hdict, "cnmon1", &lVal);
lVal = GetHistMonitor(self->pHist, 4, pCon); eMode = GetCounterMode(pCount);
NXDputalias(hfil, hdict, "cnprot", &lVal);
eMode = GetHistCountMode(self->pHist);
if (eMode == eTimer) { if (eMode == eTimer) {
strcpy(pBueffel, "timer"); strcpy(pBueffel, "timer");
} else { } else {
strcpy(pBueffel, "monitor"); strcpy(pBueffel, "monitor");
} }
NXDputalias(hfil, hdict, "cnmode", pBueffel); NXDputalias(hfil, hdict, "cnmode", pBueffel);
fVal = GetHistPreset(self->pHist); fVal = GetCounterPreset(pCount);
NXDputalias(hfil, hdict, "cnpreset", &fVal); NXDputalias(hfil, hdict, "cnpreset", &fVal);
} else {
SCWrite(pCon,"ERROR: counter not found writing data file", eLogError);
}
/* close everything */ /* close everything */

3
psi.c
View File

@ -83,6 +83,8 @@ extern void AddHttpProtocoll();
extern void AddPMACProtocoll(); extern void AddPMACProtocoll();
/* from pfeifferprot.c */ /* from pfeifferprot.c */
extern void AddPfeifferProtocoll(); extern void AddPfeifferProtocoll();
/* from termprot.c */
extern void AddTermProtocoll();
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
void SiteInit(void) void SiteInit(void)
@ -111,6 +113,7 @@ void SiteInit(void)
AddHttpProtocoll(); AddHttpProtocoll();
AddPMACProtocoll(); AddPMACProtocoll();
AddPfeifferProtocoll(); AddPfeifferProtocoll();
AddTermProtocoll();
} }

View File

@ -72,6 +72,26 @@ static double sansround(double d)
} }
} }
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
typedef struct {
int idx;
double frac;
}MediSort;
/*---------------------------------------------------------------------------*/
static int MediCompare(const void *v1, const void *v2)
{
MediSort *m1, *m2;
m1 = (MediSort *)v1;
m2 = (MediSort *)v2;
if(m1->frac > m2->frac){
return -1;
} else if (m1->frac == m2->frac ){
return 0;
} else {
return 1;
}
}
/*---------------------------------------------------------------------------*/
int SansliRebin(SConnection * pCon, SicsInterp * pSics, void *pData, int SansliRebin(SConnection * pCon, SicsInterp * pSics, void *pData,
int argc, char *argv[]) int argc, char *argv[])
{ {
@ -80,8 +100,10 @@ int SansliRebin(SConnection * pCon, SicsInterp * pSics, void *pData,
int iDim[2], ix, iy, pos, ival, xDetDim[2], yDetDim[2], nDetX, nDetY, int iDim[2], ix, iy, pos, ival, xDetDim[2], yDetDim[2], nDetX, nDetY,
posIdx; posIdx;
long totalCounts = 0; long totalCounts = 0;
double x, y, val, *xPos = NULL, *yPos = NULL, corrSum = .0, doubleCounts; double x, y, val, *xPos = NULL, *yPos = NULL, corrSum = .0, doubleCounts, sumFrac;
double low, frac;
float detectorDistance; float detectorDistance;
MediSort *sortData;
if (argc < 2) { if (argc < 2) {
SCWrite(pCon, "ERROR: Not enough arguments", eError); SCWrite(pCon, "ERROR: Not enough arguments", eError);
@ -111,7 +133,8 @@ int SansliRebin(SConnection * pCon, SicsInterp * pSics, void *pData,
weights = createNXDataset(2, NX_FLOAT64, iDim); weights = createNXDataset(2, NX_FLOAT64, iDim);
xPos = malloc(nDetX * nDetY * sizeof(double)); xPos = malloc(nDetX * nDetY * sizeof(double));
yPos = malloc(nDetX * nDetY * sizeof(double)); yPos = malloc(nDetX * nDetY * sizeof(double));
if (dataset == NULL || weights == NULL || xPos == NULL || yPos == NULL) { sortData = malloc(iDim[0]*iDim[1]*sizeof(MediSort));
if (dataset == NULL || weights == NULL || xPos == NULL || yPos == NULL || sortData == NULL) {
SCWrite(pCon, "ERROR: out of memory allocating temporary data", SCWrite(pCon, "ERROR: out of memory allocating temporary data",
eError); eError);
return 0; return 0;
@ -156,18 +179,43 @@ int SansliRebin(SConnection * pCon, SicsInterp * pSics, void *pData,
corrSum += dataset->u.dPtr[ix]; corrSum += dataset->u.dPtr[ix];
} }
doubleCounts = (double) totalCounts; doubleCounts = (double) totalCounts;
/*
* distribute counts
*/
sumFrac = .0;
for (ix = 0; ix < 128 * 128; ix++, pos++) { for (ix = 0; ix < 128 * 128; ix++, pos++) {
if (corrSum > .01) { if (corrSum > .01) {
val = sansround(dataset->u.dPtr[ix] * doubleCounts / corrSum); val = dataset->u.dPtr[ix] * doubleCounts / corrSum;
low = floor(val);
frac = val - low;
sumFrac += frac;
val = low;
sortData[ix].idx = pos;
sortData[ix].frac = frac;
} else { } else {
val = .0; val = .0;
} }
setSICSDataInt(target, pos, (int) val); setSICSDataInt(target, pos, (int) val);
} }
/*
* apply median correction
*/
qsort(sortData, iDim[0]*iDim[1], sizeof(MediSort), MediCompare);
ix = 0;
while(sumFrac > .0){
pos = sortData[ix].idx;
getSICSDataInt(target,pos,&ival);
setSICSDataInt(target,pos,ival+1);
ix++;
sumFrac -= 1.;
}
dropNXDataset(dataset); dropNXDataset(dataset);
dropNXDataset(weights); dropNXDataset(weights);
free(xPos); free(xPos);
free(yPos); free(yPos);
free(sortData);
SCSendOK(pCon); SCSendOK(pCon);
return 1; return 1;
} }

View File

@ -16,14 +16,32 @@
#include "motor.h" #include "motor.h"
#include "velo.h" #include "velo.h"
#include "sanswave.h" #include "sanswave.h"
#include "sicshipadaba.h"
#define NOTILT 801 #define NOTILT 801
static int SWGetTilt(void *data, float *fTilt)
{
pDummy pDum = (pDummy)data;
pHdb node = NULL;
if(strcmp(pDum->pDescriptor->name,"VelocitySelector") == 0) {
return VSGetTilt((pVelSel)data, fTilt);
} else if(strcmp(pDum->pDescriptor->name,"NVS") == 0){
node = GetHipadabaNode(pDum->pDescriptor->parNode,"tilt");
assert(node != NULL);
*fTilt = (float)node->value.v.doubleValue;
return 1;
} else {
assert(0);
}
return 0;
}
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
typedef struct __SANSwave { typedef struct __SANSwave {
pObjectDescriptor pDes; pObjectDescriptor pDes;
pIDrivable pDrivInt; pIDrivable pDrivInt;
pVelSel pSelector; void *pSelector;
} SANSWave; } SANSWave;
/*-----------------------------------------------------------------------*/ /*-----------------------------------------------------------------------*/
@ -89,7 +107,7 @@ static int SWLimits(void *pData, float fVal, char *error, int iErrLen)
assert(pDriv); assert(pDriv);
/* get tilt */ /* get tilt */
iRet = VSGetTilt(self->pSelector, &fTilt); iRet = SWGetTilt(self->pSelector, &fTilt);
if (!iRet) { if (!iRet) {
strncpy(error, "Failed to obtain tilt angle", iErrLen); strncpy(error, "Failed to obtain tilt angle", iErrLen);
return 0; return 0;
@ -119,7 +137,7 @@ static long SWSet(void *pData, SConnection * pCon, float fVal)
/* get tilt */ /* get tilt */
fTilt = -910; fTilt = -910;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
iRet = VSGetTilt(self->pSelector, &fTilt); iRet = SWGetTilt(self->pSelector, &fTilt);
if (iRet) { if (iRet) {
break; break;
} else { } else {
@ -169,7 +187,7 @@ static float SWGetValue(void *pData, SConnection * pCon)
/* get tilt */ /* get tilt */
fTilt = -910; fTilt = -910;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
iRet = VSGetTilt(self->pSelector, &fTilt); iRet = SWGetTilt(self->pSelector, &fTilt);
if (iRet) { if (iRet) {
break; break;
} else { } else {
@ -182,8 +200,8 @@ static float SWGetValue(void *pData, SConnection * pCon)
} }
/* get rotation speed */ /* get rotation speed */
iRet = VSGetRotation(self->pSelector, &fRot); fRot = pDriv->GetValue(self->pSelector, pCon);
if (!iRet) { if (fRot < -9999.) {
SCWrite(pCon, "ERROR: cannot reading rotation speed", eError); SCWrite(pCon, "ERROR: cannot reading rotation speed", eError);
return -99999.99; return -99999.99;
} }
@ -262,7 +280,7 @@ int MakeSANSWave(SConnection * pCon, SicsInterp * pSics, void *pData,
KillSANSWave(pNew); KillSANSWave(pNew);
return 0; return 0;
} }
pNew->pSelector = (pVelSel) pCom->pData; pNew->pSelector = pCom->pData;
if (!pNew->pSelector) { if (!pNew->pSelector) {
sprintf(pBueffel, "ERROR: velocity selector %s is invalid", argv[2]); sprintf(pBueffel, "ERROR: velocity selector %s is invalid", argv[2]);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
@ -270,7 +288,8 @@ int MakeSANSWave(SConnection * pCon, SicsInterp * pSics, void *pData,
return 0; return 0;
} }
pDum = (pDummy) pNew->pSelector; pDum = (pDummy) pNew->pSelector;
if (strcmp(pDum->pDescriptor->name, "VelocitySelector") != 0) { if (strcmp(pDum->pDescriptor->name, "VelocitySelector") != 0
&& strcmp(pDum->pDescriptor->name,"NVS") == 0) {
sprintf(pBueffel, "ERROR: velocity selector %s is invalid", argv[2]); sprintf(pBueffel, "ERROR: velocity selector %s is invalid", argv[2]);
SCWrite(pCon, pBueffel, eError); SCWrite(pCon, pBueffel, eError);
KillSANSWave(pNew); KillSANSWave(pNew);
@ -322,7 +341,7 @@ int SANSWaveAction(SConnection * pCon, SicsInterp * pSics, void *pData,
if (argc > 2) { if (argc > 2) {
strtolower(argv[1]); strtolower(argv[1]);
/* whatever we are asked to do, we need the current tilt angle */ /* whatever we are asked to do, we need the current tilt angle */
iRet = VSGetTilt(self->pSelector, &fTilt); iRet = SWGetTilt(self->pSelector, &fTilt);
if (!iRet) { if (!iRet) {
SCWrite(pCon, "ERROR: failed to read tilt angle", eError); SCWrite(pCon, "ERROR: failed to read tilt angle", eError);
return 0; return 0;

View File

@ -7,6 +7,11 @@
* copyright: see file COPYRIGHT * copyright: see file COPYRIGHT
* *
* Mark Koennecke, June 2008 * Mark Koennecke, June 2008
*
* Expanded to handle post:url:data style and node:path:data syntax
* in preparation for a full second generation HM object.
*
* Mark Koennecke, May 2009
*/ */
#include <stdio.h> #include <stdio.h>
#include <ascon.h> #include <ascon.h>
@ -15,12 +20,14 @@
#include <sicsdata.h> #include <sicsdata.h>
#include <HistMem.h> #include <HistMem.h>
#include "uselect.h" #include "uselect.h"
#include "sicshipadaba.h"
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
typedef struct { typedef struct {
ghttp_request *request; ghttp_request *request;
char *userName; char *userName;
char *password; char *password;
pSICSData binData; pSICSData binData;
pHdb node;
} HttpProt, *pHttpProt; } HttpProt, *pHttpProt;
/*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/
static int configRequest(Ascon * a) static int configRequest(Ascon * a)
@ -28,6 +35,11 @@ static int configRequest(Ascon * a)
pHttpProt pHttp = (pHttpProt) a->private; pHttpProt pHttp = (pHttpProt) a->private;
pDynString request; pDynString request;
char *uri = NULL; char *uri = NULL;
char *data, *pPtr, *path;
pHttp->node = NULL;
ghttp_clean(pHttp->request);
ghttp_set_header(pHttp->request, "connection", "keep-alive");
request = CreateDynString(64, 64); request = CreateDynString(64, 64);
if (request == NULL) { if (request == NULL) {
@ -37,12 +49,29 @@ static int configRequest(Ascon * a)
DynStringConcat(request, "http://"); DynStringConcat(request, "http://");
DynStringConcat(request, a->hostport); DynStringConcat(request, a->hostport);
DynStringConcatChar(request, '/'); DynStringConcatChar(request, '/');
data = GetCharArray(a->wrBuffer);
if(strstr(data,"node:") == data){
path = strchr(data,':')+1;
uri = strchr(path,':');
*uri = '\0';
uri++;
pHttp->node = FindHdbNode(NULL,path,pServ->dummyCon);
DynStringConcat(request,uri);
ghttp_set_type(pHttp->request, ghttp_type_get);
} else if(strstr(data,"post:") == data){
uri = strchr(data,':') + 1;
pPtr = strchr(uri,':');
*pPtr = '\0';
ghttp_set_type(pHttp->request, ghttp_type_post);
DynStringConcat(request,uri);
pPtr++;
ghttp_set_body(pHttp->request,pPtr, strlen(pPtr));
} else {
ghttp_set_type(pHttp->request, ghttp_type_get);
DynStringConcat(request, GetCharArray(a->wrBuffer)); DynStringConcat(request, GetCharArray(a->wrBuffer));
}
uri = GetCharArray(request); uri = GetCharArray(request);
ghttp_clean(pHttp->request);
ghttp_set_type(pHttp->request, ghttp_type_get);
ghttp_set_header(pHttp->request, "connection", "keep-alive");
if (ghttp_set_uri(pHttp->request, uri) < 0) { if (ghttp_set_uri(pHttp->request, uri) < 0) {
AsconError(a, "Bad URL", 0); AsconError(a, "Bad URL", 0);
return 0; return 0;
@ -82,14 +111,31 @@ static void handleReply(Ascon * a)
} }
} else { } else {
hmData = (HistInt *) pPtr; hmData = (HistInt *) pPtr;
clearSICSData(pHttp->binData);
len = len / sizeof(HistInt); len = len / sizeof(HistInt);
if(pHttp->node == NULL){
clearSICSData(pHttp->binData);
dataPtr = getSICSDataPointer(pHttp->binData, 0, len); dataPtr = getSICSDataPointer(pHttp->binData, 0, len);
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
dataPtr[i] = htonl(hmData[i]); dataPtr[i] = htonl(hmData[i]);
} }
assignSICSType(pHttp->binData, 0, len, INTTYPE); assignSICSType(pHttp->binData, 0, len, INTTYPE);
DynStringCopy(a->rdBuffer, "SICSDATA"); DynStringCopy(a->rdBuffer, "SICSDATA");
} else {
if(pHttp->node->value.arrayLength != len){
if(pHttp->node->value.v.intArray != NULL){
free(pHttp->node->value.v.intArray);
}
pHttp->node->value.v.intArray = malloc(len*sizeof(int));
if(pHttp->node->value.v.intArray == NULL){
AsconError(a,"Out of memory ",0);
return;
}
pHttp->node->value.arrayLength = len;
}
for(i = 0; i < len; i++){
pHttp->node->value.v.intArray[i] = htonl(hmData[i]);
}
}
} }
} }
} }
@ -159,12 +205,14 @@ static int HttpHandler(Ascon * a)
break; break;
case AsconReading: case AsconReading:
socke = ghttp_get_socket(pHttp->request); socke = ghttp_get_socket(pHttp->request);
/*
FD_ZERO(&rmask); FD_ZERO(&rmask);
FD_SET(socke, &rmask); FD_SET(socke, &rmask);
selStat = select(socke + 1, &rmask, NULL, NULL, &tmo); selStat = uselect(socke + 1, &rmask, NULL, NULL, &tmo);
if (selStat == 0) { if (selStat == 0) {
return 1; return 1;
} }
*/
status = ghttp_process(pHttp->request); status = ghttp_process(pHttp->request);
switch (status) { switch (status) {
case ghttp_not_done: case ghttp_not_done:

View File

@ -68,12 +68,12 @@ static int communicateSLS(pSLSDriv self, char *command,
if (strstr(reply, "ERROR") != NULL) { if (strstr(reply, "ERROR") != NULL) {
pPtr = reply; pPtr = reply;
/* jump over error */ /* jump over error */
pPtr = stptok(pPtr, "text", 80, ":"); pPtr = stptok(pPtr, text, 80, ":");
/* read error number */ /* read error number */
pPtr = stptok(pPtr, "text", 80, ":"); pPtr = stptok(pPtr, text, 80, ":");
self->iError = atoi(trim(text)); self->iError = atoi(trim(text));
/* read error description */ /* read error description */
pPtr = stptok(pPtr, "text", 80, ":"); pPtr = stptok(pPtr, text, 80, ":");
strncpy(self->errorText, text, 80); strncpy(self->errorText, text, 80);
return DEVERR; return DEVERR;
} }

View File

@ -908,8 +908,13 @@ int TableDriveAction(SConnection * pCon, SicsInterp * pSics, void *pData,
} }
return status; return status;
} else if (strcmp(argv[1], "show") == 0) { } else if (strcmp(argv[1], "show") == 0) {
SCStartBuffering(pCon);
showPositions(self, pCon, pBueffel, 1023); showPositions(self, pCon, pBueffel, 1023);
SCWrite(pCon, pBueffel, eValue); SCWrite(pCon, pBueffel, eValue);
print = SCEndBuffering(pCon);
if(print != NULL){
SCWrite(pCon,GetCharArray(print), eValue);
}
return 1; return 1;
} else if (strcmp(argv[1], "info") == 0) { } else if (strcmp(argv[1], "info") == 0) {
SCStartBuffering(pCon); SCStartBuffering(pCon);

View File

@ -1414,7 +1414,7 @@ int TASScan(SConnection * pCon, SicsInterp * pSics, void *pData,
snprintf(pLine, 1023, "%8s %3d Points Scan %3d Scanned Variable(s) %s", snprintf(pLine, 1023, "%8s %3d Points Scan %3d Scanned Variable(s) %s",
pTAS->tasPar[INST]->text, pTAS->tasPar[INST]->text,
pTAS->pScan->iNP, pTAS->pScan->iScanVar, pWork); pTAS->pScan->iNP, pTAS->pScan->iScanVar, pWork);
SCWrite(pCon, pLine, eWarning); SCWrite(pCon, pLine, eLog);
if (GetCounterMode(pTAS->pScan->pCounterData) == eTimer) { if (GetCounterMode(pTAS->pScan->pCounterData) == eTimer) {
sprintf(pLine, " %8f Seconds per point", sprintf(pLine, " %8f Seconds per point",
GetCounterPreset(pTAS->pScan->pCounterData)); GetCounterPreset(pTAS->pScan->pCounterData));
@ -1423,7 +1423,7 @@ int TASScan(SConnection * pCon, SicsInterp * pSics, void *pData,
GetCounterPreset(pTAS->pScan->pCounterData)); GetCounterPreset(pTAS->pScan->pCounterData));
} }
SCWrite(pCon, pLine, eWarning); SCWrite(pCon, pLine, eLog);
SCWrite(pCon, " ", eWarning); SCWrite(pCon, " ", eWarning);
SCWrite(pCon, " ", eWarning); SCWrite(pCon, " ", eWarning);
sprintf(pLine, sprintf(pLine,
@ -1440,7 +1440,7 @@ int TASScan(SConnection * pCon, SicsInterp * pSics, void *pData,
(pTAS->pScan->iNP / 2) * pTAS->tasPar[DEN]->fVal, (pTAS->pScan->iNP / 2) * pTAS->tasPar[DEN]->fVal,
pTAS->tasPar[DQH]->fVal, pTAS->tasPar[DQK]->fVal, pTAS->tasPar[DQH]->fVal, pTAS->tasPar[DQK]->fVal,
pTAS->tasPar[DQL]->fVal, pTAS->tasPar[DEN]->fVal); pTAS->tasPar[DQL]->fVal, pTAS->tasPar[DEN]->fVal);
SCWrite(pCon, pLine, eWarning); SCWrite(pCon, pLine, eLog);
if (iTas > 0) { if (iTas > 0) {
if (pTAS->tasPar[FX]->iVal == 1) { if (pTAS->tasPar[FX]->iVal == 1) {
sprintf(pLine, " Constant KI Scan: KI= %7.4f Angs-1; EI= %9.4f", sprintf(pLine, " Constant KI Scan: KI= %7.4f Angs-1; EI= %9.4f",
@ -1449,7 +1449,7 @@ int TASScan(SConnection * pCon, SicsInterp * pSics, void *pData,
sprintf(pLine, " Constant KF Scan: KF= %7.4f Angs-1; EF= %9.4f", sprintf(pLine, " Constant KF Scan: KF= %7.4f Angs-1; EF= %9.4f",
pTAS->tasPar[KF]->fVal, pTAS->tasPar[EF]->fVal); pTAS->tasPar[KF]->fVal, pTAS->tasPar[EF]->fVal);
} }
SCWrite(pCon, pLine, eWarning); SCWrite(pCon, pLine, eLog);
} }
/* /*
@ -1474,7 +1474,7 @@ int TASScan(SConnection * pCon, SicsInterp * pSics, void *pData,
print a message for Severian Gvassilja print a message for Severian Gvassilja
*/ */
sprintf(pLine, "Scan finished, data saved to %s", pTAS->pScan->pFile); sprintf(pLine, "Scan finished, data saved to %s", pTAS->pScan->pFile);
SCWrite(pCon, pLine, eWarning); SCWrite(pCon, pLine, eLog);
return status; return status;
} }