From ad97b3a1aa3b12a2c761460f14b65aafe099570c Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Tue, 22 May 2018 10:42:17 +0900 Subject: [PATCH 01/13] Add shebang and character-encoding declaration --- tests/emulator_serialport.py | 3 +++ tests/path_hack.py | 3 +++ tests/sock_server_test.py | 3 +++ 3 files changed, 9 insertions(+) diff --git a/tests/emulator_serialport.py b/tests/emulator_serialport.py index b2aef8d..0e7558d 100644 --- a/tests/emulator_serialport.py +++ b/tests/emulator_serialport.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + # Copyright (c) 2018 CANDY LINE INC. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/path_hack.py b/tests/path_hack.py index 9ec27f8..f81d009 100644 --- a/tests/path_hack.py +++ b/tests/path_hack.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + # Copyright (c) 2018 CANDY LINE INC. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/tests/sock_server_test.py b/tests/sock_server_test.py index a88fcdb..45b50d8 100644 --- a/tests/sock_server_test.py +++ b/tests/sock_server_test.py @@ -1,3 +1,6 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + # Copyright (c) 2018 CANDY LINE INC. # # Licensed under the Apache License, Version 2.0 (the "License"); From f03c9cdda32cb75b6e8e6049e0d785668c22133b Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Tue, 22 May 2018 10:42:46 +0900 Subject: [PATCH 02/13] Add new commands for GNSS category --- lib/candy_board_qws/__init__.py | 101 +++++++++++++++++++++++++++++++- tests/emulator_serialport.py | 46 ++++++++++++++- tests/sock_server_test.py | 88 ++++++++++++++++++++++++++++ 3 files changed, 233 insertions(+), 2 deletions(-) diff --git a/lib/candy_board_qws/__init__.py b/lib/candy_board_qws/__init__.py index 2b9c909..796a72b 100644 --- a/lib/candy_board_qws/__init__.py +++ b/lib/candy_board_qws/__init__.py @@ -387,7 +387,9 @@ def send_at(self, cmd, ok="OK"): count = count + 1 elif line == cmd: continue - elif line == ok or line == "ERROR": + elif line == ok or \ + line == "ERROR" or \ + line.startswith("+CME ERROR"): status = line elif line is None: status = "UNKNOWN" @@ -827,6 +829,103 @@ def modem_init(self, cmd={}): } return json.dumps(message) + def gnss_start(self, cmd={}): + status, result = self.send_at('AT+QGPSCFG="gpsnmeatype",31') + if status != "OK": + result = status + status = "ERROR" + message = { + 'status': status, + 'result': result, + 'cmd': 'gpsnmeatype' + } + return json.dumps(message) + + status, result = self.send_at("AT+QGPS=1,30,50,0,1") + if status == "OK": + result = "" + elif status == "+CME ERROR: 504": + status = "OK" + else: + result = status + status = "ERROR" + message = { + 'status': status, + 'result': result, + } + return json.dumps(message) + + def gnss_status(self, cmd={}): + status, result = self.send_at("AT+QGPS?") + if status == "OK": + gnssstate = result.split(':')[1].strip() + if gnssstate == "0": + result = 'stopped' + elif gnssstate == "1": + result = 'started' + message = { + 'status': status, + 'result': result, + } + return json.dumps(message) + + def gnss_stop(self, cmd={}): + status, result = self.send_at("AT+QGPSEND") + if status == "OK": + result = "" + elif status == "+CME ERROR: 505": + status = "OK" + else: + result = status + status = "ERROR" + message = { + 'status': status, + 'result': result, + } + return json.dumps(message) + + def gnss_locate(self, cmd={}): + format = cmd['format'] if 'format' in cmd else None + status, result = self.send_at("AT+QGPSLOC=%s" % (format or '2')) + if status == "OK": + csv = result.split(':')[1].strip().split(',') + result = { + 'timestamp': '20%s-%s-%sT%s:%s:%s' % + ( + csv[9][4:6], csv[9][2:4], csv[9][0:2], + csv[0][0:2], csv[0][2:4], csv[0][4:6] + ), + 'latitude': float(csv[1]), + 'longitude': float(csv[2]), + 'hdop': float(csv[3]), + 'altitude': float(csv[4]), + 'fix': '%sD' % csv[5], + 'cog': float(csv[6]), + 'spkm': float(csv[7]), + 'spkn': float(csv[8]), + 'nsat': int(csv[10]) + } + else: + code = status.split(':') + if len(code) > 1: + code = code[1].strip() + status = "ERROR" + else: + code = code[0] + if code == "516": + result = "Not fixed yet" + elif code == "502": + result = "Invalid format" + elif code == "505": + result = "Session not started" + else: + result = code + message = { + 'status': status, + 'result': result, + } + return json.dumps(message) + def service_version(self, cmd={}): message = { 'status': 'OK', diff --git a/tests/emulator_serialport.py b/tests/emulator_serialport.py index 0e7558d..c5f5956 100644 --- a/tests/emulator_serialport.py +++ b/tests/emulator_serialport.py @@ -275,7 +275,51 @@ def __init__(self): "", "OK", "" - ] + ], + 'AT+QGPSCFG=': [ + "AT+QGPSCFG=", + "", + "", + "OK", + "" + ], + 'AT+QGPS=': [ + "AT+QGPS=", + "", + "", + "OK", + "" + ], + 'AT+QGPS?': [ + "AT+QGPS?", + "", + "", + "+QGPS: 1", + "", + "", + "", + "OK", + "" + ], + 'AT+QGPSLOC=': [ + "AT+QGPSLOC=", + "", + "", + "+QGPSLOC: 071217.0,35.68116,139.76486," + "0.7,50.4,2,0.00,0.0,0.0,210518,09", + "", + "", + "", + "OK", + "" + ], + 'AT+QGPSEND': [ + "AT+QGPSEND", + "", + "", + "OK", + "" + ], } self.reset_res() diff --git a/tests/sock_server_test.py b/tests/sock_server_test.py index 45b50d8..dacb355 100644 --- a/tests/sock_server_test.py +++ b/tests/sock_server_test.py @@ -354,6 +354,94 @@ def test_modem_init_qnvw_failure(setup_sock_server): assert ret == '{"status": "ERROR", "cmd": "AT+QNVW", "result": ""}' +def test_gnss_start(setup_sock_server): + ret = setup_sock_server.perform( + {'category': 'gnss', 'action': 'start'}) + assert ret == '{"status": "OK", "result": ""}' + + +def test_gnss_start_gps_nmea(setup_sock_server): + ret = setup_sock_server.perform( + {'category': 'gnss', 'action': 'start', 'gps_nmea': 'RMC'}) + assert ret == '{"status": "OK", "result": ""}' + + +def test_gnss_start_gps_nmea_error(setup_sock_server): + ret = setup_sock_server.perform( + {'category': 'gnss', 'action': 'start', 'gps_nmea': 'no-such-type'}) + assert ret == '{"status": "ERROR", "result": "Invalid NMEA type"}' + + +def test_gnss_status_on(setup_sock_server): + ret = setup_sock_server.perform( + {'category': 'gnss', 'action': 'status'}) + assert ret == '{"status": "OK", "result": "on"}' + + +def test_gnss_status_off(setup_sock_server): + server = setup_sock_server + server.seralport.res['AT+QGPS?'] = [ + "AT+QGPS?", + "", + "", + "+QGPS: 0", + "", + "", + "", + "OK", + "" + ] + ret = setup_sock_server.perform( + {'category': 'gnss', 'action': 'status'}) + assert ret == '{"status": "OK", "result": "off"}' + + +def test_gnss_stop(setup_sock_server): + ret = setup_sock_server.perform( + {'category': 'gnss', 'action': 'stop'}) + assert ret == '{"status": "OK", "result": ""}' + + +def test_gnss_locate_ok(setup_sock_server): + ret = setup_sock_server.perform( + {'category': 'gnss', 'action': 'locate'}) + assert ret == '{"status": "OK", "result": ' \ + '{' \ + '"spkn": 0.0, "nsat": 9, "hdop": 0.7, "cog": 0.0, ' \ + '"spkm": 0.0, "latitude": 35.68116, ' \ + '"timestamp": "2018-05-21T07:12:17", ' \ + '"altitude": 50.4, "fix": "2D", "longitude": 139.76486}' \ + '}' + + +def test_gnss_locate_error_not_yet_fixed(setup_sock_server): + server = setup_sock_server + server.seralport.res['AT+QGPSLOC='] = [ + "AT+QGPSLOC=", + "", + "", + "+CME ERROR: 516", + "" + ] + ret = setup_sock_server.perform( + {'category': 'gnss', 'action': 'locate'}) + assert ret == '{"status": "ERROR", "result": "Not fixed yet"}' + + +def test_gnss_locate_error_other(setup_sock_server): + server = setup_sock_server + server.seralport.res['AT+QGPSLOC='] = [ + "AT+QGPSLOC=", + "", + "", + "+CME ERROR: 500", + "" + ] + ret = setup_sock_server.perform( + {'category': 'gnss', 'action': 'locate'}) + assert ret == '{"status": "ERROR", "result": "500"}' + + def test_service_version(setup_sock_server): ret = setup_sock_server.perform( {'category': 'service', 'action': 'version'}) From 294ef33de00ad5630d9d19a4c9e323abeda6eb5c Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Tue, 22 May 2018 17:01:19 +0900 Subject: [PATCH 03/13] Add new options to handle GNSS engine startup mode --- lib/candy_board_qws/__init__.py | 21 ++++++++++++++++- tests/sock_server_test.py | 41 ++++++++++++++++++++++----------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/lib/candy_board_qws/__init__.py b/lib/candy_board_qws/__init__.py index 796a72b..6900c7c 100644 --- a/lib/candy_board_qws/__init__.py +++ b/lib/candy_board_qws/__init__.py @@ -856,6 +856,22 @@ def gnss_start(self, cmd={}): return json.dumps(message) def gnss_status(self, cmd={}): + status, result = self.send_at('AT+QGPSCFG="autogps"') + run_on_startup = 'N/A' + if status == "OK": + autogps = result.split(',')[1].strip() + if autogps == "0": + run_on_startup = 'disabled' + else: + run_on_startup = 'enabled' + else: + message = { + 'status': status, + 'result': result, + 'cmd': 'autogps' + } + return json.dumps(message) + status, result = self.send_at("AT+QGPS?") if status == "OK": gnssstate = result.split(':')[1].strip() @@ -865,7 +881,10 @@ def gnss_status(self, cmd={}): result = 'started' message = { 'status': status, - 'result': result, + 'result': { + 'autogps': run_on_startup, + 'session': result + }, } return json.dumps(message) diff --git a/tests/sock_server_test.py b/tests/sock_server_test.py index dacb355..f8b62c9 100644 --- a/tests/sock_server_test.py +++ b/tests/sock_server_test.py @@ -360,26 +360,38 @@ def test_gnss_start(setup_sock_server): assert ret == '{"status": "OK", "result": ""}' -def test_gnss_start_gps_nmea(setup_sock_server): - ret = setup_sock_server.perform( - {'category': 'gnss', 'action': 'start', 'gps_nmea': 'RMC'}) - assert ret == '{"status": "OK", "result": ""}' - - -def test_gnss_start_gps_nmea_error(setup_sock_server): - ret = setup_sock_server.perform( - {'category': 'gnss', 'action': 'start', 'gps_nmea': 'no-such-type'}) - assert ret == '{"status": "ERROR", "result": "Invalid NMEA type"}' - - def test_gnss_status_on(setup_sock_server): + server = setup_sock_server + server.seralport.res['AT+QGPSCFG='] = [ + 'AT+QGPSCFG="autogps"', + "", + "", + '+QGPSCFG: "autogps",0', + "", + "", + "", + "OK", + "" + ] ret = setup_sock_server.perform( {'category': 'gnss', 'action': 'status'}) - assert ret == '{"status": "OK", "result": "on"}' + assert ret == '{"status": "OK", "result": ' + \ + '{"session": "started", "autogps": "disabled"}}' def test_gnss_status_off(setup_sock_server): server = setup_sock_server + server.seralport.res['AT+QGPSCFG='] = [ + 'AT+QGPSCFG="autogps"', + "", + "", + '+QGPSCFG: "autogps",1', + "", + "", + "", + "OK", + "" + ] server.seralport.res['AT+QGPS?'] = [ "AT+QGPS?", "", @@ -393,7 +405,8 @@ def test_gnss_status_off(setup_sock_server): ] ret = setup_sock_server.perform( {'category': 'gnss', 'action': 'status'}) - assert ret == '{"status": "OK", "result": "off"}' + assert ret == '{"status": "OK", "result": ' + \ + '{"session": "stopped", "autogps": "enabled"}}' def test_gnss_stop(setup_sock_server): From d28d8b376a97eab279a9c95af361e31af7fc5ddd Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Wed, 23 May 2018 15:50:33 +0900 Subject: [PATCH 04/13] Fix an issue where modem_init() returned an error when SIM card is absent --- lib/candy_board_qws/__init__.py | 36 ++++++++++++++++----------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/candy_board_qws/__init__.py b/lib/candy_board_qws/__init__.py index 6900c7c..7c34bdf 100644 --- a/lib/candy_board_qws/__init__.py +++ b/lib/candy_board_qws/__init__.py @@ -788,23 +788,20 @@ def modem_init(self, cmd={}): - Set baudrate (optional) - Reset packet counter (optional) """ + tz_update = "N/A" + counter_reset_ret = "N/A" + baudrate_ret = "N/A" if 'tz_update' not in cmd or cmd['tz_update'] is True: status, result = self.send_at("AT+CTZU?") - if status != "OK": - message = { - 'status': status, - 'result': result, - 'cmd': 'tz_update' - } - return json.dumps(message) - for at in ["AT+COPS=2", "AT+CTZU=1", "AT+COPS=0"]: - status, result = self.send_at(at) - if status != "OK": - break + if status == "OK": + tz_update = "OK" + for at in ["AT+COPS=2", "AT+CTZU=1", "AT+COPS=0"]: + status, result = self.send_at(at) + if status != "OK": + tz_update = "ERROR" + break if 'counter_reset' in cmd and cmd['counter_reset']: - counter_reset_ret = self._counter_reset() - status = counter_reset_ret['status'] - result = counter_reset_ret['result'] + counter_reset_ret = self._counter_reset()['status'] status, result_qnvw = self.send_at( 'AT+QNVW=4548,0,"0000400C00000210"') if status != "OK": @@ -815,17 +812,20 @@ def modem_init(self, cmd={}): } return json.dumps(message) if 'baudrate' in cmd: - status, result = self.send_at("AT+IPR=%s" % cmd['baudrate']) - if status != "OK": + baudrate_ret, result = self.send_at("AT+IPR=%s" % cmd['baudrate']) + if baudrate_ret != "OK": message = { - 'status': status, + 'status': baudrate_ret, 'result': result, 'cmd': 'baudrate' } return json.dumps(message) message = { 'status': status, - 'result': result + 'result': { + 'counter_reset': counter_reset_ret, + 'baudrate': baudrate_ret + } } return json.dumps(message) From 3f32e723fb8a1f042ff636a869b7d375884908fa Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Wed, 23 May 2018 18:36:08 +0900 Subject: [PATCH 05/13] Always enable NMEA output --- lib/candy_board_qws/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/candy_board_qws/__init__.py b/lib/candy_board_qws/__init__.py index 7c34bdf..040c0f3 100644 --- a/lib/candy_board_qws/__init__.py +++ b/lib/candy_board_qws/__init__.py @@ -840,7 +840,16 @@ def gnss_start(self, cmd={}): 'cmd': 'gpsnmeatype' } return json.dumps(message) - + status, result = self.send_at('AT+QGPSCFG="nmeasrc",1') + if status != "OK": + result = status + status = "ERROR" + message = { + 'status': status, + 'result': result, + 'cmd': 'nmeasrc' + } + return json.dumps(message) status, result = self.send_at("AT+QGPS=1,30,50,0,1") if status == "OK": result = "" From ea32ae64b258178cdf6418997573efad54f18950 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Wed, 23 May 2018 19:02:14 +0900 Subject: [PATCH 06/13] Fix a test case --- tests/sock_server_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/sock_server_test.py b/tests/sock_server_test.py index f8b62c9..0697f28 100644 --- a/tests/sock_server_test.py +++ b/tests/sock_server_test.py @@ -333,7 +333,8 @@ def test_modem_init(setup_sock_server): 'baudrate': '115200', 'counter_reset': True }) - assert ret == '{"status": "OK", "result": ""}' + assert ret == '{"status": "OK", ' \ + '"result": {"counter_reset": "OK", "baudrate": "OK"}}' def test_modem_init_qnvw_failure(setup_sock_server): From 1229c23511642046cc19dbee3fb9de0c4e166d81 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Wed, 23 May 2018 19:07:19 +0900 Subject: [PATCH 07/13] Bump version --- README.md | 3 +++ setup.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8e240e0..00d4eb7 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,9 @@ $ ./setup.py publish ``` # Revision history +* 2.0.0 + - Add new categories for `gnss` + - Fix an issue where modem_init() returned an error when SIM card is absent * 1.3.1 - Fix an issue where modem_show() throws a runtime error when the command result is error * 1.3.0 diff --git a/setup.py b/setup.py index 5361377..1260ec0 100755 --- a/setup.py +++ b/setup.py @@ -19,7 +19,7 @@ from setuptools import setup, find_packages from setuptools.command.test import test as TestCommand -version = "1.3.1" +version = "2.0.0" try: import pypandoc @@ -72,7 +72,13 @@ def run_tests(self): 'Operating System :: POSIX :: Linux', 'Topic :: System :: Hardware', ], - keywords=('CANDY RED', 'CANDY EGG', 'CANDY LINE'), + keywords=( + 'CANDY RED', + 'CANDY EGG', + 'CANDY LINE', + 'CANDY Pi Lite', + 'CANDY Pi Lite+' + ), tests_require=['pytest-cov>=2.2.0', 'pytest>=2.6.4', 'terminaltables>=1.2.1'], From 64ea38779ee1b4e578c4311466a0472c0ca5e347 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Wed, 23 May 2018 20:10:30 +0900 Subject: [PATCH 08/13] Fix an issue where the returned text contains unexpected format described in the spec when the format is 0 or 1 --- lib/candy_board_qws/__init__.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/candy_board_qws/__init__.py b/lib/candy_board_qws/__init__.py index 040c0f3..dce8dc5 100644 --- a/lib/candy_board_qws/__init__.py +++ b/lib/candy_board_qws/__init__.py @@ -913,20 +913,36 @@ def gnss_stop(self, cmd={}): return json.dumps(message) def gnss_locate(self, cmd={}): - format = cmd['format'] if 'format' in cmd else None - status, result = self.send_at("AT+QGPSLOC=%s" % (format or '2')) + format = (str(cmd['format']) if 'format' in cmd else None) or '2' + status, result = self.send_at("AT+QGPSLOC=%s" % (format)) if status == "OK": csv = result.split(':')[1].strip().split(',') + latitude = csv[1] + if format == '1': + latitude = '%s %s' % (latitude, csv[2]) + del csv[2] + elif format == '0': + latitude = '%s %s' % (latitude[:-1], latitude[-1]) + longitude = csv[2] + if format == '1': + longitude = '%s %s' % (longitude, csv[3]) + del csv[3] + elif format == '0': + longitude = '%s %s' % (longitude[:-1], longitude[-1]) + altitude = float(csv[4]) + if format == '2': + latitude = float(latitude) + longitude = float(longitude) result = { 'timestamp': '20%s-%s-%sT%s:%s:%s' % ( csv[9][4:6], csv[9][2:4], csv[9][0:2], csv[0][0:2], csv[0][2:4], csv[0][4:6] ), - 'latitude': float(csv[1]), - 'longitude': float(csv[2]), + 'latitude': latitude, + 'longitude': longitude, 'hdop': float(csv[3]), - 'altitude': float(csv[4]), + 'altitude': altitude, 'fix': '%sD' % csv[5], 'cog': float(csv[6]), 'spkm': float(csv[7]), From 04350cb513b580a76cc9c4ad55b2e09cd648a19b Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Wed, 23 May 2018 21:24:25 +0900 Subject: [PATCH 09/13] Fix an issue where format value failed to be resolved properly --- lib/candy_board_qws/__init__.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/candy_board_qws/__init__.py b/lib/candy_board_qws/__init__.py index dce8dc5..b264e28 100644 --- a/lib/candy_board_qws/__init__.py +++ b/lib/candy_board_qws/__init__.py @@ -913,7 +913,10 @@ def gnss_stop(self, cmd={}): return json.dumps(message) def gnss_locate(self, cmd={}): - format = (str(cmd['format']) if 'format' in cmd else None) or '2' + if 'format' in cmd and cmd['format']: + format = str(cmd['format']) + else: + format = '2' status, result = self.send_at("AT+QGPSLOC=%s" % (format)) if status == "OK": csv = result.split(':')[1].strip().split(',') From 66c0fc109dfb78ad8ca5dc56f7c2cbfcfea27b2c Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Thu, 24 May 2018 08:23:55 +0900 Subject: [PATCH 10/13] Remove unsupported property --- lib/candy_board_qws/__init__.py | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/lib/candy_board_qws/__init__.py b/lib/candy_board_qws/__init__.py index b264e28..b5dadf4 100644 --- a/lib/candy_board_qws/__init__.py +++ b/lib/candy_board_qws/__init__.py @@ -865,22 +865,6 @@ def gnss_start(self, cmd={}): return json.dumps(message) def gnss_status(self, cmd={}): - status, result = self.send_at('AT+QGPSCFG="autogps"') - run_on_startup = 'N/A' - if status == "OK": - autogps = result.split(',')[1].strip() - if autogps == "0": - run_on_startup = 'disabled' - else: - run_on_startup = 'enabled' - else: - message = { - 'status': status, - 'result': result, - 'cmd': 'autogps' - } - return json.dumps(message) - status, result = self.send_at("AT+QGPS?") if status == "OK": gnssstate = result.split(':')[1].strip() @@ -891,7 +875,6 @@ def gnss_status(self, cmd={}): message = { 'status': status, 'result': { - 'autogps': run_on_startup, 'session': result }, } From a7da6ee263176ef793fbcb7da5ed4afcac542106 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Thu, 24 May 2018 08:24:12 +0900 Subject: [PATCH 11/13] Apply ISO8601 format --- lib/candy_board_qws/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/candy_board_qws/__init__.py b/lib/candy_board_qws/__init__.py index b5dadf4..9471a29 100644 --- a/lib/candy_board_qws/__init__.py +++ b/lib/candy_board_qws/__init__.py @@ -920,7 +920,7 @@ def gnss_locate(self, cmd={}): latitude = float(latitude) longitude = float(longitude) result = { - 'timestamp': '20%s-%s-%sT%s:%s:%s' % + 'timestamp': '20%s-%s-%sT%s:%s:%s.000Z' % ( csv[9][4:6], csv[9][2:4], csv[9][0:2], csv[0][0:2], csv[0][2:4], csv[0][4:6] From 61b32463eb3109e09cce4b695b186a71efae0a84 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Thu, 24 May 2018 08:25:05 +0900 Subject: [PATCH 12/13] Swallow EPIPE error --- lib/candy_board_qws/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/candy_board_qws/__init__.py b/lib/candy_board_qws/__init__.py index 9471a29..7cde8a6 100644 --- a/lib/candy_board_qws/__init__.py +++ b/lib/candy_board_qws/__init__.py @@ -28,6 +28,7 @@ import glob import platform import traceback +import errno # SerialPort class was imported from John Wiseman's # https://github.com/wiseman/arduino-serial/blob/master/arduinoserial.py @@ -330,6 +331,13 @@ def run(self): packed_message = packer_body.pack(message) connection.sendall(packed_message) + except socket.error, e: + if isinstance(e.args, tuple): + if e[0] == errno.EPIPE: + continue + exc_type, exc_value, exc_traceback = sys.exc_info() + traceback.print_exception(exc_type, exc_value, exc_traceback) + except Exception: exc_type, exc_value, exc_traceback = sys.exc_info() traceback.print_exception(exc_type, exc_value, exc_traceback) From e65750f7475fb01511c3dad8b53402b313d75e77 Mon Sep 17 00:00:00 2001 From: Daisuke Baba Date: Thu, 24 May 2018 13:14:53 +0900 Subject: [PATCH 13/13] Test the CSV array prior to building a response message --- lib/candy_board_qws/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/candy_board_qws/__init__.py b/lib/candy_board_qws/__init__.py index 7cde8a6..c120811 100644 --- a/lib/candy_board_qws/__init__.py +++ b/lib/candy_board_qws/__init__.py @@ -911,6 +911,12 @@ def gnss_locate(self, cmd={}): status, result = self.send_at("AT+QGPSLOC=%s" % (format)) if status == "OK": csv = result.split(':')[1].strip().split(',') + if len(csv) < 11: + message = { + 'status': 'ERROR', + 'result': 'Temporary I/O Error', + } + return json.dumps(message) latitude = csv[1] if format == '1': latitude = '%s %s' % (latitude, csv[2])