Skip to content

Commit 5001b54

Browse files
authored
Merge pull request #129 from openxc/fix-usb
Fix usb
2 parents c0e4f8c + cc3bf12 commit 5001b54

6 files changed

Lines changed: 13 additions & 9 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/sources/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ def run(self):
143143
message from the buffer of bytes. When a message is parsed, passes it
144144
off to the callback if one is set.
145145
"""
146-
message_buffer = b""
146+
message_buffer = ""
147147
while self.running:
148148
try:
149149
message_buffer += self.source.read_logs()
@@ -158,7 +158,7 @@ def run(self):
158158
while True:
159159
if "\x00" not in message_buffer:
160160
break
161-
record, _, remainder = message_buffer.partition(b"\x00")
161+
record, _, remainder = message_buffer.partition("\x00")
162162
self.record(record)
163163
message_buffer = remainder
164164

@@ -191,6 +191,7 @@ def run(self):
191191
off to the callback if one is set.
192192
"""
193193
while self.running:
194+
payload = ""
194195
try:
195196
payload = self.read()
196197
except DataSourceError as e:
@@ -223,7 +224,7 @@ def run(self):
223224
self._receive_command_response(message)
224225

225226
def _receive_command_response(self, message):
226-
# TODO the controller/source are getting a litlte mixed up since the
227+
# TODO the controller/source are getting a little mixed up since the
227228
# controller now needs to receive responses from the soruce side, maybe
228229
# just mix them again. the only exception to being both is a trace
229230
# source, and we can just leave the controller methods on that

openxc/sources/usb.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class UsbDataSource(BytestreamDataSource):
2222
# throughput if the READ_REQUEST_SIZE is higher, but this delay has to be
2323
# low enough that a single request isn't held back too long.
2424
DEFAULT_READ_TIMEOUT = 200
25+
LIBUSB0_TIMEOUT_CODE = -116
26+
LIBUSB1_TIMEOUT_CODE = -7
27+
OPENUSB_TIMEOUT_CODE = -62
2528

2629
DEFAULT_INTERFACE_NUMBER = 0
2730
VEHICLE_DATA_IN_ENDPOINT = 2
@@ -83,10 +86,9 @@ def _read(self, endpoint_address, timeout=None,
8386
timeout = timeout or self.DEFAULT_READ_TIMEOUT
8487
try:
8588
return str(self.device.read(0x80 + endpoint_address,
86-
read_size, self.DEFAULT_INTERFACE_NUMBER, timeout
87-
),'utf-8')
89+
read_size, self.DEFAULT_INTERFACE_NUMBER, timeout), 'ISO-8859-1')
8890
except (usb.core.USBError, AttributeError) as e:
89-
if e.errno == 110:
91+
if e.backend_error_code in [self.LIBUSB0_TIMEOUT_CODE, self.LIBUSB1_TIMEOUT_CODE, self.OPENUSB_TIMEOUT_CODE]:
9092
# Timeout, it may just not be sending
9193
return ""
9294
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)