def general_settings(self, debug, local, remote, update, serial, network, swapnet): """ Configure serial modem @param debug debug level @param local local device definition folder @param remote remote device definition folder @param update update local device definition folder on start-up @param serial serial gateway config file @param network wireless config file @param swapnet SWAP network file """ try: config = XmlSettings(self.swap_settings) config.debug = int(debug) config.device_localdir = local config.device_remote = remote if update is not None: config.updatedef = update == "true" config.serial_file = serial config.network_file = network config.swap_file = swapnet # Save config file config.save() except: raise LagartoException("Unable to save general settings")
def __init__(self, swap_settings=None): """ Class constructor @param swap_settings: path to the main SWAP configuration file @param verbose: Print out SWAP frames or not @param monitor: Print out network events or not """ # Main configuration file self.swap_settings = swap_settings # Print SWAP activity self._print_swap = False try: self.main_settings = XmlSettings(self.swap_settings) # Set log file to trace lagarto exceptions LagartoException.error_file = XmlSettings.error_file # Superclass call SwapInterface.__init__(self, swap_settings) except: raise # Lagarto process constructor LagartoProcess.__init__(self, working_dir) if XmlSettings.debug == 2: self._print_swap = True self.lagarto_config = XmlLagarto( os.path.join(config_dir, "lagarto.xml"))
def http_command_received(self, command, params): """ Process command sent from HTTP server. Method to be overrided by data server. Method required by LagartoServer @param command: command string @param params: dictionary of parameters @return True if command successfully processed by server. Return False otherwise """ try: # Configure endpoint if command == "config_endpoint": endp = self.get_endpoint(endpid=params["id"]) endp.name = params["name"] endp.location = params["location"] if "unit" in params: endp.setUnit(params["unit"]) self.network.save() elif command == "delete_mote": self.network.delete_mote(int(params["address"])) else: # Save gateway's wireless settings if command == "modem_network": main_settings = XmlSettings(self.swap_settings) # Open network configuration config = XmlNetwork(main_settings.network_file) # Change parameters config.freq_channel = int(params["channel"]) config.network_id = int(params["netid"], 16) config.devaddress = int(params["address"]) config.security = int(params["security"]) config.password = params["password"] # Save gateway's port settings elif command == "modem_serial": main_settings = XmlSettings(self.swap_settings) # Open network configuration config = XmlSerial(main_settings.serial_file) # Change parameters config.port = params["port"] config.speed = int(params["speed"]) # Configure general settings elif command == "general_settings": config = XmlSettings(self.swap_settings) config.debug = int(params["debug"]) config.device_localdir = params["local"] config.device_remote = params["remote"] if "update" in params: config.updatedef = params["update"] == "true" config.serial_file = params["serial"] config.network_file = params["network"] config.swap_file = params["swapnet"] # Save config file config.save() # Save current network information self.network.save() # Restart server self.server.stop() self.server.start() except: return False return True
# Parse arguments parser = argparse.ArgumentParser() parser.add_argument('--port', help="Serial port connected to modem") parser.add_argument('--speed', help="Serial baud rate (bps)") parser.add_argument('--channel', help="RF channel") parser.add_argument('--netid', help="Network ID") parser.add_argument('--address', help="SWAP address of modem") parser.add_argument('--security', help="Security flag") parser.add_argument('--macro', help="Macro") opts = parser.parse_args() direc = os.path.join(os.path.dirname(sys.argv[0]), "config") settings = os.path.join(direc, "settings.xml") # General settings general_cfg = XmlSettings(settings) # Serial settings serial_cfg = XmlSerial(general_cfg.serial_file) # Network settings network_cfg = XmlNetwork(general_cfg.network_file) save_file = False # Save serial parameters if opts.port is not None: serial_cfg.port = opts.port save_file = True if opts.speed is not None: serial_cfg.speed = SwapManager.str_to_int(opts.speed) save_file = True if save_file: