diff --git a/sample/CMakeLists.txt b/sample/CMakeLists.txt index 732bd31cd..e1238106d 100644 --- a/sample/CMakeLists.txt +++ b/sample/CMakeLists.txt @@ -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 diff --git a/sample/using_logger.cpp b/sample/using_logger.cpp index 7557d5c83..0019ca327 100644 --- a/sample/using_logger.cpp +++ b/sample/using_logger.cpp @@ -3,15 +3,23 @@ #include "sls/logger.h" #include #include + +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: " diff --git a/sample/using_registers.cpp b/sample/using_registers.cpp new file mode 100644 index 000000000..e3a2f44ff --- /dev/null +++ b/sample/using_registers.cpp @@ -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 + + +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 + + +} \ No newline at end of file