| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- #!/usr/bin/env python3
- """Executable JSONL bridge contract example. SIMULATION ONLY, no hardware I/O.
- Replace operation bodies with your documented thermal-board / supply protocol.
- The explicit --simulate flag prevents accidental use as a real device driver.
- """
- import argparse
- import json
- import sys
- parser = argparse.ArgumentParser(description=__doc__)
- parser.add_argument("--simulate", action="store_true", required=True)
- parser.parse_args()
- supply = "off"
- target = 80.0
- air = 25.0
- print("SIMULATION JSONL bridge; no physical I/O", file=sys.stderr, flush=True)
- for line in sys.stdin:
- request = {}
- try:
- request = json.loads(line)
- op, args = request["operation"], request["arguments"]
- if op == "supply_set":
- if type(args["on"]) is not bool:
- raise ValueError("on must be boolean")
- supply = "on" if args["on"] else "off"
- result = {"accepted": True}
- elif op == "supply_read":
- result = {"state": supply, "simulated": True}
- elif op == "set_target":
- target = float(args["target_c"])
- result = {"confirmed_target_c": target, "simulated": True}
- elif op == "read_telemetry":
- air += (target - air) * 0.7
- result = {"air_c": round(air, 2) if supply == "on" else None,
- "dimms": [], "quality": "valid" if supply == "on" else "unavailable",
- "dimm_quality": "unavailable_in_phase", "board_state": supply,
- "confirmed_target_c": target, "simulated": True}
- else:
- raise ValueError("unsupported operation")
- reply = {"id": request["id"], "ok": True, "result": result}
- except (ValueError, KeyError, TypeError):
- reply = {"id": request.get("id"), "ok": False, "error": "invalid or unsupported request"}
- print(json.dumps(reply, allow_nan=False), flush=True)
|