mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
New LEGO-Boost Firmware 2.0.00.0017 breaks pylgbst... (#33)
* - Updated Port-Numbers (New Firmware 2.0.00.0017) - Skipping Device without Mac-Address (Seems to occur randomly after Firmware-Update, referring to https://github.com/LLK/scratch-vm/issues/2230 ) - Fixed racecondition in Hub.send() (Reply could come before entering _sync_lock) * - fixed Unit-Tests (Changed Port-Numbers) - moved the write-call in hub.send() outside the lock
This commit is contained in:
parent
b1c8667f63
commit
990ccdb268
1
.gitignore
vendored
1
.gitignore
vendored
@ -4,3 +4,4 @@
|
|||||||
build
|
build
|
||||||
*.avi
|
*.avi
|
||||||
test_real.py
|
test_real.py
|
||||||
|
.vscode/settings.json
|
||||||
|
@ -33,6 +33,7 @@ class GattoolConnection(Connection):
|
|||||||
for dev in devices:
|
for dev in devices:
|
||||||
address = dev['address']
|
address = dev['address']
|
||||||
name = dev['name']
|
name = dev['name']
|
||||||
|
if address != "00:00:00:00:00:00":
|
||||||
if (not hub_mac and name == LEGO_MOVE_HUB) or hub_mac == address:
|
if (not hub_mac and name == LEGO_MOVE_HUB) or hub_mac == address:
|
||||||
logging.info("Found %s at %s", name, address)
|
logging.info("Found %s at %s", name, address)
|
||||||
self._conn_hnd = adapter.connect(address)
|
self._conn_hnd = adapter.connect(address)
|
||||||
|
@ -61,19 +61,21 @@ class Hub(object):
|
|||||||
:rtype: pylgbst.messages.UpstreamMsg
|
:rtype: pylgbst.messages.UpstreamMsg
|
||||||
"""
|
"""
|
||||||
log.debug("Send message: %r", msg)
|
log.debug("Send message: %r", msg)
|
||||||
self.connection.write(self.HUB_HARDWARE_HANDLE, msg.bytes())
|
msgbytes = msg.bytes()
|
||||||
if msg.needs_reply:
|
if msg.needs_reply:
|
||||||
with self._sync_lock:
|
with self._sync_lock:
|
||||||
assert not self._sync_request, "Pending request %r while trying to put %r" % (self._sync_request, msg)
|
assert not self._sync_request, "Pending request %r while trying to put %r" % (self._sync_request, msg)
|
||||||
self._sync_request = msg
|
self._sync_request = msg
|
||||||
log.debug("Waiting for sync reply to %r...", msg)
|
log.debug("Waiting for sync reply to %r...", msg)
|
||||||
|
|
||||||
|
self.connection.write(self.HUB_HARDWARE_HANDLE, msgbytes)
|
||||||
resp = self._sync_replies.get()
|
resp = self._sync_replies.get()
|
||||||
log.debug("Fetched sync reply: %r", resp)
|
log.debug("Fetched sync reply: %r", resp)
|
||||||
if isinstance(resp, MsgGenericError):
|
if isinstance(resp, MsgGenericError):
|
||||||
raise RuntimeError(resp.message())
|
raise RuntimeError(resp.message())
|
||||||
return resp
|
return resp
|
||||||
else:
|
else:
|
||||||
|
self.connection.write(self.HUB_HARDWARE_HANDLE, msgbytes)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def _notify(self, handle, data):
|
def _notify(self, handle, data):
|
||||||
@ -183,12 +185,12 @@ class MoveHub(Hub):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# PORTS
|
# PORTS
|
||||||
PORT_C = 0x01
|
PORT_A = 0x00
|
||||||
PORT_D = 0x02
|
PORT_B = 0x01
|
||||||
|
PORT_C = 0x02
|
||||||
|
PORT_D = 0x03
|
||||||
|
PORT_AB = 0x10
|
||||||
PORT_LED = 0x32
|
PORT_LED = 0x32
|
||||||
PORT_A = 0x37
|
|
||||||
PORT_B = 0x38
|
|
||||||
PORT_AB = 0x39
|
|
||||||
PORT_TILT_SENSOR = 0x3A
|
PORT_TILT_SENSOR = 0x3A
|
||||||
PORT_CURRENT = 0x3B
|
PORT_CURRENT = 0x3B
|
||||||
PORT_VOLTAGE = 0x3C
|
PORT_VOLTAGE = 0x3C
|
||||||
|
@ -122,20 +122,20 @@ class HubTest(unittest.TestCase):
|
|||||||
class MoveHubTest(unittest.TestCase):
|
class MoveHubTest(unittest.TestCase):
|
||||||
def test_capabilities(self):
|
def test_capabilities(self):
|
||||||
conn = ConnectionMock()
|
conn = ConnectionMock()
|
||||||
conn.notifications.append('0f00 04 01 0125000000001000000010')
|
conn.notifications.append('0f00 04 02 0125000000001000000010')
|
||||||
conn.notifications.append('0f00 04 02 0126000000001000000010')
|
conn.notifications.append('0f00 04 03 0126000000001000000010')
|
||||||
conn.notifications.append('0f00 04 37 0127000100000001000000')
|
conn.notifications.append('0f00 04 00 0127000100000001000000')
|
||||||
conn.notifications.append('0f00 04 38 0127000100000001000000')
|
conn.notifications.append('0f00 04 01 0127000100000001000000')
|
||||||
conn.notifications.append('0900 04 39 0227003738')
|
conn.notifications.append('0900 04 10 0227003738')
|
||||||
conn.notifications.append('0f00 04 32 0117000100000001000000')
|
conn.notifications.append('0f00 04 32 0117000100000001000000')
|
||||||
conn.notifications.append('0f00 04 3a 0128000000000100000001')
|
conn.notifications.append('0f00 04 3a 0128000000000100000001')
|
||||||
conn.notifications.append('0f00 04 3b 0115000200000002000000')
|
conn.notifications.append('0f00 04 3b 0115000200000002000000')
|
||||||
conn.notifications.append('0f00 04 3c 0114000200000002000000')
|
conn.notifications.append('0f00 04 3c 0114000200000002000000')
|
||||||
|
|
||||||
conn.notification_delayed('12000101064c45474f204d6f766520487562', 0.1)
|
conn.notification_delayed('12000101064c45474f204d6f766520487562', 1.1)
|
||||||
conn.notification_delayed('0b00010d06001653a0d1d4', 0.3)
|
conn.notification_delayed('0b00010d06001653a0d1d4', 1.3)
|
||||||
conn.notification_delayed('060001060600', 0.5)
|
conn.notification_delayed('060001060600', 1.5)
|
||||||
conn.notification_delayed('0600030104ff', 0.7)
|
conn.notification_delayed('0600030104ff', 1.7)
|
||||||
MoveHub(conn.connect())
|
MoveHub(conn.connect())
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
conn.wait_notifications_handled()
|
conn.wait_notifications_handled()
|
||||||
|
@ -148,49 +148,49 @@ class PeripheralsTest(unittest.TestCase):
|
|||||||
motor = EncodedMotor(hub, MoveHub.PORT_D)
|
motor = EncodedMotor(hub, MoveHub.PORT_D)
|
||||||
hub.peripherals[MoveHub.PORT_D] = motor
|
hub.peripherals[MoveHub.PORT_D] = motor
|
||||||
|
|
||||||
hub.connection.notification_delayed('050082020a', 0.1)
|
hub.connection.notification_delayed('050082030a', 0.1)
|
||||||
motor.start_power(1.0)
|
motor.start_power(1.0)
|
||||||
self.assertEqual(b"0800810211510164", hub.writes.pop(1)[1])
|
self.assertEqual(b"0800810311510164", hub.writes.pop(1)[1])
|
||||||
|
|
||||||
hub.connection.notification_delayed('050082020a', 0.1)
|
hub.connection.notification_delayed('050082030a', 0.1)
|
||||||
motor.stop()
|
motor.stop()
|
||||||
self.assertEqual(b"090081021107006403", hub.writes.pop(1)[1])
|
self.assertEqual(b"090081031107006403", hub.writes.pop(1)[1])
|
||||||
|
|
||||||
hub.connection.notification_delayed('050082020a', 0.1)
|
hub.connection.notification_delayed('050082030a', 0.1)
|
||||||
motor.set_acc_profile(1.0)
|
motor.set_acc_profile(1.0)
|
||||||
self.assertEqual(b"090081021105e80300", hub.writes.pop(1)[1])
|
self.assertEqual(b"090081031105e80300", hub.writes.pop(1)[1])
|
||||||
|
|
||||||
hub.connection.notification_delayed('050082020a', 0.1)
|
hub.connection.notification_delayed('050082030a', 0.1)
|
||||||
motor.set_dec_profile(1.0)
|
motor.set_dec_profile(1.0)
|
||||||
self.assertEqual(b"090081021106e80300", hub.writes.pop(1)[1])
|
self.assertEqual(b"090081031106e80300", hub.writes.pop(1)[1])
|
||||||
|
|
||||||
hub.connection.notification_delayed('050082020a', 0.1)
|
hub.connection.notification_delayed('050082030a', 0.1)
|
||||||
motor.start_speed(1.0)
|
motor.start_speed(1.0)
|
||||||
self.assertEqual(b"090081021107646403", hub.writes.pop(1)[1])
|
self.assertEqual(b"090081031107646403", hub.writes.pop(1)[1])
|
||||||
|
|
||||||
hub.connection.notification_delayed('050082020a', 0.1)
|
hub.connection.notification_delayed('050082030a', 0.1)
|
||||||
motor.stop()
|
motor.stop()
|
||||||
self.assertEqual(b"090081021107006403", hub.writes.pop(1)[1])
|
self.assertEqual(b"090081031107006403", hub.writes.pop(1)[1])
|
||||||
|
|
||||||
logging.debug("\n\n")
|
logging.debug("\n\n")
|
||||||
hub.connection.notification_delayed('0500820201', 0.1)
|
hub.connection.notification_delayed('0500820301', 0.1)
|
||||||
hub.connection.notification_delayed('050082020a', 0.2)
|
hub.connection.notification_delayed('050082030a', 0.2)
|
||||||
motor.timed(1.0)
|
motor.timed(1.0)
|
||||||
self.assertEqual(b"0c0081021109e80364647f03", hub.writes.pop(1)[1])
|
self.assertEqual(b"0c0081031109e80364647f03", hub.writes.pop(1)[1])
|
||||||
|
|
||||||
hub.connection.notification_delayed('0500820201', 0.1)
|
hub.connection.notification_delayed('0500820301', 0.1)
|
||||||
hub.connection.notification_delayed('050082020a', 0.2)
|
hub.connection.notification_delayed('050082030a', 0.2)
|
||||||
motor.angled(180)
|
motor.angled(180)
|
||||||
self.assertEqual(b"0e008102110bb400000064647f03", hub.writes.pop(1)[1])
|
self.assertEqual(b"0e008103110bb400000064647f03", hub.writes.pop(1)[1])
|
||||||
|
|
||||||
hub.connection.notification_delayed('050082020a', 0.2)
|
hub.connection.notification_delayed('050082030a', 0.2)
|
||||||
motor.preset_encoder(-180)
|
motor.preset_encoder(-180)
|
||||||
self.assertEqual(b"0b0081021151024cffffff", hub.writes.pop(1)[1])
|
self.assertEqual(b"0b0081031151024cffffff", hub.writes.pop(1)[1])
|
||||||
|
|
||||||
hub.connection.notification_delayed('0500820201', 0.1)
|
hub.connection.notification_delayed('0500820301', 0.1)
|
||||||
hub.connection.notification_delayed('050082020a', 0.2)
|
hub.connection.notification_delayed('050082030a', 0.2)
|
||||||
motor.goto_position(0)
|
motor.goto_position(0)
|
||||||
self.assertEqual(b"0e008102110d00000000647f6403", hub.writes.pop(1)[1])
|
self.assertEqual(b"0e008103110d00000000647f6403", hub.writes.pop(1)[1])
|
||||||
|
|
||||||
hub.connection.wait_notifications_handled()
|
hub.connection.wait_notifications_handled()
|
||||||
|
|
||||||
@ -204,15 +204,15 @@ class PeripheralsTest(unittest.TestCase):
|
|||||||
def callback(*args):
|
def callback(*args):
|
||||||
vals.append(args)
|
vals.append(args)
|
||||||
|
|
||||||
hub.connection.notification_delayed('0a004701020100000001', 0.1)
|
hub.connection.notification_delayed('0a004702020100000001', 0.1)
|
||||||
motor.subscribe(callback)
|
motor.subscribe(callback)
|
||||||
|
|
||||||
hub.connection.notification_delayed("0800450100000000", 0.1)
|
hub.connection.notification_delayed("0800450200000000", 0.1)
|
||||||
hub.connection.notification_delayed("08004501ffffffff", 0.2)
|
hub.connection.notification_delayed("08004502ffffffff", 0.2)
|
||||||
hub.connection.notification_delayed("08004501feffffff", 0.3)
|
hub.connection.notification_delayed("08004502feffffff", 0.3)
|
||||||
time.sleep(0.4)
|
time.sleep(0.4)
|
||||||
|
|
||||||
hub.connection.notification_delayed('0a004701020000000000', 0.1)
|
hub.connection.notification_delayed('0a004702020000000000', 0.1)
|
||||||
motor.unsubscribe(callback)
|
motor.unsubscribe(callback)
|
||||||
hub.connection.wait_notifications_handled()
|
hub.connection.wait_notifications_handled()
|
||||||
|
|
||||||
@ -228,13 +228,13 @@ class PeripheralsTest(unittest.TestCase):
|
|||||||
def callback(*args):
|
def callback(*args):
|
||||||
vals.append(args)
|
vals.append(args)
|
||||||
|
|
||||||
hub.connection.notification_delayed('0a00 4701080100000001', 0.1)
|
hub.connection.notification_delayed('0a00 4702080100000001', 0.1)
|
||||||
cds.subscribe(callback)
|
cds.subscribe(callback)
|
||||||
|
|
||||||
hub.connection.notification_delayed("08004501ff0aff00", 0.1)
|
hub.connection.notification_delayed("08004502ff0aff00", 0.1)
|
||||||
time.sleep(0.2)
|
time.sleep(0.2)
|
||||||
|
|
||||||
hub.connection.notification_delayed('0a00 4701090100000001', 0.1)
|
hub.connection.notification_delayed('0a00 4702090100000001', 0.1)
|
||||||
cds.unsubscribe(callback)
|
cds.unsubscribe(callback)
|
||||||
hub.connection.wait_notifications_handled()
|
hub.connection.wait_notifications_handled()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user