check for invalid divisor/values for string and value list based types

This commit is contained in:
john30
2015-09-26 11:31:24 +02:00
parent 3b381468fd
commit c0b022782f
2 changed files with 16 additions and 1 deletions
+4
View File
@@ -371,6 +371,8 @@ result_t SingleDataField::create(const char* typeNameStr, const unsigned char le
case bt_hexstr:
case bt_dat:
case bt_tim:
if (divisor != 0 || !values.empty())
return RESULT_ERR_INVALID_ARG; // cannot set divisor or values for string field
returnField = new StringDataField(name, comment, unit, *dataType, partType, byteCount);
return RESULT_OK;
case bt_num:
@@ -409,6 +411,8 @@ result_t SingleDataField::create(const char* typeNameStr, const unsigned char le
|| values.rbegin()->first > dataType->maxValueOrLength)
return RESULT_ERR_OUT_OF_RANGE;
if (divisor != 0)
return RESULT_ERR_INVALID_ARG; // cannot use divisor != 1 for value list field
//TODO add special field for fixed values (exactly one value in the list of values)
returnField = new ValueListDataField(name, comment, unit, *dataType, partType, byteCount, bitCount, values);
return RESULT_OK;
+12 -1
View File
@@ -44,17 +44,21 @@ void verify(bool expectFailMatch, string type, string input,
int main()
{
string checks[][5] = {
//name;[len];type[;[divisor|values][;[unit][;[comment]]]], decoded value, master, slave, flags
// entry: definition, decoded value, master data, slave data, flags
// definition: name,part,type[:len][,[divisor|values][,[unit][,[comment]]]]
{"x,,ign:10", "", "10fe07000a00000000000000000000", "00", ""},
{"x,,ign,2", "", "", "", "c"},
{"x,,str:10", "Hallo, Du!", "10fe07000a48616c6c6f2c20447521", "00", ""},
{"x,,str:10", "Hallo, Du!", "10fe07000a48616c6c6f2c20447521", "00", ""},
{"x,,str:10", "Hallo, Du ", "10fe07000a48616c6c6f2c20447520", "00", ""},
{"x,,str:10", " ", "10fe07000a20202020202020202020", "00", ""},
{"x,,str:11", "", "10fe07000a20202020202020202020", "00", "rW"},
{"x,,str:24", "abcdefghijklmnopqrstuvwx", "10fe0700186162636465666768696a6b6c6d6e6f707172737475767778", "00", ""},
{"x,,str,2", "", "", "", "c"},
{"x,,hex", "20", "10fe07000120", "00", ""},
{"x,,hex:10", "48 61 6c 6c 6f 2c 20 44 75 21", "10fe07000a48616c6c6f2c20447521", "00", ""},
{"x,,hex:11", "", "10fe07000a48616c6c6f2c20447521", "00", "rW"},
{"x,,hex,2", "", "", "", "c"},
{"x,,bda", "26.10.2014","10fe07000426100614", "00", ""}, // Sunday
{"x,,bda", "01.01.2000","10fe07000401010500", "00", ""}, // Saturday
{"x,,bda", "31.12.2099","10fe07000431120399", "00", ""}, // Thursday
@@ -65,6 +69,7 @@ int main()
{"x,,bda:3", "31.12.2099","10fe070003311299", "00", ""},
{"x,,bda:3", "-.-.-", "10fe070003000000", "00", ""},
{"x,,bda:3", "", "10fe070003321299", "00", "rw"},
{"x,,bda,2", "", "", "", "c"},
{"x,,hda", "26.10.2014","10fe0700041a0a070e", "00", ""}, // Sunday
{"x,,hda", "01.01.2000","10fe07000401010600", "00", ""}, // Saturday
{"x,,hda", "31.12.2099","10fe0700041f0c0463", "00", ""}, // Thursday
@@ -75,24 +80,30 @@ int main()
{"x,,hda:3", "31.12.2099","10fe0700031f0c63", "00", ""},
{"x,,hda:3", "-.-.-", "10fe070003000000", "00", ""},
{"x,,hda:3", "", "10fe070003200c63", "00", "rw"},
{"x,,hda,2", "", "", "", "c"},
{"x,,bti", "21:04:58", "10fe070003580421", "00", ""},
{"x,,bti", "00:00:00", "10fe070003000000", "00", ""},
{"x,,bti", "23:59:59", "10fe070003595923", "00", ""},
{"x,,bti", "", "10fe070003605923", "00", "rw"},
{"x,,bti,2", "", "", "", "c"},
{"x,,hti", "21:04:58", "10fe07000315043a", "00", ""},
{"x,,hti,2", "", "", "", "c"},
{"x,,vti", "21:04:58", "10fe0700033a0415", "00", ""},
{"x,,vti", "-:-:-", "10fe070003636363", "00", ""},
{"x,,vti,2", "", "", "", "c"},
{"x,,htm", "21:04", "10fe0700021504", "00", ""},
{"x,,htm", "00:00", "10fe0700020000", "00", ""},
{"x,,htm", "23:59", "10fe070002173b", "00", ""},
{"x,,htm", "24:00", "10fe0700021800", "00", ""},
{"x,,htm", "", "10fe070002183b", "00", "rw"},
{"x,,htm", "24:01", "10fe0700021801", "00", "rw"},
{"x,,htm,2", "", "", "", "c"},
{"x,,ttm", "22:40", "10fe07000188", "00", ""},
{"x,,ttm", "00:00", "10fe07000100", "00", ""},
{"x,,ttm", "23:50", "10fe0700018f", "00", ""},
{"x,,ttm", "-:-", "10fe07000190", "00", ""},
{"x,,ttm", "", "10fe07000191", "00", "rw"},
{"x,,ttm,2", "", "", "", "c"},
{"x,,bdy", "Mon", "10fe07000300", "00", ""},
{"x,,bdy", "Sun", "10fe07000306", "00", ""},
{"x,,bdy", "", "10fe07000308", "00", "rw"},