Skip to content
Snippets Groups Projects
Commit 7b0db877 authored by Alexandre MALFREYT's avatar Alexandre MALFREYT
Browse files

fix: enhance error handling and add comments in get_device_property()

parent 22905c6e
No related branches found
No related tags found
No related merge requests found
...@@ -736,6 +736,8 @@ void SingleShotAO::get_device_property() ...@@ -736,6 +736,8 @@ void SingleShotAO::get_device_property()
// Create properties if empty and set default values // Create properties if empty and set default values
//-------------------------------------------- //--------------------------------------------
DEBUG_STREAM << "Creating properties if empty" << endl; DEBUG_STREAM << "Creating properties if empty" << endl;
// boardNum, boardType, enableRamps and outputMemorizedChannelsAtInit variables
// contain the default values at this point if the properties are not set in the database.
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, boardNum, "BoardNum"); yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, boardNum, "BoardNum");
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, boardType, "BoardType"); yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, boardType, "BoardType");
yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, enableRamps, "EnableRamps"); yat4tango::PropertyHelper::create_property_if_empty(this, dev_prop, enableRamps, "EnableRamps");
...@@ -746,8 +748,11 @@ void SingleShotAO::get_device_property() ...@@ -746,8 +748,11 @@ void SingleShotAO::get_device_property()
DEBUG_STREAM << "Checking if critical properties are valid:" << endl; DEBUG_STREAM << "Checking if critical properties are valid:" << endl;
critical_properties_missing = false; critical_properties_missing = false;
yat::OSStream errorMessages; yat::OSStream errorMessages;
errorMessages << "\nCritical properties are missing or invalid:\n" << endl;
//- <BoardNum> ----------------------- //- <BoardNum> -----------------------
// Case 1 (error): boardNum is set to the default value in the database
// (compare the current value with the default value)
Tango::DbDatum &boardNumDatum = Tango::DbDatum("BoardNum"); Tango::DbDatum &boardNumDatum = Tango::DbDatum("BoardNum");
std::string defaultBoardNum_str; std::string defaultBoardNum_str;
def_prop = ds_class->get_default_device_property(boardNumDatum.name); def_prop = ds_class->get_default_device_property(boardNumDatum.name);
...@@ -756,20 +761,24 @@ void SingleShotAO::get_device_property() ...@@ -756,20 +761,24 @@ void SingleShotAO::get_device_property()
if (boardNum == defaultBoardNum) if (boardNum == defaultBoardNum)
{ {
errorMessages << "Device property <BoardNum> is not set (default value " << defaultBoardNum << " needs to be replaced)" << endl; errorMessages << "Device property <BoardNum> is not set (default value " << defaultBoardNum << " needs to be replaced)" << endl;
ERROR_STREAM << "Device property <BoardNum> is not set (default value " << defaultBoardNum << " needs to be replaced)" << endl;
critical_properties_missing = true; critical_properties_missing = true;
} }
// Case 2 (error): boardNum is set to a value outside the valid range
else if (boardNum < 0 || boardNum > 7) else if (boardNum < 0 || boardNum > 7)
{ {
boardNum = 0; boardNum = 0;
errorMessages << "Device property <BoardNum> is invalid. Valid range is [0..7]" << endl; errorMessages << "Device property <BoardNum> is invalid. Valid range is [0..7]" << endl;
ERROR_STREAM << "Device property <BoardNum> is invalid. Valid range is [0..7]" << endl;
critical_properties_missing = true; critical_properties_missing = true;
} else { }
// Case 3 (ok): boardNum is set to a valid value
else
{
INFO_STREAM << "BoardNum resolved to " << boardNum << endl; INFO_STREAM << "BoardNum resolved to " << boardNum << endl;
} }
//- <BoardType> ----------------------- //- <BoardType> -----------------------
// Case 1 (error): boardType is set to the default value in the database
// (compare the current value with the default value)
Tango::DbDatum &boardTypeDatum = Tango::DbDatum("BoardType"); Tango::DbDatum &boardTypeDatum = Tango::DbDatum("BoardType");
std::string defaultBoardType; std::string defaultBoardType;
def_prop = ds_class->get_default_device_property(boardTypeDatum.name); def_prop = ds_class->get_default_device_property(boardTypeDatum.name);
...@@ -777,9 +786,9 @@ void SingleShotAO::get_device_property() ...@@ -777,9 +786,9 @@ void SingleShotAO::get_device_property()
if (boardType == defaultBoardType) if (boardType == defaultBoardType)
{ {
errorMessages << "Device property <BoardType> is not set (default value " << defaultBoardType << " needs to be replaced)" << endl; errorMessages << "Device property <BoardType> is not set (default value " << defaultBoardType << " needs to be replaced)" << endl;
ERROR_STREAM << "Device property <BoardType> is not set (default value " << defaultBoardType << " needs to be replaced)" << endl;
critical_properties_missing = true; critical_properties_missing = true;
} }
// Case 2 (ok): boardType is set to a valid
else if (boardType == "MAO_6208") else if (boardType == "MAO_6208")
{ {
boardType = k6208_BOARD_TYPE; boardType = k6208_BOARD_TYPE;
...@@ -792,15 +801,16 @@ void SingleShotAO::get_device_property() ...@@ -792,15 +801,16 @@ void SingleShotAO::get_device_property()
boardTypeId = adl::PCI6216; boardTypeId = adl::PCI6216;
INFO_STREAM << "BoardType resolved to PCI6216" << endl; INFO_STREAM << "BoardType resolved to PCI6216" << endl;
} }
// Case 3 (error): boardType is set to an invalid value
else else
{ {
boardType = kDEFAULT_BOARD_TYPE; boardType = kDEFAULT_BOARD_TYPE;
boardTypeId = adl::PCI6208; boardTypeId = adl::PCI6208;
errorMessages << "Device property <BoardType> is invalid [supported hw: MAO_6208 or MAO_6216]" << endl; errorMessages << "Device property <BoardType> is invalid [supported hw: MAO_6208 or MAO_6216]" << endl;
ERROR_STREAM << "Device property <BoardType> is invalid [supported hw: MAO_6208 or MAO_6216]" << endl;
critical_properties_missing = true; critical_properties_missing = true;
} }
// If any critical property is missing or invalid, throw an exception
if (critical_properties_missing) if (critical_properties_missing)
{ {
DEBUG_STREAM << "Critical properties are missing, throwing exception." << endl; DEBUG_STREAM << "Critical properties are missing, throwing exception." << endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment