예제 #1
0
    def Flash(self, fwfilep):
        if self.device == 'extbms' and self.protocol != 'ninebot':
            exit('Only Ninebot supports External BMS !')
        self.setfwfilep(fwfilep)
        file = open(fwfilep, 'rb')
        dev = self.devices.get(self.device)
        if self.interface == 'ble':
            if platform != 'android':
                try:
                    from py9b.link.ble import BLELink
                except:
                    exit('BLE is not yet working with your configuration !')
            elif platform == 'android':
                try:
                    from py9b.link.able import BLELink
                except:
                    exit('BLE is not yet supported on Android !')
            else:
                exit('BLE is not supported on your system !')
            link = BLELink()
        elif self.interface == 'tcp':
            from py9b.link.tcp import TCPLink
            link = TCPLink()
        elif self.interface == 'serial':
            if platform == 'android':
                exit('Serial is not yet supported on Android !')
            from py9b.link.serial import SerialLink
            link = SerialLink()
        else:
            exit('!!! BUG !!! Unknown interface selected: ' + interface)

        with link:
            tran = self.protocols.get(self.protocol)(link)

            if self.address != '':
                addr = self.address
            elif self.interface != 'ble':
                print('Scanning...')
                ports = link.scan()
                if not ports:
                    exit("No interfaces found !")
                print('Connecting to', ports[0][0])
                addr = ports[0][1]
            else:
                raise LinkOpenException

            link.open(addr)
            print('Connected')
            try:
                UpdateFirmware(link, tran, dev, file)
            except Exception as e:
                print('Error:', e)
                raise
예제 #2
0
if len(argv) == 1:
    parser.print_usage()
    exit()
args = parser.parse_args()

if args.device == 'extbms' and args.protocol != 'ninebot':
    exit('Only Ninebot supports External BMS !')

dev = devices.get(args.device)

if args.interface == 'ble':
    try:
        from py9b.link.ble import BLELink
    except:
        exit('BLE is not supported on your system !')
    link = BLELink()
elif args.interface == 'tcp':
    from py9b.link.tcp import TCPLink
    link = TCPLink()
elif args.interface == 'serial':
    from py9b.link.serial import SerialLink
    link = SerialLink()
else:
    exit('!!! BUG !!! Unknown interface selected: ' + args.interface)

with link:
    tran = protocols.get(args.protocol)(link)

    if args.address:
        addr = args.address
    else:
예제 #3
0
def CalcSnAuth(oldsn, newsn, uid3):
    s = 0
    for i in xrange(0x0E):
        s += ord(oldsn[i])
        s *= ord(newsn[i])
    s += uid3 + (uid3 << 4)
    s &= 0xFFFFFFFF
    if (s & 0x80000000) != 0:
        s = 0x100000000 - s

    return s % 1000000


#link = SerialLink(dump=True)
#link = TCPLink()
link = BLELink(dump=True)

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("Pinging...")
    for retry in xrange(20):
예제 #4
0
파일: read_bms.py 프로젝트: romanoLT/py9b
#!python2-32
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

READ_CHUNK_SIZE = 0x10

# 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.1", 6000))
    link.open(ports[0][1])
    print("Connected")

    hfo = open("BmsRegs.bin", "wb")
    for i in xrange(0x0, 0x100, READ_CHUNK_SIZE):