Merge pull request #127 from slsdetectorgroup/configuremac

Configuremac
This commit is contained in:
Dhanya Thattil
2020-08-05 10:22:20 +02:00
committed by GitHub
17 changed files with 120 additions and 30 deletions

View File

@ -151,7 +151,7 @@ int get_read_n_lines(int);
void calculate_and_set_position(); void calculate_and_set_position();
int set_detector_position(int); int set_detector_position(int);
int check_detector_idle(); int check_detector_idle();
int is_configurable(); int is_udp_configured();
void configure_mac(); void configure_mac();
int set_source_udp_ip(int); int set_source_udp_ip(int);
int get_source_udp_ip(int); int get_source_udp_ip(int);
@ -236,4 +236,6 @@ int set_filter(int);
int get_adc_config(int); int get_adc_config(int);
int set_adc_config(int); int set_adc_config(int);
int get_bad_channels(int); int get_bad_channels(int);
int set_bad_channels(int); int set_bad_channels(int);
int reconfigure_udp(int);
int validate_udp_configuration(int);

View File

@ -354,6 +354,8 @@ void function_table() {
flist[F_SET_ADC_CONFIGURATION] = &set_adc_config; flist[F_SET_ADC_CONFIGURATION] = &set_adc_config;
flist[F_GET_BAD_CHANNELS] = &get_bad_channels; flist[F_GET_BAD_CHANNELS] = &get_bad_channels;
flist[F_SET_BAD_CHANNELS] = &set_bad_channels; flist[F_SET_BAD_CHANNELS] = &set_bad_channels;
flist[F_RECONFIGURE_UDP] = &reconfigure_udp;
flist[F_VALIDATE_UDP_CONFIG] = &validate_udp_configuration;
// check // check
if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) { if (NUM_DET_FUNCTIONS >= RECEIVER_ENUM_START) {
@ -4864,14 +4866,14 @@ int check_detector_idle() {
return ret; return ret;
} }
int is_configurable() { int is_udp_configured() {
if (udpDetails.srcip == 0) { if (udpDetails.dstip == 0) {
strcpy(configureMessage, "udp source ip not configured\n"); strcpy(configureMessage, "udp destination ip not configured\n");
LOG(logWARNING, ("%s", configureMessage)); LOG(logWARNING, ("%s", configureMessage));
return FAIL; return FAIL;
} }
if (udpDetails.dstip == 0) { if (udpDetails.srcip == 0) {
strcpy(configureMessage, "udp destination ip not configured\n"); strcpy(configureMessage, "udp source ip not configured\n");
LOG(logWARNING, ("%s", configureMessage)); LOG(logWARNING, ("%s", configureMessage));
return FAIL; return FAIL;
} }
@ -4913,7 +4915,7 @@ int is_configurable() {
} }
void configure_mac() { void configure_mac() {
if (is_configurable() == OK) { if (is_udp_configured() == OK) {
ret = configureMAC(); ret = configureMAC();
if (ret != OK) { if (ret != OK) {
#if defined(CHIPTESTBOARDD) || defined(MOENCHD) #if defined(CHIPTESTBOARDD) || defined(MOENCHD)
@ -7391,7 +7393,7 @@ int set_veto(int file_des) {
setVeto(arg); setVeto(arg);
// if numinterfaces is 2 and veto is 1 now, then configuremac // if numinterfaces is 2 and veto is 1 now, then configuremac
if (arg > 0 && getNumberofUDPInterfaces() == 2 && if (arg > 0 && getNumberofUDPInterfaces() == 2 &&
is_configurable() == OK) { is_udp_configured() == OK) {
ret = configureMAC(); ret = configureMAC();
if (ret != OK) { if (ret != OK) {
sprintf(mess, "Configure Mac failed after enabling veto\n"); sprintf(mess, "Configure Mac failed after enabling veto\n");
@ -7976,3 +7978,37 @@ int set_bad_channels(int file_des) {
#endif #endif
return Server_SendResult(file_des, INT32, NULL, 0); return Server_SendResult(file_des, INT32, NULL, 0);
} }
int reconfigure_udp(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
if (Server_VerifyLock() == OK) {
LOG(logINFO, ("Reconfiguring UDP\n"));
if (check_detector_idle() == OK) {
configure_mac();
if (configured == FAIL) {
ret = FAIL;
strcpy(mess, "Invalid UDP Configuration because ");
strcat(mess, configureMessage);
LOG(logERROR, (mess));
}
}
}
return Server_SendResult(file_des, INT32, NULL, 0);
}
int validate_udp_configuration(int file_des) {
ret = OK;
memset(mess, 0, sizeof(mess));
LOG(logINFO, ("Validating UDP Configuration\n"));
if (configured == FAIL) {
ret = FAIL;
strcpy(mess, "Invalid UDP Configuration because ");
strcat(mess, configureMessage);
LOG(logERROR, (mess));
}
return Server_SendResult(file_des, INT32, NULL, 0);
}

View File

@ -509,6 +509,10 @@ class Detector {
*/ */
void setDestinationUDPPort2(int port, int module_id = -1); void setDestinationUDPPort2(int port, int module_id = -1);
void reconfigureUDPDestination(Positions pos = {});
void validateUDPConfiguration(Positions pos = {});
Result<std::string> printRxConfiguration(Positions pos = {}) const; Result<std::string> printRxConfiguration(Positions pos = {}) const;
/** [Eiger][CTB][Moench][Mythen3] */ /** [Eiger][CTB][Moench][Mythen3] */

View File

@ -776,6 +776,8 @@ class CmdProxy {
{"udp_dstmac2", &CmdProxy::udp_dstmac2}, {"udp_dstmac2", &CmdProxy::udp_dstmac2},
{"udp_dstport", &CmdProxy::udp_dstport}, {"udp_dstport", &CmdProxy::udp_dstport},
{"udp_dstport2", &CmdProxy::udp_dstport2}, {"udp_dstport2", &CmdProxy::udp_dstport2},
{"udp_reconfigure", &CmdProxy::udp_reconfigure},
{"udp_validate", &CmdProxy::udp_validate},
{"rx_printconfig", &CmdProxy::rx_printconfig}, {"rx_printconfig", &CmdProxy::rx_printconfig},
{"tengiga", &CmdProxy::tengiga}, {"tengiga", &CmdProxy::tengiga},
{"flowcontrol10g", &CmdProxy::flowcontrol10g}, {"flowcontrol10g", &CmdProxy::flowcontrol10g},
@ -1645,6 +1647,18 @@ class CmdProxy {
"sent to. \n[Eiger] Port number of the reciever (desintation) udp " "sent to. \n[Eiger] Port number of the reciever (desintation) udp "
"interface where the right half of the detector data is sent to."); "interface where the right half of the detector data is sent to.");
EXECUTE_SET_COMMAND(
udp_reconfigure, reconfigureUDPDestination,
"\n\tReconfigures Detector with UDP destination. More for debugging as "
"the configuration is done automatically when the detector has "
"sufficient UDP details.");
EXECUTE_SET_COMMAND(
udp_validate, validateUDPConfiguration,
"\n\tValidates that UDP configuration in the detector is "
"valid. If not configured, it will throw with error message "
"requesting missing udp information.");
GET_COMMAND(rx_printconfig, printRxConfiguration, GET_COMMAND(rx_printconfig, printRxConfiguration,
"\n\tPrints the receiver configuration."); "\n\tPrints the receiver configuration.");

View File

@ -716,6 +716,14 @@ void Detector::setDestinationUDPPort2(int port, int module_id) {
} }
} }
void Detector::reconfigureUDPDestination(Positions pos) {
pimpl->Parallel(&Module::reconfigureUDPDestination, pos);
}
void Detector::validateUDPConfiguration(Positions pos) {
pimpl->Parallel(&Module::validateUDPConfiguration, pos);
}
Result<std::string> Detector::printRxConfiguration(Positions pos) const { Result<std::string> Detector::printRxConfiguration(Positions pos) const {
return pimpl->Parallel(&Module::printReceiverConfiguration, pos); return pimpl->Parallel(&Module::printReceiverConfiguration, pos);
} }

View File

@ -638,6 +638,12 @@ void Module::setDestinationUDPPort2(const int port) {
} }
} }
void Module::reconfigureUDPDestination() { sendToDetector(F_RECONFIGURE_UDP); }
void Module::validateUDPConfiguration() {
sendToDetector(F_VALIDATE_UDP_CONFIG);
}
std::string Module::printReceiverConfiguration() { std::string Module::printReceiverConfiguration() {
std::ostringstream os; std::ostringstream os;
os << "\n\nDetector " << moduleId << "\nReceiver Hostname:\t" os << "\n\nDetector " << moduleId << "\nReceiver Hostname:\t"

View File

@ -202,6 +202,8 @@ class Module : public virtual slsDetectorDefs {
void setDestinationUDPPort(int udpport); void setDestinationUDPPort(int udpport);
int getDestinationUDPPort2() const; int getDestinationUDPPort2() const;
void setDestinationUDPPort2(int udpport); void setDestinationUDPPort2(int udpport);
void reconfigureUDPDestination();
void validateUDPConfiguration();
std::string printReceiverConfiguration(); std::string printReceiverConfiguration();
bool getTenGiga() const; bool getTenGiga() const;
void setTenGiga(bool value); void setTenGiga(bool value);

View File

@ -1268,28 +1268,28 @@ TEST_CASE("scan", "[.cmd][.new]") {
proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500"}, -1, PUT, proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500"}, -1, PUT,
oss); oss);
CHECK(oss.str() == CHECK(oss.str() ==
"scan [" + sls::ToString(ind) + ", 500, 1500, 500]\n"); "scan [" + sls::ToString(ind) + ", 500, 1500, 500]\n");
} }
{ {
std::ostringstream oss; std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss); proxy.Call("scan", {}, -1, GET, oss);
CHECK(oss.str() == "scan [enabled\ndac " + sls::ToString(ind) + CHECK(oss.str() == "scan [enabled\ndac " + sls::ToString(ind) +
"\nstart 500\nstop 1500\nstep " "\nstart 500\nstop 1500\nstep "
"500\nsettleTime 1ms\n]\n"); "500\nsettleTime 1ms\n]\n");
} }
{ {
std::ostringstream oss; std::ostringstream oss;
proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500", "2s"}, -1, proxy.Call("scan", {sls::ToString(ind), "500", "1500", "500", "2s"}, -1,
PUT, oss); PUT, oss);
CHECK(oss.str() == CHECK(oss.str() ==
"scan [" + sls::ToString(ind) + ", 500, 1500, 500, 2s]\n"); "scan [" + sls::ToString(ind) + ", 500, 1500, 500, 2s]\n");
} }
{ {
std::ostringstream oss; std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss); proxy.Call("scan", {}, -1, GET, oss);
CHECK(oss.str() == "scan [enabled\ndac " + sls::ToString(ind) + CHECK(oss.str() == "scan [enabled\ndac " + sls::ToString(ind) +
"\nstart 500\nstop 1500\nstep " "\nstart 500\nstop 1500\nstep "
"500\nsettleTime 2s\n]\n"); "500\nsettleTime 2s\n]\n");
} }
{ {
std::ostringstream oss; std::ostringstream oss;
@ -1306,15 +1306,15 @@ TEST_CASE("scan", "[.cmd][.new]") {
proxy.Call("scan", {sls::ToString(ind), "1500", "500", "-500"}, -1, PUT, proxy.Call("scan", {sls::ToString(ind), "1500", "500", "-500"}, -1, PUT,
oss); oss);
CHECK(oss.str() == CHECK(oss.str() ==
"scan [" + sls::ToString(ind) + ", 1500, 500, -500]\n"); "scan [" + sls::ToString(ind) + ", 1500, 500, -500]\n");
} }
CHECK_THROWS(proxy.Call( CHECK_THROWS(proxy.Call(
"scan", {sls::ToString(notImplementedInd), "500", "1500", "500"}, -1, "scan", {sls::ToString(notImplementedInd), "500", "1500", "500"}, -1,
PUT)); PUT));
CHECK_THROWS(proxy.Call( CHECK_THROWS(proxy.Call("scan", {sls::ToString(ind), "500", "1500", "-500"},
"scan", {sls::ToString(ind), "500", "1500", "-500"}, -1, PUT)); -1, PUT));
CHECK_THROWS(proxy.Call( CHECK_THROWS(proxy.Call("scan", {sls::ToString(ind), "1500", "500", "500"},
"scan", {sls::ToString(ind), "1500", "500", "500"}, -1, PUT)); -1, PUT));
if (det_type == defs::MYTHEN3 || defs::EIGER) { if (det_type == defs::MYTHEN3 || defs::EIGER) {
{ {
@ -1327,12 +1327,12 @@ TEST_CASE("scan", "[.cmd][.new]") {
std::ostringstream oss; std::ostringstream oss;
proxy.Call("scan", {}, -1, GET, oss); proxy.Call("scan", {}, -1, GET, oss);
CHECK(oss.str() == CHECK(oss.str() ==
"scan [enabled\ndac trimbit_scan\nstart 0\nstop 48\nstep " "scan [enabled\ndac trimbit_scan\nstart 0\nstop 48\nstep "
"16\nsettleTime 2s\n]\n"); "16\nsettleTime 2s\n]\n");
} }
} }
//Switch off scan for future tests // Switch off scan for future tests
det.setScan(defs::scanParameters()); det.setScan(defs::scanParameters());
// acquire for each? // acquire for each?
@ -1562,6 +1562,20 @@ TEST_CASE("udp_dstport2", "[.cmd][.new]") {
} }
} }
TEST_CASE("udp_reconfigure", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
REQUIRE_THROWS(proxy.Call("udp_reconfigure", {}, -1, GET));
REQUIRE_NOTHROW(proxy.Call("udp_reconfigure", {}, -1, PUT));
}
TEST_CASE("udp_validate", "[.cmd][.new]") {
Detector det;
CmdProxy proxy(&det);
REQUIRE_THROWS(proxy.Call("udp_validate", {}, -1, GET));
REQUIRE_NOTHROW(proxy.Call("udp_validate", {}, -1, PUT));
}
TEST_CASE("tengiga", "[.cmd][.new]") { TEST_CASE("tengiga", "[.cmd][.new]") {
Detector det; Detector det;
CmdProxy proxy(&det); CmdProxy proxy(&det);

View File

@ -211,6 +211,8 @@ enum detFuncs {
F_SET_ADC_CONFIGURATION, F_SET_ADC_CONFIGURATION,
F_GET_BAD_CHANNELS, F_GET_BAD_CHANNELS,
F_SET_BAD_CHANNELS, F_SET_BAD_CHANNELS,
F_RECONFIGURE_UDP,
F_VALIDATE_UDP_CONFIG,
NUM_DET_FUNCTIONS, NUM_DET_FUNCTIONS,
RECEIVER_ENUM_START = 256, /**< detector function should not exceed this RECEIVER_ENUM_START = 256, /**< detector function should not exceed this
@ -523,6 +525,8 @@ const char* getFunctionNameFromEnum(enum detFuncs func) {
case F_GET_ADC_CONFIGURATION: return "F_GET_ADC_CONFIGURATION"; case F_GET_ADC_CONFIGURATION: return "F_GET_ADC_CONFIGURATION";
case F_GET_BAD_CHANNELS: return "F_GET_BAD_CHANNELS"; case F_GET_BAD_CHANNELS: return "F_GET_BAD_CHANNELS";
case F_SET_BAD_CHANNELS: return "F_SET_BAD_CHANNELS"; case F_SET_BAD_CHANNELS: return "F_SET_BAD_CHANNELS";
case F_RECONFIGURE_UDP: return "F_RECONFIGURE_UDP";
case F_VALIDATE_UDP_CONFIG: return "F_VALIDATE_UDP_CONFIG";
case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS"; case NUM_DET_FUNCTIONS: return "NUM_DET_FUNCTIONS";
case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START"; case RECEIVER_ENUM_START: return "RECEIVER_ENUM_START";

View File

@ -3,10 +3,10 @@
#define APILIB 0x200409 #define APILIB 0x200409
#define APIRECEIVER 0x200409 #define APIRECEIVER 0x200409
#define APIGUI 0x200409 #define APIGUI 0x200409
#define APIEIGER 0x200729 #define APICTB 0x200805
#define APICTB 0x200729 #define APIGOTTHARD 0x200805
#define APIGOTTHARD 0x200729 #define APIGOTTHARD2 0x200805
#define APIJUNGFRAU 0x200729 #define APIJUNGFRAU 0x200805
#define APIMOENCH 0x200729 #define APIMYTHEN3 0x200805
#define APIGOTTHARD2 0x200730 #define APIMOENCH 0x200804
#define APIMYTHEN3 0x200804 #define APIEIGER 0x200805