diff --git a/src/UKHASExtractor.cxx b/src/UKHASExtractor.cxx index a640163..41049f4 100644 --- a/src/UKHASExtractor.cxx +++ b/src/UKHASExtractor.cxx @@ -320,18 +320,19 @@ static void attempt_settings(Json::Value &data, const Json::Value &sentence, const string &checksum_name, const vector &parts) { - if (!sentence.isObject()) - throw runtime_error("Invalid configuration (sentence not an object)"); + if (!sentence.isObject() || !sentence["callsign"].isString() || + !sentence["fields"].isArray() || !sentence["fields"].size()) + throw runtime_error("Invalid configuration " + "(missing callsign or fields)"); - const Json::Value &fields = sentence["fields"]; - - const string callsign = sentence["payload"].asString(); - if (parts[0] != callsign) + if (sentence["callsign"] != parts[0]) throw runtime_error("Incorrect callsign"); if (sentence["checksum"] != checksum_name) throw runtime_error("Wrong checksum type"); + const Json::Value &fields = sentence["fields"]; + if (fields.size() != (parts.size() - 1)) throw runtime_error("Incorrect number of fields"); diff --git a/tests/test_extractor.py b/tests/test_extractor.py index 59c19cb..74f3063 100644 --- a/tests/test_extractor.py +++ b/tests/test_extractor.py @@ -233,7 +233,7 @@ class TestUKHASExtractor: crude_parse_flight_doc = { "sentences": [ { - "payload": "TESTING", + "callsign": "TESTING", "checksum": "crc16-ccitt", "fields": [ {"name": "field_a"}, @@ -281,10 +281,10 @@ class TestUKHASExtractor: multi_config_flight_doc = { "sentences": [ - { "payload": "AWKWARD", + { "callsign": "AWKWARD", "checksum": "crc16-ccitt", "fields": [ {"name": "fa"}, {"name": "fo"}, {"name": "fc"} ] }, - { "payload": "AWKWARD", + { "callsign": "AWKWARD", "checksum": "crc16-ccitt", "fields": [ {"name": "fa"}, {"name": "fb"} ] } ] @@ -312,7 +312,7 @@ class TestUKHASExtractor: ddmmmmmm_flight_doc = { "sentences": [ { - "payload": "TESTING", + "callsign": "TESTING", "checksum": "crc16-ccitt", "fields": [ {"sensor":"stdtelem.coordinate","name":"lat_a",