76 lines
2.7 KiB
Python
76 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Host probe v4 — ``opt``-seeded payloads via the library business API.
|
|
|
|
Historical sweep from the ``communicate``-factory finding (socket payloads
|
|
always start with ``"opt": 0``). Now built into
|
|
``direct_connect_request``; kept as a variant-list driver over
|
|
``LocalDeviceClient.send_probe``.
|
|
|
|
Run from the repo root on the SoftAP-joined host:
|
|
python3 scripts/host_probe4.py --sn A03X2516013210060005 --ports 9000
|
|
"""
|
|
|
|
import argparse
|
|
import json
|
|
import os
|
|
import socket
|
|
import sys
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(
|
|
os.path.abspath(__file__))))
|
|
|
|
from franklinwh_agate_client.battery import extract_soc # noqa: E402
|
|
from franklinwh_agate_client.device_local import ( # noqa: E402
|
|
LocalDeviceClient,
|
|
)
|
|
from franklinwh_agate_client.protocol import ( # noqa: E402
|
|
CommunicationCmd,
|
|
generate_secret_key,
|
|
)
|
|
|
|
VARIANTS = (
|
|
("queryInfo+minProto+SN", CommunicationCmd.QUERY_DEVICE_INFO,
|
|
{"minProtocolVer": "V1.00.00"}, None),
|
|
("queryInfo+minProto+empty", CommunicationCmd.QUERY_DEVICE_INFO,
|
|
{"minProtocolVer": "V1.00.00"}, ""),
|
|
("apower+opt+update2", CommunicationCmd.DEVICE_APOWER_INFO,
|
|
{"update": 2}, None),
|
|
("bms+opt", CommunicationCmd.BMS, None, None),
|
|
("ems+opt", CommunicationCmd.EMS, None, None),
|
|
)
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("--sn", required=True)
|
|
ap.add_argument("--host", default="10.100.1.1")
|
|
ap.add_argument("--ports", default="9000")
|
|
ap.add_argument("--timeout", type=float, default=5.0)
|
|
args = ap.parse_args()
|
|
print("secret key for %s: %s (radix 16)"
|
|
% (args.sn, generate_secret_key(args.sn)))
|
|
for port in [int(p) for p in args.ports.split(",") if p.strip()]:
|
|
client = LocalDeviceClient(args.sn, host=args.host,
|
|
socket_port=port, timeout=args.timeout)
|
|
for label, cmd, data, equip in VARIANTS:
|
|
try:
|
|
out = client.send_probe(cmd, data=data, timeout=args.timeout,
|
|
equip_no=equip)
|
|
except (ConnectionError, socket.error, TimeoutError) as exc:
|
|
print("--- %s: error: %s: %s"
|
|
% (label, type(exc).__name__, exc))
|
|
continue
|
|
rx = out.get("reply_raw") or b""
|
|
print("--- %s tx=%dB rx=%dB"
|
|
% (label, len(out["tx"]), len(rx)))
|
|
if out.get("reply") is not None:
|
|
print(" reply: "
|
|
+ json.dumps(out["reply"], default=str)[:1500])
|
|
soc = extract_soc(out["reply"])
|
|
print(" soc: %s (source=%s)" % (soc["value"],
|
|
soc["source"]))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|