Improve platform file

This commit is contained in:
Loic Guegan 2022-09-11 15:16:30 +02:00
parent 918cc9a448
commit cb02cc0e02
2 changed files with 23 additions and 4 deletions

View file

@ -1,6 +1,7 @@
import yaml, os, importlib
import numpy as np
from esds import Simulator
class UnitsParser:
def node_range(r,limit):
@ -55,6 +56,7 @@ class YAMLPlatformFile:
"interferences": True,
"node_count": 0,
"implementations": [],
"arguments": [],
"interfaces": dict()
}
@ -156,13 +158,19 @@ class YAMLPlatformFile:
if extension != ".py":
self.parsing_error("File "+file+" must be a python file")
for node in r:
self.default["implementations"][node]=file
self.default["implementations"][node]=path
count = len(nodes["implementations"])
if count > 1 and count != self.default["node_count"]:
self.parsing_error("If more than one implementation is specified, each node implementation should be provided ("+str(self.default["node_count"])+" in total)")
else:
self.parsing_error("node implementation not provided")
##### Nodes arguments
self.default["arguments"]=[None]*self.default["node_count"]
if "arguments" in nodes:
args=nodes["arguments"]
for r in args:
for node_id in UnitsParser.node_range(r,self.default["node_count"]):
self.default["arguments"][node_id]=args[r]
def parse_general(self):
general=self.platform["general"]
@ -197,10 +205,15 @@ class YAMLPlatformFile:
self.default["interferences"]=general["interferences"]
def run(self):
callback=None
##### First load callback from file if any
callback=None
if self.default["breakpoints_file"] != None:
module, ext=os.path.splitext(self.default["breakpoints_file"])
imported=importlib.import_module(module)
callback=getattr(imported, self.default["breakpoints_callback"])
pass
##### Create simulator
simulator=Simulator(self.default["interfaces"])
for node_id in range(0,self.default["node_count"]):
simulator.create_node(self.default["implementations"][node_id], args=self.default["arguments"][node_id])
simulator.run()

View file

@ -28,6 +28,12 @@ nodes:
# 0-@ receiver.py is equivalent to 0-4 receiver.py
implementations:
- all sender.py
# Node implementations arguments
# arguments is a dictionary where key isrange of node the value is the arguments for
# this specific node range
arguments: {
"all": 2
}
##### Interfaces Section #####
interfaces: