def update_list(self): ## exec hcitool scan hcitool = ProcessInterface("%s scan hci0" % HCITOOL_CMD) while not hcitool.process_finished(): time.sleep(0.1) ## wait for command to compute hcitool_output = hcitool.read_from_process() ## exec pand list pand = ProcessInterface("pand -l") while not pand.process_finished(): time.sleep(0.1) ## wait for command to compute pand_output = pand.read_from_process() ## filter output for visible peers visible_peers = [] for line in hcitool_output.split("\n"): if line.find(":") >= 1: visible_peers.append((line.strip().split("\t")[1],\ line.strip().split("\t")[0])) ## filter output for connected peers connected_peers = [] for line in pand_output.split("\n"): if len(line.split(" ")) > 1: connected_peers.append(line.split(" ")[1]) return (visible_peers, connected_peers)
def get_name(self): hciconfig = ProcessInterface("hciconfig hci0 name") while not hciconfig.process_finished(): time.sleep(0.1) ## wait for command to compute output = hciconfig.read_from_process() if output.find("Name:") >= 0: return output.split("Name:")[1].split("'")[1] return "down"
def get_ip_address(self): if len(self.address) <= 0: return "none" else: ## todo mind more than one device ifconfig = ProcessInterface("ifconfig bnep0") while not ifconfig.process_finished(): time.sleep(0.1) ## wait for command to compute output = ifconfig.read_from_process() # print "output of get_ip_address: [%s]" % output if len(output.split("inet addr:")) > 1: return output.split("inet addr:")[1].split(" ")[0].strip()
def get_address(self): hciconfig = ProcessInterface("%s %s" % (HCICONFIG_CMD, BLUETOOTH_DEVICE)) while not hciconfig.process_finished(): time.sleep(0.1) ## wait for command to compute output = hciconfig.read_from_process() # print "output of get_address: [%s]" % output # hciconfig.close_process() ## has no effect anyway :-( TODO - fix if output.find("BD Address: "): if len(output.split("BD Address: ")) > 1 and \ len(output.split("BD Address: ")[1].split(" ")) > 1: self.address = output.split("BD Address: ")[1].split(" ")[0] return output.split("BD Address: ")[1].split(" ")[0] else: return "offline" return "unknown"