def test_usb_diff_sample_data(self):

        # Read files containing 100 Full-speed SOF packets
        # Note that these packets were collected with segmented acquisition and are ~5us
        # apart rather than the proper 1ms.
        dp_samples, sample_period, start_time = tsup.read_bin_file(
            'test/data/usb_100segs_dp.bin')
        dp_it = stream.samples_to_sample_stream(dp_samples, sample_period,
                                                start_time)

        dm_samples, sample_period, start_time = tsup.read_bin_file(
            'test/data/usb_100segs_dm.bin')
        dm_it = stream.samples_to_sample_stream(dm_samples, sample_period,
                                                start_time)

        # generate differential waveform
        d_diff_it = sigp.sum_streams(dp_it, sigp.invert(dm_it))

        records_it = usb.usb_diff_decode(d_diff_it,
                                         stream_type=stream.StreamType.Samples)
        records = list(records_it)

        self.assertEqual(len(records), 100,
                         'Missing records, expected to decode 100')

        # The SOF packet frame_num fields should be monotonically increasing
        cur_frame = records[0].packet.frame_num
        for r in records[1:]:
            cur_frame += 1
            self.assertEqual(r.packet.frame_num, cur_frame,
                             'SOF frame_num not decoded properly')
Esempio n. 2
0
    def test_uart_hello(self):
    
        bits = 8
        polarity = uart.UARTConfig.IdleLow
        parity = 'even'
        stop_bits = 2
        message = 'Hello, world!'

        samples, sample_period, start_time = tsup.read_bin_file('test/data/uart_hello_8e2.bin')
        txd = stream.samples_to_sample_stream(samples, sample_period, start_time)
        frames = list(uart.uart_decode(txd, bits=bits, polarity=polarity, parity=parity, stop_bits=stop_bits))
        
        ok_status = True
        for f in frames:
            if f.nested_status() != stream.StreamStatus.Ok:
                ok_status = False
                break
                
        self.assertTrue(ok_status, 'Decoded data has non-Ok status')
        
        # Check the message bytes
        dmsg = ''.join([chr(d.data) for d in frames])
        self.assertEqual(message, dmsg, 'Message mismatch. Expected: "{}" Got: "{}"'.format(message, dmsg))
            

        bits = 8
        polarity = uart.UARTConfig.IdleLow
        parity = None
        stop_bits = 1
        message = 'Hello, world!'

        samples, sample_period, start_time = tsup.read_bin_file('test/data/uart_hello.bin')
        txd = stream.samples_to_sample_stream(samples, sample_period, start_time)
        frames = list(uart.uart_decode(txd, bits=bits, polarity=polarity, parity=parity, stop_bits=stop_bits))
        
        ok_status = True
        for f in frames:
            if f.nested_status() != stream.StreamStatus.Ok:
                ok_status = False
                break
                
        self.assertTrue(ok_status, 'Decoded data has non-Ok status')
        
        # Check the message bytes
        dmsg = ''.join([chr(d.data) for d in frames])
        self.assertEqual(message, dmsg, 'Message 2 mismatch. Expected: "{}" Got: "{}"'.format(message, dmsg))
Esempio n. 3
0
    def test_j1850_sample_data(self):
    
        # Read files containing frames
        dp_samples, sample_period, start_time = tsup.read_bin_file('test/data/j1850_pwm_1p.bin')
        dp_it = stream.samples_to_sample_stream(dp_samples, sample_period, start_time)

        records = list(j1850.j1850_pwm_decode(dp_it))
        
        #print('### decoded records:', len(records))
        #for r in records:
        #    print(r.data)
        self.assertEqual(len(records), 9, 'Missing records, expected to decode 9')
Esempio n. 4
0
    def test_usb_sample_data(self):
    
        # Read files containing 100 Full-speed SOF packets
        # Note that these packets were collected with segmented acquisition and are ~5us
        # apart rather than the proper 1ms.
        dp_samples, sample_period, start_time = tsup.read_bin_file('test/data/usb_100segs_dp.bin')
        dp_it = stream.samples_to_sample_stream(dp_samples, sample_period, start_time)

        dm_samples, sample_period, start_time = tsup.read_bin_file('test/data/usb_100segs_dm.bin')
        dm_it = stream.samples_to_sample_stream(dm_samples, sample_period, start_time)
        
        records_it = usb.usb_decode(dp_it, dm_it, stream_type=stream.StreamType.Samples)
        records = list(records_it)
        
        self.assertEqual(len(records), 100, 'Missing records, expected to decode 100')
        
        # The SOF packet frame_num fields should be monotonically increasing
        cur_frame = records[0].packet.frame_num
        for r in records[1:]:
            cur_frame += 1
            self.assertEqual(r.packet.frame_num, cur_frame, 'SOF frame_num not decoded properly')
    def test_j1850_sample_data(self):

        # Read files containing frames
        dp_samples, sample_period, start_time = tsup.read_bin_file(
            'test/data/j1850_pwm_1p.bin')
        dp_it = stream.samples_to_sample_stream(dp_samples, sample_period,
                                                start_time)

        records = list(j1850.j1850_pwm_decode(dp_it))

        #print('### decoded records:', len(records))
        #for r in records:
        #    print(r.data)
        self.assertEqual(len(records), 9,
                         'Missing records, expected to decode 9')
Esempio n. 6
0
    def test_uart_hello(self):

        bits = 8
        polarity = uart.UARTConfig.IdleLow
        parity = 'even'
        stop_bits = 2
        message = 'Hello, world!'

        samples, sample_period, start_time = tsup.read_bin_file(
            'test/data/uart_hello_8e2.bin')
        txd = stream.samples_to_sample_stream(samples, sample_period,
                                              start_time)
        frames = list(
            uart.uart_decode(txd,
                             bits=bits,
                             polarity=polarity,
                             parity=parity,
                             stop_bits=stop_bits))

        ok_status = True
        for f in frames:
            if f.nested_status() != stream.StreamStatus.Ok:
                ok_status = False
                break

        self.assertTrue(ok_status, 'Decoded data has non-Ok status')

        # Check the message bytes
        dmsg = ''.join([chr(d.data) for d in frames])
        self.assertEqual(
            message, dmsg,
            'Message mismatch. Expected: "{}" Got: "{}"'.format(message, dmsg))

        bits = 8
        polarity = uart.UARTConfig.IdleLow
        parity = None
        stop_bits = 1
        message = 'Hello, world!'

        samples, sample_period, start_time = tsup.read_bin_file(
            'test/data/uart_hello.bin')
        txd = stream.samples_to_sample_stream(samples, sample_period,
                                              start_time)
        frames = list(
            uart.uart_decode(txd,
                             bits=bits,
                             polarity=polarity,
                             parity=parity,
                             stop_bits=stop_bits))

        ok_status = True
        for f in frames:
            if f.nested_status() != stream.StreamStatus.Ok:
                ok_status = False
                break

        self.assertTrue(ok_status, 'Decoded data has non-Ok status')

        # Check the message bytes
        dmsg = ''.join([chr(d.data) for d in frames])
        self.assertEqual(
            message, dmsg,
            'Message 2 mismatch. Expected: "{}" Got: "{}"'.format(
                message, dmsg))