def _connect_inner(self, link): try: if self.address is '': ports = link.scan() if not link.scanned.is_set(): link.scanned.wait(link.timeout) if not ports: raise Exception('No devices found') if isinstance(ports[0], tuple): self.address = ports[0][1] else: self.address = ports[0] link.open(self.address) elif self.address is not '': link.open(self.address) transport = None if self.transport == 'ninebot': from py9b.transport.ninebot import NinebotTransport transport = NinebotTransport(link) elif self.transport == 'xiaomi': from py9b.transport.xiaomi import XiaomiTransport transport = XiaomiTransport(link) if transport.execute( ReadRegs(BT.ESC, 0x68, "<H"))[0] > 0x081 and self.link is ('ble'): transport.keys = link.fetch_keys() transport.recover_keys() tprint('Keys recovered') tprint('functionality may be limited for now') self._tran = transport self._link = link if not self._link.connected.is_set(): self._link.connected.wait(self._link.timeout * 1.5) if self._link.connected.is_set(): self.update_state('connected') else: self.disconnect() return transport except Exception as exc: self.dispatch('on_error', repr(exc)) raise exc
def __enter__(self): link = None if self.link == 'bleak': from py9b.link.bleak import BleakLink link = BleakLink() elif self.link == 'tcp': from py9b.link.tcp import TCPLink link = TCPLink() elif self.link == 'serial': from py9b.link.serial import SerialLink link = SerialLink(timeout=1.0) link.__enter__() if not self.address: ports = link.scan() if not ports: raise Exception('No devices found') self.address = ports[0] link.open(self.address) transport = None if self.transport == 'ninebot': from py9b.transport.ninebot import NinebotTransport transport = NinebotTransport(link) elif self.transport == 'xiaomi': from py9b.transport.xiaomi import XiaomiTransport transport = XiaomiTransport(link) if transport.execute( ReadRegs(BT.ESC, 0x68, "<H"))[0] > 0x081 and self.link.startswith('ble'): transport.keys = link.fetch_keys_pro() transport.recover_keys() print('Keys recovered') self._transport = transport self._link = link return transport
def _connect_inner(self, link): try: if not self.address: if platform != 'android': ports = link.scan() if not ports: raise Exception('No devices found') if isinstance(ports[0], tuple): self.address = ports[0][1] else: self.address = ports[0] link.open(self.address) elif self.address: link.open(self.address) transport = None if self.transport == 'ninebot': from py9b.transport.ninebot import NinebotTransport transport = NinebotTransport(link) elif self.transport == 'xiaomi': from py9b.transport.xiaomi import XiaomiTransport transport = XiaomiTransport(link) if transport.execute( ReadRegs(BT.ESC, 0x68, "<H"))[0] > 0x081 and self.link is ('ble'): transport.keys = link.fetch_keys_pro() transport.recover_keys() tprint('Keys recovered') self._tran = transport self._link = link return transport except Exception as exc: self.update_state('disconnected') self.dispatch('on_error', repr(exc)) raise exc
print("Scanning...") ports = link.scan() print(ports) #tran = XiaomiTransport(link) tran = NinebotTransport(link) #link.open(("192.168.1.45", 6000)) link.open(ports[0][1]) print("Connected") print("Pinging...") for retry in xrange(20): print(".", end="") try: old_sn = tran.execute(ReadRegs(BT.ESC, 0x10, "14s"))[0] except LinkTimeoutException: continue break else: exit("Timed out !") print("") #lock #tran.execute(WriteRegs(BT.ESC, 0x70, "<H", 0x01)) old_sn = tran.execute(ReadRegs(BT.ESC, 0x10, "14s"))[0] print("Old S/N:", old_sn) uid3 = tran.execute(ReadRegs(BT.ESC, 0xDE, "<L"))[0] print("UID3: %08X" % (uid3))
# from py9b.link.ble import BLELink from py9b.link.serial import SerialLink from py9b.transport.base import BaseTransport as BT from py9b.transport.packet import BasePacket as PKT # from py9b.transport.xiaomi import XiaomiTransport from py9b.transport.ninebot import NinebotTransport from py9b.command.regio import ReadRegs, WriteRegs # link = SerialLink(dump=True) link = TCPLink() # link = BLELink() with link: print("Scanning...") ports = link.scan() print(ports) # tran = XiaomiTransport(link) tran = NinebotTransport(link) link.open(("127.0.0.20:6000")) # link.open(ports[0][1]) print("Connected") print("Locking...") tran.execute(WriteRegs(BT.ESC, 0x70, "<H", 0x0001)) link.close()
#link = BLELink() with link: print "Scanning..." ports = link.scan() print ports #tran = XiaomiTransport(link) tran = NinebotTransport(link) #link.open(("192.168.1.45", 6000)) link.open(ports[0][1]) print "Connected" hfo = open("EscRegs.bin", "wb") for i in xrange(0x0, 0x200, READ_CHUNK_SIZE): print ".", for retry in xrange(5): try: data = tran.execute(ReadRegs(BT.ESC, i>>1, "16s"))[0] except LinkTimeoutException: continue break else: print "No response !" break hfo.write(data) hfo.close() link.close()
# from py9b.link.ble import BLELink from py9b.link.serial import SerialLink from py9b.transport.base import BaseTransport as BT from py9b.transport.packet import BasePacket as PKT # from py9b.transport.xiaomi import XiaomiTransport from py9b.transport.ninebot import NinebotTransport from py9b.command.regio import ReadRegs, WriteRegs # link = SerialLink(dump=True) link = TCPLink() # link = BLELink() with link: print("Scanning...") ports = link.scan() print(ports) # tran = XiaomiTransport(link) tran = NinebotTransport(link) link.open(("127.0.0.20:6000")) # link.open(ports[0][1]) print("Connected") print("Reading passwd...") pwd = tran.execute(ReadRegs(BT.ESC, 0x17, "6s")) print("Passwd:", pwd) link.close()
from py9b.link.base import LinkOpenException, LinkTimeoutException from py9b.link.tcp import TCPLink from py9b.link.ble import BLELink from py9b.link.serial import SerialLink from py9b.transport.base import BaseTransport as BT from py9b.transport.packet import BasePacket as PKT from py9b.transport.xiaomi import XiaomiTransport from py9b.transport.ninebot import NinebotTransport from py9b.command.regio import ReadRegs, WriteRegs #link = SerialLink(dump=True) #link = TCPLink() link = BLELink() with link: print "Scanning..." ports = link.scan() print ports #tran = XiaomiTransport(link) tran = NinebotTransport(link) #link.open(("192.168.1.45", 6000)) link.open(ports[0][1]) print "Connected" print('Power off...') tran.execute(WriteRegs(BT.ESC, 0x79, '<H', 0x0001)) link.close()