mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-12-27 22:51:19 +01:00
added example using bits
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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: "
|
||||
|
||||
49
sample/using_registers.cpp
Normal file
49
sample/using_registers.cpp
Normal 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
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user