def test_uart_speed(self): bits = 8 baud = 9600 polarity = uart.UARTConfig.IdleHigh parity = None stop_bits = 1 char_count = 1000 data = [random.randint(0, 255) for _ in xrange(char_count)] edges = list( uart.uart_synth(data, bits, baud, parity=parity, stop_bits=stop_bits)) iterations = 10 self._t_start = time.time() for _ in xrange(iterations): records = list(uart.uart_decode(iter(edges), bits=bits, polarity=polarity, parity=parity, stop_bits=stop_bits, \ stream_type=stream.StreamType.Edges, baud_rate=baud)) characters_processed = iterations * char_count return (iterations, characters_processed, 'characters')
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)
def test_uart_decode(self): self.test_name = 'UART message' self.trial_count = 10 for i in xrange(self.trial_count): self.update_progress(i + 1) msg = [] for _ in xrange(20): msg.append(chr(random.choice(xrange(ord('0'), ord('z'))))) msg = ''.join(msg) baud = random.choice((110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, \ 56000, 57600, 115200, 128000, 153600, 230400, 256000, 460800, 921600)) sample_rate = baud * 100.0 rise_time = sigp.min_rise_time( sample_rate) * 10.0 # 10x min rise time parity = random.choice((None, 'even', 'odd')) bits = random.choice((7, 8, 9)) #print('\nTRIAL {}: msg="{}", baud={}, parity={}, bits={}'.format(i, msg, baud, parity, bits)) edges = uart.uart_synth(bytearray(msg.encode('utf-8')), bits, baud, parity=parity, idle_start=100.0 / sample_rate) samples = sigp.synth_wave(edges, sample_rate, rise_time, ripple_db=60) noisy = sigp.amplify(sigp.noisify(samples, snr_db=20), gain=-15.0) waveform = list(noisy) frames = uart.uart_decode(iter(waveform), bits=bits, polarity=uart.UARTConfig.IdleLow, parity=parity, baud_rate=None) frames = list(frames) #print(''.join(str(d) for d in frames)) decoded_msg = ''.join(str(d) for d in frames) self.assertEqual(msg, decoded_msg, \ "Message not decoded successfully msg:'{0}', baud:{1}, parity:{2}, bits:{3}".format(msg, \ baud, parity, bits))
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)
def test_uart_speed(self): bits = 8 baud = 9600 polarity = uart.UARTConfig.IdleHigh parity = None stop_bits = 1 char_count = 1000 data = [random.randint(0,255) for _ in xrange(char_count)] edges = list(uart.uart_synth(data, bits, baud, parity=parity, stop_bits=stop_bits)) iterations = 10 self._t_start = time.time() for _ in xrange(iterations): records = list(uart.uart_decode(iter(edges), bits=bits, polarity=polarity, parity=parity, stop_bits=stop_bits, \ stream_type=stream.StreamType.Edges, baud_rate=baud)) characters_processed = iterations * char_count return (iterations, characters_processed, 'characters')
def test_uart_decode(self): self.test_name = 'UART message' self.trial_count = 10 for i in xrange(self.trial_count): self.update_progress(i+1) msg = [] for _ in xrange(20): msg.append(chr(random.choice(xrange(ord('0'), ord('z')) ))) msg = ''.join(msg) baud = random.choice((110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, \ 56000, 57600, 115200, 128000, 153600, 230400, 256000, 460800, 921600)) sample_rate = baud * 100.0 rise_time = sigp.min_rise_time(sample_rate) * 10.0 # 10x min rise time parity = random.choice((None, 'even', 'odd')) bits = random.choice((7, 8, 9)) #print('\nTRIAL {}: msg="{}", baud={}, parity={}, bits={}'.format(i, msg, baud, parity, bits)) edges = uart.uart_synth(bytearray(msg.encode('utf-8')), bits, baud, parity=parity, idle_start=100.0 / sample_rate) samples = sigp.synth_wave(edges, sample_rate, rise_time, ripple_db=60) noisy = sigp.amplify(sigp.noisify(samples, snr_db=20), gain=-15.0) waveform = list(noisy) frames = uart.uart_decode(iter(waveform), bits=bits, polarity=uart.UARTConfig.IdleLow, parity=parity, baud_rate=None) frames = list(frames) #print(''.join(str(d) for d in frames)) decoded_msg = ''.join(str(d) for d in frames) self.assertEqual(msg, decoded_msg, \ "Message not decoded successfully msg:'{0}', baud:{1}, parity:{2}, bits:{3}".format(msg, \ baud, parity, bits))