Skip to content

Commit

Permalink
Merge pull request #136 from openxc/next
Browse files Browse the repository at this point in the history
Next
  • Loading branch information
jstoke53 authored Jan 27, 2020
2 parents 9a033e5 + 509ac36 commit 2054c3d
Show file tree
Hide file tree
Showing 22 changed files with 411 additions and 87 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
OpenXC Python Library Changelog
===============================

v2.0.0
----------
* Known Issue: OpenXC python must be used with firmware 8.0.0 or greater.
* Feature: openxc-generate-firmware-code generator now generates signals.cpp in a more memory efficent way.
* Feature: Add dashboard on message change highlighting.
* Feature: Add column sorting and filtering on dashboard.
* Feature: Add more verbosity to libusb errors.
* Fix: Fix more python 3 migration byte bugs.

v1.1.1
----------
* Fix: Fixed Pip included files
Expand Down
5 changes: 5 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ include LICENSE
include openxc/generator/signals.cpp.footer
include openxc/generator/signals.cpp.header
include openxc/tools/templates/dashboard.html
include openxc/tools/static/css/dashboard.css
include openxc/tools/static/js/jquery-3.4.1.min.js
include openxc/tools/static/js/dashboard.js
include openxc/tools/static/js/socket.io.slim.js
include openxc/tools/static/js/jquery.color-2.1.2.min.js
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OpenXC for Python

.. image:: https://github.com/openxc/openxc-python/raw/master/docs/_static/logo.png

:Version: 1.1.1
:Version: 2.0.0
:Web: http://openxcplatform.com
:Download: http://pypi.python.org/pypi/openxc/
:Documentation: http://python.openxcplatform.com
Expand All @@ -30,6 +30,8 @@ In addition to a port of the Android library API, the package also contains a
number of command-line tools for connecting to the CAN translator and
manipulating previously recorded vehicle data.

Due to changes in signals.cpp openxc-python Version 2.0.0 must be used with vi-firmware 8.0.0 or greater.

To package run "setup.py sdist bdist_wheel"
to push to pypi run "python -m twine upload dist/\*"
Version files:
Expand Down
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ OpenXC for Python

.. image:: https://github.com/openxc/openxc-python/raw/master/docs/_static/logo.png

:Version: 1.1.1
:Version: 2.0.0
:Web: http://openxcplatform.com
:Download: http://pypi.python.org/pypi/openxc/
:Documentation: http://python.openxcplatform.com
Expand Down
2 changes: 1 addition & 1 deletion openxc/controllers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ResponseReceiver(object):
of ResponseReceivers as they arrive.
"""

COMMAND_RESPONSE_TIMEOUT_S = .5
COMMAND_RESPONSE_TIMEOUT_S = 0.5

def __init__(self, queue, request, quit_after_first=True):
"""Construct a new ResponseReceiver.
Expand Down
48 changes: 38 additions & 10 deletions openxc/generator/coder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def build_source(self):
lines.extend(self._build_messages())
lines.extend(self._build_signal_states())
lines.extend(self._build_signals())
lines.extend(self._build_signal_managers())
lines.extend(self._build_initializers())
lines.extend(self._build_loop())
lines.extend(self._build_commands())
Expand Down Expand Up @@ -231,20 +232,45 @@ def _build_signals(self):
lines = []
lines.append("const int MAX_SIGNAL_COUNT = %d;" %
self._max_signal_count())
lines.append("CanSignal SIGNALS[][MAX_SIGNAL_COUNT] = {")
lines.append("const CanSignal SIGNALS[][MAX_SIGNAL_COUNT] __attribute__ ((section(\".rodata._ZL7SIGNALS\"))) = {")

def block(message_set):
lines = []
i = 1
for signal in message_set.all_signals():
for i, signal in enumerate(message_set.all_signals()):
if not signal.enabled:
LOG.warning("Skipping disabled signal '%s' (in 0x%x)" % (
signal.generic_name, signal.message.id))
continue
signal.array_index = i - 1
if not hasattr(signal, "array_index") or signal.array_index is None:
signal.array_index = i
lines.append(" " * 8 + "%s" % signal)
LOG.info("Added signal '%s'" % signal.generic_name)
i += 1
return lines

lines.extend(self._message_set_lister(block))
lines.append("};")
lines.append("")

return lines

def _build_signal_managers(self):
lines = []
lines.append("SignalManager SIGNAL_MANAGERS[][MAX_SIGNAL_COUNT] = {")

def block(message_set):
lines = []
for i, signal in enumerate(message_set.all_signals()):
if not signal.enabled:
LOG.warning("Skipping manager for disabled signal '%s' (in 0x%x)" % (
signal.generic_name, signal.message.id))
continue
if not hasattr(signal, "array_index") or signal.array_index is None:
signal.array_index = i

signal_arr_str = "SIGNALS[%d][%d]" % (signal.message_set.index, signal.array_index)
lines.append(" " * 8 + "{signal: &%s, frequencyClock: {%s.frequency}}," % (signal_arr_str, signal_arr_str))
LOG.info("Added signal manager '%s'" % signal.generic_name)

return lines

lines.extend(self._message_set_lister(block))
Expand Down Expand Up @@ -314,16 +340,18 @@ def block(message_set):
lines.append(" " * 12 + "case 0x%x: // %s" % (message.id,
message.name))
for handler in message.handlers:
lines.append(" " * 16 + "%s(message, SIGNALS[%d], " % (
handler, message_set.index) +
"getSignalCount(), pipeline);")
lines.append(" " * 16 + "%s(SIGNALS[%d], SIGNALS[%d], " % (
handler, message_set.index, message_set.index) +
"SIGNAL_MANAGERS[%d], SIGNAL_MANAGERS[%d], " % (
message_set.index, message_set.index) +
"getSignalCount(), message, pipeline);")
for signal in message.active_signals():
line = " " * 16
line += ("can::read::translateSignal("
"&SIGNALS[%d][%d], message, " %
(message_set.index, signal.array_index))
line += ("SIGNALS[%d], getSignalCount(), pipeline); // %s" % (
message_set.index, signal.name))
line += ("SIGNALS[%d], SIGNAL_MANAGERS[%d], getSignalCount(), pipeline); // %s" % (
message_set.index, message_set.index, signal.name))
lines.append(line)
lines.append(" " * 16 + "break;")
lines.append(" " * 12 + "}")
Expand Down
12 changes: 8 additions & 4 deletions openxc/generator/signals.cpp.footer
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ int openxc::signals::getCommandCount() {
return getActiveMessageSet()->commandCount;
}

