wip to change to enum for portposition

This commit is contained in:
maliakal_d 2021-07-20 16:05:08 +02:00
parent c6aaf2f8b1
commit ec7ba7c508
16 changed files with 117 additions and 105 deletions

View File

@ -451,19 +451,15 @@ int Beb_GetActivate(int *retval) {
return 1; return 1;
} }
int Beb_SetDataStream(int left, int enable) { int Beb_SetDataStream(enum portPositiion port, int enable) {
if (!Beb_activated) { if (!Beb_activated) {
if (left) { if (port == LEFT) {
Beb_deactivated_left_datastream = enable; Beb_deactivated_left_datastream = enable;
} else { } else {
Beb_deactivated_right_datastream = enable; Beb_deactivated_right_datastream = enable;
} }
return 1; return 1;
} }
if (left < 0) {
LOG(logERROR, ("Invalid left value\n"));
return 0;
}
if (enable < 0) { if (enable < 0) {
LOG(logERROR, ("Invalid enable value\n")); LOG(logERROR, ("Invalid enable value\n"));
return 0; return 0;
@ -475,8 +471,8 @@ int Beb_SetDataStream(int left, int enable) {
return 0; return 0;
} else { } else {
u_int32_t reg = XPAR_GPIO_P15_STREAMING_REG; u_int32_t reg = XPAR_GPIO_P15_STREAMING_REG;
u_int32_t mask = u_int32_t mask = (port == LEFT ? XPAR_GPIO_LFT_STRM_DSBL_MSK
(left ? XPAR_GPIO_LFT_STRM_DSBL_MSK : XPAR_GPIO_RGHT_STRM_DSBL_MSK); : XPAR_GPIO_RGHT_STRM_DSBL_MSK);
u_int32_t value = Beb_Read32(csp0base, reg); u_int32_t value = Beb_Read32(csp0base, reg);
// disabling in firmware // disabling in firmware
@ -488,8 +484,8 @@ int Beb_SetDataStream(int left, int enable) {
if (retval != value) { if (retval != value) {
LOG(logERROR, LOG(logERROR,
("Could not %s %s fpga datastream. Wrote 0x%x, read 0x%x\n", ("Could not %s %s fpga datastream. Wrote 0x%x, read 0x%x\n",
(enable ? "enable" : "disable"), (left ? "left" : "right"), (enable ? "enable" : "disable"),
value, retval)); (port == LEFT ? "left" : "right"), value, retval));
Beb_close(fd, csp0base); Beb_close(fd, csp0base);
} }
} }
@ -497,9 +493,9 @@ int Beb_SetDataStream(int left, int enable) {
return 1; return 1;
} }
int Beb_GetDataStream(int left, int *retval) { int Beb_GetDataStream(enum portPositiion port, int *retval) {
if (!Beb_activated) { if (!Beb_activated) {
if (left) { if (port == LEFT) {
return Beb_deactivated_left_datastream; return Beb_deactivated_left_datastream;
} else { } else {
return Beb_deactivated_right_datastream; return Beb_deactivated_right_datastream;
@ -512,8 +508,8 @@ int Beb_GetDataStream(int left, int *retval) {
return 0; return 0;
} else { } else {
u_int32_t reg = XPAR_GPIO_P15_STREAMING_REG; u_int32_t reg = XPAR_GPIO_P15_STREAMING_REG;
u_int32_t mask = u_int32_t mask = (port == LEFT ? XPAR_GPIO_LFT_STRM_DSBL_MSK
(left ? XPAR_GPIO_LFT_STRM_DSBL_MSK : XPAR_GPIO_RGHT_STRM_DSBL_MSK); : XPAR_GPIO_RGHT_STRM_DSBL_MSK);
u_int32_t value = Beb_Read32(csp0base, reg); u_int32_t value = Beb_Read32(csp0base, reg);
// disabling in firmware // disabling in firmware

View File

@ -41,8 +41,8 @@ int Beb_SetTop(enum TOPINDEX ind);
int Beb_SetMaster(enum MASTERINDEX ind); int Beb_SetMaster(enum MASTERINDEX ind);
int Beb_SetActivate(int enable); int Beb_SetActivate(int enable);
int Beb_GetActivate(int *retval); int Beb_GetActivate(int *retval);
int Beb_SetDataStream(int left, int enable); int Beb_SetDataStream(enum portPositiion port, int enable);
int Beb_GetDataStream(int left, int *retval); int Beb_GetDataStream(ienum portPositiion port, int *retval);
int Beb_Set32bitOverflow(int val); int Beb_Set32bitOverflow(int val);
int Beb_GetTenGigaFlowControl(); int Beb_GetTenGigaFlowControl();

View File

@ -2051,38 +2051,38 @@ int getActivate(int *retval) {
return OK; return OK;
} }
int setDataStream(int left, int enable) { int setDataStream(enum portPositiion port, int enable) {
if (enable < 0) { if (enable < 0) {
LOG(logERROR, ("Invalid setDataStream enable argument: %d\n", enable)); LOG(logERROR, ("Invalid setDataStream enable argument: %d\n", enable));
return FAIL; return FAIL;
} }
if (left < 0) { if (left < 0) {
LOG(logERROR, ("Invalid setDataStream left argument: %d\n", left)); LOG(logERROR, ("Invalid setDataStream port argument: %d\n", port));
return FAIL; return FAIL;
} }
#ifdef VIRTUAL #ifdef VIRTUAL
if (left) { if (port == LEFT) {
eiger_virtual_left_datastream = enable; eiger_virtual_left_datastream = enable;
} else { } else {
eiger_virtual_right_datastream = enable; eiger_virtual_right_datastream = enable;
} }
#else #else
if (!Beb_SetDataStream(left, enable)) { if (!Beb_SetDataStream(port, enable)) {
return FAIL; return FAIL;
} }
#endif #endif
return OK; return OK;
} }
int getDataStream(int left, int *retval) { int getDataStream(enum portPositiion port, int *retval) {
#ifdef VIRTUAL #ifdef VIRTUAL
if (left) { if (port == LEFT) {
*retval = eiger_virtual_left_datastream; *retval = eiger_virtual_left_datastream;
} else { } else {
*retval = eiger_virtual_right_datastream; *retval = eiger_virtual_right_datastream;
} }
#else #else
if (!Beb_GetDataStream(left, retval)) { if (!Beb_GetDataStream(port, retval)) {
return FAIL; return FAIL;
} }
#endif #endif

View File

@ -474,8 +474,8 @@ int getAllTrimbits();
int getBebFPGATemp(); int getBebFPGATemp();
int setActivate(int enable); int setActivate(int enable);
int getActivate(int *retval); int getActivate(int *retval);
int getDataStream(int left, int *retval); int getDataStream(enum portPositiion port, int *retval);
int setDataStream(int left, int enable); int setDataStream(enum portPositiion port, int enable);
// gotthard specific - adc phase // gotthard specific - adc phase
#elif GOTTHARDD #elif GOTTHARDD

View File

@ -7058,7 +7058,7 @@ int get_receiver_parameters(int file_des) {
// data stream left // data stream left
#ifdef EIGERD #ifdef EIGERD
i32 = 0; i32 = 0;
getDataStream(1, &i32); getDataStream(LEFT, &i32);
#else #else
i32 = 0; i32 = 0;
#endif #endif
@ -7069,7 +7069,7 @@ int get_receiver_parameters(int file_des) {
// data stream right // data stream right
#ifdef EIGERD #ifdef EIGERD
i32 = 0; i32 = 0;
getDataStream(0, &i32); getDataStream(RIGHT, &i32);
#else #else
i32 = 0; i32 = 0;
#endif #endif
@ -8251,33 +8251,31 @@ int get_gain_caps(int file_des) {
int get_datastream(int file_des) { int get_datastream(int file_des) {
ret = OK; ret = OK;
memset(mess, 0, sizeof(mess)); memset(mess, 0, sizeof(mess));
int arg = -1; enum portPosition arg = LEFT;
int retval = -1; int retval = -1;
if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0) if (receiveData(file_des, &arg, sizeof(arg), INT32) < 0)
return printSocketReadError(); return printSocketReadError();
LOG(logDEBUG1, ("Getting data stream enable [left:%d]\n", arg)); LOG(logDEBUG1, ("Getting data stream enable [port:%d]\n", arg));
#ifndef EIGERD #ifndef EIGERD
functionNotImplemented(); functionNotImplemented();
#else #else
// get only // get only
int leftFpga = arg; if (arg != LEFT && arg != RIGHT) {
if (leftFpga != 0 && leftFpga != 1) {
ret = FAIL; ret = FAIL;
sprintf( sprintf(
mess, mess,
"Could not get data stream enable. Invalid side %d. Left argument" "Could not get data stream enable. Invalid port position %d. Only left and right allowed\n",
"should be 0 or 1.\n", arg);
leftFpga);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else { } else {
ret = getDataStream(leftFpga, &retval); ret = getDataStream(arg, &retval);
LOG(logDEBUG1, ("datastream (%s) retval: %u\n", LOG(logDEBUG1, ("datastream (%s) retval: %u\n",
(leftFpga ? "left" : "right"), retval)); (arg == LEFT? "left" : "right"), retval));
if (ret == FAIL) { if (ret == FAIL) {
sprintf(mess, "Could not get %s data stream enable.\n", sprintf(mess, "Could not get %s data stream enable.\n",
(leftFpga ? "left" : "right")); (arg == LEFT ? "left" : "right"));
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} }
} }
@ -8300,39 +8298,38 @@ int set_datastream(int file_des) {
#else #else
// only set // only set
if (Server_VerifyLock() == OK) { if (Server_VerifyLock() == OK) {
int leftFpga = args[0]; enum portPosition port = static_cast<portPosition>(args[0]);
int enable = args[1]; int enable = args[1];
char msg[256]; char msg[256];
memset(msg, 0, sizeof(msg)); memset(msg, 0, sizeof(msg));
sprintf(msg, "%s %s fpga datastream", (enable ? "enable" : "disable"), sprintf(msg, "%s %s fpga datastream", (enable ? "enable" : "disable"),
(leftFpga ? "left" : "right")); (port == LEFT ? "left" : "right"));
if (leftFpga != 0 && leftFpga != 1) { if (port != LEFT && port != RIGHT) {
ret = FAIL; ret = FAIL;
sprintf(mess, sprintf(mess,
"Could not %s. Invalid side %d. Left argument should be 0 " "Could not %s. Invalid port position %d. Only left and right allowed\n",
"or 1.\n", msg, port);
msg, leftFpga);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else if (enable != 0 && enable != 1) { } else if (enable != 0 && enable != 1) {
ret = FAIL; ret = FAIL;
sprintf(mess, "Could not %s. Invalid enable %d. \n", msg, enable); sprintf(mess, "Could not %s. Invalid enable %d. \n", msg, enable);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} else { } else {
ret = setDataStream(leftFpga, enable); ret = setDataStream(port, enable);
if (ret == FAIL) { if (ret == FAIL) {
sprintf(mess, "Could not %s\n", msg); sprintf(mess, "Could not %s\n", msg);
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} /*else { } else {
int retval = -1; int retval = -1;
ret = getDataStream(leftFpga, &retval); ret = getDataStream(port, &retval);
LOG(logDEBUG1, ("%s retval: %u\n", msg, retval)); LOG(logDEBUG1, ("%s retval: %u\n", msg, retval));
if (ret == FAIL) { if (ret == FAIL) {
sprintf(mess, "Could not get %s data stream enable.\n", sprintf(mess, "Could not get %s data stream enable.\n",
(leftFpga ? "left" : "right")); (port == LEFT ? "left" : "right"));
LOG(logERROR, (mess)); LOG(logERROR, (mess));
} }
validate(&ret, mess, enable, retval, msg, DEC); validate(&ret, mess, enable, retval, msg, DEC);
}*/ }
} }
} }
#endif #endif

View File

@ -1062,11 +1062,13 @@ class Detector {
void setQuad(const bool enable); void setQuad(const bool enable);
/** [Eiger] */ /** [Eiger] */
Result<bool> getDataStream(const bool left, Positions pos = {}) const; Result<bool> getDataStream(const portPosition port,
Positions pos = {}) const;
/** [Eiger] enable or disable data streaming from left or right of detector /** [Eiger] enable or disable data streaming from left or right of detector
*/ */
void setDataStream(const bool left, const bool enable, Positions pos = {}); void setDataStream(const portPosition port, const bool enable,
Positions pos = {});
///@{ ///@{

View File

@ -1603,29 +1603,15 @@ std::string CmdProxy::DataStream(int action) {
if (args.size() != 1) { if (args.size() != 1) {
WrongNumberOfParameters(1); WrongNumberOfParameters(1);
} }
// TODO, enum for "left and right?" auto t = det->getDataStream(StringTo<defs::portPosition>(args[0]),
if (args[0] == "left") { std::vector<int>{det_id});
left = true;
} else if (args[0] == "right") {
left = false;
} else {
throw sls::RuntimeError("Unknown data argument " + args[0]);
}
auto t = det->getDataStream(left, std::vector<int>{det_id});
os << OutString(t) << '\n'; os << OutString(t) << '\n';
} else if (action == defs::PUT_ACTION) { } else if (action == defs::PUT_ACTION) {
if (args.size() != 2) { if (args.size() != 2) {
WrongNumberOfParameters(2); WrongNumberOfParameters(2);
} }
if (args[0] == "left") { det->setDataStream(StringTo<defs::portPosition>(args[0]),
left = true; StringTo<bool>(args[1]), std::vector<int>{det_id});
} else if (args[0] == "right") {
left = false;
} else {
throw sls::RuntimeError("Unknown data argument " + args[0]);
}
det->setDataStream(left, StringTo<bool>(args[1]),
std::vector<int>{det_id});
os << args << '\n'; os << args << '\n';
} else { } else {
throw sls::RuntimeError("Unknown action"); throw sls::RuntimeError("Unknown action");

View File

@ -1369,13 +1369,14 @@ void Detector::setQuad(const bool enable) {
pimpl->Parallel(&Module::setQuad, {}, enable); pimpl->Parallel(&Module::setQuad, {}, enable);
} }
Result<bool> Detector::getDataStream(const bool left, Positions pos) const { Result<bool> Detector::getDataStream(const portPosition port,
return pimpl->Parallel(&Module::getDataStream, pos, left); Positions pos) const {
return pimpl->Parallel(&Module::getDataStream, pos, port);
} }
void Detector::setDataStream(const bool left, const bool enable, void Detector::setDataStream(const portPosition port, const bool enable,
Positions pos) { Positions pos) {
pimpl->Parallel(&Module::setDataStream, pos, left, enable); pimpl->Parallel(&Module::setDataStream, pos, port, enable);
} }
// Jungfrau Specific // Jungfrau Specific

View File

@ -1509,12 +1509,12 @@ void Module::setQuad(const bool enable) {
} }
} }
bool Module::getDataStream(const bool left) const { bool Module::getDataStream(const portPosition port) const {
return sendToDetector<int>(F_GET_DATASTREAM, static_cast<int>(left)); return sendToDetector<int>(F_GET_DATASTREAM, static_cast<int>(port));
} }
void Module::setDataStream(const bool left, const bool enable) { void Module::setDataStream(const portPosition port, const bool enable) {
int args[]{static_cast<int>(left), static_cast<int>(enable)}; int args[]{static_cast<int>(port), static_cast<int>(enable)};
sendToDetector(F_SET_DATASTREAM, args, nullptr); sendToDetector(F_SET_DATASTREAM, args, nullptr);
if (shm()->useReceiverFlag) { if (shm()->useReceiverFlag) {
sendToReceiver(F_RECEIVER_SET_DATASTREAM, args, nullptr); sendToReceiver(F_RECEIVER_SET_DATASTREAM, args, nullptr);

View File

@ -343,8 +343,8 @@ class Module : public virtual slsDetectorDefs {
void pulseChip(int n_pulses = 0); void pulseChip(int n_pulses = 0);
bool getQuad() const; bool getQuad() const;
void setQuad(const bool enable); void setQuad(const bool enable);
bool getDataStream(const bool left) const; bool getDataStream(const portPosition port) const;
void setDataStream(const bool left, const bool enable); void setDataStream(const portPosition port, const bool enable);
/************************************************** /**************************************************
* * * *

View File

@ -1703,14 +1703,21 @@ int ClientInterface::set_all_threshold(Interface &socket) {
int ClientInterface::set_detector_datastream(Interface &socket) { int ClientInterface::set_detector_datastream(Interface &socket) {
int args[2]{-1, -1}; int args[2]{-1, -1};
socket.Receive(args); socket.Receive(args);
bool left = static_cast<int>(args[0]); portPosition port = static_cast<portPosition>(args[0]);
switch (port) {
case LEFT:
case RIGHT:
break;
default:
throw RuntimeError("Invalid port type");
}
bool enable = static_cast<int>(args[1]); bool enable = static_cast<int>(args[1]);
LOG(logDEBUG1) << "Setting datstream " << (left ? "left" : "right") LOG(logDEBUG1) << "Setting datastream (" << sls::ToString(port) << ") to "
<< ") to " << sls::ToString(enable); << sls::ToString(enable);
if (myDetectorType != EIGER) if (myDetectorType != EIGER)
functionNotImplemented(); functionNotImplemented();
verifyIdle(socket); verifyIdle(socket);
impl()->setDetectorDataStream(left, enable); impl()->setDetectorDataStream(port, enable);
return socket.Send(OK); return socket.Send(OK);
} }

View File

@ -1508,15 +1508,17 @@ void Implementation::setActivate(bool enable) {
LOG(logINFO) << "Activation: " << (activated ? "enabled" : "disabled"); LOG(logINFO) << "Activation: " << (activated ? "enabled" : "disabled");
} }
bool Implementation::getDetectorDataStream(const bool leftPort) const { bool Implementation::getDetectorDataStream(const portPosition port) const {
int index = (leftPort ? 0 : 1); int index = (port == LEFT ? 0 : 1);
return detectorDataStream[index]; return detectorDataStream[index];
} }
void Implementation::setDetectorDataStream(const bool leftPort, const bool enable) { void Implementation::setDetectorDataStream(const portPosition port,
int index = (leftPort ? 0 : 1); const bool enable) {
int index = (port == LEFT ? 0 : 1);
detectorDataStream[index] = enable; detectorDataStream[index] = enable;
LOG(logINFO) << "Detector datastream (" << (leftPort ? "Left" : "Right") << " Port): " << sls::ToString(detectorDataStream[index]); LOG(logINFO) << "Detector datastream (" << sls::ToString(port)
<< " Port): " << sls::ToString(detectorDataStream[index]);
} }
bool Implementation::getDeactivatedPadding() const { bool Implementation::getDeactivatedPadding() const {

View File

@ -211,10 +211,10 @@ class Implementation : private virtual slsDetectorDefs {
/** [Eiger] If deactivated, receiver will create dummy data if deactivated /** [Eiger] If deactivated, receiver will create dummy data if deactivated
* padding is enabled (as it will receive nothing from detector) */ * padding is enabled (as it will receive nothing from detector) */
void setActivate(const bool enable); void setActivate(const bool enable);
bool getDetectorDataStream(const bool leftPort) const; bool getDetectorDataStream(const portPosition port) const;
/** [Eiger] If datastream is disabled, receiver will create dummy data if deactivated /** [Eiger] If datastream is disabled, receiver will create dummy data if deactivated
* padding for that port is enabled (as it will receive nothing from detector) */ * padding for that port is enabled (as it will receive nothing from detector) */
void setDetectorDataStream(const bool leftPort, const bool enable); void setDetectorDataStream(const portPosition port, const bool enable);
bool getDeactivatedPadding() const; bool getDeactivatedPadding() const;
/* [Eiger] */ /* [Eiger] */
void setDeactivatedPadding(const bool enable); void setDeactivatedPadding(const bool enable);

View File

@ -37,6 +37,7 @@ std::string ToString(const std::vector<defs::dacIndex> &vec);
std::string ToString(const defs::burstMode s); std::string ToString(const defs::burstMode s);
std::string ToString(const defs::timingSourceType s); std::string ToString(const defs::timingSourceType s);
std::string ToString(const defs::M3_GainCaps s); std::string ToString(const defs::M3_GainCaps s);
std::string ToString(const defs::portPosition s);
std::string ToString(const slsDetectorDefs::xy &coord); std::string ToString(const slsDetectorDefs::xy &coord);
std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::xy &coord); std::ostream &operator<<(std::ostream &os, const slsDetectorDefs::xy &coord);
@ -299,6 +300,7 @@ template <> defs::dacIndex StringTo(const std::string &s);
template <> defs::burstMode StringTo(const std::string &s); template <> defs::burstMode StringTo(const std::string &s);
template <> defs::timingSourceType StringTo(const std::string &s); template <> defs::timingSourceType StringTo(const std::string &s);
template <> defs::M3_GainCaps StringTo(const std::string &s); template <> defs::M3_GainCaps StringTo(const std::string &s);
template <> defs::portPosition StringTo(const std::string &s);
template <> uint32_t StringTo(const std::string &s); template <> uint32_t StringTo(const std::string &s);
template <> uint64_t StringTo(const std::string &s); template <> uint64_t StringTo(const std::string &s);

View File

@ -401,6 +401,8 @@ typedef struct {
M3_C15pre = 1 << 14, M3_C15pre = 1 << 14,
}; };
enum portPosition { LEFT, RIGHT, TOP, BOTTOM };
#ifdef __cplusplus #ifdef __cplusplus
/** scan structure */ /** scan structure */

View File

@ -521,6 +521,21 @@ std::string ToString(const defs::timingSourceType s) {
} }
} }
std::string ToString(const defs::portPosition s) {
switch (s) {
case defs::LEFT:
return std::string("left");
case defs::RIGHT:
return std::string("right");
case defs::TOP:
return std::string("top");
case defs::BOTTOM:
return std::string("bottom");
default:
return std::string("Unknown");
}
}
const std::string &ToString(const std::string &s) { return s; } const std::string &ToString(const std::string &s) { return s; }
template <> defs::detectorType StringTo(const std::string &s) { template <> defs::detectorType StringTo(const std::string &s) {
@ -861,23 +876,25 @@ template <> defs::timingSourceType StringTo(const std::string &s) {
throw sls::RuntimeError("Unknown timing source type " + s); throw sls::RuntimeError("Unknown timing source type " + s);
} }
template <> defs::M3_GainCaps StringTo(const std::string &s){ template <> defs::portPosition StringTo(const std::string &s) {
if (s == "C10pre") if (s == "left")
return defs::M3_C10pre; return defs::LEFT;
if (s == "C15sh") if (s == "right")
return defs::M3_C15sh; return defs::RIGHT;
if (s == "C30sh") if (s == "top")
return defs::M3_C30sh; return defs::TOP;
if (s == "C50sh") if (s == "bottom")
return defs::M3_C50sh; return defs::BOTTOM;
if (s == "C225ACsh") throw sls::RuntimeError("Unknown port position " + s);
return defs::M3_C225ACsh;
if (s == "C15pre")
return defs::M3_C15pre;
throw sls::RuntimeError("Unknown gain cap " + s);
} }
template <> defs::timingSourceType StringTo(const std::string &s) {
if (s == "internal")
return defs::TIMING_INTERNAL;
if (s == "external")
return defs::TIMING_EXTERNAL;
throw sls::RuntimeError("Unknown timing source type " + s);
}
std::string ToString(defs::M3_GainCaps s){ std::string ToString(defs::M3_GainCaps s){
std::ostringstream os; std::ostringstream os;