Skip to content

Commit

Permalink
Deal with nested structs for cFS messages
Browse files Browse the repository at this point in the history
  • Loading branch information
the-other-james committed Feb 7, 2024
1 parent 51c34ba commit 1a9256d
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions onair/data_handling/sbn_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ def connect(self):
for msgID in self.msgID_lookup_table.keys():
sbn.subscribe(msgID)

def gather_field_names(self, field_name, field_type):
field_names = []
if "message_headers" in str(field_type):
for sub_field_name, sub_field_type in field_type._fields_:
field_names.append(self.gather_field_names(field_name + "." + sub_field_name, sub_field_type))
else:
#field_names.append(field_name)
return field_name
return field_names

def parse_meta_data_file(self, meta_data_file, ss_breakdown):
self.msgID_lookup_table = {}
self.currentData = []
Expand Down Expand Up @@ -81,9 +91,13 @@ def parse_meta_data_file(self, meta_data_file, ss_breakdown):
for msgID in self.msgID_lookup_table.keys():
app_name, data_struct = self.msgID_lookup_table[msgID]
struct_name = data_struct.__name__
# Skip the header, walk through the stuct
for field_name, field_type in data_struct._fields_[1:]:
self.currentData[x]['headers'].append(app_name + "." + struct_name + "." + str(field_name))
self.currentData[x]['data'].extend([0]*len(data_struct._fields_[1:])) #initialize all the data arrays with zero
field_names = self.gather_field_names(app_name + "." + field_name, field_type)

for field_name in field_names:
self.currentData[x]['headers'].append(field_name)
self.currentData[x]['data'].append([0]) #initialize all the data arrays with zero

return extract_meta_data_handle_ss_breakdown(meta_data_file, ss_breakdown)

Expand Down Expand Up @@ -155,11 +169,21 @@ def get_current_data(self, recv_msg, data_struct, app_name):
str_time = time.strftime("%Y-%j-%H:%M:%S.%f")
current_buffer['data'][0] = str_time

for field_name, field_type in data_struct._fields_[1:]:
header_name = app_name + "." + data_struct.__name__ + "." + str(field_name)
idx = current_buffer['headers'].index(header_name)
data = str(getattr(recv_msg, field_name))
current_buffer['data'][idx] = data
# Skip the header, walk through the stuct
for field_name, field_type in recv_msg._fields_[1:]:
field_names = self.gather_field_names(field_name, field_type)

for name in field_names:
idx = current_buffer['headers'].index(app_name + "." + name)
# Pull the data out of the message buy walking down the nested types
data = ""
current_object = recv_msg
for sub_type in name.split('.'):
print ("sub_type: " + sub_type)
current_object = getattr(current_object, sub_type)
data = str(current_object)
print("\tdata: " + data)
current_buffer['data'][idx] = data

with self.new_data_lock:
self.new_data = True

0 comments on commit 1a9256d

Please sign in to comment.