/* * DefaultValueAutomation.cpp * Helper to fill default fields of GSI template properties automatically */ #include #include "DefaultValueAutomation.h" namespace { cmw::log::Logger& logger = cmw::log::LoggerFactory::getLogger("FESA.USR.AnOpClass.RealTime.UserCode.DefaultValueAutomation"); } // namespace DefaultValueAutomation::DefaultValueAutomation() { } DefaultValueAutomation::~DefaultValueAutomation() { } /** * Provide default data for GSI specific data fields required by GSI template. * Requires adaption of the class name as namespace and in the includes. * * !Requires most probably adaption of the default values set as they are hardware dependent! * * Usage in RT action: * const fesa::MultiplexingContext* context = pEvt->getMultiplexingContext(); static_cast(context); // This line prevents an "unused variable" warning, it can be removed safely. const Devices& devices = getFilteredDeviceCollection(pEvt); for (Devices::const_iterator it = devices.begin(); it != devices.end(); ++it) { try { Device* device = *it; static_cast(device); // This line prevents an "unused variable" warning, it can be removed safely. // Apply default settings per device DataFillAutomation dfa; dfa.fillAutomaticallyInRTAction(pEvt, device); } catch (const fesa::FesaException& exception) { LOG_ERROR_IF(logger, exception.getMessage()); } } * */ void DefaultValueAutomation::fillDefaultDataAutomaticallyInRTAction(fesa::RTEvent* pEvt, AnOpClass::Device* device ) { try { std::cout << "TRACE: " __FILE__ << ": " << __FUNCTION__ << ": Line " << __LINE__ << " START " << std::endl; fesa::MultiplexingContext* context = pEvt->getMultiplexingContext(); // signal status "error" device->status.set(AnOpClass::DEVICE_STATUS::UNKNOWN, context); //set the detailed status array whole bool detailedStatus[AnOpClass::DETAILED_STATUS_SIZE] = { false, false}; device->detailedStatus.set(detailedStatus,AnOpClass::DETAILED_STATUS_SIZE,context); // set the detailed status items by index device->detailedStatus.lower(0, context); device->detailedStatus.raise(1, context); // alternatively: set the detailed status items by label name //device->detailedStatus.setBit("aStatusLabel0", false, context); //device->detailedStatus.set("aStatusLabel1", true, context); //device->detailedStatus.setCell(1, true, context); // signal that the device is turned on device->powerState.set(AnOpClass::DEVICE_POWER_STATE::ON, context); // signal that the device is set to local control device->control.set(AnOpClass::DEVICE_CONTROL::LOCAL, context); // signal the interlock status device->interlock.set(false, context); // signal the status of the device for operation according to the error status device->opReady.set(false, context); device->moduleStatus.set("myModule1", AnOpClass::MODULE_STATUS::NOT_AVAILABLE,context); device->moduleStatus.setCell( AnOpClass::MODULE_STATUS::OK ,1,context); // true if all hardware and software modules, which are required to operate the device are ready device->modulesReady.set(false, context); // invent a time stamp //int64_t stamp = fesa::getSystemTime(); int64_t realtimestamp = pEvt->getMultiplexingContext()->getTimeStamp(); device->acquisitionContext.insert(context, realtimestamp); // signal an error //std::string errorString= "This is a test error"; //int32_t error_code= 4711; //device->error_collection.addError(error_code, errorString, context, device); std::cout << "TRACE: " __FILE__ << ": " << __FUNCTION__ << ": Line " << __LINE__ << " END " << std::endl; } catch ( const std::exception& e ) { std::cout << e.what() << std::endl; std::ostringstream message; message << "Error in RT-Action:" << e.what(); LOG_ERROR_IF(logger, message.str()); throw; } }