Advertisement
martaczaska

array_decoder

May 21st, 2021
1,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.09 KB | None | 0 0
  1. import math
  2. from Agregates import arrays_aggregates
  3. from Decoder import decode_fragment
  4.  
  5. def switch_first_array(type, message):
  6.     array_dictionary = {
  7.             '6_2': 1,
  8.             '6_7': 29,
  9.             '6_8': 10,
  10.             '6_9': 11,
  11.             '6_11': 12,
  12.             '7': 13,
  13.             '8_4': 14,
  14.             '8_7': 29,
  15.             '8_9': 15,
  16.             '8_10': 11,
  17.             '8_15': 27,
  18.             '20': 28
  19.         }
  20.     decode_array(type, message, array_dictionary[type])
  21.  
  22.  
  23. def decode_array(type, message, key):
  24.     i = 0
  25.     Array = []
  26.     position = 0
  27.     fragment = ''
  28.     field_bits = 0
  29.     type_dictionary = {
  30.                 'u': decode_fragment.decode_u_int(fragment),
  31.                 'e': decode_fragment.decode_u_int(fragment),
  32.                 'b': decode_fragment.decode_u_int(fragment),
  33.                 'x': "empty",
  34.                 't': decode_fragment.decode_t(fragment),
  35.                 's': decode_fragment.decode_s_int(fragment, field_bits),
  36.                 'I1': decode_fragment.decode_IX(fragment, field_bits, 1),
  37.                 'I2': decode_fragment.decode_IX(fragment, field_bits, 2),
  38.                 'I3': decode_fragment.decode_IX(fragment, field_bits, 3),
  39.                 'I4': decode_fragment.decode_IX(fragment, field_bits, 4),
  40.                 'U1': decode_fragment.decode_UX(fragment, 1),
  41.                 'U2': decode_fragment.decode_UX(fragment, 2),
  42.                 'd': message[position:(field_bits + position)]      
  43.             }
  44.     ### pojedyncze arraye
  45.     if key < 29 & key != 15:
  46.         field_count = len(arrays_aggregates.arraysDataBitlengths[key])
  47.         while i < field_count:
  48.             field_bits = arrays_aggregates.arraysDataBitlengths[key][i]
  49.             field_type = arrays_aggregates.arraysDataTypes[key][i]
  50.             fragment = message[position:(field_bits + position)]
  51.             Array[i] = type_dictionary[field_type(fragment, field_bits)] ##czy taki zaspis zadziałą?
  52.             # MARTA: do linijki wyżej, czy nie wystarczy  type_dictionary[field_type]
  53.             position += field_bits
  54.             i +=1
  55.    
  56.     ### arraye typu 8_9   %% do poprawy, musi liczyć bity wiadomości
  57.     # i je przetwarzać aby określić jakie payloady się tu znajdują  
  58.     if key == 15:
  59.         i = 0
  60.         position = 0
  61.         while i < 12:    ### i-ty while leci po kolejnych typach weather array
  62.             field_count = len(arrays_aggregates.arraysDataBitlengths[i+15])
  63.             j = 0
  64.             # j-ta iteracja idzie po kolejnych polach i-tych arrayów
  65.             while j < field_count:
  66.                 field_bits = arrays_aggregates.arraysDataBitlengths[i+15][j]
  67.                 field_type = arrays_aggregates.arraysDataTypes[i+15][j]
  68.                 fragment = message[position:(field_bits + position)]
  69.                 Array[i][j] = type_dictionary[field_type]
  70.                 position += position    # MARTA: ??????
  71.                 j += 1
  72.             i += 1
  73.  
  74.     ##### MARTA ##### 8_9 #####
  75.     report_dictionary = {
  76.         '0000': 16, '0001': 17, '0010': 18, '0011': 19, '0100': 20, '0101': 21, '0110': 22, '0111': 23, '1000': 24, '1001': 25, '1010': 26
  77.     }
  78.  
  79.     if key == 15:
  80.         i = 0
  81.         k = 1
  82.         position = 57
  83.         reportType = 0
  84.         reportNumber = math.floor((len(message) - 56)/112)
  85.         field_count = len(arrays_aggregates.arraysDataBitlengths[15])
  86.  
  87.         for n in range(reportNumber+1): #pętla od 0 do reportNumber
  88.             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
  89.                 if i == 0:
  90.                     reportNumber = str(message[position])+str(message[position+1])+str(message[position+2])+str(message[position+3])
  91.                     reportType = report_dictionary[reportNumber]
  92.  
  93.                 field_bits = arrays_aggregates.arraysDataBitlengths[key][i]
  94.                 field_type = arrays_aggregates.arraysDataTypes[key][i]
  95.                 fragment = message[position:(field_bits + position)]
  96.                 Array[i] = type_dictionary[field_type(fragment, field_bits)] # MARTA: czy nie wystarczy  type_dictionary[field_type]
  97.                 position += field_bits
  98.                 i += 1
  99.  
  100.             #jak wyjdzie z pętli, czyli dla ostatniego field_count :
  101.             field_reportType_count = len(arrays_aggregates.arraysDataBitlengths[reportType])
  102.             while k < (field_reportType_count + 1):
  103.                 field_bits = arrays_aggregates.arraysDataBitlengths[reportType][i]
  104.                 field_type = arrays_aggregates.arraysDataTypes[reportType][i]
  105.                 fragment = message[position:(field_bits + position)]
  106.                 Array[i + k] = type_dictionary[field_type(fragment, field_bits)] # MARTA: czy nie wystarczy  type_dictionary[field_type]
  107.                 k += 1
  108.                 position += field_bits
  109.  
  110.             position += 1
  111.         ##### MARTA #####
  112.  
  113.     shape_dictionary = {
  114.         '000': 2, '001': 3, '010':4, '011':5 | 6, '100':7, '101':9
  115.     }
  116.  
  117.     if key == 29:
  118.  
  119.    
  120.         return Array
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement