Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- from Agregates import arrays_aggregates
- from Decoder import decode_fragment
- def switch_first_array(type, message):
- array_dictionary = {
- '6_2': 1,
- '6_7': 29,
- '6_8': 10,
- '6_9': 11,
- '6_11': 12,
- '7': 13,
- '8_4': 14,
- '8_7': 29,
- '8_9': 15,
- '8_10': 11,
- '8_15': 27,
- '20': 28
- }
- decode_array(type, message, array_dictionary[type])
- def decode_array(type, message, key):
- i = 0
- Array = []
- position = 0
- fragment = ''
- field_bits = 0
- type_dictionary = {
- 'u': decode_fragment.decode_u_int(fragment),
- 'e': decode_fragment.decode_u_int(fragment),
- 'b': decode_fragment.decode_u_int(fragment),
- 'x': "empty",
- 't': decode_fragment.decode_t(fragment),
- 's': decode_fragment.decode_s_int(fragment, field_bits),
- 'I1': decode_fragment.decode_IX(fragment, field_bits, 1),
- 'I2': decode_fragment.decode_IX(fragment, field_bits, 2),
- 'I3': decode_fragment.decode_IX(fragment, field_bits, 3),
- 'I4': decode_fragment.decode_IX(fragment, field_bits, 4),
- 'U1': decode_fragment.decode_UX(fragment, 1),
- 'U2': decode_fragment.decode_UX(fragment, 2),
- 'd': message[position:(field_bits + position)]
- }
- ### pojedyncze arraye
- if key < 29 & key != 15:
- field_count = len(arrays_aggregates.arraysDataBitlengths[key])
- while i < field_count:
- field_bits = arrays_aggregates.arraysDataBitlengths[key][i]
- field_type = arrays_aggregates.arraysDataTypes[key][i]
- fragment = message[position:(field_bits + position)]
- Array[i] = type_dictionary[field_type(fragment, field_bits)] ##czy taki zaspis zadziałą?
- # MARTA: do linijki wyżej, czy nie wystarczy type_dictionary[field_type]
- position += field_bits
- i +=1
- ### arraye typu 8_9 %% do poprawy, musi liczyć bity wiadomości
- # i je przetwarzać aby określić jakie payloady się tu znajdują
- if key == 15:
- i = 0
- position = 0
- while i < 12: ### i-ty while leci po kolejnych typach weather array
- field_count = len(arrays_aggregates.arraysDataBitlengths[i+15])
- j = 0
- # j-ta iteracja idzie po kolejnych polach i-tych arrayów
- while j < field_count:
- field_bits = arrays_aggregates.arraysDataBitlengths[i+15][j]
- field_type = arrays_aggregates.arraysDataTypes[i+15][j]
- fragment = message[position:(field_bits + position)]
- Array[i][j] = type_dictionary[field_type]
- position += position # MARTA: ??????
- j += 1
- i += 1
- ##### MARTA ##### 8_9 #####
- report_dictionary = {
- '0000': 16, '0001': 17, '0010': 18, '0011': 19, '0100': 20, '0101': 21, '0110': 22, '0111': 23, '1000': 24, '1001': 25, '1010': 26
- }
- if key == 15:
- i = 0
- k = 1
- position = 57
- reportType = 0
- reportNumber = math.floor((len(message) - 56)/112)
- field_count = len(arrays_aggregates.arraysDataBitlengths[15])
- for n in range(reportNumber+1): #pętla od 0 do reportNumber
- while i < (field_count - 1): #chcę o jedno pole mniej, żeby ominąć payload (który jest ogarniany niżej), ale pytanie czy to nie leci od 0, więc musi być -2
- if i == 0:
- reportNumber = str(message[position])+str(message[position+1])+str(message[position+2])+str(message[position+3])
- reportType = report_dictionary[reportNumber]
- field_bits = arrays_aggregates.arraysDataBitlengths[key][i]
- field_type = arrays_aggregates.arraysDataTypes[key][i]
- fragment = message[position:(field_bits + position)]
- Array[i] = type_dictionary[field_type(fragment, field_bits)] # MARTA: czy nie wystarczy type_dictionary[field_type]
- position += field_bits
- i += 1
- #jak wyjdzie z pętli, czyli dla ostatniego field_count :
- field_reportType_count = len(arrays_aggregates.arraysDataBitlengths[reportType])
- while k < (field_reportType_count + 1):
- field_bits = arrays_aggregates.arraysDataBitlengths[reportType][i]
- field_type = arrays_aggregates.arraysDataTypes[reportType][i]
- fragment = message[position:(field_bits + position)]
- Array[i + k] = type_dictionary[field_type(fragment, field_bits)] # MARTA: czy nie wystarczy type_dictionary[field_type]
- k += 1
- position += field_bits
- position += 1
- ##### MARTA #####
- shape_dictionary = {
- '000': 2, '001': 3, '010':4, '011':5 | 6, '100':7, '101':9
- }
- if key == 29:
- return Array
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement