mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 12:57:13 +02:00
injectchannel WIP
This commit is contained in:
Binary file not shown.
@ -41,6 +41,8 @@ int dacValues[NDAC] = {0};
|
||||
int onChipdacValues[ONCHIP_NDAC][NCHIP] = {0};
|
||||
int defaultDacValues[NDAC] = {0};
|
||||
int defaultOnChipdacValues[ONCHIP_NDAC][NCHIP] = {0};
|
||||
int injectedChannelsOffset = 0;
|
||||
int injectedChannelsIncrement = 0;
|
||||
int detPos[2] = {0, 0};
|
||||
|
||||
int isInitCheckDone() {
|
||||
@ -649,6 +651,7 @@ int setOnChipDAC(enum ONCHIP_DACINDEX ind, int chipIndex, int val) {
|
||||
FILE_LOG(logINFO, ("Setting on chip dac[%d - %s]: 0x%x\n", (int)ind, names[ind], val));
|
||||
|
||||
char buffer[2];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
buffer[1] = ((val & 0xF) << 4) | (((int)ind) & 0xF); // LSB (4 bits) + ADDR (4 bits)
|
||||
buffer[0] = (val >> 4) & 0x3F; // MSB (6 bits)
|
||||
|
||||
@ -1057,6 +1060,43 @@ int getClockDivider(enum CLKINDEX ind) {
|
||||
return (getVCOFrequency(ind) / clkFrequency[ind]);
|
||||
}
|
||||
|
||||
int setInjectChannel(int offset, int increment) {
|
||||
if (offset < 0 || increment < 1) {
|
||||
FILE_LOG(logERROR, ("Cannot inject channel. Invalid offset %d or increment %d\n", offset, increment));
|
||||
return FAIL;
|
||||
}
|
||||
|
||||
FILE_LOG(logINFO, ("Injecting channels [offset:%d, increment:%d]\n", offset, increment));
|
||||
|
||||
// 4 bits of padding + 128 bits + 4 bits for address = 136 bits
|
||||
char buffer[17];
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
int startCh = 4; // 4 due to padding
|
||||
int ich = 0;
|
||||
for (ich = startCh + offset; ich < startCh + NCHAN; ich = ich + increment) {
|
||||
buffer[ich] = 1;
|
||||
}
|
||||
|
||||
for (ich = 0; ich < sizeof(buffer); ++ich) {
|
||||
printf("%d : 0x%02hhx\n", ich, buffer[ich]);
|
||||
}
|
||||
|
||||
//int chipIndex = -1; // for all chips
|
||||
//if (ASIC_Driver_Set(chipIndex, sizeof(buffer), buffer) == FAIL) {
|
||||
// return FAIL;
|
||||
//}
|
||||
|
||||
injectedChannelsOffset = offset;
|
||||
injectedChannelsIncrement = increment;
|
||||
return OK;
|
||||
}
|
||||
|
||||
void getInjectedChannels(int* offset, int* increment) {
|
||||
*offset = injectedChannelsOffset;
|
||||
*increment = injectedChannelsIncrement;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* aquisition */
|
||||
|
||||
|
@ -448,6 +448,8 @@ int getVCOFrequency(enum CLKINDEX ind);
|
||||
int getMaxClockDivider();
|
||||
int setClockDivider(enum CLKINDEX ind, int val);
|
||||
int getClockDivider(enum CLKINDEX ind);
|
||||
int setInjectChannel(int offset, int increment);
|
||||
void getInjectedChannels(int* offset, int* increment);
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -194,4 +194,6 @@ int get_clock_divider(int);
|
||||
int set_pipeline(int);
|
||||
int get_pipeline(int);
|
||||
int set_on_chip_dac(int);
|
||||
int get_on_chip_dac(int);
|
||||
int get_on_chip_dac(int);
|
||||
int set_inject_channel(int);
|
||||
int get_inject_channel(int);
|
@ -296,6 +296,8 @@ const char* getFunctionName(enum detFuncs func) {
|
||||
case F_GET_PIPELINE: return "F_GET_PIPELINE";
|
||||
case F_SET_ON_CHIP_DAC: return "F_SET_ON_CHIP_DAC";
|
||||
case F_GET_ON_CHIP_DAC: return "F_GET_ON_CHIP_DAC";
|
||||
case F_SET_INJECT_CHANNEL: return "F_SET_INJECT_CHANNEL";
|
||||
case F_GET_INJECT_CHANNEL: return "F_GET_INJECT_CHANNEL";
|
||||
|
||||
default: return "Unknown Function";
|
||||
}
|
||||
@ -469,6 +471,8 @@ void function_table() {
|
||||
flist[F_GET_PIPELINE] = &get_pipeline;
|
||||
flist[F_SET_ON_CHIP_DAC] = &set_on_chip_dac;
|
||||
flist[F_GET_ON_CHIP_DAC] = &get_on_chip_dac;
|
||||
flist[F_SET_INJECT_CHANNEL] = &set_inject_channel;
|
||||
flist[F_GET_INJECT_CHANNEL] = &get_inject_channel;
|
||||
|
||||
// check
|
||||
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
|
||||
@ -6145,4 +6149,60 @@ int get_on_chip_dac(int file_des) {
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, UPDATE, &retval, sizeof(retval));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int set_inject_channel(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int args[2] = {-1, -1};
|
||||
|
||||
if (receiveData(file_des, args, sizeof(args), INT32) < 0)
|
||||
return printSocketReadError();
|
||||
FILE_LOG(logINFO, ("Setting inject channel: [%d, %d]\n", args[0], args[1]));
|
||||
|
||||
#ifndef GOTTHARD2D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// only set
|
||||
if (Server_VerifyLock() == OK) {
|
||||
int offset = args[0];
|
||||
int increment = args[1];
|
||||
if (offset < 0 || increment < 1) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not inject channel. Invalid offset %d or increment %d\n", offset, increment);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
} else {
|
||||
ret = setInjectChannel(offset, increment);
|
||||
if (ret == FAIL) {
|
||||
ret = FAIL;
|
||||
sprintf(mess, "Could not inject channel\n", offset, increment);
|
||||
FILE_LOG(logERROR, (mess));
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, UPDATE, NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
int get_inject_channel(int file_des) {
|
||||
ret = OK;
|
||||
memset(mess, 0, sizeof(mess));
|
||||
int retvals[2] = {-1, -1};
|
||||
|
||||
FILE_LOG(logDEBUG1, ("Getting injected channels\n"));
|
||||
|
||||
#ifndef GOTTHARD2D
|
||||
functionNotImplemented();
|
||||
#else
|
||||
// get only
|
||||
int offset = -1, increment = -1;
|
||||
getInjectedChannels(&offset, &increment);
|
||||
FILE_LOG(logDEBUG1, ("Get Injected channels: [offset:%d, increment:%d]\n", offset, increment));
|
||||
retvals[0] = offset;
|
||||
retvals[1] = increment;
|
||||
#endif
|
||||
return Server_SendResult(file_des, INT32, UPDATE, retvals, sizeof(retvals));
|
||||
}
|
||||
|
@ -775,7 +775,9 @@ class CmdProxy {
|
||||
{"extsig", &CmdProxy::extsig},
|
||||
{"imagetest", &CmdProxy::imagetest},
|
||||
|
||||
/* Gotthard2 Specific */
|
||||
/* Gotthard2 Specific */
|
||||
{"inj_ch", &CmdProxy::InjectChannel},
|
||||
|
||||
/* CTB Specific */
|
||||
{"samples", &CmdProxy::Samples},
|
||||
{"asamples", &CmdProxy::asamples},
|
||||
|
@ -873,6 +873,19 @@ class Detector {
|
||||
* Default is 0 */
|
||||
void setImageTestMode(const int value, Positions pos = {});
|
||||
|
||||
/**************************************************
|
||||
* *
|
||||
* Gotthard2 Specific *
|
||||
* *
|
||||
* ************************************************/
|
||||
|
||||
/** [Gotthard2] offset channel, increment channel */
|
||||
Result<std::array<int, 2>> getInjectChannel(Positions pos = {});
|
||||
/** [Gotthard2]
|
||||
* @param offsetChannel starting channel to be injected
|
||||
* @param incrementChannel determines succeeding channels to be injected */
|
||||
void setInjectChannel(int offsetChannel, int incrementChannel, Positions pos = {});
|
||||
|
||||
/**************************************************
|
||||
* *
|
||||
* CTB Specific *
|
||||
|
@ -1102,6 +1102,15 @@ class slsDetector : public virtual slsDetectorDefs {
|
||||
* Default is 0 */
|
||||
void setImageTestMode(const int value);
|
||||
|
||||
|
||||
/** [Gotthard2] */
|
||||
std::array<int, 2> getInjectChannel();
|
||||
|
||||
/** [Gotthard2]
|
||||
* @param offsetChannel starting channel to be injected
|
||||
* @param incrementChannel determines succeeding channels to be injected */
|
||||
void setInjectChannel(int offsetChannel, int incrementChannel);
|
||||
|
||||
/**
|
||||
* Set/get counter bit in detector (Gotthard)
|
||||
* @param i is -1 to get, 0 to reset and any other value to set the counter
|
||||
|
@ -1017,7 +1017,33 @@ std::string CmdProxy::ClearROI(int action) {
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
/* Gotthard2 Specific */
|
||||
|
||||
std::string CmdProxy::InjectChannel(int action) {
|
||||
std::ostringstream os;
|
||||
os << cmd << ' ';
|
||||
if (action == defs::HELP_ACTION) {
|
||||
os << "[offset] [increment]\n\t[Gotthard2] Inject channels with current source for calibration. Offset is starting channel that is injected, increment determines succeeding channels to be injected." << '\n';
|
||||
} else if (action == defs::GET_ACTION) {
|
||||
if (args.size() != 0) {
|
||||
WrongNumberOfParameters(0);
|
||||
}
|
||||
auto t = det->getInjectChannel({det_id});
|
||||
os << OutString(t) << '\n';
|
||||
} else if (action == defs::PUT_ACTION) {
|
||||
if (args.size() != 2) {
|
||||
WrongNumberOfParameters(2);
|
||||
}
|
||||
det->setInjectChannel(std::stoi(args[0]), std::stoi(args[1]),{det_id});
|
||||
os << sls::ToString(args) << '\n';
|
||||
} else {
|
||||
throw sls::RuntimeError("Unknown action");
|
||||
}
|
||||
return os.str();
|
||||
}
|
||||
|
||||
|
||||
/* CTB Specific */
|
||||
|
||||
std::string CmdProxy::Samples(int action) {
|
||||
|
@ -1086,6 +1086,16 @@ void Detector::setImageTestMode(int value, Positions pos) {
|
||||
pimpl->Parallel(&slsDetector::setImageTestMode, pos, value);
|
||||
}
|
||||
|
||||
// Gotthard2 Specific
|
||||
|
||||
Result<std::array<int, 2>> Detector::getInjectChannel(Positions pos) {
|
||||
return pimpl->Parallel(&slsDetector::getInjectChannel, pos);
|
||||
}
|
||||
|
||||
void Detector::setInjectChannel(int offsetChannel, int incrementChannel, Positions pos) {
|
||||
pimpl->Parallel(&slsDetector::setInjectChannel, pos, offsetChannel, incrementChannel);
|
||||
}
|
||||
|
||||
// CTB Specific
|
||||
|
||||
Result<int> Detector::getNumberOfAnalogSamples(Positions pos) const {
|
||||
|
@ -2345,6 +2345,19 @@ void slsDetector::setImageTestMode(const int value) {
|
||||
sendToDetector(F_SET_IMAGE_TEST_MODE, value, nullptr);
|
||||
}
|
||||
|
||||
std::array<int, 2> slsDetector::getInjectChannel() {
|
||||
std::array<int, 2> retvals{};
|
||||
sendToDetector(F_GET_INJECT_CHANNEL, nullptr, retvals);
|
||||
FILE_LOG(logDEBUG1) << "Inject Channel: [offset: " << retvals[0] << ", increment: " << retvals[1] << ']';
|
||||
return retvals;
|
||||
}
|
||||
|
||||
void slsDetector::setInjectChannel(int offsetChannel, int incrementChannel) {
|
||||
int args[]{offsetChannel, incrementChannel};
|
||||
FILE_LOG(logDEBUG1) << "Setting inject channels [offset: " << offsetChannel << ", increment: " << incrementChannel << ']';
|
||||
sendToDetector(F_SET_INJECT_CHANNEL, args, nullptr);
|
||||
}
|
||||
|
||||
int slsDetector::setCounterBit(int cb) {
|
||||
int retval = -1;
|
||||
FILE_LOG(logDEBUG1) << "Sending counter bit " << cb;
|
||||
|
@ -177,6 +177,8 @@ enum detFuncs{
|
||||
F_GET_PIPELINE,
|
||||
F_SET_ON_CHIP_DAC,
|
||||
F_GET_ON_CHIP_DAC,
|
||||
F_SET_INJECT_CHANNEL,
|
||||
F_GET_INJECT_CHANNEL,
|
||||
NUM_DET_FUNCTIONS,
|
||||
|
||||
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this (detector server should not compile anyway) */
|
||||
@ -418,6 +420,8 @@ static const char* getFunctionNameFromEnum(enum detFuncs func) {
|
||||
case F_GET_PIPELINE: return "F_GET_PIPELINE";
|
||||
case F_SET_ON_CHIP_DAC: return "F_SET_ON_CHIP_DAC";
|
||||
case F_GET_ON_CHIP_DAC: return "F_GET_ON_CHIP_DAC";
|
||||
case F_SET_INJECT_CHANNEL: return "F_SET_INJECT_CHANNEL";
|
||||
case F_GET_INJECT_CHANNEL: return "F_GET_INJECT_CHANNEL";
|
||||
|
||||
|
||||
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
|
||||
|
@ -9,4 +9,4 @@
|
||||
#define APIJUNGFRAU 0x191111
|
||||
#define APIEIGER 0x191111
|
||||
#define APIMYTHEN3 0x191111
|
||||
#define APIGOTTHARD2 0x191112
|
||||
#define APIGOTTHARD2 0x191113
|
||||
|
Reference in New Issue
Block a user