updated mac address

This commit is contained in:
2026-05-29 15:56:20 +02:00
parent 349425adb6
commit 7dba319355
6 changed files with 160 additions and 66 deletions
@@ -55,7 +55,13 @@ class BaseMatterhornServer
ReturnCode get_receiver_parameters(ServerInterface &socket) const;
ReturnCode set_module_position(ServerInterface &socket);
ReturnCode set_source_udp_mac(ServerInterface &socket);
ReturnCode
set_module_position_and_update_srcudpmac(ServerInterface &socket);
void set_module_position(const size_t module_row, const size_t module_col,
const size_t module_index);
ReturnCode set_counter_mask(ServerInterface &socket);
@@ -266,22 +272,9 @@ uint32_t BaseMatterhornServer<DerivedServer>::getNumTriggers() const {
}
template <typename DerivedServer>
ReturnCode BaseMatterhornServer<DerivedServer>::set_module_position(
ServerInterface &socket) {
std::array<int, 2> position_info{}; // [num_modules_in_y, module_index]
try {
int ret = socket.Receive(position_info.data(),
position_info.size() * sizeof(int));
} catch (const SocketError &e) {
LOG(logERROR)
<< "Failed to receive num modules in y dimension and module index: "
<< e.what();
return ReturnCode::FAIL;
}
const size_t module_row = position_info[1] % position_info[0];
const size_t module_col = position_info[1] / position_info[0];
void BaseMatterhornServer<DerivedServer>::set_module_position(
const size_t module_row, const size_t module_col,
const size_t module_index) {
// write to register
uint32_t register_value_LSB{};
@@ -295,13 +288,13 @@ ReturnCode BaseMatterhornServer<DerivedServer>::set_module_position(
} catch (const std::exception &e) {
LOG(logERROR) << "Failed to read module position register: "
<< e.what();
return ReturnCode::FAIL;
throw;
}
setRegisterField(register_value_LSB, Reg::ModuleRow, module_row);
setRegisterField(register_value_LSB, Reg::ModuleCol, module_col);
setRegisterField(register_value_MSB, Reg::ModuleCoordz, 0);
setRegisterField(register_value_MSB, Reg::ModuleIndex, position_info[1]);
setRegisterField(register_value_MSB, Reg::ModuleIndex, module_index);
try {
busCommunication.writeRegister(Reg::Frame_HDR_ModCoord_LSB_Reg,
@@ -311,25 +304,8 @@ ReturnCode BaseMatterhornServer<DerivedServer>::set_module_position(
} catch (const std::exception &e) {
LOG(logERROR) << "Failed to write module position register: "
<< e.what();
return ReturnCode::FAIL;
throw;
}
// configure mac address based on module position
if (this->udpDetails[0].srcmac ==
0) { // only configure if source mac address is not set already
this->udpDetails[0].srcmac = generaterandomMacAddress();
uint64_t newSrcMac = (this->udpDetails[0].srcmac & 0xffffffffffff0000) |
(module_row << 16) | module_col;
try {
this->updateSrcMacAddress(newSrcMac);
} catch (const std::invalid_argument &e) {
LOG(logERROR) << "Failed to update source MAC address: "
<< e.what();
return ReturnCode::FAIL;
}
}
return static_cast<ReturnCode>(socket.Send(ReturnCode::OK));
}
template <typename DerivedServer>
@@ -400,4 +376,18 @@ ReturnCode BaseMatterhornServer<DerivedServer>::get_counter_mask(
return static_cast<ReturnCode>(socket.sendResult(actual_counter_mask));
}
template <typename DerivedServer>
ReturnCode BaseMatterhornServer<DerivedServer>::set_source_udp_mac(
ServerInterface &socket) {
return static_cast<DerivedServer *>(this)->set_source_udp_mac(socket);
}
template <typename DerivedServer>
ReturnCode
BaseMatterhornServer<DerivedServer>::set_module_position_and_update_srcudpmac(
ServerInterface &socket) {
return static_cast<DerivedServer *>(this)
->set_module_position_and_update_srcudpmac(socket);
}
} // namespace sls
@@ -22,6 +22,11 @@ class MatterhornServer : public BaseMatterhornServer<MatterhornServer> {
~MatterhornServer() = default;
ReturnCode initial_checks(ServerInterface &socket);
ReturnCode
set_module_position_and_update_srcudpmac(ServerInterface &socket);
ReturnCode set_source_udp_mac(ServerInterface &socket);
};
} // namespace sls
@@ -21,6 +21,11 @@ class VirtualMatterhornServer
ReturnCode initial_checks(ServerInterface &socket);
ReturnCode get_run_status(ServerInterface &socket) const;
ReturnCode
set_module_position_and_update_srcudpmac(ServerInterface &socket);
ReturnCode set_source_udp_mac(ServerInterface &socket);
};
} // namespace sls
@@ -7,6 +7,8 @@ MatterhornServer::MatterhornServer(uint16_t port)
// map the IP core base addresses to memory
busCommunication.mapToMemory(); // TODO: should this happen in constructor?
spiCommunication.mapToMemory(); // TODO: should this happen in constructor?
// should maybe be part of the constructor?
tcpInterface->startTCPServer();
@@ -23,4 +25,55 @@ ReturnCode MatterhornServer::initial_checks(ServerInterface &socket) {
return static_cast<ReturnCode>(socket.sendResult(initial_checks_passed));
}
ReturnCode MatterhornServer::set_module_position_and_update_srcudpmac(
ServerInterface &socket) {
std::array<int, 2> position_info{}; // [num_modules_in_y, module_index]
try {
int ret = socket.Receive(position_info.data(),
position_info.size() * sizeof(int));
} catch (const SocketError &e) {
LOG(logERROR)
<< "Failed to receive num modules in y dimension and module index: "
<< e.what();
return ReturnCode::FAIL;
}
const size_t module_row = position_info[1] % position_info[0];
const size_t module_col = position_info[1] / position_info[0];
try {
this->set_module_position(module_row, module_col, position_info[1]);
} catch (const std::exception &e) {
LOG(logERROR) << "Failed to set module position: " << e.what();
return ReturnCode::FAIL;
}
// configure mac address based on module position
// TODO: update
if (this->udpDetails[0].srcmac ==
0) { // only configure if source mac address is not set already
this->udpDetails[0].srcmac = generaterandomMacAddress();
uint64_t newSrcMac = (this->udpDetails[0].srcmac & 0xffffffffffff0000) |
(module_row << 16) | module_col;
try {
this->updateSrcMacAddress(newSrcMac);
} catch (const std::invalid_argument &e) {
LOG(logERROR) << "Failed to update source MAC address: "
<< e.what();
return ReturnCode::FAIL;
}
}
return static_cast<ReturnCode>(socket.Send(ReturnCode::OK));
}
ReturnCode MatterhornServer::set_source_udp_mac(ServerInterface &socket) {
LOG(logERROR) << "Cannot overwrite vendor specific source UDP MAC address.";
return static_cast<ReturnCode>(socket.Send(ReturnCode::FAIL));
}
} // namespace sls
@@ -51,4 +51,68 @@ VirtualMatterhornServer::get_run_status(ServerInterface &socket) const {
return static_cast<ReturnCode>(socket.sendResult(status));
}
ReturnCode VirtualMatterhornServer::set_module_position_and_update_srcudpmac(
ServerInterface &socket) {
std::array<int, 2> position_info{}; // [num_modules_in_y, module_index]
try {
int ret = socket.Receive(position_info.data(),
position_info.size() * sizeof(int));
} catch (const SocketError &e) {
LOG(logERROR)
<< "Failed to receive num modules in y dimension and module index: "
<< e.what();
return ReturnCode::FAIL;
}
const size_t module_row = position_info[1] % position_info[0];
const size_t module_col = position_info[1] / position_info[0];
try {
this->set_module_position(module_row, module_col, position_info[1]);
} catch (const std::exception &e) {
LOG(logERROR) << "Failed to set module position: " << e.what();
return ReturnCode::FAIL;
}
// configure mac address based on module position
if (this->udpDetails[0].srcmac ==
0) { // only configure if source mac address is not set already
uint64_t newSrcMac = generaterandomMacAddress();
newSrcMac =
(newSrcMac & 0xffffffffffff0000) | (module_row << 16) | module_col;
try {
this->updateSrcMacAddress(newSrcMac);
} catch (const std::invalid_argument &e) {
LOG(logERROR) << "Failed to update source MAC address: "
<< e.what();
return ReturnCode::FAIL;
}
}
return static_cast<ReturnCode>(socket.Send(ReturnCode::OK));
}
ReturnCode
VirtualMatterhornServer::set_source_udp_mac(ServerInterface &socket) {
uint64_t newsrcudpMac;
try {
int ret = socket.Receive<uint64_t>(newsrcudpMac);
} catch (const SocketError &e) {
LOG(logERROR) << "Failed to receive new source UDP MAC address: "
<< e.what();
return ReturnCode::FAIL;
}
try {
updateSrcMacAddress(newsrcudpMac);
} catch (const std::invalid_argument &e) {
LOG(logERROR) << "Failed to update source MAC address: " << e.what();
return ReturnCode::FAIL;
}
return static_cast<ReturnCode>(socket.Send(ReturnCode::OK));
}
} // namespace sls
@@ -103,8 +103,6 @@ template <typename DerivedDetectorServer> class DetectorServer {
ReturnCode get_source_udp_mac(ServerInterface &socket) const;
ReturnCode set_source_udp_mac(ServerInterface &socket);
ReturnCode get_source_udp_ip(ServerInterface &socket) const;
ReturnCode set_source_udp_ip(ServerInterface &socket);
@@ -173,7 +171,8 @@ ReturnCode DetectorServer<DerivedDetectorServer>::processFunction(
case detFuncs::F_GET_UPDATE_MODE:
return get_update_mode(socket);
case detFuncs::F_SET_SOURCE_UDP_MAC:
return set_source_udp_mac(socket);
return static_cast<DerivedDetectorServer *>(this)->set_source_udp_mac(
socket);
case detFuncs::F_GET_SOURCE_UDP_MAC:
return get_source_udp_mac(socket);
case detFuncs::F_SET_SOURCE_UDP_IP:
@@ -207,8 +206,8 @@ ReturnCode DetectorServer<DerivedDetectorServer>::processFunction(
return static_cast<DerivedDetectorServer *>(this)
->get_receiver_parameters(socket);
case detFuncs::F_SET_POSITION:
return static_cast<DerivedDetectorServer *>(this)->set_module_position(
socket);
return static_cast<DerivedDetectorServer *>(this)
->set_module_position_and_update_srcudpmac(socket);
default:
LOG(logDEBUG) << "Checking specific server functions for function ID: "
<< function_id;
@@ -265,33 +264,11 @@ ReturnCode DetectorServer<DerivedDetectorServer>::get_update_mode(
socket.sendResult(static_cast<int>(updateMode)));
}
template <typename DerivedDetectorServer>
ReturnCode DetectorServer<DerivedDetectorServer>::set_source_udp_mac(
ServerInterface &socket) {
uint64_t newsrcudpMac;
try {
int ret = socket.Receive<uint64_t>(newsrcudpMac);
} catch (const SocketError &e) {
LOG(logERROR) << "Failed to receive new source UDP MAC address: "
<< e.what();
return ReturnCode::FAIL;
}
try {
updateSrcMacAddress(newsrcudpMac);
} catch (const std::invalid_argument &e) {
LOG(logERROR) << "Failed to update source MAC address: " << e.what();
return ReturnCode::FAIL;
}
return static_cast<ReturnCode>(socket.Send(ReturnCode::OK));
}
template <typename DerivedDetectorServer>
ReturnCode DetectorServer<DerivedDetectorServer>::get_source_udp_mac(
ServerInterface &socket) const {
return static_cast<ReturnCode>(socket.sendResult(udpDetails[0].srcmac));
auto srcUdpMac = udpDetails[0].srcmac;
return static_cast<ReturnCode>(socket.sendResult(srcUdpMac));
}
template <typename DerivedDetectorServer>