Skip to content
This repository was archived by the owner on Jul 8, 2022. It is now read-only.

Commit 6fa50bb

Browse files
authored
Merge pull request #692 from mliszcz/fix-401-alarm-range-for-memorized
Always allow to change attribute alarm thresholds
2 parents 7c65021 + 1667935 commit 6fa50bb

File tree

3 files changed

+74
-2
lines changed

3 files changed

+74
-2
lines changed

cpp_test_suite/new_tests/cxx_attr_misc.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,6 +1078,30 @@ cout << "status = " << status << endl;
10781078
#undef QUOTE
10791079
#undef __QUOTE
10801080

1081+
/*
1082+
* Test for changing alarm treshold to value lower than currently read from
1083+
* hardware. Attribute should have alarm quality after property change.
1084+
*/
1085+
1086+
void test_change_max_alarm_threshold_below_current_value()
1087+
{
1088+
const char* attr_name = "Short_attr_rw";
1089+
const DevShort attr_value = 20;
1090+
1091+
DeviceAttribute value(attr_name, attr_value);
1092+
TS_ASSERT_THROWS_NOTHING(device1->write_attribute(value));
1093+
1094+
TS_ASSERT_EQUALS(Tango::ON, device1->state());
1095+
TS_ASSERT_EQUALS(Tango::ATTR_VALID, device1->read_attribute(attr_name).get_quality());
1096+
1097+
auto config = device1->get_attribute_config(attr_name);
1098+
config.alarms.max_alarm = std::to_string(attr_value - 1);
1099+
AttributeInfoListEx config_in = { config };
1100+
TS_ASSERT_THROWS_NOTHING(device1->set_attribute_config(config_in));
1101+
1102+
TS_ASSERT_EQUALS(Tango::ALARM, device1->state());
1103+
TS_ASSERT_EQUALS(Tango::ATTR_ALARM, device1->read_attribute(attr_name).get_quality());
1104+
}
10811105
};
10821106
#undef cout
10831107
#endif // AttrMiscTestSuite_h

cpp_test_suite/new_tests/cxx_mem_attr.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,54 @@ class MemAttrTestSuite: public CxxTest::TestSuite
166166
TS_ASSERT(s_val_2 == 10);
167167
}
168168

169+
/*
170+
* Test for changing min and max alarm threshold of a memorized attribute
171+
* with neither min_ nor max_value specified. Such scenario used to fail
172+
* (#401), with misleading error message claiming that memorized value
173+
* is above new limit.
174+
*/
175+
176+
void test_change_max_alarm_threshold_of_memorized_attribute()
177+
{
178+
const char* attr_name = "Short_attr_w";
179+
const DevShort attr_value = 20;
180+
181+
unset_attribute_min_max_value(attr_name);
182+
183+
DeviceAttribute value(attr_name, attr_value);
184+
TS_ASSERT_THROWS_NOTHING(device1->write_attribute(value));
185+
186+
auto config = device1->get_attribute_config(attr_name);
187+
config.alarms.max_alarm = std::to_string(attr_value + 1);
188+
AttributeInfoListEx config_in = { config };
189+
TS_ASSERT_THROWS_NOTHING(device1->set_attribute_config(config_in));
190+
}
191+
192+
void test_change_min_alarm_threshold_of_memorized_attribute()
193+
{
194+
const char* attr_name = "Short_attr_w";
195+
const DevShort attr_value = -20;
196+
197+
unset_attribute_min_max_value(attr_name);
198+
199+
DeviceAttribute value(attr_name, attr_value);
200+
TS_ASSERT_THROWS_NOTHING(device1->write_attribute(value));
201+
202+
auto config = device1->get_attribute_config(attr_name);
203+
config.alarms.min_alarm = std::to_string(attr_value - 1);
204+
AttributeInfoListEx config_in = { config };
205+
TS_ASSERT_THROWS_NOTHING(device1->set_attribute_config(config_in));
206+
}
207+
208+
void unset_attribute_min_max_value(const char* attr_name)
209+
{
210+
auto config = device1->get_attribute_config(attr_name);
211+
config.min_value = AlrmValueNotSpec;
212+
config.max_value = AlrmValueNotSpec;
213+
AttributeInfoListEx config_in = { config };
214+
TS_ASSERT_THROWS_NOTHING(device1->set_attribute_config(config_in));
215+
}
169216
};
217+
170218
#undef cout
171219
#endif // MemAttrTestSuite_h

cppapi/server/attrgetsetprop.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1320,12 +1320,12 @@ void Attribute::set_one_alarm_prop(const char *prop_name,const CORBA::String_mem
13201320
{
13211321
WAttribute *w_att = static_cast<WAttribute *>(this);
13221322
std::string mem_value;
1323-
if (strcmp(prop_name,"min_value") == 0 || strcmp(prop_name,"min_alarm") == 0)
1323+
if (strcmp(prop_name,"min_value") == 0)
13241324
{
13251325
if ((w_att->is_memorized() == true) && (w_att->mem_value_below_above(MIN,mem_value) == true))
13261326
throw_min_max_value(d_name,mem_value,MIN);
13271327
}
1328-
else if (strcmp(prop_name,"max_value") == 0 || strcmp(prop_name,"max_alarm") == 0)
1328+
else if (strcmp(prop_name,"max_value") == 0)
13291329
{
13301330
if ((w_att->is_memorized() == true) && (w_att->mem_value_below_above(MAX,mem_value) == true))
13311331
throw_min_max_value(d_name,mem_value,MAX);

0 commit comments

Comments
 (0)