From dddcc60f2deac4eadd029c22e9a0cd3c2f1636ca Mon Sep 17 00:00:00 2001 From: Robert Falkenberg Date: Thu, 6 May 2021 09:55:57 +0200 Subject: [PATCH] ModemATCommandLink: improve response time for "+CME ERROR" Change-Id: I41af33c1898f5ed3d1c5238e45f956c6ceab2826 --- pySim/transport/modem_atcmd.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py index 3d39a209..04f92210 100644 --- a/pySim/transport/modem_atcmd.py +++ b/pySim/transport/modem_atcmd.py @@ -67,12 +67,16 @@ class ModemATCommandLink(LinkBase): t_start = time.time() while True: rsp = rsp + self._sl.read(self._sl.in_waiting) - if rsp.endswith(b'OK\r\n'): - log.debug('Command finished with result: OK') - break - if rsp.endswith(b'ERROR\r\n'): - log.error('Command finished with result: ERROR') - break + lines = rsp.split(b'\r\n') + if len(lines) >= 2: + res = lines[-2] + if res == b'OK': + log.debug('Command finished with result: %s', res) + break + if res == b'ERROR' or res.startswith(b'+CME ERROR:'): + log.error('Command failed with result: %s', res) + break + if time.time() - t_start >= timeout: log.info('Command finished with timeout >= %ss', timeout) break