pyvisionect 0.1.0__py3-none-any.whl
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.
- pyvisionect/__init__.py +120 -0
- pyvisionect/devices/__init__.py +92 -0
- pyvisionect/devices/enums.py +403 -0
- pyvisionect/devices/panels.py +242 -0
- pyvisionect/devices/tclv.py +460 -0
- pyvisionect/imaging/README.md +175 -0
- pyvisionect/imaging/__init__.py +181 -0
- pyvisionect/imaging/checksum.py +114 -0
- pyvisionect/imaging/constants.py +131 -0
- pyvisionect/imaging/data/blue_noise_64.npy +0 -0
- pyvisionect/imaging/decode.py +172 -0
- pyvisionect/imaging/dither.py +357 -0
- pyvisionect/imaging/encoder.py +594 -0
- pyvisionect/imaging/geometry.py +129 -0
- pyvisionect/imaging/grey.py +104 -0
- pyvisionect/imaging/interlace.py +244 -0
- pyvisionect/imaging/pack.py +142 -0
- pyvisionect/imaging/panel.py +339 -0
- pyvisionect/imaging/partial.py +931 -0
- pyvisionect/imaging/rects.py +466 -0
- pyvisionect/io/__init__.py +33 -0
- pyvisionect/io/tcp.py +795 -0
- pyvisionect/io/usb/__init__.py +237 -0
- pyvisionect/io/usb/cli.py +278 -0
- pyvisionect/io/usb/commands.py +781 -0
- pyvisionect/io/usb/console.py +730 -0
- pyvisionect/io/usb/device.py +914 -0
- pyvisionect/io/usb/discovery.py +260 -0
- pyvisionect/io/usb/encryption.py +262 -0
- pyvisionect/io/usb/errors.py +175 -0
- pyvisionect/io/usb/fake.py +292 -0
- pyvisionect/io/usb/parsers.py +1464 -0
- pyvisionect/io/usb/provisioning.py +502 -0
- pyvisionect/packets/__init__.py +135 -0
- pyvisionect/packets/control.py +95 -0
- pyvisionect/packets/file.py +325 -0
- pyvisionect/packets/image.py +234 -0
- pyvisionect/packets/misc.py +202 -0
- pyvisionect/packets/param.py +284 -0
- pyvisionect/packets/status.py +518 -0
- pyvisionect/packets/stored.py +217 -0
- pyvisionect/py.typed +0 -0
- pyvisionect/session/__init__.py +100 -0
- pyvisionect/session/connection.py +1043 -0
- pyvisionect/session/device.py +587 -0
- pyvisionect/session/events.py +196 -0
- pyvisionect/session/filetransfer.py +251 -0
- pyvisionect/session/pending.py +425 -0
- pyvisionect/wire/__init__.py +91 -0
- pyvisionect/wire/blocks.py +350 -0
- pyvisionect/wire/checksum.py +115 -0
- pyvisionect/wire/errors.py +176 -0
- pyvisionect/wire/framing.py +334 -0
- pyvisionect-0.1.0.dist-info/METADATA +1030 -0
- pyvisionect-0.1.0.dist-info/RECORD +58 -0
- pyvisionect-0.1.0.dist-info/WHEEL +4 -0
- pyvisionect-0.1.0.dist-info/entry_points.txt +3 -0
- pyvisionect-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,502 @@
|
|
|
1
|
+
'''Provisioning flows, every one of them dry-runnable.
|
|
2
|
+
|
|
3
|
+
A :class:`Plan` is the exact sequence of command lines a flow would send,
|
|
4
|
+
produced without touching the port. Build it, read it, then
|
|
5
|
+
:meth:`~Plan.execute` it -- or never execute it at all, which is the point.
|
|
6
|
+
Printing the plan is the only way to review a bootstrap *before* it strands a
|
|
7
|
+
sign somewhere you cannot reach it, and every command in here is in the
|
|
8
|
+
``DESTRUCTIVE`` tier precisely because getting it wrong means fetching a cable.
|
|
9
|
+
|
|
10
|
+
Why USB at all
|
|
11
|
+
--------------
|
|
12
|
+
|
|
13
|
+
Eight TCLV ids are ``canWrite: false`` in the vendor's own admin-UI descriptor
|
|
14
|
+
table, and they are exactly the ones a bootstrap needs: ``CONN_TYPE`` (2),
|
|
15
|
+
``IPV4_SERVER_IP`` (18), ``IPV4_SERVER_PORT`` (19), ``WIFI_SSID`` (65),
|
|
16
|
+
``WIFI_SECURITY`` (66), ``WIFI_PSK`` (67), ``WIFI_BAND`` (68) and
|
|
17
|
+
``MOB_SECURITY`` (70). The network protocol can read them and will never write
|
|
18
|
+
them, so there is no over-the-air escape: you cannot tell a sign about a new
|
|
19
|
+
WiFi network over the network it does not have. See
|
|
20
|
+
:data:`pyvisionect.devices.tclv.NETWORK_READ_ONLY`.
|
|
21
|
+
|
|
22
|
+
The cheaper alternative
|
|
23
|
+
-----------------------
|
|
24
|
+
|
|
25
|
+
**If the sign already holds a hostname, you do not need any of this.** The live
|
|
26
|
+
sign holds ``visionect.internal.example.com`` in TCLV 18, so re-pointing that
|
|
27
|
+
name at your own listener moves the sign with zero commands and zero risk.
|
|
28
|
+
:func:`describe_alternatives` says so in the output of a dry run, because it is
|
|
29
|
+
the first thing someone about to run a bootstrap should consider and the last
|
|
30
|
+
thing they will think of.
|
|
31
|
+
|
|
32
|
+
Whitespace in an SSID or passphrase
|
|
33
|
+
-----------------------------------
|
|
34
|
+
|
|
35
|
+
**A spaced SSID works, and is emitted.** Measured on firmware 7.4.4407:
|
|
36
|
+
``wifi_ssid_set`` takes **everything after the command name and one separating
|
|
37
|
+
space, verbatim** -- interior spaces, runs of spaces, leading and trailing
|
|
38
|
+
spaces, apostrophes, quotes and backslashes all land in TCLV 65 byte for byte.
|
|
39
|
+
There is **no quoting or escaping convention**, so ``"My Home WiFi"`` sets an
|
|
40
|
+
SSID whose first and last characters are double quotes. See ``A2`` in
|
|
41
|
+
``OPEN-QUESTIONS.md`` for the full table of what landed for each form.
|
|
42
|
+
|
|
43
|
+
So when the SSID contains whitespace, :func:`plan_wifi` drops ``wifi_conf_set``
|
|
44
|
+
-- which really is positional, and would shift the psk, security and band
|
|
45
|
+
arguments along by one -- and emits the three single-argument setters instead::
|
|
46
|
+
|
|
47
|
+
wifi_psk_set <psk>
|
|
48
|
+
wifi_security_set <security>
|
|
49
|
+
wifi_ssid_set <ssid>
|
|
50
|
+
|
|
51
|
+
SSID last, so the field that decides association is the final write. Two
|
|
52
|
+
things do not come free:
|
|
53
|
+
|
|
54
|
+
* **Band (TCLV 68) cannot be written this way.** There is no ``wifi_band_set``
|
|
55
|
+
-- not in ``help``, not in the vendor's 162 documented commands --
|
|
56
|
+
``wifi_conf_set`` is its only writer, and that is the one command the space
|
|
57
|
+
rules out. A spaced SSID with a non-default *band* is therefore still
|
|
58
|
+
refused; with ``band=0`` the plan carries a note that TCLV 68 is left alone.
|
|
59
|
+
* **``help`` still does not list ``wifi_ssid_set``.** It is hidden, not absent
|
|
60
|
+
(:data:`pyvisionect.io.usb.commands.HIDDEN_IN_7_4_4407`), so
|
|
61
|
+
:meth:`Plan.execute` exempts hidden names from its missing-command check and
|
|
62
|
+
sends them with the firmware-command gate off. Nothing else about that gate
|
|
63
|
+
changes: ``help`` is still the only evidence available on a firmware this
|
|
64
|
+
library has not seen.
|
|
65
|
+
|
|
66
|
+
**The passphrase is still refused.** ``wifi_psk_set`` is a single-argument
|
|
67
|
+
command of exactly the same shape, so it very probably carries a space too --
|
|
68
|
+
but there is **no read path for TCLV 67**. ``wifi_conf_get`` returns SSID,
|
|
69
|
+
security and band and never the passphrase, so nothing can be read back to
|
|
70
|
+
check. The SSID experiment was safe because every write was read straight
|
|
71
|
+
back; a truncated passphrase has no such oracle and fails silently, as a sign
|
|
72
|
+
that will not associate and then power-cycles itself on
|
|
73
|
+
``E: Max conn errs. Reboot`` with ``ErrorCode`` still ``0x0``. Rename the
|
|
74
|
+
network, or move the sign by re-pointing the DNS name it already holds.
|
|
75
|
+
'''
|
|
76
|
+
|
|
77
|
+
from __future__ import annotations
|
|
78
|
+
|
|
79
|
+
from collections.abc import Sequence
|
|
80
|
+
from dataclasses import dataclass, field
|
|
81
|
+
|
|
82
|
+
from .commands import COMMANDS, HIDDEN_IN_7_4_4407, Kind
|
|
83
|
+
from .console import CommandResult
|
|
84
|
+
from .device import Sign
|
|
85
|
+
|
|
86
|
+
__all__ = [
|
|
87
|
+
"DEFAULT_SERVER_PORT",
|
|
88
|
+
"Plan",
|
|
89
|
+
"Step",
|
|
90
|
+
"WifiSecurity",
|
|
91
|
+
"describe_alternatives",
|
|
92
|
+
"plan_bootstrap",
|
|
93
|
+
"plan_repoint",
|
|
94
|
+
"plan_wifi",
|
|
95
|
+
]
|
|
96
|
+
|
|
97
|
+
DEFAULT_SERVER_PORT = 11113
|
|
98
|
+
"""The port a sign dials out to, and the port :mod:`pyvisionect.io.tcp` listens on."""
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class WifiSecurity:
|
|
102
|
+
"""``WIFI_SECURITY`` (TCLV 66) values. **ASCII strings, not integers.**
|
|
103
|
+
|
|
104
|
+
Confirmed on the live sign, which reports ``Security: wpa2`` from
|
|
105
|
+
``wifi_conf_get``.
|
|
106
|
+
"""
|
|
107
|
+
|
|
108
|
+
OPEN = "none"
|
|
109
|
+
WPA2 = "wpa2"
|
|
110
|
+
WPA2_ENTERPRISE = "wpa2e"
|
|
111
|
+
|
|
112
|
+
ALL = (OPEN, WPA2, WPA2_ENTERPRISE)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
@dataclass(frozen=True, slots=True)
|
|
116
|
+
class Step:
|
|
117
|
+
"""One command in a :class:`Plan`.
|
|
118
|
+
|
|
119
|
+
Attributes:
|
|
120
|
+
command: the exact line that would be written.
|
|
121
|
+
why: one sentence on what it does and what it costs. Shown by
|
|
122
|
+
:meth:`Plan.describe`, so a dry run reads as an explanation rather
|
|
123
|
+
than a list of strings.
|
|
124
|
+
expect_prompt: False for ``reboot``, which never prompts again.
|
|
125
|
+
"""
|
|
126
|
+
|
|
127
|
+
command: str
|
|
128
|
+
why: str
|
|
129
|
+
expect_prompt: bool = True
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def name(self) -> str:
|
|
133
|
+
return self.command.split()[0] if self.command.split() else ""
|
|
134
|
+
|
|
135
|
+
@property
|
|
136
|
+
def kind(self) -> Kind:
|
|
137
|
+
entry = COMMANDS.get(self.name)
|
|
138
|
+
return entry.kind if entry is not None else Kind.WRITE
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def in_firmware(self) -> bool:
|
|
142
|
+
"""Whether 7.4.4407 is known to have this command.
|
|
143
|
+
|
|
144
|
+
Checked against :data:`~pyvisionect.io.usb.commands.COMMANDS`, which is
|
|
145
|
+
every command known to exist -- including the ones ``help`` does not
|
|
146
|
+
print. False therefore means "not in the table", which is weaker than
|
|
147
|
+
"not in the firmware": see
|
|
148
|
+
:data:`~pyvisionect.io.usb.commands.HIDDEN_IN_7_4_4407`.
|
|
149
|
+
"""
|
|
150
|
+
return self.name in COMMANDS
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def hidden(self) -> bool:
|
|
154
|
+
"""Whether ``help`` omits this command although the firmware has it.
|
|
155
|
+
|
|
156
|
+
True only for :data:`~pyvisionect.io.usb.commands.HIDDEN_IN_7_4_4407`
|
|
157
|
+
-- ``wifi_ssid_set``, and nothing else as of 7.4.4407. Such a step has
|
|
158
|
+
to bypass :meth:`~pyvisionect.io.usb.device.Sign`'s ``help``-derived
|
|
159
|
+
gate, which would otherwise refuse a command that demonstrably works.
|
|
160
|
+
"""
|
|
161
|
+
return self.name in HIDDEN_IN_7_4_4407
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@dataclass(frozen=True, slots=True)
|
|
165
|
+
class Plan:
|
|
166
|
+
"""A provisioning sequence that has not happened yet.
|
|
167
|
+
|
|
168
|
+
Attributes:
|
|
169
|
+
name: what the plan is for, e.g. ``"bootstrap"``.
|
|
170
|
+
steps: the commands, in order.
|
|
171
|
+
notes: caveats worth reading before executing, including the
|
|
172
|
+
"you may not need this at all" alternatives.
|
|
173
|
+
|
|
174
|
+
Example:
|
|
175
|
+
>>> plan = plan_repoint("my-server.example.com")
|
|
176
|
+
>>> print(plan.describe()) # doctest: +ELLIPSIS
|
|
177
|
+
bootstrap plan: repoint
|
|
178
|
+
...
|
|
179
|
+
>>> plan.commands
|
|
180
|
+
('server_tcp_set my-server.example.com 11113', 'flash_save', 'reboot')
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
name: str
|
|
184
|
+
steps: tuple[Step, ...]
|
|
185
|
+
notes: tuple[str, ...] = ()
|
|
186
|
+
|
|
187
|
+
@property
|
|
188
|
+
def commands(self) -> tuple[str, ...]:
|
|
189
|
+
"""Just the command lines -- what a dry run is usually asked for."""
|
|
190
|
+
return tuple(step.command for step in self.steps)
|
|
191
|
+
|
|
192
|
+
@property
|
|
193
|
+
def unavailable(self) -> tuple[str, ...]:
|
|
194
|
+
"""Steps whose command firmware 7.4.4407 does not have.
|
|
195
|
+
|
|
196
|
+
Non-empty means this plan cannot run as written on that firmware.
|
|
197
|
+
"""
|
|
198
|
+
return tuple(step.name for step in self.steps if not step.in_firmware)
|
|
199
|
+
|
|
200
|
+
def describe(self) -> str:
|
|
201
|
+
"""The plan as readable text: every command, what it does, and the caveats."""
|
|
202
|
+
out = [f"bootstrap plan: {self.name}", ""]
|
|
203
|
+
for index, step in enumerate(self.steps, 1):
|
|
204
|
+
if not step.in_firmware:
|
|
205
|
+
flag = " [NOT IN FIRMWARE 7.4.4407]"
|
|
206
|
+
elif step.hidden:
|
|
207
|
+
flag = " [HIDDEN FROM help, BUT PRESENT AND VERIFIED]"
|
|
208
|
+
else:
|
|
209
|
+
flag = ""
|
|
210
|
+
out.append(f"{index}. {step.command}{flag}")
|
|
211
|
+
out.append(f" {step.why}")
|
|
212
|
+
if self.notes:
|
|
213
|
+
out.append("")
|
|
214
|
+
out.append("Before you run this:")
|
|
215
|
+
out.extend(f" - {note}" for note in self.notes)
|
|
216
|
+
return "\n".join(out)
|
|
217
|
+
|
|
218
|
+
def execute(self, sign: Sign) -> list[CommandResult]:
|
|
219
|
+
"""Send every step, in order.
|
|
220
|
+
|
|
221
|
+
*sign* must have been built with ``allow_destructive=True``; every step
|
|
222
|
+
in every plan here is in that tier, so a read-only or write-only
|
|
223
|
+
:class:`~pyvisionect.io.usb.device.Sign` refuses at the first command
|
|
224
|
+
and nothing partial happens.
|
|
225
|
+
|
|
226
|
+
Returns:
|
|
227
|
+
One :class:`~pyvisionect.io.usb.console.CommandResult` per step.
|
|
228
|
+
|
|
229
|
+
Raises:
|
|
230
|
+
RuntimeError: if the plan contains a command this firmware lacks and
|
|
231
|
+
the firmware's command list is known. Better to refuse than to
|
|
232
|
+
run half a bootstrap and leave the sign with new WiFi and an old
|
|
233
|
+
server, which is the worst of both. A :attr:`Step.hidden`
|
|
234
|
+
command is exempt: ``help`` does not list ``wifi_ssid_set`` and
|
|
235
|
+
the device answers it anyway, so refusing on ``help`` alone
|
|
236
|
+
would block a verified command.
|
|
237
|
+
"""
|
|
238
|
+
missing = [
|
|
239
|
+
step.name
|
|
240
|
+
for step in self.steps
|
|
241
|
+
if sign.has(step.name) is False and not step.hidden
|
|
242
|
+
]
|
|
243
|
+
if missing:
|
|
244
|
+
raise RuntimeError(
|
|
245
|
+
f"this firmware does not have {missing!r}, so the {self.name!r} "
|
|
246
|
+
f"plan cannot run as written. Running it part-way would leave the "
|
|
247
|
+
f"sign half-provisioned."
|
|
248
|
+
)
|
|
249
|
+
results: list[CommandResult] = []
|
|
250
|
+
for step in self.steps:
|
|
251
|
+
results.append(
|
|
252
|
+
sign._run(
|
|
253
|
+
step.command,
|
|
254
|
+
check=not step.hidden,
|
|
255
|
+
expect_prompt=step.expect_prompt,
|
|
256
|
+
)
|
|
257
|
+
)
|
|
258
|
+
return results
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def describe_alternatives(server: str) -> tuple[str, ...]:
|
|
262
|
+
"""The notes every plan carries: what to consider instead of writing flash."""
|
|
263
|
+
return (
|
|
264
|
+
"Nothing persists until flash_save, so you can run the setters, read "
|
|
265
|
+
"them back, and power-cycle to undo everything up to that point.",
|
|
266
|
+
"If the sign already holds a DNS *name* in TCLV 18 (the live one holds "
|
|
267
|
+
"visionect.internal.example.com), re-pointing that name at your "
|
|
268
|
+
"listener moves it with no commands at all. Check server_tcp_get first.",
|
|
269
|
+
f"After reboot the sign dials out to {server}; if it cannot reach it, "
|
|
270
|
+
"IPV4_SERVER_IP is read-only over the network, so USB is the only way "
|
|
271
|
+
"back. Have the cable to hand.",
|
|
272
|
+
"The sign holds its network session while on USB, so you can watch the "
|
|
273
|
+
"old server drop and the new one pick up.",
|
|
274
|
+
)
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
def plan_wifi(
|
|
278
|
+
ssid: str,
|
|
279
|
+
psk: str,
|
|
280
|
+
*,
|
|
281
|
+
security: str = WifiSecurity.WPA2,
|
|
282
|
+
band: int = 0,
|
|
283
|
+
) -> Plan:
|
|
284
|
+
"""Set the WiFi credentials -- TCLV 65/67/66/68.
|
|
285
|
+
|
|
286
|
+
Normally one ``wifi_conf_set``. When *ssid* contains whitespace that
|
|
287
|
+
command cannot be used, because it is positional and the space would shift
|
|
288
|
+
*psk*, *security* and *band* along by one; the plan becomes
|
|
289
|
+
``wifi_psk_set`` -> ``wifi_security_set`` -> ``wifi_ssid_set`` instead, with
|
|
290
|
+
the SSID written last. ``wifi_ssid_set`` takes the rest of the line
|
|
291
|
+
verbatim -- verified on 7.4.4407, see the module docstring -- so no quoting
|
|
292
|
+
is applied, and none would help.
|
|
293
|
+
|
|
294
|
+
Args:
|
|
295
|
+
ssid: TCLV 65. May contain spaces. May **not** contain a tab: the
|
|
296
|
+
console's line editor treats TAB as its usage-lookup key and eats
|
|
297
|
+
it, so the SSID that lands is the two halves concatenated.
|
|
298
|
+
psk: TCLV 67. Whitespace is refused; see the module docstring.
|
|
299
|
+
security: TCLV 66. One of :attr:`WifiSecurity.ALL`.
|
|
300
|
+
band: TCLV 68 -- 0 dual, 1 2.4 GHz, 2 5 GHz. Only ``wifi_conf_set``
|
|
301
|
+
writes it, so a spaced *ssid* requires the default ``0``.
|
|
302
|
+
|
|
303
|
+
Raises:
|
|
304
|
+
ValueError: if *security* is not a known value; if *psk* contains
|
|
305
|
+
whitespace; if *ssid* contains a tab, a carriage return or a
|
|
306
|
+
newline; or if *ssid* contains whitespace and *band* is not 0.
|
|
307
|
+
"""
|
|
308
|
+
if security not in WifiSecurity.ALL:
|
|
309
|
+
raise ValueError(
|
|
310
|
+
f"security must be one of {WifiSecurity.ALL}, got {security!r}; "
|
|
311
|
+
"these are ASCII strings, not integers"
|
|
312
|
+
)
|
|
313
|
+
if any(c.isspace() for c in psk):
|
|
314
|
+
raise ValueError(
|
|
315
|
+
"psk contains whitespace. wifi_psk_set is a single-argument "
|
|
316
|
+
"command and so probably would carry it -- wifi_ssid_set, the same "
|
|
317
|
+
"shape, provably does -- but there is no read path for TCLV 67: "
|
|
318
|
+
"wifi_conf_get returns SSID, security and band and never the "
|
|
319
|
+
"passphrase, so there is no way to check what landed. A truncated "
|
|
320
|
+
"passphrase does not fail loudly, it just stops the sign "
|
|
321
|
+
"associating, and this firmware then power-cycles itself on "
|
|
322
|
+
"'E: Max conn errs. Reboot' with ErrorCode still 0x0. Rename the "
|
|
323
|
+
"network, or leave WiFi alone and move the sign by re-pointing the "
|
|
324
|
+
"DNS name it already holds."
|
|
325
|
+
)
|
|
326
|
+
bad = {"\t": "a tab", "\r": "a carriage return", "\n": "a newline"}
|
|
327
|
+
for char, name in bad.items():
|
|
328
|
+
if char in ssid:
|
|
329
|
+
raise ValueError(
|
|
330
|
+
f"ssid contains {name}, which this console cannot carry. CR "
|
|
331
|
+
"and LF submit the line; TAB is the line editor's "
|
|
332
|
+
"usage-lookup key and is swallowed, so 'Two<TAB>Words' sets "
|
|
333
|
+
"'TwoWords' -- measured on 7.4.4407. Spaces are fine."
|
|
334
|
+
)
|
|
335
|
+
if not any(c.isspace() for c in ssid):
|
|
336
|
+
return Plan(
|
|
337
|
+
name="wifi",
|
|
338
|
+
steps=(
|
|
339
|
+
Step(
|
|
340
|
+
f"wifi_conf_set {ssid} {psk} {security} {band}",
|
|
341
|
+
"writes TCLV 65/67/66/68 (SSID, password, security, band) to RAM. "
|
|
342
|
+
"Note the argument order is ssid, psk, security, band while the "
|
|
343
|
+
"ids run 65, 67, 66, 68.",
|
|
344
|
+
),
|
|
345
|
+
),
|
|
346
|
+
notes=(
|
|
347
|
+
"RAM only. Follow with flash_save, or use plan_bootstrap.",
|
|
348
|
+
"wifi_conf_get will read back the SSID, security and band but never "
|
|
349
|
+
"the passphrase -- there is no read path for TCLV 67.",
|
|
350
|
+
),
|
|
351
|
+
)
|
|
352
|
+
if band != 0:
|
|
353
|
+
raise ValueError(
|
|
354
|
+
f"ssid {ssid!r} contains whitespace, so wifi_conf_set is out, and "
|
|
355
|
+
f"wifi_conf_set is the only command that writes the band (TCLV 68) "
|
|
356
|
+
f"-- there is no wifi_band_set in help or in the vendor's 162 "
|
|
357
|
+
f"documented commands. So band={band} cannot be combined with a "
|
|
358
|
+
f"spaced SSID. Pass band=0 (dual, the default) to leave TCLV 68 as "
|
|
359
|
+
f"the device already has it, or rename the network."
|
|
360
|
+
)
|
|
361
|
+
return Plan(
|
|
362
|
+
name="wifi",
|
|
363
|
+
steps=(
|
|
364
|
+
Step(
|
|
365
|
+
f"wifi_psk_set {psk}",
|
|
366
|
+
"writes TCLV 67. Separate from the SSID because wifi_conf_set is "
|
|
367
|
+
"positional and the space in the SSID would shift this argument.",
|
|
368
|
+
),
|
|
369
|
+
Step(
|
|
370
|
+
f"wifi_security_set {security}",
|
|
371
|
+
"writes TCLV 66, an ASCII string -- 'none', 'wpa2' or 'wpa2e'.",
|
|
372
|
+
),
|
|
373
|
+
Step(
|
|
374
|
+
f"wifi_ssid_set {ssid}",
|
|
375
|
+
"writes TCLV 65. Hidden from help on 7.4.4407 but present, and it "
|
|
376
|
+
"takes the rest of the line verbatim, which is what carries the "
|
|
377
|
+
"space. Last on purpose: the SSID is the field that decides "
|
|
378
|
+
"association, so it is the one written once everything else is in "
|
|
379
|
+
"place.",
|
|
380
|
+
),
|
|
381
|
+
),
|
|
382
|
+
notes=(
|
|
383
|
+
"RAM only. Follow with flash_save, or use plan_bootstrap.",
|
|
384
|
+
f"The SSID has whitespace, so this is the three-setter route and "
|
|
385
|
+
f"wifi_conf_set is not used. The SSID is sent unquoted and "
|
|
386
|
+
f"unescaped, because wifi_ssid_set takes the rest of the line "
|
|
387
|
+
f"literally: it will land as exactly {ssid!r}, quotes and "
|
|
388
|
+
f"backslashes included if you put any there.",
|
|
389
|
+
"Band (TCLV 68) is NOT written by this route -- only wifi_conf_set "
|
|
390
|
+
"writes it and there is no wifi_band_set. The device keeps whatever "
|
|
391
|
+
"it already has; read it back with wifi_conf_get.",
|
|
392
|
+
"wifi_ssid_set is absent from help, so Sign's help-derived command "
|
|
393
|
+
"gate is bypassed for that one step. The device answers it; help is "
|
|
394
|
+
"simply an incomplete index.",
|
|
395
|
+
"wifi_conf_get will read back the SSID, security and band but never "
|
|
396
|
+
"the passphrase -- there is no read path for TCLV 67.",
|
|
397
|
+
),
|
|
398
|
+
)
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
def plan_repoint(
|
|
402
|
+
server: str, port: int = DEFAULT_SERVER_PORT, *, reboot: bool = True
|
|
403
|
+
) -> Plan:
|
|
404
|
+
"""Move a sign to a new server, leaving WiFi alone.
|
|
405
|
+
|
|
406
|
+
``server_tcp_set`` -> ``flash_save`` -> ``reboot``. The common case: the
|
|
407
|
+
sign is already on a network you control and you only want it talking to
|
|
408
|
+
your listener instead of the vendor's.
|
|
409
|
+
|
|
410
|
+
Args:
|
|
411
|
+
server: an IP or a DNS name. A name works and is what the live sign
|
|
412
|
+
holds.
|
|
413
|
+
port: TCLV 19, :data:`DEFAULT_SERVER_PORT` by default.
|
|
414
|
+
reboot: drop the final reboot, to batch it with other changes.
|
|
415
|
+
"""
|
|
416
|
+
steps = [
|
|
417
|
+
Step(
|
|
418
|
+
f"server_tcp_set {server} {port}",
|
|
419
|
+
"writes TCLV 18 (server IP or DNS name) and 19 (port) to RAM. Both "
|
|
420
|
+
"are canWrite:false over the network, which is why this needs USB.",
|
|
421
|
+
),
|
|
422
|
+
Step(
|
|
423
|
+
"flash_save",
|
|
424
|
+
"TCLV 53. Commits the above to flash. Until this runs, a power-cycle "
|
|
425
|
+
"undoes everything; after it, USB is the only way back.",
|
|
426
|
+
),
|
|
427
|
+
]
|
|
428
|
+
if reboot:
|
|
429
|
+
steps.append(
|
|
430
|
+
Step(
|
|
431
|
+
"reboot",
|
|
432
|
+
"applies the new server. The console goes away and does not "
|
|
433
|
+
"prompt again; the sign is back in about a minute and chirps.",
|
|
434
|
+
expect_prompt=False,
|
|
435
|
+
)
|
|
436
|
+
)
|
|
437
|
+
return Plan(
|
|
438
|
+
name="repoint", steps=tuple(steps), notes=describe_alternatives(server)
|
|
439
|
+
)
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
def plan_bootstrap(
|
|
443
|
+
ssid: str | None,
|
|
444
|
+
psk: str | None,
|
|
445
|
+
server: str,
|
|
446
|
+
port: int = DEFAULT_SERVER_PORT,
|
|
447
|
+
*,
|
|
448
|
+
security: str = WifiSecurity.WPA2,
|
|
449
|
+
band: int = 0,
|
|
450
|
+
conn_type: int | None = None,
|
|
451
|
+
reboot: bool = True,
|
|
452
|
+
) -> Plan:
|
|
453
|
+
"""The full first-time sequence, verbatim from the vendor reference.
|
|
454
|
+
|
|
455
|
+
``wifi_conf_set`` -> ``server_tcp_set`` -> ``flash_save`` -> ``reboot``,
|
|
456
|
+
with the WiFi step expanding to three commands when the SSID has a space in
|
|
457
|
+
it (see :func:`plan_wifi`).
|
|
458
|
+
|
|
459
|
+
Args:
|
|
460
|
+
ssid: TCLV 65, or None to leave WiFi untouched -- in which case this is
|
|
461
|
+
:func:`plan_repoint` with extra notes.
|
|
462
|
+
psk: TCLV 67. Required when *ssid* is given.
|
|
463
|
+
server: TCLV 18.
|
|
464
|
+
port: TCLV 19.
|
|
465
|
+
security: TCLV 66.
|
|
466
|
+
band: TCLV 68.
|
|
467
|
+
conn_type: TCLV 2, inserted before the WiFi step when given. **Enumerate
|
|
468
|
+
with ``conn_type_list`` first**: firmware 7.4.4407 offers 0, 3 and 6,
|
|
469
|
+
while the vendor's own 4G example passes 8.
|
|
470
|
+
reboot: drop the final reboot.
|
|
471
|
+
|
|
472
|
+
Raises:
|
|
473
|
+
ValueError: if *ssid* is given without *psk*, or whatever
|
|
474
|
+
:func:`plan_wifi` refuses -- a *psk* containing whitespace, a tab
|
|
475
|
+
in the *ssid*, or a spaced *ssid* with a non-default *band*. A
|
|
476
|
+
spaced *ssid* on its own is fine and expands to the three-setter
|
|
477
|
+
route.
|
|
478
|
+
"""
|
|
479
|
+
steps: list[Step] = []
|
|
480
|
+
if conn_type is not None:
|
|
481
|
+
steps.append(
|
|
482
|
+
Step(
|
|
483
|
+
f"conn_type_set {conn_type}",
|
|
484
|
+
f"writes TCLV 2. Check conn_type_list first -- this firmware only "
|
|
485
|
+
f"offers the values it lists, and {conn_type} may not be one.",
|
|
486
|
+
)
|
|
487
|
+
)
|
|
488
|
+
if ssid is not None:
|
|
489
|
+
if psk is None:
|
|
490
|
+
raise ValueError("psk is required when ssid is given")
|
|
491
|
+
steps.extend(plan_wifi(ssid, psk, security=security, band=band).steps)
|
|
492
|
+
steps.extend(plan_repoint(server, port, reboot=reboot).steps)
|
|
493
|
+
return Plan(
|
|
494
|
+
name="bootstrap",
|
|
495
|
+
steps=tuple(steps),
|
|
496
|
+
notes=describe_alternatives(server)
|
|
497
|
+
+ (
|
|
498
|
+
"Read the whole plan back with .describe() before executing. A "
|
|
499
|
+
"half-run bootstrap leaves the sign on the new WiFi and the old "
|
|
500
|
+
"server, or vice versa.",
|
|
501
|
+
),
|
|
502
|
+
)
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"""Per-type payload codecs. Pure: no sockets, no clock.
|
|
2
|
+
|
|
3
|
+
Every codec is a plain dataclass with ``decode(payload) -> Packet`` and
|
|
4
|
+
``encode() -> bytes``, and every one of them round-trips byte-exactly on the
|
|
5
|
+
captured traffic.
|
|
6
|
+
|
|
7
|
+
Dispatch is a dict, not a class hierarchy, because that is what the gateway does
|
|
8
|
+
(``map[packet.Type]handlers.Handler``, seven entries, built with seven
|
|
9
|
+
``mapassign_fast32`` calls).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from typing import Any, Callable
|
|
15
|
+
|
|
16
|
+
from ..devices.enums import PacketType
|
|
17
|
+
from .control import NO_ACK_ID, ControlPacket
|
|
18
|
+
from .file import (
|
|
19
|
+
DEVICE_FILE_READ_CHUNK,
|
|
20
|
+
DEVICE_IMAGE_FILES,
|
|
21
|
+
FILE_LIST_LENGTH,
|
|
22
|
+
FILE_LIST_PATH,
|
|
23
|
+
FileBytes,
|
|
24
|
+
FileErase,
|
|
25
|
+
FileListEntry,
|
|
26
|
+
FileOpen,
|
|
27
|
+
FilePacket,
|
|
28
|
+
FileWriteDone,
|
|
29
|
+
parse_file_listing,
|
|
30
|
+
screen_cache_name,
|
|
31
|
+
)
|
|
32
|
+
from .image import (
|
|
33
|
+
IMAGE_HEADER_SIZE,
|
|
34
|
+
MAX_RECTANGLES,
|
|
35
|
+
RECT_HEADER_SIZE,
|
|
36
|
+
RECT_UPDATE_OPTIONS_DEFAULT,
|
|
37
|
+
ImagePacket,
|
|
38
|
+
Rectangle,
|
|
39
|
+
)
|
|
40
|
+
from .misc import ButtonPacket, CborPacket, CommandPacket, GpsPacket, TouchPacket
|
|
41
|
+
from .stored import (
|
|
42
|
+
STORED_FRAME_HEADER_SIZE,
|
|
43
|
+
StoredFrame,
|
|
44
|
+
StoredFrameHeader,
|
|
45
|
+
parse_stored_frame,
|
|
46
|
+
parse_stored_frame_header,
|
|
47
|
+
)
|
|
48
|
+
from .param import ParamItem, ParamPacket, decode_value, encode_value
|
|
49
|
+
from .status import (
|
|
50
|
+
ABSENT,
|
|
51
|
+
SENTINEL_TAG,
|
|
52
|
+
STATUS_TAG_NAMES,
|
|
53
|
+
STATUS_TAGS,
|
|
54
|
+
StatusCodec,
|
|
55
|
+
StatusPacket,
|
|
56
|
+
StatusTag,
|
|
57
|
+
decode_status_fields,
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
__all__ = [
|
|
61
|
+
"ABSENT",
|
|
62
|
+
"DEVICE_FILE_READ_CHUNK",
|
|
63
|
+
"DEVICE_IMAGE_FILES",
|
|
64
|
+
"FILE_LIST_LENGTH",
|
|
65
|
+
"FILE_LIST_PATH",
|
|
66
|
+
"FileListEntry",
|
|
67
|
+
"parse_file_listing",
|
|
68
|
+
"ButtonPacket",
|
|
69
|
+
"CborPacket",
|
|
70
|
+
"CommandPacket",
|
|
71
|
+
"ControlPacket",
|
|
72
|
+
"DECODERS",
|
|
73
|
+
"FileBytes",
|
|
74
|
+
"FileErase",
|
|
75
|
+
"FileOpen",
|
|
76
|
+
"FilePacket",
|
|
77
|
+
"FileWriteDone",
|
|
78
|
+
"GpsPacket",
|
|
79
|
+
"IMAGE_HEADER_SIZE",
|
|
80
|
+
"ImagePacket",
|
|
81
|
+
"MAX_RECTANGLES",
|
|
82
|
+
"NO_ACK_ID",
|
|
83
|
+
"ParamItem",
|
|
84
|
+
"ParamPacket",
|
|
85
|
+
"RECT_HEADER_SIZE",
|
|
86
|
+
"RECT_UPDATE_OPTIONS_DEFAULT",
|
|
87
|
+
"Rectangle",
|
|
88
|
+
"SENTINEL_TAG",
|
|
89
|
+
"STATUS_TAGS",
|
|
90
|
+
"STATUS_TAG_NAMES",
|
|
91
|
+
"STORED_FRAME_HEADER_SIZE",
|
|
92
|
+
"StoredFrame",
|
|
93
|
+
"StoredFrameHeader",
|
|
94
|
+
"parse_stored_frame",
|
|
95
|
+
"parse_stored_frame_header",
|
|
96
|
+
"StatusCodec",
|
|
97
|
+
"StatusPacket",
|
|
98
|
+
"StatusTag",
|
|
99
|
+
"TouchPacket",
|
|
100
|
+
"decode_payload",
|
|
101
|
+
"decode_status_fields",
|
|
102
|
+
"decode_value",
|
|
103
|
+
"encode_value",
|
|
104
|
+
"screen_cache_name",
|
|
105
|
+
]
|
|
106
|
+
|
|
107
|
+
DECODERS: dict[int, Callable[[bytes], Any]] = {
|
|
108
|
+
PacketType.CONTROL: ControlPacket.decode,
|
|
109
|
+
PacketType.COMMAND: CommandPacket.decode,
|
|
110
|
+
PacketType.STATUS: StatusPacket.decode,
|
|
111
|
+
PacketType.IMAGE: ImagePacket.decode,
|
|
112
|
+
PacketType.TOUCH: TouchPacket.decode,
|
|
113
|
+
PacketType.GPS: GpsPacket.decode,
|
|
114
|
+
PacketType.PARAM: ParamPacket.decode,
|
|
115
|
+
PacketType.FILE: FilePacket.decode,
|
|
116
|
+
PacketType.BUTTON: ButtonPacket.decode,
|
|
117
|
+
PacketType.CBOR: CborPacket.decode,
|
|
118
|
+
}
|
|
119
|
+
"""``packet.Type`` -> payload decoder.
|
|
120
|
+
|
|
121
|
+
Types 4 (``input``) and 9 are holes in the vendor's own tables, and the
|
|
122
|
+
bootloader type moved out to its own mux protocol versions, so neither appears
|
|
123
|
+
here.
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
def decode_payload(packet_type: int, payload: bytes) -> Any | None:
|
|
128
|
+
"""Decode *payload* for *packet_type*, or return None for an unknown type.
|
|
129
|
+
|
|
130
|
+
Returning None rather than raising mirrors the gateway's dispatcher, which
|
|
131
|
+
NACKs an unknown type (``WriteControl(id, 0)``, ``pv3.go:473``) instead of
|
|
132
|
+
dropping the connection.
|
|
133
|
+
"""
|
|
134
|
+
decoder = DECODERS.get(packet_type)
|
|
135
|
+
return decoder(payload) if decoder else None
|