|
1 | 1 | # SPDX-License-Identifier: MIT |
2 | 2 | # Copyright (c) 2021-2022 The Pybricks Authors |
3 | 3 |
|
4 | | -"""This module and its submodules are used for Bluetooth Low Energy |
| 4 | +""" |
| 5 | +This module and its submodules are used for Bluetooth Low Energy |
5 | 6 | communications with devices that provide the LEGO Wireless Protocol v3. |
6 | 7 | """ |
7 | 8 |
|
8 | | -from enum import IntEnum |
9 | | - |
10 | | -from .bytecodes import Capabilities, HubKind, LastNetwork, Status, Version |
| 9 | +from .bytecodes import Capabilities, HubKind, LastNetwork, Status |
11 | 10 |
|
12 | 11 | # LEGO Wireless Protocol v3 is defined at: |
13 | 12 | # https://lego.github.io/lego-ble-wireless-protocol-docs/ |
@@ -47,105 +46,6 @@ def _lwp3_uuid(short: int) -> str: |
47 | 46 | """LEGO wireless protocol v3 bootloader characteristic UUID.""" |
48 | 47 |
|
49 | 48 |
|
50 | | -# Bootloader characteristic bytecodes |
51 | | - |
52 | | - |
53 | | -class BootloaderCommand(IntEnum): |
54 | | - """Commands that are sent to the bootloader GATT characteristic.""" |
55 | | - |
56 | | - ERASE_FLASH = 0x11 |
57 | | - """Erases the flash memory.""" |
58 | | - |
59 | | - PROGRAM_FLASH = 0x22 |
60 | | - """Writes to a segment of the flash memory.""" |
61 | | - |
62 | | - START_APP = 0x33 |
63 | | - """Starts running the firmware (causes Bluetooth to disconnect).""" |
64 | | - |
65 | | - INIT_LOADER = 0x44 |
66 | | - """Initializes the firmware flasher.""" |
67 | | - |
68 | | - GET_INFO = 0x55 |
69 | | - """Gets info about the hub and flash memory layout.""" |
70 | | - |
71 | | - GET_CHECKSUM = 0x66 |
72 | | - """Gets the current checksum for the data that has been written so far.""" |
73 | | - |
74 | | - GET_FLASH_STATE = 0x77 |
75 | | - """Gets the STM32 flash memory debug protection state. |
76 | | -
|
77 | | - Not all bootloaders support this command. |
78 | | - """ |
79 | | - |
80 | | - DISCONNECT = 0x88 |
81 | | - """Causes the remote device to disconnect from Bluetooth.""" |
82 | | - |
83 | | - |
84 | | -class BootloaderMessageKind(IntEnum): |
85 | | - """Type for messages received from bootlaoder GATT characteristic notifications. |
86 | | -
|
87 | | - Messages that are a response to a command will have the same value as |
88 | | - :class:`BootloaderCommand` instead of a value from this enum. |
89 | | - """ |
90 | | - |
91 | | - ERROR = 0x05 |
92 | | - """Indicates that an error occurred.""" |
93 | | - |
94 | | - |
95 | | -class BootloaderResult(IntEnum): |
96 | | - """Status returned by certain bootloader commands.""" |
97 | | - |
98 | | - OK = 0x00 |
99 | | - """The command was successful.""" |
100 | | - |
101 | | - ERROR = 0xFF |
102 | | - """The command failed.""" |
103 | | - |
104 | | - |
105 | | -class BootloaderError(IntEnum): |
106 | | - """Error type returned by bootloader error messages.""" |
107 | | - |
108 | | - UNKNOWN_COMMAND = 0x05 |
109 | | - """The command was not recognized.""" |
110 | | - |
111 | | - |
112 | | -class BootloaderAdvertisementData: |
113 | | - """ |
114 | | - The 6-byte manufacturer-specific advertisement data sent when a hub in |
115 | | - bootloader mode is advertising. |
116 | | - """ |
117 | | - |
118 | | - def __init__(self, data: bytes) -> None: |
119 | | - if len(data) != 6: |
120 | | - raise ValueError("expecting 6 bytes of data") |
121 | | - |
122 | | - self._data = data |
123 | | - |
124 | | - def __bytes__(self) -> bytes: |
125 | | - return self._data |
126 | | - |
127 | | - @property |
128 | | - def version(self) -> Version: |
129 | | - """ |
130 | | - Gets the bootloader software version. |
131 | | - """ |
132 | | - return Version(int.from_bytes(self._data[:4], "little")) |
133 | | - |
134 | | - @property |
135 | | - def hub_kind(self) -> HubKind: |
136 | | - """ |
137 | | - Gets the hub type identifier. |
138 | | - """ |
139 | | - return HubKind(self._data[4]) |
140 | | - |
141 | | - @property |
142 | | - def hub_capabilities(self) -> Capabilities: |
143 | | - """ |
144 | | - Gets the hub capability flags. |
145 | | - """ |
146 | | - return Capabilities(self._data[5]) |
147 | | - |
148 | | - |
149 | 49 | class AdvertisementData: |
150 | 50 | """ |
151 | 51 | The 6-byte manufacturer-specific advertisement data sent when a hub running |
|
0 commit comments