added slsWarnings and c++17 compiler option

This commit is contained in:
2026-07-06 22:28:16 +02:00
parent 474bda497e
commit 059b9c7177
8 changed files with 51 additions and 30 deletions
@@ -30,7 +30,11 @@ if(SLS_USE_SIMULATOR)
target_link_libraries(matterhornDetectorServer_virtual
PUBLIC
slsSupportStatic
slsServerStatic)
slsServerStatic
slsProjectOptions
PRIVATE
slsProjectWarnings
)
set_target_properties(matterhornDetectorServer_virtual PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
@@ -74,7 +78,11 @@ if(SLS_USE_MATTERHORN)
target_link_libraries(matterhornDetectorServer
PUBLIC
slsSupportStatic
slsServerStatic)
slsServerStatic
slsProjectOptions
PRIVATE
slsProjectWarnings
)
if(${CROSS_COMPILE}) # change output directory to stay consitent with c server binaries when cross compiling
set(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin)
@@ -53,9 +53,13 @@ class BaseMatterhornServer
using ImplType = typename implementation_typetrait<DerivedServer>::ImplType;
protected:
auto *const getImpl() const { return this->getDerivedImpl(); }
auto *getImpl() { return this->getDerivedImpl(); }
const auto *getImpl() const { return this->getDerivedImpl(); }
private:
DerivedServer *getDerived() { return static_cast<DerivedServer *>(this); }
const DerivedServer *getDerived() const {
return static_cast<const DerivedServer *>(this);
}
@@ -25,7 +25,9 @@ class MatterhornServer : public BaseMatterhornServer<MatterhornServer> {
~MatterhornServer() = default;
private:
ImplType *const getImpl() const { return this->getDerivedImpl(); }
ImplType *getImpl() { return this->getDerivedImpl(); }
const ImplType *getImpl() const { return this->getDerivedImpl(); }
};
} // namespace sls
@@ -27,8 +27,8 @@ template <typename DerivedSPIModel> class SPICommunication {
void open_spi();
private:
DerivedSPIModel *const getDerived() {
return static_cast<DerivedSPIModel *const>(this);
DerivedSPIModel *getDerived() {
return static_cast<DerivedSPIModel *>(this);
}
};
@@ -42,7 +42,7 @@ std::vector<std::byte>
SPICommunication<DerivedSPIModel>::SPIread(const SPIRegister &spi_reg,
const uint8_t chip_id) const {
if (chip_id >= MatterhornDefs::NUM_CHIPS_PER_MODULE || chip_id < 0) {
if (chip_id >= MatterhornDefs::NUM_CHIPS_PER_MODULE) {
throw RuntimeError(
fmt::format("Chip id {} is out of range (0-{})", chip_id,
MatterhornDefs::NUM_CHIPS_PER_MODULE - 1));
@@ -56,7 +56,7 @@ void SPICommunication<DerivedSPIModel>::SPIwrite(
const SPIRegister &spi_reg, const uint8_t chip_id,
const std::vector<std::byte> &data) {
if (chip_id >= MatterhornDefs::NUM_CHIPS_PER_MODULE || chip_id < 0) {
if (chip_id >= MatterhornDefs::NUM_CHIPS_PER_MODULE) {
throw RuntimeError(
fmt::format("Chip id {} is out of range (0-{})", chip_id,
MatterhornDefs::NUM_CHIPS_PER_MODULE - 1));
@@ -21,7 +21,9 @@ class VirtualMatterhornServer
~VirtualMatterhornServer() = default;
private:
ImplType *const getImpl() { return this->getDerivedImpl(); }
ImplType *getImpl() { return this->getDerivedImpl(); }
const ImplType *getImpl() const { return this->getDerivedImpl(); }
};
} // namespace sls
@@ -35,7 +35,12 @@ HardwareSPICommunication::spi_read(const size_t n_bytes, const uint8_t chip_id,
const uint8_t register_id) const {
// allocate dummy data to shift out the data (first byte is command byte)
std::vector<std::byte> dummy_data(n_bytes + 1);
if (n_bytes == std::numeric_limits<size_t>::max()) {
throw RuntimeError("SPI read size overflow");
}
std::vector<std::byte> dummy_data(
n_bytes + 1, std::byte{0x00}); // +1 for the command byte
// First byte of the message is 4 bits chip_id then 4 bits register_id
dummy_data[0] =
@@ -66,13 +71,6 @@ HardwareSPICommunication::spi_read(const size_t n_bytes, const uint8_t chip_id,
std::vector<std::byte> output_data(n_bytes);
std::memcpy(output_data.data(), read_data_buffer.data() + 1, n_bytes);
/*
LOG(logDEBUG1) << "Read data: ";
std::for_each(output_data.begin(), output_data.end(), [](std::byte b) {
LOG(logDEBUG1) << fmt::format("{} ", std::to_integer<int>(b));
});
*/
// copy the read out data back to the dummy data buffer to shift it back in
send_cmd.tx_buf = send_cmd.rx_buf;
@@ -93,6 +91,10 @@ void HardwareSPICommunication::spi_write(const uint8_t chip_id,
const size_t n_bytes = data.size();
if (n_bytes == std::numeric_limits<size_t>::max()) {
throw RuntimeError("SPI read size overflow");
}
// First byte of the message is 4 bits chip_id then 4 bits register_id
std::vector<std::byte> write_data(n_bytes + 1); // +1 for the command byte
@@ -101,13 +103,6 @@ void HardwareSPICommunication::spi_write(const uint8_t chip_id,
std::memcpy(write_data.data() + 1, data.data(), n_bytes);
/*
LOG(logDEBUG1) << "Write data: ";
std::for_each(write_data.begin(), write_data.end(), [](std::byte b) {
LOG(logDEBUG1) << fmt::format("{} ", std::to_integer<int>(b));
});
*/
spi_ioc_transfer send_cmd{};
send_cmd.len = n_bytes + 1; // +1 for the command byte
send_cmd.tx_buf = reinterpret_cast<std::uintptr_t>(write_data.data());
@@ -38,15 +38,24 @@ template <typename DerivedDetectorServer> class DetectorServer {
std::unique_ptr<DetectorServerImpl> impl;
auto *const getDerivedImpl() const {
return static_cast<typename DerivedDetectorServer::ImplType *const>(
auto *getDerivedImpl() {
return static_cast<typename DerivedDetectorServer::ImplType *>(
impl.get());
}
const auto *getDerivedImpl() const {
return static_cast<const typename DerivedDetectorServer::ImplType *>(
impl.get());
}
private:
/// @brief get derived class
DerivedDetectorServer *const getDerived() {
return static_cast<DerivedDetectorServer *const>(this);
DerivedDetectorServer *getDerived() {
return static_cast<DerivedDetectorServer *>(this);
}
const DerivedDetectorServer *getDerived() const {
return static_cast<const DerivedDetectorServer *>(this);
}
ProcessedResult processFunction(const detFuncs function_id,
@@ -423,7 +432,8 @@ ProcessedResult DetectorServer<DerivedDetectorServer>::get_version(
->get_server_version(); // TODO: get Impl from derived server
char version_cstr[MAX_STR_LENGTH]{};
strncpy(version_cstr, version.c_str(), version.size());
std::snprintf(version_cstr, sizeof(version_cstr), "%s",
version.c_str()); // ensures temination
LOG(TLogLevel::logDEBUG) << "Server Version: " << version;
return ProcessedResult{static_cast<ReturnCode>(socket.sendResult(
version_cstr))}; // TODO: check what would be possible return codes!!!
@@ -35,7 +35,7 @@ template <typename T>
void setRegisterField(uint32_t &registervalue, const RegisterField &reg_field,
T field_value) {
if (field_value > reg_field.bitmask) {
if (field_value > static_cast<T>(reg_field.bitmask)) {
throw std::invalid_argument(
fmt::format("Value {} cannot fit in field with bitmask {}",
field_value, reg_field.bitmask));