EnvelopeCodec message layer; scripts are thin business-API wrappers
This commit is contained in:
1 parent
f15ae42db7
commit
363c7cc6a2
14 files changed
+551
-900
No files matched your search
@@ -258,12 +258,9 @@ def _recv_all(sock: socket.socket, idle: float = 4.0) -> bytes:
|
||||
|
||||
def _apower_tx(sn: str, key_radix: int) -> Tuple[bytes, Dict[str, Any]]:
|
||||
"""Canonical ``queryAPowerData`` wire bytes (fresh snno/timeStamp)."""
|
||||
from .protocol import (
|
||||
direct_connect_request,
|
||||
encrypt_object,
|
||||
generate_secret_key,
|
||||
)
|
||||
from .protocol import direct_connect_request
|
||||
from .protocol.envelope import SequenceNumber
|
||||
from .protocol.messages import EnvelopeCodec
|
||||
|
||||
_apower_tx_seq = getattr(_apower_tx, "_seq", None)
|
||||
if _apower_tx_seq is None:
|
||||
@@ -272,9 +269,8 @@ def _apower_tx(sn: str, key_radix: int) -> Tuple[bytes, Dict[str, Any]]:
|
||||
CommunicationCmd.DEVICE_APOWER_INFO, sn,
|
||||
data={"update": 2}, snno=_apower_tx_seq.next(),
|
||||
)
|
||||
wire = encrypt_object(
|
||||
env.to_json_string(), generate_secret_key(sn), radix=key_radix)
|
||||
return wire, env.to_dict()
|
||||
codec = EnvelopeCodec.for_serial(sn, radix=key_radix)
|
||||
return codec.encode(env), env.to_dict()
|
||||
|
||||
|
||||
#: Minimal MQTT v3.1.1 CONNECT (client id ``probe01``) — rules out / confirms
|
||||
@@ -297,7 +293,7 @@ def probe_transport(
|
||||
prefixes (LE16/BE16/LE32), an MQTT CONNECT, and a double-send over one
|
||||
persistent connection. Each entry carries exact ``tx``/``rx`` bytes.
|
||||
"""
|
||||
from .protocol import decrypt_wire
|
||||
from .protocol.messages import EnvelopeCodec
|
||||
|
||||
results: List[Dict[str, Any]] = []
|
||||
for port in ports:
|
||||
@@ -330,15 +326,8 @@ def probe_transport(
|
||||
except (ConnectionError, socket.error, TimeoutError) as exc:
|
||||
entry["error"] = f"{type(exc).__name__}: {exc}"
|
||||
if entry["rx"]:
|
||||
try:
|
||||
decoded = decrypt_wire(entry["rx"], radix=key_radix)
|
||||
except ValueError:
|
||||
decoded = ""
|
||||
if decoded:
|
||||
try:
|
||||
entry["reply"] = json.loads(decoded)
|
||||
except ValueError:
|
||||
entry["reply"] = {"_ undecodable": decoded}
|
||||
entry["reply"] = EnvelopeCodec.for_serial(
|
||||
sn, radix=key_radix).try_decode(entry["rx"])
|
||||
results.append(entry)
|
||||
|
||||
run("greet-first/read-then-raw", tx, pre_read=4.0)
|
||||
|
||||
Reference in new issue
Block a user