ripyl.protocol package¶
Subpackages¶
Submodules¶
ripyl.protocol.can module¶
CAN protocol decoder
-
exception
ripyl.protocol.can.
AutoRateError
¶ Bases:
ripyl.streaming.StreamError
Error for failed bit rate detection
-
class
ripyl.protocol.can.
CANConfig
¶ Bases:
ripyl.util.enum.Enum
Enumeration of configuration settings
-
IdleHigh
= 1¶
-
IdleLow
= 2¶
-
-
class
ripyl.protocol.can.
CANErrorFrame
(flag_bits=6, ifs_bits=0)¶ Bases:
object
CAN Error frame
-
__init__
(flag_bits=6, ifs_bits=0)¶
-
get_edges
(t, bit_period)¶ Generate an edge sequence for this frame
Parameters: - t (float) – Start time for the edges
- bit_period (float) – The period for each bit of the frame
:param : :returns: A list of 2-tuples representing each edge.
-
-
class
ripyl.protocol.can.
CANExtendedFrame
(full_id, data, dlc=None, crc=None, ack=True, trim_bits=0, ifs_bits=3)¶ Bases:
ripyl.protocol.can.CANFrame
CAN frame format for 29-bit ID
-
__init__
(full_id, data, dlc=None, crc=None, ack=True, trim_bits=0, ifs_bits=3)¶ Parameters: - full_id (int) – 29-bit CAN frame ID
- data (sequence of int or None) – Data bytes for a data frame. None or empty list for a remote frame.
- dlc (int or None) – The Data Length Code (number of data bytes) for the frame.
- crc (int or None) – The decoded CRC for the frame. Leave as None to generate CRC automatically.
- ack (bool) – Indicates that the ack field is dominant (True) or recessive (False).
- trim_bits (int) – The number of bits to trim off the end of the frame. Used to simulate error conditions.
- ifs_bits (int) – The number of Inter-Frame Space bits at the start of this frame. Normally 3.
-
full_id
¶ The full 29-bit ID for this frame
-
get_bits
()¶ Generate extended frame bits
-
-
class
ripyl.protocol.can.
CANFrame
(id, data, dlc=None, crc=None, ack=True, trim_bits=0, ifs_bits=3)¶ Bases:
object
Base class for CAN Data and Remote frames
-
__init__
(id, data, dlc=None, crc=None, ack=True, trim_bits=0, ifs_bits=3)¶ Parameters: - id (int) – CAN frame ID
- data (sequence of int or None) – Data bytes for a data frame. None or empty list for a remote frame.
- dlc (int or None) – The Data Length Code (number of data bytes) for the frame.
- crc (int or None) – The decoded CRC for the frame. Leave as None to generate CRC automatically.
- ack (bool) – Indicates that the ack field is dominant (True) or recessive (False).
- trim_bits (int) – The number of bits to trim off the end of the frame. Used to simulate error conditions.
- ifs_bits (int) – The number of Inter-Frame Space bits at the start of this frame. Normally 3.
-
crc
¶
-
crc_is_valid
(recv_crc=None)¶ Check if a decoded CRC is valid.
Parameters: recv_crc (int or None) – The decoded CRC to check against. If None, the CRC passed in the constructor is used. Returns: True when the crc is correct.
-
dlc
¶
-
full_id
¶ The full 11-bit ID for this frame
-
get_bits
()¶ Get the raw bits for this frame
-
get_edges
(t, bit_period)¶ Generate an edge sequence for this frame
Parameters: - t (float) – Start time for the edges
- bit_period (float) – The period for each bit of the frame
:param : :returns: A list of 2-tuples representing each edge.
-
rtr
¶
-
-
class
ripyl.protocol.can.
CANOverloadFrame
(flag_bits=6, ifs_bits=0)¶ Bases:
ripyl.protocol.can.CANErrorFrame
CAN Overload frame
-
__init__
(flag_bits=6, ifs_bits=0)¶
-
-
class
ripyl.protocol.can.
CANStandardFrame
(id, data, dlc=None, crc=None, ack=True, trim_bits=0, ifs_bits=3)¶ Bases:
ripyl.protocol.can.CANFrame
CAN frame format for 11-bit ID
-
__init__
(id, data, dlc=None, crc=None, ack=True, trim_bits=0, ifs_bits=3)¶ Parameters: - id (int) – 11-bit CAN frame ID
- data (sequence of int or None) – Data bytes for a data frame. None or empty list for a remote frame.
- dlc (int or None) – The Data Length Code (number of data bytes) for the frame.
- crc (int or None) – The decoded CRC for the frame. Leave as None to generate CRC automatically.
- ack (bool) – Indicates that the ack field is dominant (True) or recessive (False).
- trim_bits (int) – The number of bits to trim off the end of the frame. Used to simulate error conditions.
- ifs_bits (int) – The number of Inter-Frame Space bits at the start of this frame. Normally 3.
-
get_bits
()¶ Generate standard frame bits
-
-
class
ripyl.protocol.can.
CANStreamFrame
(bounds, frame, field_info=None, stuffed_bits=None, status=0)¶ Bases:
ripyl.streaming.StreamSegment
Encapsulates a CANFrame object into a StreamSegment
-
__init__
(bounds, frame, field_info=None, stuffed_bits=None, status=0)¶
-
-
class
ripyl.protocol.can.
CANStreamStatus
¶ Bases:
ripyl.util.enum.Enum
Enumeration for CANStreamFrame status codes
-
AckError
= 204¶
-
CRCError
= 203¶
-
FormError
= 202¶
-
ShortFrameError
= 201¶
-
-
class
ripyl.protocol.can.
CANTiming
(prop, p1, ipt=2, resync_jump_quanta=None)¶ Bases:
object
Represent CAN bit timing and adaptive sampling point info
-
__init__
(prop, p1, ipt=2, resync_jump_quanta=None)¶ Parameters: - prop (int) – Propagataion time in quanta.
- p1 (int) – Phase segment 1 time in quanta.
- ipt (int) – Information Processing Time in quanta.
- resync_jump_quanta (int or None) – The number of quanta to jump by on a resync. Default is minimum of 4 and p1.
-
bit_period
¶ Total time covered by this timing specification
-
post_sample_delay
¶ The delay from the sample point to the end of the bit
-
resync_jump
¶ Time span for resync jump
-
resync_jump_quanta
¶ Number of quanta to jump for resync
-
sample_point_delay
¶ The delay from the start of the bit to the sample point
-
set_quantum_period
(nominal_bit_period)¶ Establish the time period for one quantum
-
total_quanta
¶ Number of quanta in this timing specification
-
-
ripyl.protocol.can.
can_crc15
(d)¶ Calculate CAN CRC-15 on data
Parameters: d (sequence of int) – Array of integers representing 0 or 1 bits in transmission order :param : :returns: Array of integers for each bit in the crc with msb first
-
ripyl.protocol.can.
can_decode
(can, polarity=1, bit_rate=None, bit_timing=None, coerce_rates=None, logic_levels=None, stream_type=1, decode_info=None)¶ Decode a CAN data stream
This is a generator function that can be used in a pipeline of waveform procesing operations.
Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data is consumed to determine the most likely logic levels in the signal.
Parameters: - can (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a CAN data signal. This can be one of CAN-High, CAN-Low, or the differential voltage between them.
- polarity (CANConfig) – Set the polarity (idle state high or low). This will be low when the can parameter is from CAN-Low, high when CAN-High, and dependent on probe orientation when using a differential input.
- bit_rate (number or None) – The bit rate of the stream. If None, the first 50 edges will be analyzed to automatically determine the most likely bit rate for the stream. On average 50 edges will occur after 11 bytes have been captured.
- bit_timing (CANTiming or None) – An optional CANTiming object that specifies the time quanta for each bit phase. If None, a default timing object is used with prop. delay = 1q and p1 & p2 = 4q.
- coerce_rates (sequence of number or None) – An optional list of standard bit rates to coerce the automatically detected bit rate to.
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the can parameter represents either Samples or Edges
- decode_info (dict or None) – An optional dictionary object that is used to monitor the results of automatic parameter analysis and retrieve bit timing.
:param : :returns: An iterator yielding a series of CANStreamFrame objects. Each frame contains subrecords marking the location
of sub-elements within the frame. CRC and Ack errors are recorded as an error status in their respective subrecords.Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined. Raises: AutoRateError if auto-rate detection is active and the bit rate cannot be determined.
-
ripyl.protocol.can.
can_id
(variant, **kwargs)¶ Generate a CAN ID for a protocol variant from separate fields
Parameters: - variant (string) – Name of the variant to take field definitions from.
- kwargs (dict of string:int) – Each additional keyword argument names a field for the selected variant. The value is applied to the range of bits specified for the field.
Returns: An int representing an 11-bit or 29-bit can id composed from the values in kwargs.
-
ripyl.protocol.can.
can_synth
(frames, bit_rate, idle_start=0.0, idle_end=0.0)¶ Generate synthesized CAN data streams
Parameters: - frames (sequence of CANFrame compatible objects) – Frames to be synthesized.
- bit_rate (number) – The frequency of the clock generator
- idle_start (float) – The amount of idle time before the transmission of frames begins.
- idle_end (float) – The amount of idle time after the last frame.
Returns: An iterator yielding an edge stream of (float, int) pairs. The first element in the iterator is the initial state of the stream.
ripyl.protocol.ethernet module¶
Ethernet protocol decoder
-
class
ripyl.protocol.ethernet.
EthernetFrame
(dest, source, data, length_type=None, tags=None, crc=None)¶ Bases:
object
Ethernet frame object
-
__init__
(dest, source, data, length_type=None, tags=None, crc=None)¶ Parameters: - dest (MACAddr, str, or sequence of int) – The destination address of the frame.
- source (MACAddr, str, or sequence of int) – The source address of the frame.
- data (sequence of int) – The data for the frame. Padding is not necessary.
- length_type (int or None) – The Ethertype / length field. Ethertypes should be >= 0x600.
- tags (sequence of EthernetTag or None) – Optional sequence of 802.1Q tags to insert into frame.
- crc (int or None) – The decoded CRC for the frame. Leave as None to generate CRC automatically.
-
bit_stream
()¶ Get the sequence of raw bits for the frame.
This includes the SOF and SFD at the start and the IDL phase at end of frame.
-
bytes
¶ Get the bytes for this frame.
Returns: A series of bytes representing the header, payload, and crc. this does not include the SOF and SFD sequence.
-
crc
¶
-
crc_is_valid
(recv_crc=None)¶ Check if a decoded CRC is valid.
Parameters: recv_crc (int or None) – The decoded CRC to check against. If None, the CRC passed in the constructor is used. Returns: True when the crc is correct.
-
length_type
¶
-
-
class
ripyl.protocol.ethernet.
EthernetLinkCode
(selector, tech_ability, rem_fault, ack, next_page)¶ Bases:
object
Representation of the pulses in a 100Mbps Ethernet autonegotiation
-
__init__
(selector, tech_ability, rem_fault, ack, next_page)¶ Parameters: - selector (int) – Identify which standard is in use
- tech_ability (int) – Technology ability. Identifies posible modes of operation.
- rem_fault (int or bool) – Flag indicating a link failure
- ack (int or bool) – Flag to indicate reception of the base link code word.
- next_page (int or bool) – Flag to indicate intention to send other link code words.
-
word
¶ Generate 16-bit word from the fields
-
-
class
ripyl.protocol.ethernet.
EthernetLinkTest
(link_code=None)¶ Bases:
object
An link test pulse or auto-negotiation pulse stream
-
__init__
(link_code=None)¶ Parameters: link_code (int or None) – When None, this object represents a single link test pulse. When an int, this object represents a series of pulses for the link code
-
edges
(bit_period)¶ Get the edges for this object
Parameters: bit_period (float) – The period of a single bit. Returns: A list of (float, int) edges representing the pulse(s) for this object
-
-
class
ripyl.protocol.ethernet.
EthernetStreamFrame
(bounds, frame, status=0)¶ Bases:
ripyl.streaming.StreamSegment
Encapsulates an EthernetFrame object into a StreamSegment
-
__init__
(bounds, frame, status=0)¶
-
-
class
ripyl.protocol.ethernet.
EthernetStreamStatus
¶ Bases:
ripyl.util.enum.Enum
Enumeration for EthernetStreamFrame status codes
-
CRCError
= 201¶
-
-
class
ripyl.protocol.ethernet.
EthernetTag
(tpid, tci)¶ Bases:
object
Tag object representing 802.1Q tag
-
__init__
(tpid, tci)¶
-
bytes
¶
-
dei
¶
-
pcp
¶
-
vid
¶
-
-
class
ripyl.protocol.ethernet.
MACAddr
(addr)¶ Bases:
object
Ethernet MAC address
-
__init__
(addr)¶ Parameters: addr (str or sequence of int) – The address can be specified as in two formats: a list of int or a string. The string is a series of hex digits with optional colon separators on byteboundaries. Raises: ValueError if the address does not contain 6 bytes.
-
-
ripyl.protocol.ethernet.
add_overshoot
(bits, duration, overshoot=0.75, undershoot=0.8)¶ Add simulated overshoot to an edge stream
This function is intended to simulate the overshoot behavior produced by the output drivers and magnetics of 10Base-T ethernet. This is done crudely by scaling the edge stream values by the overshoot and undershoot factors. This results in a non-standard edge stream that can be processed by synth_wave() to create a realistic sampled waveform but is otherwise not useful.
Parameters: - bits (iterable of (float, int)) – A differential edge stream to add overshoot to.
- duration (float) – The amount of time to add overshoot after each edge transition.
- overshoot (float) – The fraction of a high-level that the overshoot extends past.
- undershoot (float) – The fraction of the overshoot that the undershoot extends past. Only used for transitions to idle.
Returns: An iterator yielding an edge stream with overshoot transitions inserted.
-
ripyl.protocol.ethernet.
ethernet_decode
(rxtx, tag_ethertypes=None, logic_levels=None, stream_type=1)¶ Decode an ethernet data stream
This is a generator function that can be used in a pipeline of waveform procesing operations.
Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data is consumed to determine the most likely logic levels in the signal.
Parameters: - rxtx (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a differential ethernet signal.
- tag_ethertypes (sequence of int or None) – The ethertypes to use for identifying 802.1Q tags. Default is 0x8100, 0x88a8, and 0x9100.
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the can parameter represents either Samples or Edges
Returns: An iterator yielding a series of EthernetStreamFrame objects. Each frame contains subrecords marking the location of sub-elements within the frame. CRC errors are recorded as an error status in their respective subrecords.
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined.
Raises: StreamError if ethernet speed cannot be determined.
-
ripyl.protocol.ethernet.
ethernet_synth
(frames, overshoot=None, idle_start=0.0, frame_interval=0.0, idle_end=0.0)¶ Generate synthesized Ethernet frames
Parameters: - frames (sequence of EthernetFrame) – Frames to be synthesized.
- overshoot (None or (float, float)) – When a pair of floats is provided these indicate the overshoot parameters to add to the waveform. The first number is the fraction of a bit period that the overshoot covers. This should be less than 0.5. The second number is the fraction of a high-level that the overshoot extends past. When used, the edge stream must be converted to a sample stream with low-pass filtering by synth_wave() before it accurately represents overshoot.
- idle_start (float) – The amount of idle time before the transmission of frames begins.
- frame_interval (float) – The amount of time between frames.
- idle_end (float) – The amount of idle time after the last frame.
Returns: An iterator yielding an edge stream of (float, int) pairs. The first element in the iterator is the initial state of the stream.
-
ripyl.protocol.ethernet.
table_ethernet_crc32
(d)¶ Calculate Ethernet CRC-32 on data
This is a table-based byte-wise implementation
Parameters: d (sequence of int) – Array of integers representing bytes :param : :returns: An integer with the crc value.
ripyl.protocol.i2c module¶
I2C protocol decoder
-
class
ripyl.protocol.i2c.
I2C
¶ Bases:
ripyl.util.enum.Enum
Enumeration for I2C r/w bit states
-
Read
= 1¶
-
Write
= 0¶
-
-
class
ripyl.protocol.i2c.
I2CAddress
(bounds, address=None, r_wn=None)¶ Bases:
ripyl.streaming.StreamSegment
Segment for an I2C address
The byte(s) composing the address are contained as subrecords
-
__init__
(bounds, address=None, r_wn=None)¶ Parameters: r_wn (int) – Read (1) / Write (0) bit
-
address
¶ Alias of data attribute
-
-
class
ripyl.protocol.i2c.
I2CByte
(bounds, data=None, ack_bit=None)¶ Bases:
ripyl.streaming.StreamSegment
Segment for a byte of I2C data
-
__init__
(bounds, data=None, ack_bit=None)¶
-
-
class
ripyl.protocol.i2c.
I2CTransfer
(r_wn, address, data)¶ Bases:
ripyl.streaming.StreamRecord
Represent a transaction over the I2C bus
-
__init__
(r_wn, address, data)¶ Parameters: - r_wn (int) – Read/write mode for the transfer
- address (int) – Address of the transfer. Can be either a 7-bit or 10-bit address.
- data (sequence of ints) – Array of bytes sent in the transfer
-
ack_bits
()¶ Generate a list of ack bits for each byte of data
Returns: A list of ints
-
bytes
()¶ Get a list of raw bytes for the transfer including the formatted address
Returns: A list of ints
-
end_time
¶
-
start_time
¶
-
-
ripyl.protocol.i2c.
i2c_decode
(scl, sda, logic_levels=None, stream_type=1)¶ Decode an I2C data stream
This is a generator function that can be used in a pipeline of waveform processing operations.
The scl, and sda parameters are edge or sample streams. Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data on the scl stream is consumed to determine the most likely logic levels in the signal.
Parameters: - scl (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing the I2C serial clock
- sda (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing the I2C serial data
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – Indicates the type of stream used for scl and sda.
- :param :
- When StreamType.Samples, the iterators represent a sequence of samples. Each sample is a 2-tuple representing the time of the sample and the sample’s value. When this type is used, the scl stream is analyzed to determine the logic levels of the two streams.
- :param :
- When StreamType.Edges, the iterators represent a series of edges. scl and sda are iterables of 2-tuples representing each edge transition. The 2-tuples must be in the absolute time form (time, logic level).
Returns: An iterator yielding a series of StreamRecord-based objects. These will be one of three event types or two data types. The three events are represented by StreamEvent object with these obj.kind attribute values: - ’I2C start’ The start of an I2C transfer
- ’I2C restart’ A start condition during a transfer
- ’I2C stop’ The end of a transfer
The two data types are represented by the objects I2CAddress and I2CByte. The former is a 7-bit or 10-bit address from the start of a transfer or restart. The latter contains the data read or written during the transfer. I2CByte has an attribute ack_bit that records the value of the ACK for that byte. I2CAddress has a r_wn attribute that indicates if the transfer is a read or write. The subrecords attribute contains the I2CByte object or objects that composed the address.
Raises: AutoLevelError when the stream_type is Samples and the logic levels cannot be determined automatically.
-
ripyl.protocol.i2c.
i2c_synth
(transfers, clock_freq, idle_start=0.0, transfer_interval=0.0, idle_end=0.0)¶ Generate synthesized I2C waveforms
This function simulates I2C transfers on the SCL and SDA signals.
Parameters: - transfers (sequence of I2CTransfer objects) – Data to be synthesized.
- clock_freq (float) – Clock frequency for the I2C bus. Standard rates are 100kHz (100.0e3) and 400kHz (400.0e3) but any frequency can be specified.
- idle_start (float) – The amount of idle time before the transmission of transfers begins
- transfer_interval (float) – The amount of time between transfers
- idle_end (float) – The amount of idle time after the last transfer
Returns: A pair of iterators representing the two edge streams for scl, and sda respectively. Each edge stream pair is in (time, value) format representing the time and logic value (0 or 1) for each edge transition. The first elements in the iterators are the initial state of the waveforms.
-
ripyl.protocol.i2c.
reconstruct_i2c_transfers
(records)¶ Recreate I2CTransfer objects using the output of i2c_decode()
This is a generator function that can be used in a pipeline of waveform processing operations.
Parameters: records (sequence of I2CByte and I2CAddress) – An iterable of records produced by i2c_decode(). All StreamEvent records are discarded. :param : :returns: An iterator yielding a stream of I2CTransfer objects containing aggregated address and data
from the input records.
ripyl.protocol.i2s module¶
I2S protocol decoder
-
class
ripyl.protocol.i2s.
I2SFrame
(bounds, data)¶ Bases:
ripyl.streaming.StreamSegment
Frame object for I2S data
-
__init__
(bounds, data)¶ Parameters: - bounds ((float, float)) – 2-tuple (start_time, end_time) for the bounds of the frame
- data (sequence of int) – Data representing the sample(s) in the frame
-
-
class
ripyl.protocol.i2s.
I2SVariant
¶ Bases:
ripyl.util.enum.Enum
-
DSPModeLongSync
= 2¶
-
DSPModeShortSync
= 1¶
-
Standard
= 0¶
-
-
ripyl.protocol.i2s.
duplicate
(samples)¶
-
ripyl.protocol.i2s.
i2s_decode
(sck, sd, ws, word_size, frame_size=None, cpol=0, wspol=0, msb_justified=True, channels=2, i2s_variant=0, data_offset=1, logic_levels=None, stream_type=1)¶
-
ripyl.protocol.i2s.
i2s_synth
(data, word_size, frame_size, sample_rate, cpol=0, wspol=0, msb_justified=True, channels=2, i2s_variant=0, data_offset=1, idle_start=0.0, idle_end=0.0)¶
-
ripyl.protocol.i2s.
mono_to_stereo
(samples, duplicate_samples=True)¶
-
ripyl.protocol.i2s.
spi_decode
(clk, data_io, cs=None, cpol=0, cpha=0, lsb_first=True, logic_levels=None, stream_type=1)¶ Decode an SPI data stream
This is a generator function that can be used in a pipeline of waveform processing operations.
The clk, data_io, and cs parameters are edge or sample streams. Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data on the clk stream is consumed to determine the most likely logic levels in the signal.
Parameters: - clk (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing an SPI clk signal
- data_io (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing an SPI MOSI or MISO signal.
- cs (iterable of SampleChunk objects or (float, int) pairs or None) – A sample stream or edge stream representing an SPI chip select signal. Can be None if cs is not available.
- cpol (int) – Clock polarity: 0 or 1 (the idle state of the clock signal)
- cpha (int) – Clock phase: 0 or 1 (data is sampled on the 1st clock edge (0) or the 2nd (1))
- lsb_first (bool) – Flag indicating whether the Least Significant Bit is transmitted first.
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the clk, data_io, and cs parameters represent either Samples or Edges
Returns: An iterator yielding a series of SPIFrame objects.
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined.
-
ripyl.protocol.i2s.
stereo_to_mono
(samples)¶
ripyl.protocol.iso_k_line module¶
ISO K-line protocol decoder
Decodes ISO9141 and ISO14230 automotive data bus protocols
-
class
ripyl.protocol.iso_k_line.
ISO14230Header
(option, target, source, length=None)¶ Bases:
object
ISO14230 header object
- Header byte 1: length 0x10nnnnnn
- 5-0 data bytes in message
Header byte 2: optional data byte count if nnnnnn is 0
Header byte 2(3): target address Header byte 3(4): source address
-
__init__
(option, target, source, length=None)¶ - option, target, source, length
- USBFrame objects for the header bytes
-
bytes
()¶ Returns: A list of header bytes in original order
-
class
ripyl.protocol.iso_k_line.
ISO9141Header
(option, target, source)¶ Bases:
object
ISO9141 header object
Header byte 1: option
7-5 priority: 000 = high, 111 = low4 header type: 0 = 3-byte; 1 = 1-byte3 in frame response: 0 = required (Ford); 1 = not allowed (GM)2 addressing mode: 1 = physical; 0 = functional1-0 message typeParameters: | – message type:bit: 3 2 1 0——-1 0 0 0 function1 0 0 1 broadcast1 0 1 0 query1 0 1 1 read1 1 0 0 node-to-node1 1 0 1 reserved1 1 1 0 reserved1 1 1 1 reservedParameters: | – Header byte 2: target address Header byte 3: source address
-
__init__
(option, target, source)¶ - option, target, source
- USBFrame objects for the header bytes
-
bytes
()¶ Returns: A list of header bytes in original order
-
-
class
ripyl.protocol.iso_k_line.
ISO9141Init
(recs, status=0)¶ Bases:
ripyl.streaming.StreamSegment
Encapsulates initialization exchange before messaging begins on ISO9141 These are the bytes in the 0x55, key1, key2, ~key2 ~wakeup init sequence.
-
__init__
(recs, status=0)¶
-
-
class
ripyl.protocol.iso_k_line.
KLineMessage
(msg_type, header, data, checksum)¶ Bases:
ripyl.protocol.obd2.OBD2Message
Message object for the K-line protocols ISO9141 and ISO14230
-
__init__
(msg_type, header, data, checksum)¶
-
checksum_good
()¶ Validate the message checksum
Returns: A bool that is true when checksum is valid.
-
end_time
¶
-
raw_data
(full_message=False)¶ Get the raw data for the message
Parameters: full_message (bool) – Returns: Complete message including header and checksum when true Returns: A list of bytes.
-
start_time
¶
-
-
class
ripyl.protocol.iso_k_line.
KLineProtocol
¶ Bases:
ripyl.util.enum.Enum
Enumeration for identifying the message protocol
-
ISO14230
= 2¶
-
ISO9141
= 1¶
-
Unknown
= 0¶
-
-
class
ripyl.protocol.iso_k_line.
KLineStreamMessage
(msg, status=0)¶ Bases:
ripyl.protocol.obd2.OBD2StreamMessage
StreamMessage object for the K-line protocols ISO9141 and ISO14230
-
__init__
(msg, status=0)¶
-
classmethod
status_text
(status)¶ Returns: The string representation of a status code
-
-
class
ripyl.protocol.iso_k_line.
KLineStreamStatus
¶ Bases:
ripyl.util.enum.Enum
Enumeration for KLineStreamMessage status codes
-
BadInitError
= 202¶
-
ChecksumError
= 201¶
-
InvalidMessageError
= 203¶
-
-
class
ripyl.protocol.iso_k_line.
KLineWakeup
(bounds, edges, status=0)¶ Bases:
ripyl.streaming.StreamSegment
Encapsulates BRK data values representing the wakeup pattern
This is used for the slow init (0x33 at 5-baud) and the fast init (25ms low, 25ms high)
-
__init__
(bounds, edges, status=0)¶
-
-
ripyl.protocol.iso_k_line.
iso_k_line_decode
(stream_data, min_message_interval=0.007, logic_levels=None, stream_type=1)¶ Decode ISO9141 and ISO14230 data streams
This is a generator function that can be used in a pipeline of waveform procesing operations.
Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data is consumed to determine the most likely logic levels in the signal.
Parameters: - stream_data (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream of K-line messages.
- min_message_interval (float) – The minimum time between bytes for identifying the end and start of messages. For ISO14230 this is used in addition to the message length encoded in the header.
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the stream parameter represents either Samples or Edges
:param : :param : :returns: An iterator yielding a series of KLineStreamMessage objects.
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined.
-
ripyl.protocol.iso_k_line.
iso_k_line_synth
(messages, idle_start=0.0, message_interval=0.008, idle_end=0.0, word_interval=0.001)¶ Generate synthesized ISO9141 and ISO14230 data streams
Parameters: - messages (sequence of tuple of int) – Messages to be synthesized. Each element is a tuple of bytes to send for each message.
- idle_start (float) – The amount of idle time before the transmission of messages begins.
- message_interval (float) – The amount of time between messages.
- idle_end (float) – The amount of idle time after the last message.
- word_interval (float) – The amount of time between message bytes.
Returns: An iterator yielding an edge stream of (float, int) pairs. The first element in the iterator is the initial state of the stream.
ripyl.protocol.j1850 module¶
J1850 protocol decoder
-
class
ripyl.protocol.j1850.
J1850Break
¶ Bases:
object
Representation of a J1850 break condition
-
__init__
()¶
-
-
class
ripyl.protocol.j1850.
J1850Frame
(priority, msg_type, data, target=None, source=None, ifr_data=None, crc=None, ifr_crc=None)¶ Bases:
object
Base class for J1850 frames
-
__init__
(priority, msg_type, data, target=None, source=None, ifr_data=None, crc=None, ifr_crc=None)¶ Parameters: - priority (int) – The 3-bit frame priority field. Lower values have higher priority.
- msg_type (J1850MT) – Message type.
- data (sequence of int or None) – Data bytes for the frame.
- target (int) – Target address or function.
- source (int) – Source address.
- ifr_data (sequence of int or None) – Optional data for the In-Frame Response.
- crc (int or None) – CRC for the data bytes and header.
- ifr_crc (int or None) – CRC for the IFR (FunctionRead message type only)
-
bytes
¶ Get the bytes for this frame. Does not include IFR.
-
crc
¶
-
crc_is_valid
(recv_crc=None)¶ Check if a decoded CRC is valid.
Parameters: recv_crc (int or None) – The decoded CRC to check against. If None, the CRC passed in the constructor is used. Returns: True when the crc is correct.
-
ifr_bytes
¶ Get the IFR bytes for this frame.
-
ifr_crc
¶
-
ifr_crc_is_valid
(recv_crc=None)¶ Check if a decoded IFR CRC is valid.
Parameters: recv_crc (int or None) – The decoded CRC to check against. If None, the CRC passed in the constructor is used. Returns: True when the crc is correct.
-
-
class
ripyl.protocol.j1850.
J1850MT
¶ Bases:
ripyl.util.enum.Enum
Enumeration of J1850 message types (last 4 bits of header byte)
-
Ack
= 14¶
-
Broadcast
= 1¶
-
Function
= 0¶
-
FunctionCmd
= 8¶
-
FunctionExtCmd
= 10¶
-
FunctionExtRqst
= 11¶
-
FunctionQuery
= 2¶
-
FunctionRead
= 3¶
-
FunctionRqst
= 9¶
-
NodeToNode
= 12¶
-
NodeToNodeIFR
= 4¶
-
Reserved13
= 13¶
-
Reserved15
= 15¶
-
Reserved5
= 5¶
-
Reserved6
= 6¶
-
Reserved7
= 7¶
-
-
class
ripyl.protocol.j1850.
J1850StreamFrame
(bounds, frame, status=0)¶ Bases:
ripyl.streaming.StreamSegment
Encapsulates a J1850Frame object into a StreamSegment
-
__init__
(bounds, frame, status=0)¶
-
-
class
ripyl.protocol.j1850.
J1850StreamStatus
¶ Bases:
ripyl.util.enum.Enum
Enumeration for J1850StreamFrame status codes
-
CRCError
= 201¶
-
-
class
ripyl.protocol.j1850.
VPWNormBitStyle
¶ Bases:
ripyl.util.enum.Enum
Enumeration of VPW normalization bit coding scheme
-
GM
= 2¶
-
SAE
= 1¶
-
-
ripyl.protocol.j1850.
j1850_pwm_decode
(pwm, logic_levels=None, stream_type=1)¶ Decode a J1850 PWM data stream
This decodes the Pulse Width Modulated version of J1850 (Ford).
This is a generator function that can be used in a pipeline of waveform procesing operations.
Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data is consumed to determine the most likely logic levels in the signal.
Parameters: - pwm (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a PWM Bus+ signal or the differential Bus+ - Bus-.
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the can parameter represents either Samples or Edges
Returns: An iterator yielding a series of J1850StreamFrame objects. Each frame contains subrecords marking the location of sub-elements within the frame. CRC errors are recorded as an error status in their respective subrecords.
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined.
-
ripyl.protocol.j1850.
j1850_pwm_synth
(frames, breaks=None, idle_start=0.0, frame_interval=0.0, idle_end=0.0)¶ Generate synthesized J1850 PWM data streams
Parameters: - frames (sequence of J1850Frame or J1850Break) – Frames to be synthesized.
- breaks (sequence of (int, float)) – A set of tuples that identify which frames are interrupted by a break condition. The first int portion of the tuple identifies the frame index and the second float is the percentage (0.0 to 1.0) of the total frame that is generated before the break.
- idle_start (float) – The amount of idle time before the transmission of frames begins.
- frame_interval (float) – The amount of time between frames.
- idle_end (float) – The amount of idle time after the last frame.
Returns: An iterator yielding an edge stream of (float, int) pairs. The first element in the iterator is the initial state of the stream.
-
ripyl.protocol.j1850.
j1850_vpw_decode
(vpw, norm_bit=1, logic_levels=None, stream_type=1)¶ Decode a J1850 VPW data stream
This decodes the Variable Pulse Width version of J1850 (GM & Chrysler).
This is a generator function that can be used in a pipeline of waveform procesing operations.
Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data is consumed to determine the most likely logic levels in the signal.
Parameters: - vpw (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a VPW data signal.
- norm_bit (VPWNormBitStyle) – How to interpret the normalization bit for In-Frame Response. Either standard SAE style or the GM specific variant. This determines whether the IFR is expected to have a CRC independently from the message type.
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the can parameter represents either Samples or Edges
Returns: An iterator yielding a series of J1850StreamFrame objects. Each frame contains subrecords marking the location of sub-elements within the frame. CRC errors are recorded as an error status in their respective subrecords.
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined.
-
ripyl.protocol.j1850.
j1850_vpw_synth
(frames, norm_bit=1, breaks=None, idle_start=0.0, frame_interval=0.0, idle_end=0.0)¶ Generate synthesized J1850 VPW data streams
Parameters: - frames (sequence of J1850Frame or J1850Break) – Frames to be synthesized.
- norm_bit (VPWNormBitStyle) – How to interpret the normalization bit for In-Frame Response. Either standard SAE style or the GM specific variant. This determines whether the IFR is expected to have a CRC independently from the message type.
- breaks (sequence of (int, float)) – A set of tuples that identify which frames are interrupted by a break condition. The first int portion of the tuple identifies the frame index and the second float is the percentage (0.0 to 1.0) of the total frame that is generated before the break.
- idle_start (float) – The amount of idle time before the transmission of frames begins.
- frame_interval (float) – The amount of time between frames.
- idle_end (float) – The amount of idle time after the last frame.
Returns: An iterator yielding an edge stream of (float, int) pairs. The first element in the iterator is the initial state of the stream.
-
ripyl.protocol.j1850.
pwm_encode
(bytes, start_time, bit_slice)¶ Convert bytes to a PWM edge sequence
Parameters: - bytes (sequence of int) – The bytes to encode
- start_time (float) – The Start time for the first edge
- bit_slice (float) – The time for 1/3 of a bit period.
Returns: A list of (float, int) edge pairs.
-
ripyl.protocol.j1850.
single_to_diff
(signal)¶ Convert a single-ended edge stream to a differential pair
Parameters: signal (edge stream) – The edges to convert to differential Returns: A pair of edge streams p and m representing the + and - differential pair.
-
ripyl.protocol.j1850.
table_j1850_crc8
(d)¶ Calculate J1850 CRC-8 on data
This is a table-based byte-wise implementation
Parameters: d (sequence of int) – Array of integers representing bytes :param : :returns: An integer with the crc value.
-
ripyl.protocol.j1850.
vpw_encode
(bytes, start_time)¶ Convert bytes to a VPW edge sequence
Parameters: - bytes (sequence of int) – The bytes to encode
- start_time (float) – The Start time for the first edge
Returns: A list of (float, int) edge pairs.
ripyl.protocol.lin module¶
LIN protocol decoder
-
class
ripyl.protocol.lin.
LINChecksum
¶ Bases:
ripyl.util.enum.Enum
Enumeration for LIN checksum type
-
Classic
= 0¶
-
Enhanced
= 1¶
-
-
class
ripyl.protocol.lin.
LINFrame
(id, data=None, checksum=None, pid_parity=None, cs_type=0)¶ Bases:
object
LIN frame object
-
__init__
(id, data=None, checksum=None, pid_parity=None, cs_type=0)¶ Parameters: - id (int) – The ID field from the PID
- data (sequence of int or None) – Optional sequence of data bytes for the frame. Should be between 1 and 8 bytes long. An empty list is converted to None.
- checksum (int or None) – Optional checksum for the frame
- pid_parity (int or None) – Optional parity bits from the PID field
- cs_type (LINChecksum) – The checksum type to use for this frame
-
bytes
()¶ Returns: A sequence of raw frame bytes including the sync field
-
checksum
¶ The frame checksum
-
checksum_is_valid
(recv_cs=None)¶ Determine if the checksum is valid
Parameters: recv_cs (int or None) – Optional received checksum value. If None, the stored checksum for the frame is used instead.
-
data_checksum
¶ Get the checksum over the data bytes without reference to any existing _checksum value
-
pid
¶ Get the frame PID
-
pid_is_valid
()¶ Determine if the PID parity bits are correct
-
pid_parity
¶ The parity bits from the PID
-
-
class
ripyl.protocol.lin.
LINStreamFrame
(bounds, frame, status=0)¶ Bases:
ripyl.streaming.StreamSegment
Encapsulates a LINFrame object into a StreamSegment
-
__init__
(bounds, frame, status=0)¶
-
-
class
ripyl.protocol.lin.
LINStreamStatus
¶ Bases:
ripyl.util.enum.Enum
Enumeration for LINStreamFrame status codes
-
ChecksumError
= 202¶
-
PIDError
= 201¶
-
-
ripyl.protocol.lin.
lin_checksum
(data)¶ Compute the LIN checksum
Parameters: data (sequence of int) – The bytes (including ID if enhanced format) to compute the checksum over Returns: The checksum as an int.
-
ripyl.protocol.lin.
lin_decode
(stream_data, enhanced_ids=None, baud_rate=None, logic_levels=None, stream_type=1, param_info=None)¶ Decode a LIN data stream
This is a generator function that can be used in a pipeline of waveform procesing operations.
Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data is consumed to determine the most likely logic levels in the signal.
Parameters: - stream_data (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a LIN signal.
- enhanced_ids (sequence of int or None) – An optional sequence of frame IDs that are to use LIN 2.x enhanced checksums. If None, the checksum type is guessed by trying both methods to see if one matches decoded checksum.
- baud_rate (int or None) – The baud rate of the stream. If None, the first 50 edges will be analyzed to automatically determine the most likely baud rate for the stream. On average 50 edges will occur after 11 bytes have been captured.
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the stream parameter represents either Samples or Edges
- param_info (dict or None) – An optional dictionary object that is used to monitor the results of automatic baud detection.
:param : :param : :returns: An iterator yielding a series of LINStreamFrame objects.
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined. Raises: AutoBaudError if auto-baud is active and the baud rate cannot be determined.
-
ripyl.protocol.lin.
lin_pid
(id)¶ Generate a LIN PID from an ID
Parameters: id (int) – The ID to generate parity for Returns: The pid as an int.
-
ripyl.protocol.lin.
lin_synth
(frames, baud, idle_start=0.0, frame_interval=0.008, idle_end=0.0, byte_interval=0.001)¶ Generate synthesized LIN data streams
Parameters: - frames (sequence of LINFrame) – Frames to be synthesized.
- baud (int) – The baud rate.
- idle_start (float) – The amount of idle time before the transmission of messages begins.
- frame_interval (float) – The amount of time between frames.
- idle_end (float) – The amount of idle time after the last message.
- byte_interval (float) – The amount of time between message bytes.
Returns: An iterator yielding an edge stream of (float, int) pairs. The first element in the iterator is the initial state of the stream.
ripyl.protocol.lm73 module¶
LM73 (temperature sensor) protocol decoder
-
class
ripyl.protocol.lm73.
LM73Operation
¶ Bases:
ripyl.util.enum.Enum
Enumeration for LM73 bus operations
-
ReadData
= 2¶
-
SetPointer
= 0¶
-
WriteData
= 1¶
-
-
class
ripyl.protocol.lm73.
LM73Register
¶ Bases:
ripyl.util.enum.Enum
Enumeration for LM73 registers
-
Configuration
= 1¶
-
ControlStatus
= 4¶
-
Identification
= 7¶
-
THigh
= 2¶
-
TLow
= 3¶
-
Temperature
= 0¶
-
-
class
ripyl.protocol.lm73.
LM73StreamStatus
¶ Bases:
ripyl.util.enum.Enum
Enumeration of LM73 status codes
-
MissingDataError
= 201¶
-
-
class
ripyl.protocol.lm73.
LM73Transfer
(address, op, reg=0, data=None)¶ Bases:
ripyl.streaming.StreamRecord
Represent a transaction for the LM73
-
__init__
(address, op, reg=0, data=None)¶ Parameters: address (int) – Address of the transfer :param : :type op: LM73Operation :param op:
The operation for this transfer:param : :type reg: LM73Register :param reg:
The register used in this transfer:param : :type data: sequence of ints :param data:
List of bytes read/written in the transfer
-
end_time
¶
-
i2c_tfer
¶
-
start_time
¶
-
temperature
¶ Compute the temperature in Celcius
Returns: A float
-
-
ripyl.protocol.lm73.
convert_temp
(temperature)¶ Convert a temperature to the LM73 encoding
-
ripyl.protocol.lm73.
lm73_decode
(i2c_stream, addresses=set([72, 73, 74, 76, 77, 78]))¶ Decode an LM73 data stream
Parameters: - i2c_stream (sequence of StreamRecord or I2CTransfer) – An iterable representing either a stream of I2C StreamRecord objects or I2CTransfer objects produced by i2c_decode() or reconstruct_i2c_transfers() respectively.
- addresses (set of ints) – A collection identifying the valid LM73 addresses to decode. All others are ignored.
:param : :returns: An iterator yielding a series of LM73Transfer objects and any unrelated I2CTransfer objects.
ripyl.protocol.obd2 module¶
OBD-2 protocol support
-
class
ripyl.protocol.obd2.
OBD2Message
(msg_type)¶ Bases:
object
Abstract base class for OBD-2 messages
This is to be specialized in each protocol implementation.
-
__init__
(msg_type)¶
-
checksum_good
()¶ Validate the message checksum
Returns: A bool that is true when checksum is valid.
-
end_time
¶ Message end time
-
raw_data
(full_message=False)¶ Get the raw data for the message
Parameters: full_message (bool) – Returns: Complete message including header and checksum when true Returns: A list of bytes.
-
start_time
¶ Message start time
-
-
class
ripyl.protocol.obd2.
OBD2MsgType
¶ Bases:
ripyl.util.enum.Enum
Enumeration for message types
-
Request
= 0¶
-
Response
= 1¶
-
Unknown
= 2¶
-
-
class
ripyl.protocol.obd2.
OBD2StreamMessage
(msg, status=0)¶ Bases:
ripyl.streaming.StreamSegment
Encapsulates an OBD2Message object into a StreamSegment
-
__init__
(msg, status=0)¶ Parameters: bounds ((float, float)) – 2-tuple (start_time, end_time) for the packet :param : :type msg: OBD2Message :param msg:
OBD2Message object to wrap in a StreamSegmentParameters: status (int) – Status code for the packet
-
end_time
¶ Message end time
-
msg
¶
-
start_time
¶ Message start time
-
classmethod
status_text
(status)¶
-
-
class
ripyl.protocol.obd2.
OBD2StreamTransfer
(messages, status=0)¶ Bases:
ripyl.streaming.StreamSegment
Represent a collection of messages involved in a request/response transaction.
-
__init__
(messages, status=0)¶ Parameters: messages (sequence of OBD2StreamMessage) – A sequence of OBD2StreamMessage objects that form a transfer
-
end_time
¶
-
start_time
¶
-
-
class
ripyl.protocol.obd2.
PIDTableEntry
(bytes_returned, description, units='', decoder=None)¶ Bases:
object
Data structure for string PID decode info
-
__init__
(bytes_returned, description, units='', decoder=None)¶
-
-
ripyl.protocol.obd2.
PTE
¶ alias of
PIDTableEntry
-
ripyl.protocol.obd2.
decode_dtc
(dtc)¶ Convert encoded DTC to a string
Parameters: dtc (int) – The binary coded DTC. Returns: A string representing the dtc in readable form.
-
ripyl.protocol.obd2.
decode_obd2_command
(msg_type, raw_data)¶ Decode the contents of an OBD-2 message
Parameters: - msg_type (OBD2MsgType) – The type of message (request or response) to be decoded.
- raw_data (sequence of ints) – The bytes forming the message
Returns: A 3-tuple containing a string description, a parameter value, and a string for parameter units. The parameter value is None for request messages and for response messages with no defined decode routine.
-
ripyl.protocol.obd2.
reconstruct_obd2_transfers
(records)¶ Aggregate a stream of OBD2StreamMessage objects into OBD2StreamTransfers.
A transfer consists of a request message followed by 0 or more responses from each ECU on the bus. A new transfer starts with every request message. Objects other than OBD2StreamMessage are passed through unchanged
Parameters: records (sequence of OBD2StreamMessage) – The message objects to reconstruct the transfers from. Returns: An iterator yielding a stream of OBD2StreamTransfer objects containing aggregated messages from the input records and any additional non-message stream objects.
-
ripyl.protocol.obd2.
register_command_decoder
(name, func)¶ Add a decoder function for additional manufacturer specific SIDs
Parameters: - name (string) – The name of the command set to register the decoder under.
- func (function(OBD2MsgType, (int,..))) – A Python function object that will be called as a command decoder.
ripyl.protocol.ps2 module¶
PS/2 and AT keyboard protocol decoder
-
class
ripyl.protocol.ps2.
PS2Dir
¶ Bases:
ripyl.util.enum.Enum
Enumeration for PS/2 frame direction
-
DeviceToHost
= 0¶
-
HostToDevice
= 1¶
-
-
class
ripyl.protocol.ps2.
PS2Frame
(data, direction=0)¶ Bases:
object
Frame object for PS/2 data
-
__init__
(data, direction=0)¶
-
-
class
ripyl.protocol.ps2.
PS2StreamFrame
(bounds, frame, status=0)¶ Bases:
ripyl.streaming.StreamSegment
Streaming frame object for PS/2 data
-
__init__
(bounds, frame, status=0)¶
-
classmethod
status_text
(status)¶
-
-
class
ripyl.protocol.ps2.
PS2StreamStatus
¶ Bases:
ripyl.util.enum.Enum
Enumeration of PS/2 status codes
-
AckError
= 203¶
-
FramingError
= 201¶
-
ParityError
= 202¶
-
TimingError
= 204¶
-
-
ripyl.protocol.ps2.
ps2_decode
(clk, data, logic_levels=None, stream_type=1)¶ Decode a PS/2 data stream
This is a generator function that can be used in a pipeline of waveform processing operations.
Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data on the clk stream is consumed to determine the most likely logic levels in the signal.
Parameters: - clk (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a PS/2 clk signal
- data (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a PS/2 data signal.
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the clk and data parameters represent either Samples or Edges
Returns: An iterator yielding a series of PS2StreamFrame objects.
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined.
-
ripyl.protocol.ps2.
ps2_synth
(frames, clock_freq, idle_start=0.0, word_interval=0.0)¶ Generate synthesized PS/2 waveform
This function simulates a transmission of data over PS/2.
This is a generator function that can be used in a pipeline of waveform procesing operations.
Parameters: - frames (sequence of PS2Frame) – A sequence of PS2Frame objects that will be transmitted serially
- clock_freq (float) – The PS/2 clock frequency. 10kHz - 13KHz typ.
- idle_start (float) – The amount of idle time before the transmission of data begins
- word_interval (float) – The amount of time between data bytes
Returns: An iterator yielding a set of pairs representing the two edge streams for clk and data respectively. Each edge stream pair is in (time, value) format representing the time and logic value (0 or 1) for each edge transition. The first set of pairs yielded is the initial state of the waveforms.
ripyl.protocol.sagem_ecu module¶
Sagem ECU protocol support
This module should be included along with ripyl.protocol.obd2. The Sagem decode functions will be registered with the OBD-2 decoder and are accessed through obd2.decode_obd2_command().
-
ripyl.protocol.sagem_ecu.
decode_sagem_msg
(sid, pid_table, pid_size, msg_type, raw_data)¶ Decode SAGEM message with one or two byte PIDs
Parameters: - sid (int) – The message SID
- pid_table (dict of PIDTableEntry) – A dict associating PIDs with decode information
- pid_size (int) – The number of bytes in the PID: 1 or 2
- msg_type (OBD2MsgType) – Request or response message
- raw_data (sequence of ints) – Bytes for the message
ripyl.protocol.spi module¶
SPI protocol decoder
-
class
ripyl.protocol.spi.
SPIFrame
(bounds, data=None)¶ Bases:
ripyl.streaming.StreamSegment
Frame object for SPI data
-
__init__
(bounds, data=None)¶ Parameters: - bounds ((float, float)) – 2-tuple (start_time, end_time) for the bounds of the frame
- data (sequence of int or None) – Optional data representing the contents of the frame
-
-
ripyl.protocol.spi.
spi_decode
(clk, data_io, cs=None, cpol=0, cpha=0, lsb_first=True, logic_levels=None, stream_type=1)¶ Decode an SPI data stream
This is a generator function that can be used in a pipeline of waveform processing operations.
The clk, data_io, and cs parameters are edge or sample streams. Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data on the clk stream is consumed to determine the most likely logic levels in the signal.
Parameters: - clk (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing an SPI clk signal
- data_io (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing an SPI MOSI or MISO signal.
- cs (iterable of SampleChunk objects or (float, int) pairs or None) – A sample stream or edge stream representing an SPI chip select signal. Can be None if cs is not available.
- cpol (int) – Clock polarity: 0 or 1 (the idle state of the clock signal)
- cpha (int) – Clock phase: 0 or 1 (data is sampled on the 1st clock edge (0) or the 2nd (1))
- lsb_first (bool) – Flag indicating whether the Least Significant Bit is transmitted first.
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the clk, data_io, and cs parameters represent either Samples or Edges
Returns: An iterator yielding a series of SPIFrame objects.
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined.
-
ripyl.protocol.spi.
spi_synth
(data, word_size, clock_freq, cpol=0, cpha=0, lsb_first=True, idle_start=0.0, word_interval=0.0, idle_end=0.0)¶ Generate synthesized SPI waveform
This function simulates a transmission of data over SPI.
This is a generator function that can be used in a pipeline of waveform procesing operations.
Parameters: - data (sequence of int) – A sequence of words that will be transmitted serially
- word_size (int) – The number of bits in each word
- clock_freq (float) – The SPI clock frequency
- cpol (int) – Clock polarity: 0 or 1
- cpha (int) – Clock phase: 0 or 1
- lsb_first (bool) – Flag indicating whether the Least Significant Bit is transmitted first.
- idle_start (float) – The amount of idle time before the transmission of data begins
- word_interval (float) – The amount of time between data words
- idle_end (float) – The amount of idle time after the last transmission
Returns: An iterator yielding a triplet of pairs representing the three edge streams for clk, data_io, and cs respectively. Each edge stream pair is in (time, value) format representing the time and logic value (0 or 1) for each edge transition. The first set of pairs yielded is the initial state of the waveforms.
ripyl.protocol.uart module¶
UART protocol decoder
-
exception
ripyl.protocol.uart.
AutoBaudError
¶ Bases:
ripyl.streaming.StreamError
Error for failed baud rate detection
-
class
ripyl.protocol.uart.
UARTConfig
¶ Bases:
ripyl.util.enum.Enum
Enumeration of configuration settings
-
IdleHigh
= 1¶
-
IdleLow
= 2¶
-
-
class
ripyl.protocol.uart.
UARTFrame
(bounds, data=None, status=0)¶ Bases:
ripyl.streaming.StreamSegment
Frame object for UART data
-
__init__
(bounds, data=None, status=0)¶
-
classmethod
status_text
(status)¶
-
-
class
ripyl.protocol.uart.
UARTStreamStatus
¶ Bases:
ripyl.util.enum.Enum
Enumeration of UART status codes
-
FramingError
= 201¶
-
ParityError
= 202¶
-
-
ripyl.protocol.uart.
uart_decode
(stream_data, bits=8, parity=None, stop_bits=1.0, lsb_first=True, polarity=1, baud_rate=None, use_std_baud=True, logic_levels=None, stream_type=1, param_info=None)¶ Decode a UART data stream
This is a generator function that can be used in a pipeline of waveform procesing operations.
Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data is consumed to determine the most likely logic levels in the signal.
Parameters: - stream_data (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a serial data signal.
- bits (int) – The number of bits in each word. Typically 5, 7, 8, or 9.
- parity (string or None) – The type of parity to use. One of None, ‘even’, or ‘odd’
- stop_bits (number) – The number of stop bits. Typically 1, 1.5, or 2
- lsb_first (bool) – Flag indicating whether the Least Significant Bit is transmitted first.
- inverted (bool) – Flag indicating if the signal levels have been inverted from their logical meaning. Use this when the input stream derives from an inverting driver such as those used for RS-232.
- polarity (UARTConfig) – Set the polarity (idle state high or low).
- baud_rate (int) – The baud rate of the stream. If None, the first 50 edges will be analyzed to automatically determine the most likely baud rate for the stream. On average 50 edges will occur after 11 frames have been captured.
- use_std_baud (bool) – Flag that forces coercion of automatically detected baud rate to the set of standard rates
:param : :type logic_levels: (float, float) or None :param logic_levels:
Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.Parameters: stream_type (streaming.StreamType) – A StreamType value indicating that the stream parameter represents either Samples or Edges :param : :type param_info: dict or None :param param_info:
An optional dictionary object that is used to monitor the results of automatic baud detection.:param : :returns: An iterator yielding a series of UARTFrame objects. Each frame contains subrecords marking the location
of sub-elements within the frame (start, data, parity, stop). Parity errors are recorded as an error status in the parity subrecord. BRK conditions are reported as a data value 0x00 with a framing error in the status code.Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined. Raises: AutoBaudError if auto-baud is active and the baud rate cannot be determined. Raises: ValueError if the parity argument is invalid.
-
ripyl.protocol.uart.
uart_synth
(data, bits=8, baud=115200, parity=None, stop_bits=1.0, idle_start=0.0, idle_end=0.0, word_interval=1e-05)¶ Generate synthesized UART waveform
This function simulates a single, unidirectional channel of a UART serial connection. Its output is analagous to txd. The signal is generated with idle-high polarity.
This is a generator function that can be used in a pipeline of waveform procesing operations.
Parameters: - data (sequence of int) – A sequence of words that will be transmitted serially
- bits (int) – The number of bits in each word. Typically 5, 7, 8, or 9.
- baud (int) – The baud rate
:param : :type parity: string or None :param parity:
The type of parity to use. One of None, ‘even’, or ‘odd’Parameters: - stop_bits (number) – The number of stop bits. Typically 1, 1.5, or 2
- idle_start (float) – The amount of idle time before the transmission of data begins
- idle_end (float) – The amount of idle time after the transmission of data ends
- word_interval (float) – The amount of time between data words
Returns: An iterator yielding a series of 2-tuples (time, value) representing the time and logic value (0 or 1) for each edge transition on txd. The first tuple yielded is the initial state of the waveform. All remaining tuples are edges where the txd state changes.
ripyl.protocol.usb module¶
USB protocol decoder
This Supports all of USB 2.0 including Low, Full, and High speed; Link Power Management extended tokens; and USB 1.x mixed Low and Full speed transmissions. HSIC protocol is also supported.
-
class
ripyl.protocol.usb.
USBDataPacket
(pid, data, speed=1, delay=0.0)¶ Bases:
ripyl.protocol.usb.USBPacket
Data packet
-
__init__
(pid, data, speed=1, delay=0.0)¶
-
field_offsets
(with_stuffing=False)¶ Get a dict of packet field bit offsets
Parameters: with_stuffing (bool) – Flag indicating whether to return fields adjusted for stuffed bits Returns: A dict keyed by the field name and a pair (start, end) for each value. Start and end are the inclusive bit offsets for the start and end of a field relative to the end of SOP.
-
get_bits
()¶ Generate data packet bits
-
-
class
ripyl.protocol.usb.
USBEXTPacket
(pid, addr, endp, sub_pid, variable, speed=1, delay=0.0)¶ Bases:
ripyl.protocol.usb.USBPacket
Extended packet
-
__init__
(pid, addr, endp, sub_pid, variable, speed=1, delay=0.0)¶
-
field_offsets
(with_stuffing=False)¶ Get a dict of packet field bit offsets
Parameters: with_stuffing (bool) – Flag indicating whether to return fields adjusted for stuffed bits Returns: A dict keyed by the field name and a pair (start, end) for each value. Start and end are the inclusive bit offsets for the start and end of a field relative to the end of SOP.
-
-
class
ripyl.protocol.usb.
USBHandshakePacket
(pid, speed=1, delay=0.0)¶ Bases:
ripyl.protocol.usb.USBPacket
Handshake packet
-
__init__
(pid, speed=1, delay=0.0)¶
-
field_offsets
(with_stuffing=False)¶ Get a dict of packet field bit offsets
Parameters: with_stuffing (bool) – Flag indicating whether to return fields adjusted for stuffed bits Returns: A dict keyed by the field name and a pair (start, end) for each value. Start and end are the inclusive bit offsets for the start and end of a field relative to the end of SOP.
-
get_bits
()¶ Generate handshake packet bits
-
-
class
ripyl.protocol.usb.
USBPID
¶ Bases:
ripyl.util.enum.Enum
Enumeration for the packet PIDs
-
ACK
= 2¶
-
Data0
= 3¶
-
Data1
= 11¶
-
Data2
= 7¶
-
ERR
= 12¶
-
EXT
= 0¶
-
MData
= 15¶
-
NAK
= 10¶
-
NYET
= 6¶
-
PING
= 4¶
-
PRE
= 12¶
-
SOF
= 5¶
-
SPLIT
= 8¶
-
STALL
= 14¶
-
TokenIn
= 9¶
-
TokenOut
= 1¶
-
TokenSetup
= 13¶
-
-
class
ripyl.protocol.usb.
USBPacket
(pid, speed=1, delay=0.0)¶ Bases:
object
Base class for USB packet objects
This class should not be instanced directly. Use the various subclasses instead.
These objects have methods meant to be used by the usb_synth() routine. When these objects are embedded in a USBStreamPacket object they are used for attribute access only.
-
__init__
(pid, speed=1, delay=0.0)¶
-
field_offsets
(with_stuffing=None)¶ Get a dict of packet field bit offsets
Returns: A dict keyed by the field name and a pair (start, end) for each value. Start and end are the inclusive bit offsets for the start and end of a field relative to the end of SOP.
-
get_bits
()¶ Generate the raw data bits of a packet in LSB-first order
-
get_diff_edges
(cur_time=0.0)¶ Produce a set of edges corresponding to USB differential (D+ - D-) signal
Parameters: cur_time (float) – The starting offset time for the edges Returns: A list of differential edges
-
get_edges
(cur_time=0.0)¶ Produce a set of edges corresponding to USB D+ and D- signals
Parameters: cur_time (float) – The starting offset time for the edges Returns: A 2-tuple containing the d+ and d- edge lists
-
get_hsic_edges
(cur_time=0.0)¶ Produce a set of edges corresponding to USB HSIC (strobe, data) signals
Parameters: cur_time (float) – The starting offset time for the edges Returns: A 2-tuple containing the strobe and data edge lists
-
sop_bits
()¶ Return number of SOP bits in packet
-
-
class
ripyl.protocol.usb.
USBPacketKind
¶ Bases:
ripyl.util.enum.Enum
Enumeration for packet kind (lower two bits of PID)
-
Data
= 3¶
-
Handshake
= 2¶
-
Special
= 0¶
-
Token
= 1¶
-
-
class
ripyl.protocol.usb.
USBSOFPacket
(pid, frame_num, speed=1, delay=0.0)¶ Bases:
ripyl.protocol.usb.USBPacket
Start of Frame packet
-
__init__
(pid, frame_num, speed=1, delay=0.0)¶
-
field_offsets
(with_stuffing=False)¶ Get a dict of packet field bit offsets
Parameters: with_stuffing (bool) – Flag indicating whether to return fields adjusted for stuffed bits Returns: A dict keyed by the field name and a pair (start, end) for each value. Start and end are the inclusive bit offsets for the start and end of a field relative to the end of SOP.
-
get_bits
()¶ Generate SOF packet bits
-
-
class
ripyl.protocol.usb.
USBSpeed
¶ Bases:
ripyl.util.enum.Enum
Enumeration for the USB bus speeds
-
FullSpeed
= 1¶
-
HighSpeed
= 2¶
-
LowSpeed
= 0¶
-
-
class
ripyl.protocol.usb.
USBSplitPacket
(pid, addr, sc, port, s, e, et, speed=2, delay=0.0)¶ Bases:
ripyl.protocol.usb.USBPacket
Split packet
-
__init__
(pid, addr, sc, port, s, e, et, speed=2, delay=0.0)¶
-
field_offsets
(with_stuffing=False)¶ Get a dict of packet field bit offsets
Parameters: with_stuffing (bool) – Flag indicating whether to return fields adjusted for stuffed bits Returns: A dict keyed by the field name and a pair (start, end) for each value. Start and end are the inclusive bit offsets for the start and end of a field relative to the end of SOP.
-
get_bits
()¶ Generate split packet bits
-
-
class
ripyl.protocol.usb.
USBState
¶ Bases:
ripyl.util.enum.Enum
Enumeration for logical bus states
-
J
= 1¶
-
K
= 2¶
-
SE0
= 0¶
-
SE1
= 3¶
-
-
class
ripyl.protocol.usb.
USBStreamError
(bounds, error_data, pid=-1, status=200)¶ Bases:
ripyl.streaming.StreamSegment
Contains partially decoded packet data after an error has been found in the data stream
-
__init__
(bounds, error_data, pid=-1, status=200)¶ Parameters: bounds ((float, float)) – 2-tuple (start_time, end_time) for the packet :param : :type error_data: sequence of int :param error_data:
An array of bits (potentially unstuffed) for the packetParameters: - pid (int) – The PID for the packet if it was successfully extracted. -1 if the PID was invalid or unavailable.
- status (int) – Status code for the packet
-
-
class
ripyl.protocol.usb.
USBStreamPacket
(bounds, sop_end, packet, crc=None, status=0, sop_end2=None, crc2=None)¶ Bases:
ripyl.streaming.StreamSegment
Encapsulates a USBPacket object (see below) into a StreamSegment
-
__init__
(bounds, sop_end, packet, crc=None, status=0, sop_end2=None, crc2=None)¶ Parameters: bounds ((float, float)) – 2-tuple (start_time, end_time) for the packet :param : :type sop_end: float :param sop_end:
The time for the end of the SOP portion of the packet. Used to measure bit positions for the packet fields.:param : :type packet: USBPacket :param packet:
USBPacket object to encapsulateParameters: crc (int or None) – Optional CRC extracted from a decoded packet. Not used for encoding with usb_synth(). :param : :type status: int :param status:
Status code for the packetParameters: - sop_end2 (float or None) – The time for the end of the second SOP in an EXT packet
- crc2 (int or None) – Optional CRC from second part of EXT packet
-
field_offsets
()¶ Get a dict of packet field bit offsets
Returns: A dict keyed by the field name and a pair (start, end) for each value. Start and end are the inclusive times for the start and end of a field.
-
packet
¶
-
classmethod
status_text
(status)¶
-
-
class
ripyl.protocol.usb.
USBStreamStatus
¶ Bases:
ripyl.util.enum.Enum
Enumeration for USBStreamPacket and USBStreamError status codes
-
BitStuffingError
= 203¶
-
CRCError
= 204¶
-
MissingEOPError
= 202¶
-
ShortPacketError
= 201¶
-
-
class
ripyl.protocol.usb.
USBTokenPacket
(pid, addr, endp, speed=1, delay=0.0)¶ Bases:
ripyl.protocol.usb.USBPacket
Token packet
-
__init__
(pid, addr, endp, speed=1, delay=0.0)¶
-
field_offsets
(with_stuffing=False)¶ Get a dict of packet field bit offsets
Parameters: with_stuffing (bool) – Flag indicating whether to return fields adjusted for stuffed bits Returns: A dict keyed by the field name and a pair (start, end) for each value. Start and end are the inclusive bit offsets for the start and end of a field relative to the end of SOP.
-
get_bits
()¶ Generate token packet bits
-
-
ripyl.protocol.usb.
table_usb_crc16
(d)¶ Calculate USB CRC-16 on data
This is a table-based byte-wise implementation
Parameters: d (sequence of int) – Array of integers representing bytes :param : :returns: Array of integers for each bit in the crc with lsb first
-
ripyl.protocol.usb.
usb_crc16
(d)¶ Calculate USB CRC-16 on data
Parameters: d (sequence of int) – Array of integers representing 0 or 1 bits in transmission order :param : :returns: Array of integers for each bit in the crc with lsb first
-
ripyl.protocol.usb.
usb_crc5
(d)¶ Calculate USB CRC-5 on data
Parameters: d (sequence of int) – Array of integers representing 0 or 1 bits in transmission order :param : :returns: Array of integers for each bit in the crc with lsb first
-
ripyl.protocol.usb.
usb_decode
(dp, dm, logic_levels=None, stream_type=1)¶ Decode a USB data stream
This is a generator function that can be used in a pipeline of waveform processing operations.
This function decodes USB data captured from the two single-ended D+ and D- signals. For differential USB decode see the function usb_diff_decode().
Low speed device keep-alive EOPs are not reported in the decoded results.
The dp and dm parameters are edge or sample streams. Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data on the dp stream is consumed to determine the most likely logic levels in the signal and the bus speed.
Parameters: - dp (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a USB D+ signal
- dm (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a USB D- signal
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the dp, and dm parameters represent either Samples or Edges
:param : :returns: An iterator yielding a series of USBStreamPacket and USBStreamError objects
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined. Raises: StreamError if the bus speed cannot be determined.
-
ripyl.protocol.usb.
usb_diff_decode
(d_diff, logic_levels=None, stream_type=1)¶ Decode a differential USB data stream
This is a generator function that can be used in a pipeline of waveform processing operations.
This function decodes USB data captured from a differential (D+)-(D-) signal. For single-ended USB decode see the function usb_decode().
Low speed device keep-alive EOPs are not reported in the decoded results.
The d_diff parameter is an edge or sample stream. Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data is consumed to determine the most likely logic levels in the signal and the bus speed.
Parameters: - d_diff (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing a USB differential (D+ - D-) signal.
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the dp, and dm parameters represent either Samples or Edges
:param : :returns: An iterator yielding a series of USBStreamPacket and USBStreamError objects
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined. Raises: StreamError if the bus speed cannot be determined.
-
ripyl.protocol.usb.
usb_diff_synth
(packets, idle_start=0.0, idle_end=0.0)¶ Generate synthesized differential USB waveforms
This function simulates USB packet transmission on the differential D+ - D- signal.
Parameters: - packets (sequence of USBPacket) – The packet objects that are to be simulated
- idle_start (float) – The amount of idle time before the transmission of packets begins
- idle_end (float) – The amount of idle time after the last packet
Returns: An iterator of 2-tuples for the d+ - d- differential channel. each 2-tuple is a (time, value) pair representing the time and the logic value (-1, 0, or 1) for each edge transition. The first tuple yielded is the initial state of the waveform. All remaining tuples are edges where the state changes.
-
ripyl.protocol.usb.
usb_hsic_decode
(strobe, data, logic_levels=None, stream_type=1)¶ Decode a USB HSIC data stream
This is a generator function that can be used in a pipeline of waveform processing operations.
This function decodes USB HSIC data captured from the two single-ended strobe and data signals.
The strobe and data parameters are edge or sample streams. Sample streams are a sequence of SampleChunk Objects. Edge streams are a sequence of 2-tuples of (time, int) pairs. The type of stream is identified by the stream_type parameter. Sample streams will be analyzed to find edge transitions representing 0 and 1 logic states of the waveforms. With sample streams, an initial block of data on the strobe stream is consumed to determine the most likely logic levels in the signal.
The bus speed is fixed at 480Mb/s.
Parameters: - strobe (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing an HSIC strobe signal
- data (iterable of SampleChunk objects or (float, int) pairs) – A sample stream or edge stream representing an HSIC data signal
- logic_levels ((float, float) or None) – Optional pair that indicates (low, high) logic levels of the sample stream. When present, auto level detection is disabled. This has no effect on edge streams.
- stream_type (streaming.StreamType) – A StreamType value indicating that the strobe, and data parameters represent either Samples or Edges
:param : :returns: An iterator yielding a series of USBStreamPacket and USBStreamError objects
Raises: AutoLevelError if stream_type = Samples and the logic levels cannot be determined.
-
ripyl.protocol.usb.
usb_hsic_synth
(packets, idle_start=0.0, idle_end=0.0)¶ Generate synthesized USB HSIC waveforms
This function simulates USB packet transmission on the HSIC strobe and data signals.
Parameters: - packets (sequence of USBPacket) – The packet objects that are to be simulated
- idle_start (float) – The amount of idle time before the transmission of packets begins
- idle_end (float) – The amount of idle time after the last packet
Returns: A pair of iterators (strobe, data) for the strobe and data channels. each iterator is a 2-tuple (time, value) representing the time and the logic value (0 or 1) for each edge transition on strobe and data. The first tuple yielded is the initial state of the waveform. All remaining tuples are edges where the state changes.
-
ripyl.protocol.usb.
usb_synth
(packets, idle_start=0.0, idle_end=0.0)¶ Generate synthesized USB waveforms
This function simulates USB packet transmission on the D+ and D- signals.
Parameters: - packets (sequence of USBPacket) – The packet objects that are to be simulated
- idle_start (float) – The amount of idle time before the transmission of packets begins
- idle_end (float) – The amount of idle time after the last packet
Returns: A pair of iterators (dp, dm) for the d+ and d- channels. each iterator is a 2-tuple (time, value) representing the time and the logic value (0 or 1) for each edge transition on D+ and D-. The first tuple yielded is the initial state of the waveform. All remaining tuples are edges where the state changes.
ripyl.protocol.usb_transact module¶
USB transaction decoder
Processes a USB packet stream into a set of USBTransaction objects
-
class
ripyl.protocol.usb_transact.
USBTransaction
(packets, status=0)¶ Bases:
ripyl.streaming.StreamRecord
Collection of packets forming a USB transaction
The ‘subrecords’ attribute is aliased to the ‘packets’ attribute. These “packets” are USBStreamPacket objects rather than unadorned USBPacket objects.
-
__init__
(packets, status=0)¶ Parameters: packets (USBStreamPacket) – A sequence of packet objects in the transaction
-
end_time
¶ The end time of the last packet
-
packets
¶ A list of USBStreamPacket objects from this transaction
-
start_time
¶ The start time of the first packet
-
-
ripyl.protocol.usb_transact.
extract_transaction_packets
(records)¶ Convert a stream of USB transactions into raw USBPacket objects
Parameters: records (sequence of USBTransaction) – Iterator of USBTransaction objects :param : :returns: An iterator yielding a stream of USBPacket objects
-
ripyl.protocol.usb_transact.
usb_transactions_decode
(records)¶ Convert a stream of USB packets into transactions
Parameters: records (sequence of USBPacket) – An iterator containing USBPacket objects as produced by usb.usb_decode() :param : :returns: An iterator yielding a stream of USBTransaction objects containing packets merged into identifiable
transactions. Any non-USBPacket objects in the input stream will also be present as will SOF packets.
Module contents¶
Protocol package