Index: leahi_dialin/utils/abstract_classes.py =================================================================== diff -u -r5ebadf2099b379c5ee6d8417be5e3121c74611cf -r0bc2d3976315c12417c992717621a0284bbedef4 --- leahi_dialin/utils/abstract_classes.py (.../abstract_classes.py) (revision 5ebadf2099b379c5ee6d8417be5e3121c74611cf) +++ leahi_dialin/utils/abstract_classes.py (.../abstract_classes.py) (revision 0bc2d3976315c12417c992717621a0284bbedef4) @@ -86,22 +86,37 @@ for decode_details in decoder_list: # Content of the decode list variable_name = decode_details[0] - datatype: DataTypes = decode_details[-1] + + # If last position is multichar length + if isinstance(decode_details[-1], int): + length = decode_details[-1] + datatype: DataTypes = decode_details[-2] + else: + length = 1 + datatype: DataTypes = decode_details[-1] end_pos = start_pos + datatype.size() - try: - value = struct.unpack(datatype.unpack_attrib(), bytearray(message['message'][start_pos:end_pos]))[0] - except Exception as e: - value = None + + for i in range(0, length): + try: + new_value = struct.unpack(datatype.unpack_attrib(), bytearray(message['message'][start_pos:end_pos]))[0] + if i == 0: + value = new_value + else: + value += new_value + except Exception as e: + value = None + break + if debug: print(f'{variable_name}: {value} ({datatype.name})') print(f'pos: {start_pos} - {end_pos}') if 'nan' in str(value).lower(): value = None + break # raise ValueError(f'{value} is not an accepted value!') - if datatype is DataTypes.BOOL: + if datatype in [DataTypes.BOOL, DataTypes.BOOL_U08]: value = True if value == 1 else False results[variable_name] = value - # If it's a instance variable (self.) then set it's value if variable_name.startswith('self'): attr_path = variable_name[5:].split('.') @@ -110,6 +125,7 @@ obj = getattr(obj, attr) setattr(obj, attr_path[-1], value) start_pos = end_pos + if debug: print('Finished cycle\n') if debug: @@ -136,20 +152,39 @@ key_1 = decode_details[0] key_2 = decode_details[1] if len(decode_details) >= 3 else None key_3 = decode_details[2] if len(decode_details) >= 4 else None - datatype: DataTypes = decode_details[-1] + + # If last position is multichar length + if isinstance(decode_details[-1], int): + length = decode_details[-1] + datatype: DataTypes = decode_details[-2] + else: + length = 1 + datatype: DataTypes = decode_details[-1] end_pos = start_pos + datatype.size() - value = struct.unpack(datatype.unpack_attrib(), bytearray(message['message'][start_pos:end_pos]))[0] + + for i in range(0, length): + try: + new_value = struct.unpack(datatype.unpack_attrib(), bytearray(message['message'][start_pos:end_pos]))[0] + if i == 0: + value = new_value + else: + value += new_value + except Exception as e: + value = None + break + if debug: print(f'key_1: {key_1}') print(f'key_2: {key_2}') print(f'value: {value} ({datatype.name})') print(f'pos: {start_pos} - {end_pos}') + if 'nan' in str(value).lower(): value = None # raise ValueError(f'{value} is not an accepted value!') # If the type is Bool, convert the value from Integer to Boolean - if datatype is DataTypes.BOOL: + if datatype in [DataTypes.BOOL, DataTypes.BOOL_U08]: value = True if value == 1 else False # Save the value into the Dictionary if len(decode_details) == 2: