Skip to content

Commit

Permalink
Incorporating changes made to support accessories
Browse files Browse the repository at this point in the history
During development of the accessories many features and tests were added to the standard Python library to support new functionality.  This update captures those changes.
  • Loading branch information
carpenma committed May 26, 2016
1 parent c4a3f02 commit f188b13
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 3 deletions.
Binary file added openxc-python.udb
Binary file not shown.
35 changes: 35 additions & 0 deletions openxc/controllers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ def _response_matches_request(self, response):
"""Return true if the 'command' field in the response matches the
original request.
"""
if 'modem_command' in self.request :
return response.get('modem_command_response', None) == self.request['modem_command']

return response.get('command_response', None) == self.request['command']

class DiagnosticResponseReceiver(ResponseReceiver):
Expand Down Expand Up @@ -339,6 +342,38 @@ def device_id(self):
}
return self._check_command_response_message(request)

def modem_version(self):
"""Request a firmware version identifier from the modem.
"""
request = {
"modem_command": "version"
}
return self._check_command_response_message(request)

def modem_device_id(self):
"""Request the unique device ID of the attached modem.
"""
request = {
"modem_command": "device_id"
}
return self._check_command_response_message(request)

def modem_diag_enable(self):
"""Request the modem enable diagnostics mode.
"""
request = {
"modem_command": "diagnostics_enable"
}
return self._check_command_response_message(request)

def modem_diag_disable(self):
"""Request the modem disable diagnostics mode.
"""
request = {
"modem_command": "diagnostics_disable"
}
return self._check_command_response_message(request)

def write(self, **kwargs):
"""Serialize a raw or translated write request and send it to the VI,
following the OpenXC message format.
Expand Down
7 changes: 6 additions & 1 deletion openxc/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,12 @@ def from_dict(cls, data):
args.append(data['data'])
# TODO grab bus
else:
measurement_class = cls._class_from_name(data['name'])
if 'modem_label' in data:
measurement_class = Measurement
data['name'] = data['modem_label']
data['value'] = data['modem_value']
else:
measurement_class = cls._class_from_name(data['name'])
if measurement_class == Measurement:
args.append(data['name'])
args.append(data['value'])
Expand Down
1 change: 1 addition & 0 deletions openxc/sources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ def _message_valid(self, message):
if not hasattr(message, '__iter__'):
return False
if not ('name' in message and 'value' in message or
('modem_label' in message and 'modem_value' in message) or
('id' in message and 'data' in message) or
('id' in message and 'bus' in message) or
'command_response' in message):
Expand Down
1 change: 1 addition & 0 deletions openxc/sources/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def read(self):
if line == '':
if self.loop:
self._reopen_file()
line = self.trace_file.readline() # read in first line after reopen
else:
self.trace_file.close()
self.trace_file = None
Expand Down
5 changes: 5 additions & 0 deletions openxc/tools/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ def device_options():
choices=["json", "protobuf"],
dest="format",
help="select the data format for sending and receiving with the VI")
parser.add_argument("--modem",
action="store_true",
dest="modem",
default=False,
help="receive diagnostic messages from attached modem")
return parser


Expand Down
24 changes: 23 additions & 1 deletion openxc/tools/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ def version(interface):
def device_id(interface):
print("Device ID is %s" % interface.device_id())

def modem_version(interface):
print("Modem is running version %s" % interface.modem_version())

def modem_device_id(interface):
print("Modem Device ID is %s" % interface.modem_device_id())

def modem_diag_enable(interface):
interface.modem_diag_enable()
print("Modem Diagnostics Enabled")

def modem_diag_disable(interface):
interface.modem_diag_disable()
print("Modem Diagnostics Disabled")

def passthrough(interface, bus, passthrough_enabled):
if interface.set_passthrough(bus, passthrough_enabled):
print("Bus %u passthrough set to %s" % (bus, passthrough_enabled))
Expand Down Expand Up @@ -75,7 +89,7 @@ def parse_options():
parser = argparse.ArgumentParser(description="Send control messages to an "
"attached OpenXC vehicle interface", parents=[device_options()])
parser.add_argument("command", type=str,
choices=['version', 'write', 'id', 'set'])
choices=['version', 'write', 'id', 'set', 'modem_version', 'modem_id', 'modem_diag_enable', 'modem_diag_disable'])
write_group = parser.add_mutually_exclusive_group()
write_group.add_argument("--name", action="store", dest="write_name",
help="name for message write request")
Expand Down Expand Up @@ -123,6 +137,14 @@ def main():
version(interface)
elif arguments.command == "id":
device_id(interface)
elif arguments.command == "modem_version":
modem_version(interface)
elif arguments.command == "modem_id":
modem_device_id(interface)
elif arguments.command == "modem_diag_enable":
modem_diag_enable(interface)
elif arguments.command == "modem_diag_disable":
modem_diag_disable(interface)
elif arguments.command == "set":
if arguments.passthrough_enabled is not None:
passthrough(interface, int(arguments.bus), arguments.passthrough_enabled)
Expand Down
4 changes: 4 additions & 0 deletions openxc/tools/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ def run_dashboard(window, source_class, source_kwargs):
dashboard.scroll_down(25)
elif c == curses.KEY_PPAGE:
dashboard.scroll_up(25)
elif c == 3: # Control-C
break # Stop on Control-C
elif c == 27: # ESC
break # Stop on ESC



Expand Down
5 changes: 4 additions & 1 deletion openxc/vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ def add_sink(self, sink):
sink.start()

def _receive(self, message, **kwargs):
name = message.get('name', 'can_message')
if 'modem_label' in message:
name = message['modem_label']
else:
name = message.get('name', 'can_message')
self.measurements[name] = message

for sink in self.sinks:
Expand Down

0 comments on commit f188b13

Please sign in to comment.