Skip to content

Commit

Permalink
implement multibit flags
Browse files Browse the repository at this point in the history
  • Loading branch information
HotNoob committed Sep 25, 2024
1 parent 64d2e10 commit ecced5f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions classes/protocol_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,17 +720,30 @@ def process_register_bytes(self, registry : dict[int,bytes], entry : registry_ma
end_bit = flag_size + start_bit

if entry.documented_name+'_codes' in self.codes:
code_key : str = entry.documented_name+'_codes'
flags : list[str] = []
flag_indexes : list[str] = []
for i in range(start_bit, end_bit): # Iterate over each bit position (0 to 15)
byte = i // 8
bit = i % 8
val = register[byte]
# Check if the i-th bit is set
if (val >> bit) & 1:
flag_index = "b"+str(i)
if flag_index in self.codes[entry.documented_name+'_codes']:
flags.append(self.codes[entry.documented_name+'_codes'][flag_index])

flag_indexes.append(flag_index)
if flag_index in self.codes[code_key]:
flags.append(self.codes[code_key][flag_index])

#check multibit flags
multibit_flags = [key for key in self.codes if '&' in key]

if multibit_flags: #if multibit flags are found
flag_indexes_set : set[str] = set(flag_indexes)
for multibit_flag in multibit_flags:
bits = multibit_flag.split('&') # Split key into 'bits'
if all(bit in flag_indexes_set for bit in bits): # Check if all bits are present in the flag_indexes_set
flags.append(self.codes[code_key][multibit_flag])

value = ",".join(flags)
else:
flags : list[str] = []
Expand Down

1 comment on commit ecced5f

@HotNoob
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.