diff --git a/network.py b/network.py --- a/network.py +++ b/network.py @@ -1,21 +1,35 @@ -#!/usr/bin/env python - import network_interface import module +import logging class Network(): - def __init__(self, logger): + def __init__(self, database, config): + self.logger = logging.getLogger('hydrobot') + self.database = database + self.config = config + self.interfaces = [] - self.module_list = module.ModuleList() - self.logger = logger + self.load_interfaces() + self.module_list = module.ModuleList(self, database, config) def add_interface(self, interface): self.interfaces.append(interface) def load_interfaces(self): - #TODO: Load interfaces from config file - pass + #load interfaces from config file + for section in self.config.sections(): + if "interface" in section: + interface = None + interface_type = self.config.get(section, "type") + interface_name = self.config.get(section, "name") + if interface_type == "CAN": + interface = network_interface.CanBusNetworkInterface(self, interface_name) + self.add_interface(interface) + if interface_type == "WIFI": + interface = network_interface.CanBusNetworkInterface(self, interface_name) + self.add_interface(interface) + def get_interface(self, interface_name): for interface in self.interfaces: @@ -23,14 +37,13 @@ class Network(): return interface def start_interface(self, interface_name): - print("Network: start interface " + interface_name) - #TODO: Start interface + self.logger.info("Network: start interface " + interface_name) for interface in self.interfaces: if interface.interface_name == interface_name: interface.start() def start_all_interfaces(self): - print("Network: start all interfaces") + self.logger.info("Network: start all interfaces") for interface in self.interfaces: interface.start() @@ -39,9 +52,9 @@ class Network(): if not module == None: module.interface.send_message(message) else: - print("Could not find module " + str(message.module_uuid)) + self.logger.warning("Could not find module " + str(message.module_uuid)) def process_message(self, message): - print("Network: process message") - self.module_list.lookup_module(message.module_uuid).receive_message() + self.logger.debug("Network: process message") + self.module_list.lookup_module(message.module_uuid).receive_message(message)