From ef844f754a22a102301fb9a97bb3b497b6f626a6 Mon Sep 17 00:00:00 2001 From: s171894 <s171894@student.pg.edu.pl> Date: Tue, 15 Jun 2021 01:39:29 +0200 Subject: [PATCH] =?UTF-8?q?Kontrola=20d=C5=82ugo=C5=9Bci=20wiadomo=C5=9Bci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Decoder/decode_messages.py | 16 ++++++++++++---- Reader/read_file.py | 7 +++++++ main.py | 4 ++++ 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Decoder/decode_messages.py b/Decoder/decode_messages.py index 6c6604c..c7742b5 100644 --- a/Decoder/decode_messages.py +++ b/Decoder/decode_messages.py @@ -6,7 +6,7 @@ from Decoder import dictionaries # specyficzne typy wiadomoĹci need_adjustment = ["8_6", "24", "25", "26"] has_array = ['6_2', '6_7', '6_8', '6_9', '6_11', '7', '8_4', '8_7', '8_9', '8_10', '8_15', '20'] -shorter_than_expected = ["15", "16", "21"] +shorter_than_expected = {"15":88, "16":96, "21":272} is_type_26 = ["26_00", "26_10", "26_01", "26_11"] @@ -29,11 +29,19 @@ def decode_message(message): return "message data error" shorter_in_wild = ["24_A", "24_B"] - length_exceptions = shorter_in_wild + shorter_than_expected + length_exceptions = shorter_in_wild + list(shorter_than_expected.keys()) + if message["type"] not in list(message_aggregates.datapartsBitlengths.keys()): + print("Nielegalny klucz: " + message["type"]) expected_length = sum(message_aggregates.datapartsBitlengths[message["type"]]) if (len(message["message"]) < expected_length) and (message["type"] not in length_exceptions): return "message data error" + if (message["type"] in list(shorter_than_expected.keys())): + min_length = shorter_than_expected[message["type"]] + if len(message["message"]) < min_length: + return "message data error" + + mainfields_bitstrings = split_to_fields(message) dataParts = decode_bitstrings(mainfields_bitstrings, message) @@ -141,7 +149,7 @@ def split_to_fields(message): i = 0 position = 0 fragment = [] - if message["type"] in shorter_than_expected: + if message["type"] in list(shorter_than_expected.keys()): field_count = len(shorten_message(message)) else: field_count = len(message_aggregates.datapartsBitlengths[message["type"]]) @@ -172,7 +180,7 @@ def decode_bitstrings(bit_strings, message): i = 0 dataParts = [] - if message["type"] in shorter_than_expected: + if message["type"] in list(shorter_than_expected.keys()): field_count = len(shorten_message(message)) else: field_count = len(message_aggregates.datapartsBitlengths[message["type"]]) diff --git a/Reader/read_file.py b/Reader/read_file.py index 9819692..fcdf2a6 100644 --- a/Reader/read_file.py +++ b/Reader/read_file.py @@ -1,5 +1,8 @@ from Reader import counters from Aggregates import message_aggregates + +line_counter = 0 + def read_message(file): """Odczytuje Zwraca sĹownik typ wiadomoĹci i informacjÄ uĹźytecznÄ , zlicza liczbÄ odczytanych wiadomoĹci oraz liczbÄ wiadomoĹci, ktĂłrych suma kontrolna jest bĹÄdna @@ -72,6 +75,7 @@ def read_message_lines(file): elif len(lines) == 2: counters.double_line_counter += 1 + line_counter + len(lines) return lines def extract_data(line): @@ -208,6 +212,9 @@ def add_type(payload): type_bin = payload[0:6] type_dec = int(type_bin, 2) + if (type_dec < 1) or (type_dec > 27): + return "message data error" + message = { "type": str(type_dec), "message": payload diff --git a/main.py b/main.py index 52fde38..86538c1 100644 --- a/main.py +++ b/main.py @@ -14,6 +14,10 @@ def main(): if message == "message data error": continue else: + # if message["type"] == "21": + # print("Linia: {}".format(reader.line_counter)) + # print("wiadomoĹÄ: {}".format(message)) + # print("dĹugoĹÄ: {}".format(len(message["message"]))) message_decoded = decoder.decode_message(message) if message_decoded == "message data error": continue -- GitLab