def test_rc6_decode(self):
        self.test_name = 'RC-6 IR protocol'
        self.trial_count = 20

        carrier_freq = 36.0e3
        sample_rate = 10.0 * carrier_freq
        rise_time = sigp.min_rise_time(sample_rate) * 1.01

        for i in xrange(self.trial_count):
            self.update_progress(i + 1)

            msg_count = randint(1, 10)

            msgs = []
            for i in xrange(msg_count):
                do_mode6 = choice([True, False])
                if do_mode6:
                    msg = rc6.RC6Message(addr=randint(0,255), cmd=randint(0,255), toggle=randint(0,1), \
                        mode=6, customer=randint(0,2**15-1))
                else:
                    msg = rc6.RC6Message(addr=randint(0, 255),
                                         cmd=randint(0, 255),
                                         toggle=randint(0, 1),
                                         mode=randint(0, 5))
                msgs.append(msg)

            do_modulation = choice((True, False))

            edges = rc6.rc6_synth(msgs, message_interval=5.0e-3)
            if do_modulation:
                duty = uniform(0.1, 0.9)
                edges = ir.modulate(edges, carrier_freq, duty_cycle=duty)

            samples = sigp.synth_wave(edges, sample_rate, rise_time)
            #samples = sigp.dropout(samples, 2.6e-4, 3.8e-4)
            #samples = sigp.capacify(samples, 4.0e-7, 50.0)
            noisy = sigp.amplify(sigp.noisify(samples, snr_db=30), gain=5.0)
            waveform = list(noisy)

            #wave_samples = stream.sample_stream_to_samples(waveform)
            #plt.plot(wave_samples)
            #plt.show()

            records = list(rc6.rc6_decode(iter(waveform)))
            #print('\nDecoded {} records'.format(len(records)))

            #for m in msgs:
            #    print(m)

            #for r in records:
            #    for s in r.summary():
            #        print(s)

            self.assertEqual(len(msgs), len(records),
                             'Mismatch in decoded record count')

            for rec, msg in zip(records, msgs):
                self.assertEqual(rec.data, msg, 'Mismatched messages')
示例#2
0
    def test_rc6_decode(self):
        self.test_name = 'RC-6 IR protocol'
        self.trial_count = 20

        carrier_freq = 36.0e3
        sample_rate = 10.0 * carrier_freq
        rise_time = sigp.min_rise_time(sample_rate) * 1.01

        for i in xrange(self.trial_count):
            self.update_progress(i+1)

            msg_count = randint(1,10)

            msgs = []
            for i in xrange(msg_count):
                do_mode6 = choice([True, False])
                if do_mode6:
                    msg = rc6.RC6Message(addr=randint(0,255), cmd=randint(0,255), toggle=randint(0,1), \
                        mode=6, customer=randint(0,2**15-1))
                else:
                    msg = rc6.RC6Message(addr=randint(0,255), cmd=randint(0,255), toggle=randint(0,1), mode=randint(0,5))
                msgs.append(msg)

            do_modulation = choice((True, False))

            edges = rc6.rc6_synth(msgs, message_interval=5.0e-3)
            if do_modulation:
                duty = uniform(0.1, 0.9)
                edges = ir.modulate(edges, carrier_freq, duty_cycle=duty)

            samples = sigp.synth_wave(edges, sample_rate, rise_time)
            #samples = sigp.dropout(samples, 2.6e-4, 3.8e-4)
            #samples = sigp.capacify(samples, 4.0e-7, 50.0)
            noisy = sigp.amplify(sigp.noisify(samples, snr_db=30), gain=5.0)
            waveform = list(noisy)

            #wave_samples = stream.sample_stream_to_samples(waveform)
            #plt.plot(wave_samples)
            #plt.show()

            records = list(rc6.rc6_decode(iter(waveform)))
            #print('\nDecoded {} records'.format(len(records)))

            #for m in msgs:
            #    print(m)

            #for r in records:
            #    for s in r.summary():
            #        print(s)

            self.assertEqual(len(msgs), len(records), 'Mismatch in decoded record count')

            for rec, msg in zip(records, msgs):
                self.assertEqual(rec.data, msg, 'Mismatched messages')
示例#3
0
    def test_sirc_decode(self):
        self.test_name = 'SIRC IR protocol'
        self.trial_count = 20

        carrier_freq = 40.0e3
        sample_rate = 10.0 * carrier_freq
        rise_time = sigp.min_rise_time(sample_rate) * 1.01

        for i in xrange(self.trial_count):
            self.update_progress(i+1)

            msg_count = randint(1,10)

            msgs = []
            for i in xrange(msg_count):
                if choice((True, False)):
                    msg = sirc.SIRCMessage(cmd=randint(0, 127), device=randint(0, 255))
                else:
                    msg = sirc.SIRCMessage(cmd=randint(0, 127), device=randint(0, 31), \
                        extended=randint(0,255))
                msgs.append(msg)

            do_modulation = choice((True, False))

            edges = sirc.sirc_synth(msgs)
            if do_modulation:
                duty = uniform(0.1, 0.9)
                edges = ir.modulate(edges, carrier_freq, duty_cycle=duty)

            samples = sigp.synth_wave(edges, sample_rate, rise_time)
            #samples = sigp.dropout(samples, 2.6e-4, 3.8e-4)
            noisy = sigp.amplify(sigp.noisify(samples, snr_db=30), gain=5.0)
            waveform = list(noisy)

            #wave_samples = stream.sample_stream_to_samples(waveform)
            #plt.plot(wave_samples)
            #plt.show()

            records = list(sirc.sirc_decode(iter(waveform)))
            #print('\nDecoded {} records'.format(len(records)))

            self.assertEqual(len(msgs), len(records), 'Mismatch in decoded record count')

            for rec, msg in zip(records, msgs):
                self.assertEqual(rec.data, msg, 'Mismatched messages')
    def test_nec_decode(self):
        self.test_name = 'NEC IR protocol'
        self.trial_count = 20

        carrier_freq = 38.0e3

        for i in xrange(self.trial_count):
            self.update_progress(i+1)

            msg_count = randint(1,10)

            msgs = []
            for i in xrange(msg_count):
                msg = nec.NECMessage(cmd=randint(0,255), addr_low=randint(0,255), \
                    addr_high=choice((None, randint(0,255))) )
                msgs.append(msg)

            sample_rate = uniform(8.0, 15.0) * carrier_freq
            rise_time = sigp.min_rise_time(sample_rate) * 1.01

            do_modulation = choice((True, False))

            edges = nec.nec_synth(msgs)

            if do_modulation:
                duty = uniform(0.2, 0.8)
                edges = ir.modulate(edges, carrier_freq, duty_cycle=duty)

            samples = sigp.synth_wave(edges, sample_rate, rise_time)
            #samples = sigp.dropout(samples, 2.6e-4, 3.8e-4)
            noisy = sigp.quantize(sigp.amplify(sigp.noisify(samples, snr_db=20), gain=5.0), 70.0)
            waveform = list(noisy)

            #wave_samples = stream.sample_stream_to_samples(waveform)
            #plt.plot(wave_samples)
            #plt.show()

            records = list(nec.nec_decode(iter(waveform)))
            #print('\nDecoded {} records'.format(len(records)))

            self.assertEqual(len(msgs), len(records), 'Mismatch in decoded record count')

            for rec, msg in zip(records, msgs):
                self.assertEqual(rec.data, msg, 'Mismatched messages')