From 436910448005fa449a0c131bb391d6a9a0b8c10b Mon Sep 17 00:00:00 2001 From: Mark Koennecke Date: Tue, 6 Dec 2016 09:31:28 +0100 Subject: [PATCH] Added a zebraswap in order to fix the zebra data issue --- make_gen | 2 +- psi.c | 2 +- zebraswap.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 zebraswap.c diff --git a/make_gen b/make_gen index 6f3393a..105b2f6 100644 --- a/make_gen +++ b/make_gen @@ -26,7 +26,7 @@ OBJ=psi.o buffer.o ruli.o sps.o pimotor.o \ pfeifferprot.o termprot.o phytron.o autowin.o eigera2.o \ jvlprot.o \ eigermono.o sputterprot.o zwickroll.o astriumnet.o poldifold.o \ - epicsadapter.o + epicsadapter.o zebraswap.o .SECONDARY.: sanslirebin.c diff --git a/psi.c b/psi.c index f0b84c4..349b69d 100644 --- a/psi.c +++ b/psi.c @@ -125,7 +125,7 @@ static void AddPsiCommands(SicsInterp * pInter) SCMD("MakeEigerMono", InitEigerMono); PCMD("cnvrt", CnvrtAction); SCMD("MakeEpicsAdapter", MakeEpicsAdapter); - + PCMD("zebraswap", ZebraSwap); /* * Tcl 8.5 has implemented the clock command in tcl rather then C. * This includes the same command, backported from Tcl 8.4 diff --git a/zebraswap.c b/zebraswap.c new file mode 100644 index 0000000..65a16ab --- /dev/null +++ b/zebraswap.c @@ -0,0 +1,79 @@ +/* + +This is an ugly hack to swap histogram memory data on ZEBRA. +Ported over from sinqhttp.c. Fixing this properly would mean changes +to the HM code. Which in turn would affect AMOR and BOA too. I also +do not seem to need magic swaps at AMOR or BOA..... + +copyright: see file COPYRIGHT + +Mark Koennecke, December 2016 + + */ + +#include +#include +#include + +/*---------------------------------------------------------------*/ +static void swapTrics(HistInt *data, int xdim, int ydim) +{ + int x,y, length; + HistInt *tmpData = NULL, val; + + length = xdim*ydim; + tmpData = malloc(length*sizeof(HistInt)); + if(tmpData == NULL){ + return; + } + memcpy(tmpData, data, length*sizeof(HistInt)); + for(y = 0; y < ydim; y++){ + for(x = 0; x < xdim; x++){ + val = tmpData[x*ydim + y]; + data[y*xdim+x] = val; + } + } + free(tmpData); +} +/*----------------------------------------------------------------*/ +int ZebraSwap(SConnection * pCon, SicsInterp * pSics, void *pData, + int argc, char *argv[]) +{ + int xdim, ydim, status; + pHdb dataNode = NULL; + hdbValue val; + + if(argc < 4) { + SCWrite(pCon,"ERROR: insufficient number of argument to zebraswap\nUsage: zebraswap hmdatanode xdim ydim", eError); + return 0; + } + + dataNode = FindHdbIntern(argv[1]); + if(dataNode == NULL){ + SCPrintf(pCon,eError,"ERROR: data node %s not found", argv[1]); + return 0; + } + + status = Tcl_GetInt(InterpGetTcl(pSics),argv[2],&xdim); + if(status != TCL_OK){ + SCPrintf(pCon,eError,"ERROR: failed to convert %s to integer", argv[2]); + return 0; + } + + status = Tcl_GetInt(InterpGetTcl(pSics),argv[3],&ydim); + if(status != TCL_OK){ + SCPrintf(pCon,eError,"ERROR: failed to convert %s to integer", argv[3]); + return 0; + } + + val = dataNode->value; + if(val.dataType != HIPINTVARAR || val.arrayLength < xdim*ydim){ + SCWrite(pCon,"ERROR: data type or dimension mismatch between node and parameters", eError); + return 0; + } + + swapTrics((HistInt *)val.v.intArray,xdim,ydim); + + SCSendOK(pCon); + return 1; +}