neovi.spec module¶
This module provides classes and functions to allow a network specification to be created for use with pyneovi. A network specification defines the valid networks for a given model of vehicle, along with the ECUs on those networks and the identifiers and signals made available by the ECUs.
Below is an example of a simple network specification. Only the medium speed CAN bus is defined and only a single ECU is associated with that network. The ECU provides four identifiers, each made up of a single signal.
from neovi.spec import *
from neovi.neovi import NETID_MSCAN, BitRate
import json
networks = {NETID_MSCAN: {'bitrate': BitRate.BR_125000}}
hvac_ecu = ECU(NETID_MSCAN, 0x456, 'HVAC')
hvac_identifiers = [
Identifier('Blower Speed Output', 0x9601, [Signal(units='%', m=100./255.)], IOType.ReadWrite),
Identifier('External Ambient Temperature', 0x9628, [Signal(units='Deg C', m=0.25)], IOType.ReadWrite),
Identifier('Left Solar Radiation Sensor', 0x9734, [Signal(units='W', m=10, max_val=1250)]),
Identifier('Cabin Temperature', 0x97A5, [Signal(units='Deg C', length=16, m=0.01, b=-100, min_val=-50, max_val=100)]),
]
ECUs = {
'HVAC': {'ecu': hvac_ecu, 'identifiers': hvac_identifiers}
}
output_file = open('vehicle.spec', 'wt')
json.dump({'networks': networks, 'ECUs': ECUs}, output_file, cls=PyNeoViJSONEncoder)
output_file.close()
See the ecu
module page for an example of using a network specification.
-
exception
NonByteBoundarySignalError
¶ Bases:
Exception
-
exception
ValueTooLargeError
¶ Bases:
Exception
-
exception
UnsupportedValueTypeError
¶ Bases:
Exception
-
class
Signal
(self, name='value', signal_type=ANALOG, value_type=UNSIGNED_INT, start=0, length=8, min=None, max=None, units='', m=1, b=0, description='')¶ Bases:
object
Represents a signal. An
Identifier
will contain one or more signals.Parameters: - name (str) – The name of this signal.
- signal_type (
SignalType
) – The type of signal. Currently, onlySignalType.Analog
is supported. - value_type (
ValueType
) – The type of value returned for the signal. Currently onlyValueType.UnsignedInt
is supported. - start (int) – The bit within the identifier’s aggregate value at which this signal starts.
- length (int) – The length in bits of this signal.
- min_val (float) – The minimum value for this signal. This is not enforced and is for reference only. If not specified then b is used as the default value.
- max_val (float) – The minimum value for this signal. This is not enforced and is for reference only. If not specified then (255. * m) + b is used as the default value.
- units (str) – The units of the signal once converted.
- m (float) – The slope for conversion of the signal into engineering units.
- b (float) – The offset for conversion of the signal into engineering units.
- description (str) – A human-readable description of the signal.
Raises: NonByteBoundarySignalError – If length or start are not integer multiples of 8. This is a limitation of the current implementation.
-
decode_signal_bytes
(signal_bytes)¶ Converts the individual data bytes into the final value for the signal.
Parameters: signal_bytes (list of ints) – The bytes received from the ECU. Returns: Tuple of final value (float) and the units of the signal (str). Raises: UnsupportedValueTypeError – If the signal is of a type that is currently unsupported.
-
encode_value
(value)¶ Converts a value into the individual data bytes required for transmission.
Parameters: value (float/int) – The value for conversion.
Raises: - UnsupportedValueTypeError – If the signal is of a type that is currently unsupported.
- ValueTooLargeError – If the value does not fit into the number of bits specified for the signal.
-
class
Identifier
(self, name, data_id, signals, io_type = IOType.Read)¶ Bases:
object
Represents an identifier (an example of which would be “Blower Speed Output” in a HVAC ECU). The value of an identifier can consist of multiple individual signals but often there is only a single signal associated with an identifier.
Parameters: -
get_data_id_bytes
()¶ Returns: The data_id as individual bytes. Used when constructing a message.
-
-
class
ECU
(network, address, short_desc='', long_desc='')¶ Bases:
object
Represents an ECU for the purpose of building a network specification. Note that if you need an object that allows you to communicate with the ECU then you’re looking for
ecu.ECU
.Parameters: - network (int) – The network to transmit on. See NETID_* in
neovi
. - address (int) – The address of the ECU.
- short_desc (str) – A short name for the ECU (e.g. “HVAC”).
- long_desc (str) – A long description for the ECU (e.g. including model number or other information).
-
get_network
()¶
-
get_request_id
()¶
-
get_response_id
()¶
- network (int) – The network to transmit on. See NETID_* in
-
class
PyNeoViJSONEncoder
(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)¶ Bases:
json.encoder.JSONEncoder
Can be passed to json.dump as the cls parameter to handle the additional object types defined here.
-
default
(o)¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
from_json
(json_object)¶ Can be passed to json.load as the object_hook parameter to handle the additional object types defined here.