示例#1
0
def iso_k_line_synth(messages, idle_start=0.0, message_interval=8.0e-3, idle_end=0.0, word_interval=1.0e-3):
    '''Generate synthesized ISO9141 and ISO14230 data streams
    
    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.

    Yields an edge stream of (float, int) pairs. The first element in the iterator
      is the initial state of the stream.
    '''

    msg_its = []
    for i, msg in enumerate(messages):
        istart = idle_start if i == 0 else 0.0
        iend = idle_end if i == len(messages)-1 else 0.0
        msg_its.append(uart.uart_synth(msg, bits=8, baud=10400, idle_start=istart, \
            idle_end=iend, word_interval=word_interval))

    return sigp.chain_edges(message_interval, *msg_its)
def iso_k_line_synth(messages,
                     idle_start=0.0,
                     message_interval=8.0e-3,
                     idle_end=0.0,
                     word_interval=1.0e-3):
    '''Generate synthesized ISO9141 and ISO14230 data streams
    
    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.

    Yields an edge stream of (float, int) pairs. The first element in the iterator
      is the initial state of the stream.
    '''

    msg_its = []
    for i, msg in enumerate(messages):
        istart = idle_start if i == 0 else 0.0
        iend = idle_end if i == len(messages) - 1 else 0.0
        msg_its.append(uart.uart_synth(msg, bits=8, baud=10400, idle_start=istart, \
            idle_end=iend, word_interval=word_interval))

    return sigp.chain_edges(message_interval, *msg_its)
示例#3
0
def ethernet_synth(frames,
                   overshoot=None,
                   idle_start=0.0,
                   frame_interval=0.0,
                   idle_end=0.0):
    '''Generate synthesized Ethernet frames
    
    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.

    Yields an edge stream of (float, int) pairs. The first element in the iterator
      is the initial state of the stream.
    '''
    bit_period = 1.0 / 10.0e6  #FIX set speed

    frame_its = []
    for i, frame in enumerate(frames):
        istart = idle_start if i == 0 else 0.0
        iend = idle_end if i == len(frames) - 1 else bit_period

        if hasattr(frame, 'edges'):  # Link pulse
            edges = iter(frame.edges(bit_period))
        else:  # A proper frame
            edges = manchester_encode(frame.bit_stream(),
                                      bit_period,
                                      idle_start=istart,
                                      idle_end=iend)

        if overshoot is not None and len(overshoot) == 2:
            frame_its.append(
                add_overshoot(diff_encode(edges), bit_period * overshoot[1],
                              overshoot[0]))
        else:
            frame_its.append(diff_encode(edges))

    return sigp.chain_edges(frame_interval, *frame_its)
def _lin_synth(frames, baud, idle_start=0.0, frame_interval=8.0e-3, idle_end=0.0, byte_interval=1.0e-3):
    '''The LIN core synthesizer'''

    bit_period = 1.0 / baud

    frame_its = []
    for i, f in enumerate(frames):
        iend = idle_end if i == len(frames)-1 else 0.0

        # Generate the break character starting the frame
        if i == 0 and idle_start > 0.0:
            break_edges = [(0.0, 1), (idle_start, 0), (idle_start + 14.0 * bit_period, 1)]
        else:
            break_edges = [(0.0, 0), (14.0 * bit_period, 1)]
        
        # Generate bytes for the rest of the frame
        byte_edges = uart.uart_synth(f.bytes(), bits=8, baud=baud, idle_start=0.0, \
                    idle_end=iend, word_interval=byte_interval)

        frame_its.append(sigp.chain_edges(bit_period, break_edges, byte_edges))

    return sigp.chain_edges(frame_interval, *frame_its)
示例#5
0
def ethernet_synth(frames, overshoot=None, idle_start=0.0, frame_interval=0.0, idle_end=0.0):
    '''Generate synthesized Ethernet frames
    
    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.

    Yields an edge stream of (float, int) pairs. The first element in the iterator
      is the initial state of the stream.
    '''
    bit_period = 1.0 / 10.0e6 #FIX set speed

    frame_its = []
    for i, frame in enumerate(frames):
        istart = idle_start if i == 0 else 0.0
        iend = idle_end if i == len(frames)-1 else bit_period

        if hasattr(frame, 'edges'): # Link pulse
            edges = iter(frame.edges(bit_period))
        else: # A proper frame
            edges = manchester_encode(frame.bit_stream(), bit_period, idle_start=istart, idle_end=iend)

        if overshoot is not None and len(overshoot) == 2:
            frame_its.append(add_overshoot(diff_encode(edges), bit_period * overshoot[1], overshoot[0]))
        else:
            frame_its.append(diff_encode(edges))

    return sigp.chain_edges(frame_interval, *frame_its)