added example using bits

This commit is contained in:
froejdh_e
2025-12-12 09:47:45 +01:00
parent 5295e148da
commit c34eec033a
3 changed files with 69 additions and 4 deletions

View File

@@ -4,12 +4,20 @@ add_executable(using_logger using_logger.cpp)
target_link_libraries(using_logger
slsSupportShared
)
set_target_properties(using_logger PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
add_executable(using_registers using_registers.cpp)
target_link_libraries(using_registers
slsDetectorShared
)
set_target_properties(using_registers PROPERTIES
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
)
# add_executable(result useResult.cpp)
# target_link_libraries(result
# slsDetectorShared

View File

@@ -3,15 +3,23 @@
#include "sls/logger.h"
#include <iostream>
#include <chrono>
using sls::logINFO;
using sls::logINFORED;
using sls::logINFOBLUE;
using sls::logINFOGREEN;
using sls::logERROR;
using sls::logWARNING;
int main() {
//compare old and new
std::cout << "Compare output between old and new:\n";
LOG(logINFO) << "Some info message";
LOG(logERROR) << "This is an error";
LOG(logWARNING) << "While this is only a warning"; prefix="/afs/psi.ch/project/sls_det_software/dhanya_softwareDevelopment/mySoft/slsDetectorPackage/"
p=${file#"$prefix"}
LOG(logWARNING) << "While this is only a warning";
//Logging level can be configure at runtime
std::cout << "\n\n";
std::cout << "The default macro controlled level is: "

View File

@@ -0,0 +1,49 @@
// SPDX-License-Identifier: LGPL-3.0-or-other
// Copyright (C) 2021 Contributors to the SLS Detector Package
/* This example assumes that you have a ctb configured or using the virtual ctb detector server*/
#include "sls/Detector.h"
#include "sls/bit_utils.h"
#include <iostream>
void somefunc(uint32_t addr){
std::cout << "somefunc called with: " << addr << std::endl;
}
int main(){
// Config file has the following defines
// define addr somereg 0x5
// define bit mybit somereg 7
sls::Detector d;
auto somereg = d.getRegisterDefinition("somereg");
d.writeRegister(somereg, sls::RegisterValue(0));
auto val = d.readRegister(somereg);
std::cout << "somereg has the address: " << somereg << " and value " << val.squash() << std::endl;
auto mybit = d.getBitDefinition("mybit");
std::cout << "mybit refers to register: " << mybit.address() << " bit nr: " << mybit.bitPosition() << std::endl;
d.setBit(mybit);
val = d.readRegister(somereg);
std::cout << "somereg has the address: " << somereg << " and value " << val.squash() << std::endl;
std::cout << "mybit: " << d.getBit(mybit) << std::endl;
//Let's define a bit
sls::BitAddress newbit(sls::RegisterAddress(0x6), 4);
d.setBitDefinition("newbit", newbit);
//This can now be usef from command line "g getbit newbit"
uint32_t addr = somereg; //I'm not sure this should compile
somefunc(somereg); //This should also not compile
}