From 5a4249745965045927823904ad3c6d9a2adbf318 Mon Sep 17 00:00:00 2001 From: Martin Prudek Date: Tue, 14 May 2019 12:50:01 +0200 Subject: [PATCH 1/3] gps: Handle serial exceptions --- netmetr/gps.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/netmetr/gps.py b/netmetr/gps.py index adfae84..d761e9f 100644 --- a/netmetr/gps.py +++ b/netmetr/gps.py @@ -26,18 +26,24 @@ class Location: if not os.path.exists(console_path): raise ConfigError("GPS special file not found!") - with serial.Serial(console_path, timeout=5) as console: - console.write(b"AT!GPSLOC?\r") - console.readline() # AT command echo - - self.lat = get_lat(console.readline().decode("utf-8")) - self.lon = get_lon(console.readline().decode("utf-8")) - console.readline() # Time - self.hepe = get_hepe(console.readline().decode("utf-8")) - console.readline() # 3DFix - self.altitude = get_alt(console.readline().decode("utf-8")) - self.bearing, self.velocity = get_heading_velocity( - console.readline().decode("utf-8")) + try: + with serial.Serial(console_path, timeout=5) as console: + self._fetch_console(console) + except serial.serialutil.SerialException as e: + raise RunError("GPS measurement failed ({})".format(e)) + + def _fetch_console(self, console): + console.write(b"AT!GPSLOC?\r") + console.readline() # AT command echo + + self.lat = get_lat(console.readline().decode("utf-8")) + self.lon = get_lon(console.readline().decode("utf-8")) + console.readline() # Time + self.hepe = get_hepe(console.readline().decode("utf-8")) + console.readline() # 3DFix + self.altitude = get_alt(console.readline().decode("utf-8")) + self.bearing, self.velocity = get_heading_velocity( + console.readline().decode("utf-8")) def get_lat(line): -- GitLab From 92c57b1e6580643021389802e49696beed0bc2ff Mon Sep 17 00:00:00 2001 From: Martin Prudek Date: Tue, 14 May 2019 12:51:44 +0200 Subject: [PATCH 2/3] gitignore: Ignore python cache --- .gitignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0eaa0f7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +## .gitignore + +# Python cache files and directories +*.pyc +__pycache__ +*.egg-info/ -- GitLab From f50a45bc9e2400145ed958bf0cb754e237872824 Mon Sep 17 00:00:00 2001 From: Martin Prudek Date: Tue, 14 May 2019 12:54:14 +0200 Subject: [PATCH 3/3] version bump --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 13411d7..6abf437 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ DESCRIPTION = "Netmetr client (basically a wrapper around RMBT binary)" setup( name='netmetr', - version="1.5.1", + version="1.5.2", author='CZ.NIC, z.s.p.o. (http://www.nic.cz/)', author_email='martin.prudek@nic.cz', packages=[ -- GitLab