smpclient 3.2.0__tar.gz → 4.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {smpclient-3.2.0 → smpclient-4.0.0}/PKG-INFO +2 -2
- {smpclient-3.2.0 → smpclient-4.0.0}/pyproject.toml +1 -1
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/__init__.py +128 -17
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/extensions/intercreate.py +2 -2
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/generics.py +19 -14
- smpclient-4.0.0/smpclient/requests/file_management.py +30 -0
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/requests/image_management.py +2 -2
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/requests/os_management.py +1 -1
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/requests/shell_management.py +1 -1
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/requests/user/intercreate.py +1 -1
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/transport/ble.py +23 -4
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/transport/serial.py +1 -1
- {smpclient-3.2.0 → smpclient-4.0.0}/LICENSE +0 -0
- {smpclient-3.2.0 → smpclient-4.0.0}/README.md +0 -0
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/exceptions.py +0 -0
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/extensions/__init__.py +0 -0
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/mcuboot.py +0 -0
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/py.typed +0 -0
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/requests/__init__.py +0 -0
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/requests/user/__init__.py +0 -0
- {smpclient-3.2.0 → smpclient-4.0.0}/smpclient/transport/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: smpclient
|
|
3
|
-
Version:
|
|
3
|
+
Version: 4.0.0
|
|
4
4
|
Summary: Simple Management Protocol (SMP) Client for remotely managing MCU firmware
|
|
5
5
|
License: Apache-2.0
|
|
6
6
|
Author: J.P. Hutchins
|
|
@@ -16,7 +16,7 @@ Requires-Dist: async-timeout (>=4.0.3,<5.0.0) ; python_version < "3.11"
|
|
|
16
16
|
Requires-Dist: bleak (>=0.22.1,<0.23.0)
|
|
17
17
|
Requires-Dist: intelhex (>=2.3.0,<3.0.0)
|
|
18
18
|
Requires-Dist: pyserial (>=3.5,<4.0)
|
|
19
|
-
Requires-Dist: smp (>=
|
|
19
|
+
Requires-Dist: smp (>=3.0.1,<4.0.0)
|
|
20
20
|
Description-Content-Type: text/markdown
|
|
21
21
|
|
|
22
22
|
# Simple Management Protocol (SMP) Client
|
|
@@ -6,14 +6,15 @@ import asyncio
|
|
|
6
6
|
import logging
|
|
7
7
|
from hashlib import sha256
|
|
8
8
|
from types import TracebackType
|
|
9
|
-
from typing import AsyncIterator, Final, Tuple, Type
|
|
9
|
+
from typing import AsyncIterator, Final, Tuple, Type
|
|
10
10
|
|
|
11
11
|
from pydantic import ValidationError
|
|
12
12
|
from smp import header as smpheader
|
|
13
13
|
from smp import message as smpmsg
|
|
14
14
|
|
|
15
15
|
from smpclient.exceptions import SMPBadSequence, SMPUploadError
|
|
16
|
-
from smpclient.generics import SMPRequest,
|
|
16
|
+
from smpclient.generics import SMPRequest, TEr1, TEr2, TRep, error, success
|
|
17
|
+
from smpclient.requests.file_management import FileDownload, FileUpload
|
|
17
18
|
from smpclient.requests.image_management import ImageUploadWrite
|
|
18
19
|
from smpclient.requests.os_management import MCUMgrParametersRead
|
|
19
20
|
from smpclient.transport import SMPTransport
|
|
@@ -42,8 +43,8 @@ class SMPClient:
|
|
|
42
43
|
await self._transport.disconnect()
|
|
43
44
|
|
|
44
45
|
async def request(
|
|
45
|
-
self, request: SMPRequest[TRep,
|
|
46
|
-
) -> TRep |
|
|
46
|
+
self, request: SMPRequest[TRep, TEr1, TEr2], timeout_s: float = 120.000
|
|
47
|
+
) -> TRep | TEr1 | TEr2:
|
|
47
48
|
"""Make an `SMPRequest` to the SMP server."""
|
|
48
49
|
|
|
49
50
|
try:
|
|
@@ -56,23 +57,25 @@ class SMPClient:
|
|
|
56
57
|
|
|
57
58
|
header = smpheader.Header.loads(frame[: smpheader.Header.SIZE])
|
|
58
59
|
|
|
59
|
-
if header.sequence != request.header.sequence:
|
|
60
|
-
raise SMPBadSequence(
|
|
60
|
+
if header.sequence != request.header.sequence:
|
|
61
|
+
raise SMPBadSequence(
|
|
62
|
+
f"Bad sequence {header.sequence}, expected {request.header.sequence}"
|
|
63
|
+
)
|
|
61
64
|
|
|
62
65
|
try:
|
|
63
66
|
return request._Response.loads(frame) # type: ignore
|
|
64
67
|
except ValidationError:
|
|
65
68
|
pass
|
|
66
69
|
try:
|
|
67
|
-
return request.
|
|
70
|
+
return request._ErrorV1.loads(frame)
|
|
68
71
|
except ValidationError:
|
|
69
72
|
pass
|
|
70
73
|
try:
|
|
71
|
-
return request.
|
|
74
|
+
return request._ErrorV2.loads(frame)
|
|
72
75
|
except ValidationError:
|
|
73
76
|
error_message = (
|
|
74
77
|
f"Response could not by parsed as one of {request._Response}, "
|
|
75
|
-
f"{request.
|
|
78
|
+
f"{request._ErrorV1}, or {request._ErrorV2}. {header=} {frame=}"
|
|
76
79
|
)
|
|
77
80
|
logger.error(error_message)
|
|
78
81
|
raise ValidationError(error_message)
|
|
@@ -107,7 +110,7 @@ class SMPClient:
|
|
|
107
110
|
"""
|
|
108
111
|
|
|
109
112
|
response = await self.request(
|
|
110
|
-
self.
|
|
113
|
+
self._maximize_image_upload_write_packet(
|
|
111
114
|
ImageUploadWrite(
|
|
112
115
|
off=0,
|
|
113
116
|
data=b"",
|
|
@@ -133,7 +136,9 @@ class SMPClient:
|
|
|
133
136
|
# send chunks until the SMP server reports that the offset is at the end of the image
|
|
134
137
|
while response.off != len(image):
|
|
135
138
|
response = await self.request(
|
|
136
|
-
self.
|
|
139
|
+
self._maximize_image_upload_write_packet(
|
|
140
|
+
ImageUploadWrite(off=response.off, data=b""), image
|
|
141
|
+
),
|
|
137
142
|
timeout_s=subsequent_timeout_s,
|
|
138
143
|
)
|
|
139
144
|
if error(response):
|
|
@@ -145,6 +150,90 @@ class SMPClient:
|
|
|
145
150
|
else: # pragma: no cover
|
|
146
151
|
raise Exception("Unreachable")
|
|
147
152
|
|
|
153
|
+
logger.info("Upload complete")
|
|
154
|
+
|
|
155
|
+
if response.match is not None:
|
|
156
|
+
logger.info(f"Server reports {response.match=}")
|
|
157
|
+
if response.match is not True:
|
|
158
|
+
message: Final = f"Upload failed, server reported mismatched SHA256: {response}"
|
|
159
|
+
logger.error(message)
|
|
160
|
+
raise SMPUploadError(message)
|
|
161
|
+
|
|
162
|
+
async def upload_file(
|
|
163
|
+
self,
|
|
164
|
+
file_data: bytes,
|
|
165
|
+
file_path: str,
|
|
166
|
+
timeout_s: float = 2.500,
|
|
167
|
+
) -> AsyncIterator[int]:
|
|
168
|
+
response = await self.request(
|
|
169
|
+
self._maximize_file_upload_packet(
|
|
170
|
+
FileUpload(name=file_path, off=0, data=b"", len=len(file_data)),
|
|
171
|
+
file_data,
|
|
172
|
+
),
|
|
173
|
+
timeout_s=timeout_s,
|
|
174
|
+
)
|
|
175
|
+
|
|
176
|
+
if error(response):
|
|
177
|
+
raise SMPUploadError(response)
|
|
178
|
+
elif success(response):
|
|
179
|
+
if response.off is None:
|
|
180
|
+
raise SMPUploadError(f"No offset received: {response=}")
|
|
181
|
+
yield response.off
|
|
182
|
+
else: # pragma: no cover
|
|
183
|
+
raise Exception("Unreachable")
|
|
184
|
+
|
|
185
|
+
# send chunks until the SMP server reports that the offset is at the end of the image
|
|
186
|
+
while response.off != len(file_data):
|
|
187
|
+
response = await self.request(
|
|
188
|
+
self._maximize_file_upload_packet(
|
|
189
|
+
FileUpload(name=file_path, off=response.off, data=b""), file_data
|
|
190
|
+
),
|
|
191
|
+
timeout_s=timeout_s,
|
|
192
|
+
)
|
|
193
|
+
if error(response):
|
|
194
|
+
raise SMPUploadError(response)
|
|
195
|
+
elif success(response):
|
|
196
|
+
yield response.off
|
|
197
|
+
else: # pragma: no cover
|
|
198
|
+
raise Exception("Unreachable")
|
|
199
|
+
|
|
200
|
+
logger.info("Upload complete")
|
|
201
|
+
|
|
202
|
+
async def download_file(
|
|
203
|
+
self,
|
|
204
|
+
file_path: str,
|
|
205
|
+
timeout_s: float = 2.500,
|
|
206
|
+
) -> bytes:
|
|
207
|
+
response = await self.request(FileDownload(off=0, name=file_path), timeout_s=timeout_s)
|
|
208
|
+
file_length = 0
|
|
209
|
+
|
|
210
|
+
if error(response):
|
|
211
|
+
raise SMPUploadError(response)
|
|
212
|
+
elif success(response):
|
|
213
|
+
if response.len is None:
|
|
214
|
+
raise SMPUploadError(f"No length received: {response=}")
|
|
215
|
+
file_length = response.len
|
|
216
|
+
else: # pragma: no cover
|
|
217
|
+
raise Exception("Unreachable")
|
|
218
|
+
|
|
219
|
+
file_data = response.data
|
|
220
|
+
|
|
221
|
+
# send chunks until the SMP server reports that the offset is at the end of the image
|
|
222
|
+
while response.off + len(response.data) != file_length:
|
|
223
|
+
response = await self.request(
|
|
224
|
+
FileDownload(off=response.off + len(response.data), name=file_path),
|
|
225
|
+
timeout_s=timeout_s,
|
|
226
|
+
)
|
|
227
|
+
if error(response):
|
|
228
|
+
raise SMPUploadError(response)
|
|
229
|
+
elif success(response):
|
|
230
|
+
file_data += response.data
|
|
231
|
+
else: # pragma: no cover
|
|
232
|
+
raise Exception("Unreachable")
|
|
233
|
+
|
|
234
|
+
logger.info("Download complete")
|
|
235
|
+
return file_data
|
|
236
|
+
|
|
148
237
|
@property
|
|
149
238
|
def address(self) -> str:
|
|
150
239
|
return self._address
|
|
@@ -175,8 +264,6 @@ class SMPClient:
|
|
|
175
264
|
def _get_max_cbor_and_data_size(self, request: smpmsg.WriteRequest) -> Tuple[int, int]:
|
|
176
265
|
"""Given an `ImageUploadWrite`, return the maximum CBOR size and data size."""
|
|
177
266
|
|
|
178
|
-
h: Final = cast(smpheader.Header, request.header)
|
|
179
|
-
|
|
180
267
|
# given empty data in the request, how many bytes are available for the data?
|
|
181
268
|
unencoded_bytes_available: Final = self._transport.max_unencoded_size - len(bytes(request))
|
|
182
269
|
|
|
@@ -188,17 +275,18 @@ class SMPClient:
|
|
|
188
275
|
# the final data size is the unencoded bytes available minus the bytes
|
|
189
276
|
# required to encode the data size
|
|
190
277
|
data_size: Final = max(0, unencoded_bytes_available - bytes_required_to_encode_data_size)
|
|
191
|
-
|
|
192
278
|
# the final CBOR size is the original header length plus the data size
|
|
193
279
|
# plus the bytes required to encode the data size
|
|
194
|
-
cbor_size: Final =
|
|
280
|
+
cbor_size: Final = request.header.length + data_size + self._cbor_integer_size(data_size)
|
|
195
281
|
|
|
196
282
|
return cbor_size, data_size
|
|
197
283
|
|
|
198
|
-
def
|
|
284
|
+
def _maximize_image_upload_write_packet(
|
|
285
|
+
self, request: ImageUploadWrite, image: bytes
|
|
286
|
+
) -> ImageUploadWrite:
|
|
199
287
|
"""Given an `ImageUploadWrite` with empty `data`, return the largest packet possible."""
|
|
200
288
|
|
|
201
|
-
h: Final =
|
|
289
|
+
h: Final = request.header
|
|
202
290
|
cbor_size, data_size = self._get_max_cbor_and_data_size(request)
|
|
203
291
|
|
|
204
292
|
if data_size > len(image) - request.off: # final packet
|
|
@@ -223,6 +311,29 @@ class SMPClient:
|
|
|
223
311
|
upgrade=request.upgrade,
|
|
224
312
|
)
|
|
225
313
|
|
|
314
|
+
def _maximize_file_upload_packet(self, request: FileUpload, data: bytes) -> FileUpload:
|
|
315
|
+
"""Given an `FileUpload` with empty `data`, return the largest packet possible."""
|
|
316
|
+
h: Final = request.header
|
|
317
|
+
cbor_size, data_size = self._get_max_cbor_and_data_size(request)
|
|
318
|
+
if data_size > len(data) - request.off: # final packet
|
|
319
|
+
data_size = len(data) - request.off
|
|
320
|
+
cbor_size = h.length + data_size + self._cbor_integer_size(data_size)
|
|
321
|
+
return FileUpload(
|
|
322
|
+
header=smpheader.Header(
|
|
323
|
+
op=h.op,
|
|
324
|
+
version=h.version,
|
|
325
|
+
flags=h.flags,
|
|
326
|
+
length=cbor_size,
|
|
327
|
+
group_id=h.group_id,
|
|
328
|
+
sequence=h.sequence,
|
|
329
|
+
command_id=h.command_id,
|
|
330
|
+
),
|
|
331
|
+
name=request.name,
|
|
332
|
+
off=request.off,
|
|
333
|
+
data=data[request.off : request.off + data_size],
|
|
334
|
+
len=request.len,
|
|
335
|
+
)
|
|
336
|
+
|
|
226
337
|
async def _initialize(self) -> None:
|
|
227
338
|
"""Gather initialization information from the SMP server."""
|
|
228
339
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Intercreate extensions of the `SMPClient`."""
|
|
2
2
|
|
|
3
|
-
from typing import AsyncIterator, Final
|
|
3
|
+
from typing import AsyncIterator, Final
|
|
4
4
|
|
|
5
5
|
from smp import header as smpheader
|
|
6
6
|
|
|
@@ -42,7 +42,7 @@ class ICUploadClient(SMPClient):
|
|
|
42
42
|
def _ic_maximize_packet(self, request: ic.ImageUploadWrite, data: bytes) -> ic.ImageUploadWrite:
|
|
43
43
|
"""Given an `ic.ImageUploadWrite` with empty `data`, return the largest packet possible."""
|
|
44
44
|
|
|
45
|
-
h: Final =
|
|
45
|
+
h: Final = request.header
|
|
46
46
|
cbor_size, data_size = self._get_max_cbor_and_data_size(request)
|
|
47
47
|
|
|
48
48
|
if data_size > len(data) - request.off: # final packet
|
|
@@ -5,53 +5,58 @@ from __future__ import annotations
|
|
|
5
5
|
from typing import Protocol, Type, TypeVar, Union
|
|
6
6
|
|
|
7
7
|
from smp import error as smperror
|
|
8
|
+
from smp import header as smphdr
|
|
8
9
|
from smp import message as smpmessage
|
|
9
10
|
from typing_extensions import TypeGuard
|
|
10
11
|
|
|
11
|
-
TEr0 = TypeVar("TEr0", bound=smperror.ErrorV0)
|
|
12
12
|
TEr1 = TypeVar("TEr1", bound=smperror.ErrorV1)
|
|
13
|
+
TEr2 = TypeVar("TEr2", bound=smperror.ErrorV2)
|
|
13
14
|
TRep = TypeVar("TRep", bound=Union[smpmessage.ReadResponse, smpmessage.WriteResponse])
|
|
14
15
|
|
|
15
16
|
|
|
16
|
-
class SMPRequest(Protocol[TRep,
|
|
17
|
+
class SMPRequest(Protocol[TRep, TEr1, TEr2]):
|
|
17
18
|
"""A `Protocol` that groups the expected response and errors with a request.
|
|
18
19
|
|
|
19
20
|
To use, inherit from an SMP Read or Write `Request` and define its expected
|
|
20
|
-
`Response`, `
|
|
21
|
+
`Response`, `ErrorV1`, and `ErrorV2`.
|
|
21
22
|
|
|
22
23
|
Example:
|
|
23
24
|
```python
|
|
24
25
|
class ImageStatesRead(smpimg.ImageStatesReadRequest):
|
|
25
26
|
_Response = smpimg.ImageStatesReadResponse
|
|
26
|
-
_ErrorV0 = smpimg.ImageManagementErrorV0
|
|
27
27
|
_ErrorV1 = smpimg.ImageManagementErrorV1
|
|
28
|
+
_ErrorV2 = smpimg.ImageManagementErrorV2
|
|
28
29
|
```
|
|
29
30
|
"""
|
|
30
31
|
|
|
31
32
|
_Response: Type[TRep]
|
|
32
|
-
_ErrorV0: Type[TEr0]
|
|
33
33
|
_ErrorV1: Type[TEr1]
|
|
34
|
+
_ErrorV2: Type[TEr2]
|
|
34
35
|
|
|
35
36
|
@property
|
|
36
37
|
def BYTES(self) -> bytes: # pragma: no cover
|
|
37
38
|
...
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
def
|
|
41
|
-
|
|
42
|
-
return response.RESPONSE_TYPE == smpmessage.ResponseType.ERROR_V0
|
|
40
|
+
@property
|
|
41
|
+
def header(self) -> smphdr.Header: # pragma: no cover
|
|
42
|
+
...
|
|
43
43
|
|
|
44
44
|
|
|
45
|
-
def error_v1(response: smperror.
|
|
45
|
+
def error_v1(response: smperror.ErrorV1 | TEr2 | TRep) -> TypeGuard[smperror.ErrorV1]:
|
|
46
46
|
"""`TypeGuard` that returns `True` if the `response` is an `ErrorV1`."""
|
|
47
47
|
return response.RESPONSE_TYPE == smpmessage.ResponseType.ERROR_V1
|
|
48
48
|
|
|
49
49
|
|
|
50
|
-
def
|
|
51
|
-
"""`TypeGuard` that returns `True` if the `response` is an `
|
|
52
|
-
return
|
|
50
|
+
def error_v2(response: smperror.ErrorV1 | TEr2 | TRep) -> TypeGuard[TEr2]:
|
|
51
|
+
"""`TypeGuard` that returns `True` if the `response` is an `ErrorV2`."""
|
|
52
|
+
return response.RESPONSE_TYPE == smpmessage.ResponseType.ERROR_V2
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def error(response: smperror.ErrorV1 | TEr2 | TRep) -> TypeGuard[smperror.ErrorV1 | TEr2]:
|
|
56
|
+
"""`TypeGuard` that returns `True` if the `response` is an `ErrorV1` or `ErrorV2`."""
|
|
57
|
+
return error_v1(response) or error_v2(response)
|
|
53
58
|
|
|
54
59
|
|
|
55
|
-
def success(response: smperror.
|
|
60
|
+
def success(response: smperror.ErrorV1 | TEr2 | TRep) -> TypeGuard[TRep]:
|
|
56
61
|
"""`TypeGuard` that returns `True` if the `response` is a successful `Response`."""
|
|
57
62
|
return response.RESPONSE_TYPE == smpmessage.ResponseType.SUCCESS
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from smp import file_management as smpfs
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class _FileGroupBase:
|
|
5
|
+
_ErrorV1 = smpfs.FileSystemManagementErrorV1
|
|
6
|
+
_ErrorV2 = smpfs.FileSystemManagementErrorV2
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class FileDownload(smpfs.FileDownloadRequest, _FileGroupBase):
|
|
10
|
+
_Response = smpfs.FileDownloadResponse
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class FileUpload(smpfs.FileUploadRequest, _FileGroupBase):
|
|
14
|
+
_Response = smpfs.FileUploadResponse
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class FileStatus(smpfs.FileStatusRequest, _FileGroupBase):
|
|
18
|
+
_Response = smpfs.FileStatusResponse
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class FileHashChecksum(smpfs.FileHashChecksumRequest, _FileGroupBase):
|
|
22
|
+
_Response = smpfs.FileHashChecksumResponse
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class SupportedFileHashChecksumTypes(smpfs.SupportedFileHashChecksumTypesRequest, _FileGroupBase):
|
|
26
|
+
_Response = smpfs.SupportedFileHashChecksumTypesResponse
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class FileClose(smpfs.FileCloseRequest, _FileGroupBase):
|
|
30
|
+
_Response = smpfs.FileCloseResponse
|
|
@@ -2,8 +2,8 @@ from smp import image_management as smpimg
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
class _ImageGroupBase:
|
|
5
|
-
_ErrorV0 = smpimg.ImageManagementErrorV0
|
|
6
5
|
_ErrorV1 = smpimg.ImageManagementErrorV1
|
|
6
|
+
_ErrorV2 = smpimg.ImageManagementErrorV2
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class ImageStatesRead(smpimg.ImageStatesReadRequest, _ImageGroupBase):
|
|
@@ -15,7 +15,7 @@ class ImageStatesWrite(smpimg.ImageStatesWriteRequest, _ImageGroupBase):
|
|
|
15
15
|
|
|
16
16
|
|
|
17
17
|
class ImageUploadWrite(smpimg.ImageUploadWriteRequest, _ImageGroupBase):
|
|
18
|
-
_Response = smpimg.
|
|
18
|
+
_Response = smpimg.ImageUploadWriteResponse
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
class ImageErase(smpimg.ImageEraseRequest, _ImageGroupBase):
|
|
@@ -2,8 +2,8 @@ from smp import shell_management as smpshell
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
class _ShellGroupBase:
|
|
5
|
-
_ErrorV0 = smpshell.ShellManagementErrorV0
|
|
6
5
|
_ErrorV1 = smpshell.ShellManagementErrorV1
|
|
6
|
+
_ErrorV2 = smpshell.ShellManagementErrorV2
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
class Execute(smpshell.ExecuteRequest, _ShellGroupBase):
|
|
@@ -4,10 +4,9 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
import asyncio
|
|
6
6
|
import logging
|
|
7
|
-
import platform
|
|
8
7
|
import re
|
|
9
8
|
import sys
|
|
10
|
-
from typing import Final, List
|
|
9
|
+
from typing import Final, List, Protocol
|
|
11
10
|
from uuid import UUID
|
|
12
11
|
|
|
13
12
|
from bleak import BleakClient, BleakGATTCharacteristic, BleakScanner
|
|
@@ -23,11 +22,24 @@ if sys.platform == "linux":
|
|
|
23
22
|
from bleak.backends.bluezdbus.client import BleakClientBlueZDBus
|
|
24
23
|
else: # stub for mypy
|
|
25
24
|
|
|
26
|
-
class BleakClientBlueZDBus:
|
|
25
|
+
class BleakClientBlueZDBus(Protocol):
|
|
27
26
|
async def _acquire_mtu(self) -> None:
|
|
28
27
|
...
|
|
29
28
|
|
|
30
29
|
|
|
30
|
+
if sys.platform == "win32":
|
|
31
|
+
from bleak.backends.winrt.client import BleakClientWinRT
|
|
32
|
+
else: # stub for mypy
|
|
33
|
+
|
|
34
|
+
class GattSession(Protocol):
|
|
35
|
+
max_pdu_size: int
|
|
36
|
+
|
|
37
|
+
class BleakClientWinRT(Protocol):
|
|
38
|
+
@property
|
|
39
|
+
def _session(self) -> GattSession:
|
|
40
|
+
...
|
|
41
|
+
|
|
42
|
+
|
|
31
43
|
SMP_SERVICE_UUID: Final = UUID("8D53DC1D-1DB7-4CD3-868B-8A527460AA84")
|
|
32
44
|
SMP_CHARACTERISTIC_UUID: Final = UUID("DA2E7828-FBCE-4E01-AE9E-261174997C48")
|
|
33
45
|
|
|
@@ -95,7 +107,10 @@ class SMPBLETransport(SMPTransport):
|
|
|
95
107
|
logger.debug(f"Found SMP characteristic: {smp_characteristic=}")
|
|
96
108
|
logger.info(f"{smp_characteristic.max_write_without_response_size=}")
|
|
97
109
|
self._max_write_without_response_size = smp_characteristic.max_write_without_response_size
|
|
98
|
-
if
|
|
110
|
+
if (
|
|
111
|
+
self._winrt_backend(self._client._backend)
|
|
112
|
+
and self._max_write_without_response_size == 20
|
|
113
|
+
):
|
|
99
114
|
# https://github.com/hbldh/bleak/pull/1552#issuecomment-2105573291
|
|
100
115
|
logger.warning(
|
|
101
116
|
"The SMP characteristic MTU is 20 bytes, possibly a Windows bug, checking again"
|
|
@@ -201,6 +216,10 @@ class SMPBLETransport(SMPTransport):
|
|
|
201
216
|
def _bluez_backend(client_backend: BaseBleakClient) -> TypeGuard[BleakClientBlueZDBus]:
|
|
202
217
|
return client_backend.__class__.__name__ == "BleakClientBlueZDBus"
|
|
203
218
|
|
|
219
|
+
@staticmethod
|
|
220
|
+
def _winrt_backend(client_backend: BaseBleakClient) -> TypeGuard[BleakClientWinRT]:
|
|
221
|
+
return client_backend.__class__.__name__ == "BleakClientWinRT"
|
|
222
|
+
|
|
204
223
|
def _set_disconnected_event(self, client: BleakClient) -> None:
|
|
205
224
|
if client is not self._client:
|
|
206
225
|
raise SMPBLETransportException(
|
|
@@ -316,7 +316,7 @@ class SMPSerialTransport(SMPTransport):
|
|
|
316
316
|
packet_framing_size: Final = (
|
|
317
317
|
_base64_cost(smppacket.FRAME_LENGTH_STRUCT.size + smppacket.CRC16_STRUCT.size)
|
|
318
318
|
+ smppacket.DELIMITER_SIZE
|
|
319
|
-
) * self._line_buffers + len(smppacket.
|
|
319
|
+
) * self._line_buffers + len(smppacket.END_DELIMITER)
|
|
320
320
|
|
|
321
321
|
# Get the number of unencoded bytes that can fit in self.mtu and
|
|
322
322
|
# subtract the cost of framing the separate packets.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|