Get trimbits (#462)

* added the possibility to save settings file for m3 and eiger

* added save trimbits to gui

* update release notes

* python wip

* moved location of trimbits save option in gui

* python works

* updating getModule with all its parameters in the server side

* updating binaries
This commit is contained in:
Dhanya Thattil
2022-05-24 11:08:08 +02:00
committed by GitHub
parent d61741c28b
commit 365ac835eb
27 changed files with 528 additions and 244 deletions

View File

@ -57,7 +57,6 @@ int normal = 0;
int eiger_highvoltage = 0;
int eiger_theo_highvoltage = 0;
int eiger_iodelay = 0;
int eiger_photonenergy = 0;
int eiger_dynamicrange = 0;
int eiger_parallelmode = 0;
int eiger_overflow32 = 0;
@ -682,17 +681,17 @@ void allocateDetectorStructureMemory() {
("modules from 0x%x to 0x%x\n", detectorModules, detectorModules));
LOG(logDEBUG1, ("chans from 0x%x to 0x%x\n", detectorChans, detectorChans));
LOG(logDEBUG1, ("dacs from 0x%x to 0x%x\n", detectorDacs, detectorDacs));
(detectorModules)->dacs = detectorDacs;
(detectorModules)->chanregs = detectorChans;
(detectorModules)->ndac = NDAC;
(detectorModules)->nchip = NCHIP;
(detectorModules)->nchan = NCHIP * NCHAN;
(detectorModules)->reg = 0;
(detectorModules)->iodelay = 0;
(detectorModules)->tau = 0;
(detectorModules)->eV[0] = 0;
(detectorModules)->eV[1] = 0;
(detectorModules)->eV[2] = 0;
detectorModules->dacs = detectorDacs;
detectorModules->chanregs = detectorChans;
detectorModules->ndac = NDAC;
detectorModules->nchip = NCHIP;
detectorModules->nchan = NCHIP * NCHAN;
detectorModules->reg = 0;
detectorModules->iodelay = 0;
detectorModules->tau = 0;
detectorModules->eV[0] = -1;
detectorModules->eV[1] = -1;
detectorModules->eV[2] = -1;
thisSettings = UNINITIALIZED;
// if trimval requested, should return -1 to acknowledge unknown
@ -732,9 +731,8 @@ void setupDetector() {
getSubExpTime(DEFAULT_SUBFRAME_DEADTIME);
setPeriod(DEFAULT_PERIOD);
setNumTriggers(DEFAULT_NUM_CYCLES);
eiger_dynamicrange = DEFAULT_DYNAMIC_RANGE;
setDynamicRange(DEFAULT_DYNAMIC_RANGE);
eiger_photonenergy = DEFAULT_PHOTON_ENERGY;
detectorModules->eV[0] = DEFAULT_PHOTON_ENERGY;
setParallelMode(DEFAULT_PARALLEL_MODE);
setOverFlowMode(DEFAULT_READOUT_OVERFLOW32_MODE);
setReadoutSpeed(DEFAULT_CLK_SPEED);
@ -1127,25 +1125,43 @@ int64_t getMeasuredSubPeriod() {
/* parameters - channel, module, settings */
void getModule(sls_detector_module* myMod) {
// serial number
myMod->serialnumber = detectorModules->serialnumber;
// reg (settings)
myMod->reg = detectorModules->reg;
// iodelay
myMod->iodelay = setIODelay(-1);
// tau
myMod->tau = (int) getCurrentTau();
// eV
myMod->eV[0] = detectorModules->eV[0];
// dacs
for (int idac = 0; idac < (detectorModules->ndac); idac++) {
*((myMod->dacs) + idac) = *((detectorModules->dacs) + idac);
}
// trimbits
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((myMod->chanregs) + ichan) = *((detectorModules->chanregs) + ichan);
}
}
int setModule(sls_detector_module myMod, char *mess) {
LOG(logINFO, ("Setting module with settings %d\n", myMod.reg));
if (((myMod.nchan) > (detectorModules->nchan)) || ((myMod.ndac) > (detectorModules->ndac))) {
strcpy(mess, "Could not set module as the number of channels or dacs do not match to the one in the detector server\n");
LOG(logERROR, (mess));
return FAIL;
}
// serial number (pointless)
detectorModules->serialnumber = myMod.serialnumber;
// settings
setSettings((enum detectorSettings)myMod.reg);
// copy module locally (module number, serial number
// dacs (pointless), trimbit values(if needed)
if (detectorModules) {
if (copyModule(detectorModules, &myMod) == FAIL) {
sprintf(mess, "Could not copy module\n");
LOG(logERROR, (mess));
setSettings(UNDEFINED);
LOG(logERROR, ("Settings has been changed to undefined\n"));
return FAIL;
}
}
// iodelay
if (setIODelay(myMod.iodelay) != myMod.iodelay) {
sprintf(mess, "Could not set module. Could not set iodelay %d\n",
@ -1178,60 +1194,15 @@ int setModule(sls_detector_module myMod, char *mess) {
}
}
#ifndef VIRTUAL
// trimbits
#ifndef VIRTUAL
if (myMod.nchan == 0) {
LOG(logINFO, ("Setting module without trimbits\n"));
} else {
LOG(logINFO, ("Setting module with trimbits\n"));
// includ gap pixels
unsigned int tt[263680];
int ip = 0, ich = 0;
for (int iy = 0; iy < 256; ++iy) {
for (int ichip = 0; ichip < 4; ++ichip) {
for (int ix = 0; ix < 256; ++ix) {
tt[ip++] = myMod.chanregs[ich++];
}
if (ichip < 3) {
tt[ip++] = 0;
tt[ip++] = 0;
}
}
}
// set trimbits
sharedMemory_lockLocalLink();
// if quad, set M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(1)) {
sharedMemory_unlockLocalLink();
if (setTrimbits(myMod.chanregs, mess) == FAIL) {
return FAIL;
}
if (!Feb_Control_SetTrimbits(tt, top)) {
sprintf(mess, "Could not set module. Could not set trimbits\n");
LOG(logERROR, (mess));
setSettings(UNDEFINED);
LOG(logERROR, ("Settings has been changed to undefined (random "
"trim file)\n"));
// if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
return FAIL;
}
// if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
}
#endif
@ -1284,6 +1255,7 @@ enum detectorSettings setSettings(enum detectorSettings sett) {
return thisSettings;
}
thisSettings = sett;
detectorModules->reg = sett;
LOG(logINFO, ("Settings: %d\n", thisSettings));
return thisSettings;
}
@ -1294,13 +1266,14 @@ enum detectorSettings getSettings() { return thisSettings; }
int getThresholdEnergy() {
LOG(logDEBUG1, ("Getting Threshold energy\n"));
return eiger_photonenergy;
return detectorModules->eV[0];
}
int setThresholdEnergy(int ev) {
LOG(logINFO, ("Setting threshold energy:%d\n", ev));
if (ev >= 0)
eiger_photonenergy = ev;
if (ev >= 0) {
detectorModules->eV[0] = ev;
}
return getThresholdEnergy();
}
@ -1910,6 +1883,7 @@ int setIODelay(int val) {
#else
eiger_iodelay = val;
#endif
detectorModules->iodelay = val;
}
return eiger_iodelay;
}
@ -2153,7 +2127,6 @@ void setDefaultSettingsTau_in_nsec(int t) {
int64_t getCurrentTau() {
if (!getRateCorrectionEnable()) {
eiger_tau_ns = 0;
return 0;
} else {
#ifndef VIRTUAL
sharedMemory_lockLocalLink();
@ -2162,8 +2135,9 @@ int64_t getCurrentTau() {
#else
eiger_tau_ns = eiger_virtual_ratetable_tau_in_ns;
#endif
return eiger_tau_ns;
}
detectorModules->tau = eiger_tau_ns;
return eiger_tau_ns;
}
void setExternalGating(int enable[]) {
@ -2184,6 +2158,68 @@ void setExternalGating(int enable[]) {
enable[1] = eiger_extgatingpolarity;
}
int setTrimbits(int* chanregs, char* mess) {
LOG(logINFO, ("Setting module with trimbits\n"));
#ifndef VIRTUAL
// include gap pixels
unsigned int tt[263680];
int ip = 0, ich = 0;
for (int iy = 0; iy < 256; ++iy) {
for (int ichip = 0; ichip < 4; ++ichip) {
for (int ix = 0; ix < 256; ++ix) {
tt[ip++] = chanregs[ich++];
}
if (ichip < 3) {
tt[ip++] = 0;
tt[ip++] = 0;
}
}
}
// set trimbits
sharedMemory_lockLocalLink();
// if quad, set M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(1)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
if (!Feb_Control_SetTrimbits(tt, top)) {
sprintf(mess, "Could not set module. Could not set trimbits\n");
LOG(logERROR, (mess));
setSettings(UNDEFINED);
LOG(logERROR, ("Settings has been changed to undefined (random "
"trim file)\n"));
// if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
return FAIL;
}
// if quad, reset M8 and PROGRAM manually
if (!Feb_Control_SetChipSignalsToTrimQuad(0)) {
sharedMemory_unlockLocalLink();
return FAIL;
}
sharedMemory_unlockLocalLink();
// copying trimbits locally (if tirmbit value > -1)
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
if (*(chanregs + ichan) >= 0)
*((detectorModules->chanregs) + ichan) = *(chanregs + ichan);
}
#endif
return OK;
}
int setAllTrimbits(int val) {
LOG(logINFO, ("Setting all trimbits to %d\n", val));
#ifndef VIRTUAL
@ -2195,6 +2231,8 @@ int setAllTrimbits(int val) {
}
sharedMemory_unlockLocalLink();
#endif
// copying trimbits locally
if (detectorModules) {
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((detectorModules->chanregs) + ichan) = val;
@ -2906,53 +2944,6 @@ void readFrame(int *ret, char *mess) {
/* common */
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
LOG(logDEBUG1, ("Copying module\n"));
if (srcMod->serialnumber >= 0) {
destMod->serialnumber = srcMod->serialnumber;
}
// no trimbit feature
if (destMod->nchan && ((srcMod->nchan) > (destMod->nchan))) {
LOG(logINFO, ("Number of channels of source is larger than number of "
"channels of destination\n"));
return FAIL;
}
if ((srcMod->ndac) > (destMod->ndac)) {
LOG(logINFO, ("Number of dacs of source is larger than number of dacs "
"of destination\n"));
return FAIL;
}
LOG(logDEBUG1, ("DACs: src %d, dest %d\n", srcMod->ndac, destMod->ndac));
LOG(logDEBUG1, ("Chans: src %d, dest %d\n", srcMod->nchan, destMod->nchan));
if (srcMod->reg >= 0)
destMod->reg = srcMod->reg;
if (srcMod->iodelay >= 0)
destMod->iodelay = srcMod->iodelay;
if (srcMod->tau >= 0)
destMod->tau = srcMod->tau;
if (srcMod->eV[0] >= 0)
destMod->eV[0] = srcMod->eV[0];
LOG(logDEBUG1, ("Copying register %x (%x)\n", destMod->reg, srcMod->reg));
if (destMod->nchan != 0 && srcMod->nchan != 0) {
for (int ichan = 0; ichan < (srcMod->nchan); ichan++) {
if (*((srcMod->chanregs) + ichan) >= 0)
*((destMod->chanregs) + ichan) = *((srcMod->chanregs) + ichan);
}
} else
LOG(logINFO, ("Not Copying trimbits\n"));
for (int idac = 0; idac < (srcMod->ndac); idac++) {
if (*((srcMod->dacs) + idac) >= 0) {
*((destMod->dacs) + idac) = *((srcMod->dacs) + idac);
}
}
return OK;
}
int calculateDataBytes() {
if (send_to_ten_gig)
return eiger_dynamicrange * ONE_GIGA_CONSTANT * TEN_GIGA_BUFFER_SIZE;

View File

@ -421,7 +421,7 @@ void allocateDetectorStructureMemory() {
detectorDacs[idac] = 0;
}
// trimbits start at 0 //TODO: restart server will not have 0 always
// trimbits start at 0
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((detectorModules->chanregs) + ichan) = 0;
}
@ -1255,21 +1255,52 @@ int setDACS(int *dacs) {
return OK;
}
void getModule(sls_detector_module* myMod) {
// serial number
myMod->serialnumber = detectorModules->serialnumber;
// csr reg
myMod->reg = detectorModules->reg;
// eV
myMod->eV[0] = detectorModules->eV[0];
myMod->eV[1] = detectorModules->eV[1];
myMod->eV[2] = detectorModules->eV[2];
// dacs
for (int idac = 0; idac < (detectorModules->ndac); idac++) {
*((myMod->dacs) + idac) = *((detectorModules->dacs) + idac);
}
// trimbits
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
*((myMod->chanregs) + ichan) = *((detectorModules->chanregs) + ichan);
}
}
int setModule(sls_detector_module myMod, char *mess) {
LOG(logINFO, ("Setting module\n"));
if (((myMod.nchan) > (detectorModules->nchan)) || ((myMod.ndac) > (detectorModules->ndac))) {
strcpy(mess, "Could not set module as the number of channels or dacs do not match to the one in the detector server\n");
LOG(logERROR, (mess));
return FAIL;
}
// serial number (pointless)
detectorModules->serialnumber = myMod.serialnumber;
// csr reg
if (setChipStatusRegister(myMod.reg)) {
sprintf(mess, "Could not CSR from module\n");
LOG(logERROR, (mess));
return FAIL;
}
// dacs
if (setDACS(myMod.dacs)) {
sprintf(mess, "Could not set dacs\n");
LOG(logERROR, (mess));
return FAIL;
}
// threshold energy
for (int i = 0; i < NCOUNTERS; ++i) {
if (myMod.eV[i] >= 0) {
setThresholdEnergy(i, myMod.eV[i]);
@ -1338,6 +1369,12 @@ int setTrimbits(int *trimbits) {
return FAIL;
}
// copying trimbits locally (if tirmbit value > -1)
for (int ichan = 0; ichan < (detectorModules->nchan); ichan++) {
if (*(trimbits + ichan) >= 0)
*((detectorModules->chanregs) + ichan) = *(trimbits + ichan);
}
return (error ? FAIL : OK);
}
@ -2572,56 +2609,6 @@ u_int32_t runBusy() {
/* common */
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod) {
LOG(logDEBUG1, ("Copying module\n"));
if (srcMod->serialnumber >= 0) {
destMod->serialnumber = srcMod->serialnumber;
}
// no trimbit feature
if (destMod->nchan && ((srcMod->nchan) > (destMod->nchan))) {
LOG(logINFO, ("Number of channels of source is larger than number of "
"channels of destination\n"));
return FAIL;
}
if ((srcMod->ndac) > (destMod->ndac)) {
LOG(logINFO, ("Number of dacs of source is larger than number of dacs "
"of destination\n"));
return FAIL;
}
LOG(logDEBUG1, ("DACs: src %d, dest %d\n", srcMod->ndac, destMod->ndac));
LOG(logDEBUG1, ("Chans: src %d, dest %d\n", srcMod->nchan, destMod->nchan));
if (srcMod->reg >= 0)
destMod->reg = srcMod->reg;
/*
if (srcMod->iodelay >= 0)
destMod->iodelay = srcMod->iodelay;
if (srcMod->tau >= 0)
destMod->tau = srcMod->tau;
*/
for (int i = 0; i < NCOUNTERS; ++i) {
if (srcMod->eV[i] >= 0)
destMod->eV[i] = srcMod->eV[i];
}
LOG(logDEBUG1, ("Copying register %x (%x)\n", destMod->reg, srcMod->reg));
if (destMod->nchan != 0 && srcMod->nchan != 0) {
for (int ichan = 0; ichan < (srcMod->nchan); ichan++) {
*((destMod->chanregs) + ichan) = *((srcMod->chanregs) + ichan);
}
} else
LOG(logINFO, ("Not Copying trimbits\n"));
for (int idac = 0; idac < (srcMod->ndac); idac++) {
if (*((srcMod->dacs) + idac) >= 0) {
*((destMod->dacs) + idac) = *((srcMod->dacs) + idac);
}
}
return OK;
}
int calculateDataBytes() {
int numCounters = __builtin_popcount(getCounterMask());
int dr = 0;
@ -2670,5 +2657,6 @@ int setChipStatusRegister(int csr) {
return FAIL;
}
detectorModules->reg = csr;
return iret;
}

View File

@ -26,6 +26,7 @@ int receiveData(int file_des, void *buf, int length, intType itype);
int sendDataOnly(int file_des, void *buf, int length);
int receiveDataOnly(int file_des, void *buf, int length);
int sendModule(int file_des, sls_detector_module *myMod);
int receiveModule(int file_des, sls_detector_module *myMod);
/**

View File

@ -308,9 +308,16 @@ int64_t getMeasurementTime();
#endif
// parameters - module, settings
#if defined(MYTHEN3D) || defined(EIGERD)
void getModule(sls_detector_module* myMod);
#endif
#if (!defined(CHIPTESTBOARDD)) && (!defined(MOENCHD)) && (!defined(GOTTHARD2D))
int setModule(sls_detector_module myMod, char *mess);
#endif
#ifdef EIGERD
int setTrimbits(int* chanregs, char* mess);
#endif
#ifdef MYTHEN3D
int setTrimbits(int *trimbits);
int setAllTrimbits(int val);
@ -662,9 +669,6 @@ u_int32_t runState(enum TLogLevel lev);
#endif
// common
#if defined(EIGERD) || defined(MYTHEN3D)
int copyModule(sls_detector_module *destMod, sls_detector_module *srcMod);
#endif
int calculateDataBytes();
int getTotalNumberOfChannels();
#if defined(MOENCHD) || defined(CHIPTESTBOARDD)

View File

@ -303,3 +303,4 @@ int get_analog_pulsing(int);
int set_analog_pulsing(int);
int get_digital_pulsing(int);
int set_digital_pulsing(int);
int get_module(int);

View File

@ -406,66 +406,139 @@ int receiveDataOnly(int file_des, void *buf, int length) {
return total_received;
}
int sendModule(int file_des, sls_detector_module *myMod) {
enum TLogLevel level = logDEBUG1;
LOG(level, ("Sending Module\n"));
int ts = 0, n = 0;
n = sendData(file_des, &(myMod->serialnumber),
sizeof(myMod->serialnumber), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("serialno sent %d bytes. serialno: %d\n", n,
myMod->serialnumber));
n = sendData(file_des, &(myMod->nchan), sizeof(myMod->nchan), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("nchan sent %d bytes. nchan: %d\n", n, myMod->nchan));
n = sendData(file_des, &(myMod->nchip), sizeof(myMod->nchip), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("nchip sent %d bytes. nchip: %d\n", n, myMod->nchip));
n = sendData(file_des, &(myMod->ndac), sizeof(myMod->ndac), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("ndac sent %d bytes. ndac: %d\n", n, myMod->ndac));
n = sendData(file_des, &(myMod->reg), sizeof(myMod->reg), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("reg sent %d bytes. reg: %d\n", n, myMod->reg));
n = sendData(file_des, &(myMod->iodelay), sizeof(myMod->iodelay), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level,
("iodelay sent %d bytes. iodelay: %d\n", n, myMod->iodelay));
n = sendData(file_des, &(myMod->tau), sizeof(myMod->tau), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("tau sent %d bytes. tau: %d\n", n, myMod->tau));
n = sendData(file_des, myMod->eV, sizeof(myMod->eV), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("eV sent %d bytes. eV: %d\n", n, myMod->eV[0]));
// dacs
n = sendData(file_des, myMod->dacs, sizeof(int) * (myMod->ndac), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("dacs sent %d bytes.\n", n));
// channels
n = sendData(file_des, myMod->chanregs, sizeof(int) * (myMod->nchan),
INT32);
LOG(level, ("chanregs sent %d bytes.\n", n));
if (!n) {
return -1;
}
ts += n;
LOG(level, ("received module of size %d register %x\n", ts, myMod->reg));
return ts;
}
int receiveModule(int file_des, sls_detector_module *myMod) {
enum TLogLevel level = logDEBUG1;
LOG(level, ("Receiving Module\n"));
int ts = 0, n = 0;
int nDacs = myMod->ndac;
#if defined(EIGERD) || defined(MYTHEN3D)
int nChans = myMod->nchan; // can be zero for no trimbits
LOG(level, ("nChans: %d\n", nChans));
#endif
n = receiveData(file_des, &(myMod->serialnumber),
sizeof(myMod->serialnumber), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("serialno received. %d bytes. serialno: %d\n", n,
LOG(level, ("serialno received %d bytes. serialno: %d\n", n,
myMod->serialnumber));
n = receiveData(file_des, &(myMod->nchan), sizeof(myMod->nchan), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("nchan received. %d bytes. nchan: %d\n", n, myMod->nchan));
LOG(level, ("nchan received %d bytes. nchan: %d\n", n, myMod->nchan));
n = receiveData(file_des, &(myMod->nchip), sizeof(myMod->nchip), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("nchip received. %d bytes. nchip: %d\n", n, myMod->nchip));
LOG(level, ("nchip received %d bytes. nchip: %d\n", n, myMod->nchip));
n = receiveData(file_des, &(myMod->ndac), sizeof(myMod->ndac), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("ndac received. %d bytes. ndac: %d\n", n, myMod->ndac));
LOG(level, ("ndac received %d bytes. ndac: %d\n", n, myMod->ndac));
n = receiveData(file_des, &(myMod->reg), sizeof(myMod->reg), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("reg received. %d bytes. reg: %d\n", n, myMod->reg));
LOG(level, ("reg received %d bytes. reg: %d\n", n, myMod->reg));
n = receiveData(file_des, &(myMod->iodelay), sizeof(myMod->iodelay), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level,
("iodelay received. %d bytes. iodelay: %d\n", n, myMod->iodelay));
("iodelay received %d bytes. iodelay: %d\n", n, myMod->iodelay));
n = receiveData(file_des, &(myMod->tau), sizeof(myMod->tau), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("tau received. %d bytes. tau: %d\n", n, myMod->tau));
LOG(level, ("tau received %d bytes. tau: %d\n", n, myMod->tau));
n = receiveData(file_des, myMod->eV, sizeof(myMod->eV), INT32);
if (!n) {
return -1;
}
ts += n;
LOG(level, ("eV received. %d bytes. eV: %d\n", n, myMod->eV[0]));
LOG(level, ("eV received %d bytes. eV: %d\n", n, myMod->eV[0]));
// dacs
if (nDacs != (myMod->ndac)) {
LOG(logERROR, ("received wrong number of dacs. "
@ -478,24 +551,22 @@ int receiveModule(int file_des, sls_detector_module *myMod) {
return -1;
}
ts += n;
LOG(level, ("dacs received. %d bytes.\n", n));
LOG(level, ("dacs received %d bytes.\n", n));
// channels
#if defined(EIGERD) || defined(MYTHEN3D)
if (((myMod->nchan) != 0) && // no trimbits
(nChans != (myMod->nchan))) { // with trimbits
LOG(logERROR, ("received wrong number of channels. "
"Expected %d, got %d\n",
nChans, (myMod->nchan)));
return 0;
return -1;
}
n = receiveData(file_des, myMod->chanregs, sizeof(int) * (myMod->nchan),
INT32);
LOG(level, ("chanregs received. %d bytes.\n", n));
LOG(level, ("chanregs received %d bytes.\n", n));
if (!n && myMod->nchan != 0) {
return -1;
}
ts += n;
#endif
LOG(level, ("received module of size %d register %x\n", ts, myMod->reg));
return ts;
}

View File

@ -468,6 +468,7 @@ void function_table() {
flist[F_SET_ANALOG_PULSING] = &set_analog_pulsing;
flist[F_GET_DIGITAL_PULSING] = &get_digital_pulsing;
flist[F_SET_DIGITAL_PULSING] = &set_digital_pulsing;
flist[F_GET_MODULE] = &get_module;
// check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -1555,6 +1556,71 @@ int read_register(int file_des) {
return Server_SendResult(file_des, INT32, &retval, sizeof(retval));
}
int get_module(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
sls_detector_module module;
int *myDac = NULL;
int *myChan = NULL;
module.dacs = NULL;
module.chanregs = NULL;
#if !defined(MYTHEN3D) && !defined(EIGERD)
functionNotImplemented();
#else
// allocate to receive module structure
// allocate dacs
myDac = malloc(getNumberOfDACs() * sizeof(int));
// error
if (getNumberOfDACs() > 0 && myDac == NULL) {
ret = FAIL;
sprintf(mess, "Could not allocate dacs\n");
LOG(logERROR, (mess));
} else
module.dacs = myDac;
// allocate chans
if (ret == OK) {
myChan = malloc(getTotalNumberOfChannels() * sizeof(int));
if (getTotalNumberOfChannels() > 0 && myChan == NULL) {
ret = FAIL;
sprintf(mess, "Could not allocate chans\n");
LOG(logERROR, (mess));
} else
module.chanregs = myChan;
}
// receive module structure
if (ret == OK) {
module.nchip = getNumberOfChips();
module.nchan = getTotalNumberOfChannels();
module.ndac = getNumberOfDACs();
// ensure nchan is not 0, else trimbits not copied
if (module.nchan == 0) {
strcpy(mess, "Could not get module as the number of channels to copy is 0\n");
LOG(logERROR, (mess));
return FAIL;
}
getModule(&module);
}
#endif
Server_SendResult(file_des, INT32, NULL, 0);
if (ret != FAIL) {
if (sendModule(file_des, &module) < 0) {
ret = FAIL;
}
}
if (myChan != NULL)
free(myChan);
if (myDac != NULL)
free(myDac);
return ret;
}
int set_module(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
@ -1631,8 +1697,10 @@ int set_module(int file_des) {
#endif
LOG(logDEBUG1, ("Settings: %d\n", retval));
}
free(myChan);
free(myDac);
if (myChan != NULL)
free(myChan);
if (myDac != NULL)
free(myDac);
#endif
return Server_SendResult(file_des, INT32, NULL, 0);