import hashlib
from copy import deepcopy
import caspia.meadow
import caspia.node
from caspia.gateway.cidmanagement import CidManagement
[docs]class Network:
""" Manages Caspia CAN Network """
def __init__(self, pollen_client, cidmng: CidManagement):
self.pollen_client = pollen_client
self.cidmng = cidmng
self.nodes = dict()
self._component_cache = dict()
[docs] def get_node(self, name):
""" Return node for a given name.
Create a new one, if it does not exist yet.
"""
if name in self.nodes:
return self.nodes[name]
cid = self.cidmng.lease(name)
node = caspia.node.Node(self.pollen_client, cid)
self.nodes[name] = node
return node
[docs] def reset_configuration(self):
self._component_cache = dict()
def _get_config_hash(self, node, comp_cfg):
hsh = hashlib.sha1(comp_cfg.get_bytes())
hsh.update(int.to_bytes(node.can_id, 3, 'little'))
return hsh.hexdigest()