Verified Commit 5f25af6b authored by Clayton Craft's avatar Clayton Craft
Browse files

stm_agps: allow setting a custom device read command

Object that inherit stm_agps, like the _serial variant, can use a
different read method than `read()`
parent 892a0b3d
......@@ -36,6 +36,7 @@ class STM_AGPS:
try:
self._ser = await trio.open_file(self._ser_port,
"w+b", buffering=0)
self._ser_read_cmd = self._ser.read
except Exception as e:
raise LoggedException(e)
......@@ -48,7 +49,7 @@ class STM_AGPS:
self._buf = bytearray(self._buf[idx+1:])
return bytes(line)
while True:
data = await self._ser.receive_some(40)
data = await self._ser_read_cmd(40)
idx = data.find(b'\n')
if idx >= 0:
line = self._buf + data[:idx+1]
......
......@@ -35,6 +35,8 @@ class STM_AGPS_SERIAL(STM_AGPS):
try:
self._ser = SerialStream(self._ser_port, baudrate=self._baud)
await self._ser.aopen()
# command to read from the device
self._ser_read_cmd = self._ser.receive_some
except Exception as e:
raise LoggedException(e)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment