added changesn back
parent
e5520e5ef7
commit
ecf20d57ae
|
@ -105,3 +105,5 @@ venv.bak/
|
||||||
|
|
||||||
# mypy
|
# mypy
|
||||||
.mypy_cache/
|
.mypy_cache/
|
||||||
|
|
||||||
|
ffwupd.py
|
||||||
|
|
|
@ -0,0 +1,24 @@
|
||||||
|
"""Manufacturer commands"""
|
||||||
|
|
||||||
|
from struct import pack, unpack
|
||||||
|
from .base import BaseCommand, InvalidResponse
|
||||||
|
|
||||||
|
|
||||||
|
class AuthError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class WriteSN(BaseCommand):
|
||||||
|
def __init__(self, dev, sn, auth):
|
||||||
|
super(WriteSN, self).__init__(dst=dev, cmd=0x18, arg=0x10, data=pack("<14sL", sn, auth), has_response=True)
|
||||||
|
self.dev = dev
|
||||||
|
|
||||||
|
def handle_response(self, response):
|
||||||
|
if len(response.data)!=0:
|
||||||
|
raise InvalidResponse("WriteSN {0:X}".format(self.dev))
|
||||||
|
if response.arg!=1:
|
||||||
|
raise AuthError("WriteSN {0:X}".format(self.dev))
|
||||||
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
__all__=["AuthError", "WriteSN"]
|
|
@ -0,0 +1,88 @@
|
||||||
|
#!python2-32
|
||||||
|
from __future__ import print_function
|
||||||
|
from sys import exit
|
||||||
|
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
|
||||||
|
from py9b.command.mfg import WriteSN
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
#new_sn = "16133/00101234"
|
||||||
|
#new_sn = "N2GTR1826C1234"
|
||||||
|
|
||||||
|
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):
|
||||||
|
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))
|
||||||
|
|
||||||
|
auth = CalcSnAuth(old_sn, new_sn, uid3)
|
||||||
|
#auth = 0
|
||||||
|
print("Auth: %08X" % (auth))
|
||||||
|
|
||||||
|
try:
|
||||||
|
tran.execute(WriteSN(BT.ESC, new_sn, auth))
|
||||||
|
print("OK")
|
||||||
|
except LinkTimeoutException:
|
||||||
|
print("Timeout !")
|
||||||
|
|
||||||
|
# save config and restart
|
||||||
|
tran.execute(WriteRegs(BT.ESC, 0x78, "<H", 0x01))
|
||||||
|
sleep(3)
|
||||||
|
|
||||||
|
old_sn = tran.execute(ReadRegs(BT.ESC, 0x10, "14s"))[0]
|
||||||
|
print("Current S/N:", old_sn)
|
||||||
|
|
||||||
|
link.close()
|
Loading…
Reference in New Issue