CanMessageDefinition* openxc::signals::getMessages() {
const CanMessageDefinition* openxc::signals::getMessages() {
return CAN_MESSAGES[getActiveMessageSet()->index];
}

int openxc::signals::getMessageCount() {
return getActiveMessageSet()->messageCount;
}

CanSignal* openxc::signals::getSignals() {
const CanSignal* openxc::signals::getSignals() {
return SIGNALS[getActiveMessageSet()->index];
}

SignalManager* openxc::signals::getSignalManagers() {
return SIGNAL_MANAGERS[getActiveMessageSet()->index];
}

int openxc::signals::getSignalCount() {
return getActiveMessageSet()->signalCount;
}
Expand All @@ -30,11 +34,11 @@ int openxc::signals::getCanBusCount() {
return getActiveMessageSet()->busCount;
}

CanMessageSet* openxc::signals::getActiveMessageSet() {
const CanMessageSet* openxc::signals::getActiveMessageSet() {
return &MESSAGE_SETS[getConfiguration()->messageSetIndex];
}

CanMessageSet* openxc::signals::getMessageSets() {
const CanMessageSet* openxc::signals::getMessageSets() {
return MESSAGE_SETS;
}

Expand Down
1 change: 1 addition & 0 deletions openxc/generator/signals.cpp.header
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace can = openxc::can;

using openxc::util::log::debug;
using openxc::util::time::FrequencyClock;
using openxc::pipeline::Pipeline;
using openxc::config::getConfiguration;
using openxc::can::read::booleanDecoder;
Expand Down
2 changes: 1 addition & 1 deletion openxc/generator/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def _invert_bit_index(cls, bit_index, length):
return inverted_index

def __str__(self):
result = ("{message: &CAN_MESSAGES[%d][%d], genericName: \"%s\", bitPosition: %s, bitSize: %d, factor: %f, offset: %f, minValue: %f, maxValue: %f, frequencyClock: {%f}, sendSame: %s, forceSendChanged: %s, " % (
result = ("{message: &CAN_MESSAGES[%d][%d], genericName: \"%s\", bitPosition: %s, bitSize: %d, factor: %f, offset: %f, minValue: %f, maxValue: %f, frequency: %f, sendSame: %s, forceSendChanged: %s, " % (
self.message_set.index,
self.message_set.lookup_message_index(self.message),
self.generic_name, self.bit_position, self.bit_size,
Expand Down
7 changes: 4 additions & 3 deletions openxc/sources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def run(self):
message from the buffer of bytes. When a message is parsed, passes it
off to the callback if one is set.
"""
message_buffer = b""
message_buffer = ""
while self.running:
try:
message_buffer += self.source.read_logs()
Expand All @@ -158,7 +158,7 @@ def run(self):
while True:
if "\x00" not in message_buffer:
break
record, _, remainder = message_buffer.partition(b"\x00")
record, _, remainder = message_buffer.partition("\x00")
self.record(record)
message_buffer = remainder

Expand Down Expand Up @@ -191,6 +191,7 @@ def run(self):
off to the callback if one is set.
"""
while self.running:
payload = ""
try:
payload = self.read()
except DataSourceError as e:
Expand Down Expand Up @@ -223,7 +224,7 @@ def run(self):
self._receive_command_response(message)

def _receive_command_response(self, message):
# TODO the controller/source are getting a litlte mixed up since the
# TODO the controller/source are getting a little mixed up since the
# controller now needs to receive responses from the soruce side, maybe
# just mix them again. the only exception to being both is a trace
# source, and we can just leave the controller methods on that
Expand Down
8 changes: 5 additions & 3 deletions openxc/sources/usb.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class UsbDataSource(BytestreamDataSource):
# throughput if the READ_REQUEST_SIZE is higher, but this delay has to be
# low enough that a single request isn't held back too long.
DEFAULT_READ_TIMEOUT = 200
LIBUSB0_TIMEOUT_CODE = -116
LIBUSB1_TIMEOUT_CODE = -7
OPENUSB_TIMEOUT_CODE = -62

DEFAULT_INTERFACE_NUMBER = 0
VEHICLE_DATA_IN_ENDPOINT = 2
Expand Down Expand Up @@ -83,10 +86,9 @@ def _read(self, endpoint_address, timeout=None,
timeout = timeout or self.DEFAULT_READ_TIMEOUT
try:
return str(self.device.read(0x80 + endpoint_address,
read_size, self.DEFAULT_INTERFACE_NUMBER, timeout
),'utf-8')
read_size, self.DEFAULT_INTERFACE_NUMBER, timeout), 'ISO-8859-1')
except (usb.core.USBError, AttributeError) as e:
if e.errno == 110:
if e.backend_error_code in [self.LIBUSB0_TIMEOUT_CODE, self.LIBUSB1_TIMEOUT_CODE, self.OPENUSB_TIMEOUT_CODE]:
# Timeout, it may just not be sending
return ""
raise DataSourceError("USB device couldn't be read", e)
3 changes: 2 additions & 1 deletion openxc/tools/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def parse_options():
dest="host")
parser.add_argument("--port", action="store", default=80,
dest="port")
parser.set_defaults(format="json")
return parser.parse_args()


Expand Down Expand Up @@ -182,4 +183,4 @@ def main():
else:
sys.exit("%s requires a signal name, message ID or filename" % arguments.command)
else:
print(("Unrecognized command \"%s\"" % arguments.command))
print(("Unrecognized command \"%s\"" % arguments.command))
1 change: 1 addition & 0 deletions openxc/tools/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def parse_options():
parser.add_argument("--pid", help="Parameter ID (e.g. for Mode 1 request")
parser.add_argument("--payload", help="A byte array as a hex string to send as payload, e.g. 0x123")
parser.add_argument("--frequency", help="Frequency (Hz) to repeat this request. If omitted or 0, it will be a one-time request.")
parser.set_defaults(format="json")

return parser.parse_args()

Expand Down
1 change: 0 additions & 1 deletion openxc/tools/gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def main():
arguments = parse_options()

transcoder = GPXTranscoder()

source = TraceDataSource(transcoder.receive, filename=arguments.trace_file,
loop=False, realtime=False)
source.start()
Expand Down
52 changes: 49 additions & 3 deletions openxc/tools/static/css/dashboard.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
#page-contents {
display: flex;
justify-content: space-evenly;
height: 100%;
margin-top: 3%;
}

form {
display: table;
}

.error {
color: red;
display: block;
font-size: 0.85em;
font-style: italic;
}

form li {
list-style-type: none;
display: table-row;
}

form label, input {
display: table-cell;
}

#dashboardSettingsSubmitBtn {
margin-left: 9%;
}

caption {
font-size: 1.5em;
margin-bottom: 4.5%;
}

table, th, td {
text-align: left;
border-spacing: 8px 1px;
text-align: left;
border-spacing: 8px 1px;
}

.metric {
text-align: right;
}
}

th:hover {
cursor: pointer;
background-color: #AAA;
}

table, th, td {
border: 1px solid black;
}

table {
padding-top: 2%;
padding-bottom: 2%;
}
Loading

0 comments on commit 2054c3d

Please sign in to comment.