def __init__(self, parent=None, devAddr=255, netid=0xB547, freq_channel=0, interval=255): """ Class constructor @param parent Parent object """ ConfigDialog.__init__(self, parent, title="Network settings") ## Configuration settings self.config = XmlNetwork(XmlSettings.network_file) ## SWAP device address self.devaddress = devAddr ## SWAP Network ID self.netid = netid ## Frequency channel self.freq_channel = freq_channel ## Periodic Tx interval self.interval = interval # Create widgets self._createControls() # Layout widgets self.doLayout() # Fit dialog size to its contents self.Fit()
def _OnGatewayNetworkConfig(self, evn): """ Gateway->Network pressed. Callback function """ # Configuration settings config = XmlNetwork(XmlSettings.network_file) # Open network config dialog if self.server.modem is None: dialog = NetworkDialog(self, config.devaddress, hex(config.network_id)[2:], config.freq_channel) else: dialog = NetworkDialog(self, self.server.modem.devaddress, hex(self.server.modem.syncword)[2:], self.server.modem.freq_channel) res = dialog.ShowModal() # Save new settings in xml file if res == wx.ID_CANCEL: return config.devaddress = int(dialog.devaddress) config.network_id = int(dialog.netid, 16) config.freq_channel = int(dialog.freq_channel) config.save() self._Info( "In order to take the new settings, you need to restart the gateway", "Gateway restart required")
def _OnSecurityConfig(self, evn): """ Gateway->Security pressed. Callback function """ # Configuration settings config = XmlNetwork(XmlSettings.network_file) # Open security config dialog dialog = SecurityDialog(self, config.security, config.password) res = dialog.ShowModal() # Save new settings in xml file if res == wx.ID_CANCEL: return config.security = 0 if dialog.playbk: config.security += 1 if dialog.smartencrypt: config.security += 2 config.password = dialog.password config.save() self._Info( "In order to take the new settings, you need to restart the gateway", "Gateway restart required")
def _OnSecurityConfig(self, evn): """ Gateway->Security pressed. Callback function """ # Configuration settings config = XmlNetwork(XmlSettings.network_file) # Open security config dialog dialog = SecurityDialog(self, config.security, config.password) res = dialog.ShowModal() # Save new settings in xml file if res == wx.ID_CANCEL: return config.security = 0 if dialog.playbk: config.security += 1 if dialog.smartencrypt: config.security += 2 config.password = dialog.password config.save() self._Info("In order to take the new settings, you need to restart the gateway", "Gateway restart required")
def config_network(self, channel, netid, address, security, password): """ Configure network parameters from the serial modem @param channel RF channel @param netid SWAP network ID @param address network address @param security wireless security flag @param password password for wireless security """ try: # Open network configuration config = XmlNetwork(self.main_settings.network_file) # Change parameters config.freq_channel = int(channel) config.network_id = int(netid, 16) config.devaddress = int(address) config.security = int(security) config.password = password config.save() except: raise LagartoException("Unable to save modem network settings")
def __init__(self, parent=None, secu=0, password=0): """ Class constructor @param parent Parent object """ ConfigDialog.__init__(self, parent, title="Security settings") ## Configuration settings self.config = XmlNetwork(XmlSettings.network_file) ## Anti-playback self.playbk = secu & 0x01 == 0x01 ## Smart encryption self.smartencrypt = secu & 0x02 == 0x02 ## Encryption password self.password = password # Create widgets self._createControls() # Layout widgets self.doLayout() # Fit dialog size to its contents self.Fit()
def _OnGatewayNetworkConfig(self, evn): """ Gateway->Network pressed. Callback function """ # Configuration settings config = XmlNetwork(XmlSettings.network_file) # Open network config dialog if self.server.modem is None: dialog = NetworkDialog(self, config.devaddress, hex(config.network_id)[2:], config.freq_channel) else: dialog = NetworkDialog(self, self.server.modem.devaddress, hex(self.server.modem.syncword)[2:], self.server.modem.freq_channel) res = dialog.ShowModal() # Save new settings in xml file if res == wx.ID_CANCEL: return config.devaddress = int(dialog.devaddress) config.network_id = int(dialog.netid, 16) config.freq_channel = int(dialog.freq_channel) config.save() self._Info("In order to take the new settings, you need to restart the gateway", "Gateway restart required")
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
def onMoteNetworkConfig(self, evn): """ Devices->Network settings pressed. Callback function """ paramsOk = False # Configuration settings config = XmlNetwork(XmlSettings.network_file) # This is our mote mote = None # Any mote selected from the tree? itemID = self.browser_panel.tree.GetSelection() if itemID is not None: obj = self.browser_panel.tree.GetPyData(itemID) if obj.__class__.__name__ == "SwapMote": mote = obj address = mote.address netid = config.network_id freqChann = config.freq_channel if mote.pwrdownmode == True: txinterval = mote.txinterval mote = None else: txinterval = None paramsOk = True # No mote selected from the tree? if not paramsOk: address = 0xFF netid = config.network_id freqChann = config.freq_channel txinterval = "" # Open network config dialog dialog = NetworkDialog(self, address, hex(netid)[2:], freqChann, txinterval) res = dialog.ShowModal() if res == wx.ID_CANCEL: return # No mote selected? if mote is None: # Ask for SYNC mode res = self.waitForSync() if not res: return mote = self._moteinsync # Send new config to mote if int(dialog.devaddress) != address: if not mote.setAddress(int(dialog.devaddress)): self._Warning("Unable to set mote's address") if dialog.netid != hex(netid)[2:]: if not mote.setNetworkId(int(dialog.netid, 16)): self._Warning("Unable to set mote's Network ID") if dialog.interval is not None: if dialog.interval != txinterval and dialog.interval != "": if not mote.setTxInterval(int(dialog.interval)): self._Warning("Unable to set mote's Tx interval") if int(dialog.freq_channel) != freqChann: if not mote.setFreqChannel(int(dialog.freq_channel)): self._Warning("Unable to set mote's frequency channel")
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"])) elif command == "config_mote": mote_addr = int(params.get("moteaddr", "-1")) new_address = int(params.get("address", "-1")) state = int(params.get("state", "-1")) channel = int(params.get("channel", "-1")) interval = int(params.get("interval", "-1")) self.network.config_mote(mote_addr, new_address, state, channel, interval) 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
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: serial_cfg.save() save_file = False # Save network parameters