Skip to content

Commit 099b266

Browse files
BaldwinBaldwin
authored andcommitted
Fixed timeout error handling
1 parent e77a42c commit 099b266

7 files changed

Lines changed: 14 additions & 7 deletions

File tree

openxc/controllers/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class ResponseReceiver(object):
2828
of ResponseReceivers as they arrive.
2929
"""
3030

31-
COMMAND_RESPONSE_TIMEOUT_S = .5
31+
COMMAND_RESPONSE_TIMEOUT_S = 0.5
3232

3333
def __init__(self, queue, request, quit_after_first=True):
3434
"""Construct a new ResponseReceiver.

openxc/controllers/usb.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def write_bytes(self, data):
2727
self.out_endpoint)
2828
return 0
2929
else:
30-
return self.out_endpoint.write(data)
30+
ret = self.out_endpoint.write(data)
31+
return ret
3132

3233
def _send_complex_request(self, request):
3334
"""Send a request via the USB control request endpoint, rather than as a

openxc/sources/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def run(self):
156156
break
157157

158158
while True:
159-
if "\x00" not in message_buffer:
159+
if b"\x00" not in message_buffer:
160160
break
161161
record, _, remainder = message_buffer.partition(b"\x00")
162162
self.record(record)
@@ -191,6 +191,7 @@ def run(self):
191191
off to the callback if one is set.
192192
"""
193193
while self.running:
194+
payload = b""
194195
try:
195196
payload = self.read()
196197
except DataSourceError as e:

openxc/sources/usb.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ def _read(self, endpoint_address, timeout=None,
8686
read_size, self.DEFAULT_INTERFACE_NUMBER, timeout
8787
),'utf-8')
8888
except (usb.core.USBError, AttributeError) as e:
89-
if e.errno == 110:
89+
# timeout error codes:
90+
# libusb0: -116
91+
# libusb1: -7
92+
# openusb: -62
93+
if e.backend_error_code in [-116, -7, -62]:
9094
# Timeout, it may just not be sending
91-
return ""
95+
return b""
9296
raise DataSourceError("USB device couldn't be read", e)

openxc/tools/control.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ def parse_options():
131131
dest="host")
132132
parser.add_argument("--port", action="store", default=80,
133133
dest="port")
134+
parser.set_defaults(format="json")
134135
return parser.parse_args()
135136

136137

@@ -182,4 +183,4 @@ def main():
182183
else:
183184
sys.exit("%s requires a signal name, message ID or filename" % arguments.command)
184185
else:
185-
print(("Unrecognized command \"%s\"" % arguments.command))
186+
print(("Unrecognized command \"%s\"" % arguments.command))

openxc/tools/diagnostics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def parse_options():
7676
parser.add_argument("--pid", help="Parameter ID (e.g. for Mode 1 request")
7777
parser.add_argument("--payload", help="A byte array as a hex string to send as payload, e.g. 0x123")
7878
parser.add_argument("--frequency", help="Frequency (Hz) to repeat this request. If omitted or 0, it will be a one-time request.")
79+
parser.set_defaults(format="json")
7980

8081
return parser.parse_args()
8182

openxc/tools/gps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ def main():
5454
arguments = parse_options()
5555

5656
transcoder = GPXTranscoder()
57-
5857
source = TraceDataSource(transcoder.receive, filename=arguments.trace_file,
5958
loop=False, realtime=False)
6059
source.start()

0 commit comments

Comments
 (0)