Skip to content

Commit

Permalink
Merge branch 'master' of github.com:AircommDrones/splash
Browse files Browse the repository at this point in the history
  • Loading branch information
GiovanniGrieco committed Mar 14, 2021
2 parents 1575ec8 + caeb0fe commit 6b8218c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
6 changes: 4 additions & 2 deletions generate_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ def run(self):
type = self._sim_type_lookup(attr['type'])
input_metacode = f'self.input({i})' if type is None else f'{type}(self.input({i}))'

node_outputs.append(f'\'{attr["name"]}\': {input_metacode}')
node_outputs.append(f'if self.input({i}): d["attributes"].append({{"name": "{attr["name"]}", "value": {input_metacode}}})')
i += 1

newline_char = '\n '
node_metacode = template_code
node_metacode = node_metacode.replace('%OUTPUT_CONSTRUCT%', f'{{{",".join(node_outputs)}}}')
node_metacode = node_metacode.replace('%NODE_NAME%', f'"ns3::{node["name"]}"')
node_metacode = node_metacode.replace('%POPULATE_DICTIONARY%', f'{newline_char.join(node_outputs)}')

with open(f'{node_dir}/{self.package_name}___{node["name"]}0___METACODE.py', 'w') as f:
f.write(node_metacode)
Expand Down
9 changes: 8 additions & 1 deletion metacode_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ def __init__(self, params):
super(%CLASS%, self).__init__(params)

def update_event(self, input_called=-1):
self.set_output_val(0, %OUTPUT_CONSTRUCT%)
d = {
'name': %NODE_NAME%,
'attributes': []
}

%POPULATE_DICTIONARY%

self.set_output_val(0, d)

def get_data(self):
data = {}
Expand Down

0 comments on commit 6b8218c

Please sign in to comment.