From eed3b9dcb739341c62e5431e49bc9296d7ab9bc5 Mon Sep 17 00:00:00 2001 From: Paul Yan Date: Tue, 19 Oct 2021 12:14:01 -0700 Subject: [PATCH] Fix python example issues on Gen4 device Gen4 device does not need sending MRPC_DIETEMP_SET_MEAS command before reading device temperature. Device generation information is determined using MRPC_PING command --- examples/temp_linux.py | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/examples/temp_linux.py b/examples/temp_linux.py index 6a486189..7355a69b 100755 --- a/examples/temp_linux.py +++ b/examples/temp_linux.py @@ -42,12 +42,47 @@ MRPC_DIETEMP_SET_MEAS = 1 MRPC_DIETEMP_GET = 2 +MRPC_PING = 256 + +GEN3 = 3 +GEN4 = 4 +GEN5 = 5 +GEN_UNKNOWN = 0 + class SwitchtecError(Exception): pass class Switchtec(object): def __init__(self, devpath): self.fd = os.open(devpath, os.O_RDWR) + self.gen = self.get_dev_gen() + + def map_to_gen(self, gen): + if gen == 0: + return GEN4 + if gen == 1: + return GEN5 + + return GEN_UNKNOWN + + def get_dev_gen(self): + + number = int(time.time()) + indata = struct.pack("> 12) & 0x0f + return self.map_to_gen(gen) def cmd(self, cmd, indata=b"", outdata_len=0): indata = struct.pack("