Exemple #1
0
    def setup(self):
        self.logger.info("--------------------------------------")
        self.logger.info("   Balloon Mission Computer V4.01     ")
        self.logger.info("--------------------------------------")
        self.logger.debug("setup")
        # setup
        with open('data/config.json') as fin:
            self.config = json.load(fin)
        self.images_dir = self.config["directories"][
            "images"] if "directories" in self.config and "images" in self.config[
                "directories"] else "./images"
        self.tmp_dir = self.config["directories"][
            "tmp"] if "directories" in self.config and "tmp" in self.config[
                "directories"] else "./tmp"

        if not os.path.exists(self.tmp_dir):
            os.makedirs(self.tmp_dir)
        if not os.path.exists(self.images_dir):
            os.makedirs(self.images_dir)

        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)  # Broadcom pin-numbering scheme
        GPIO.setup(self.config['pins']['BUZZER'], GPIO.OUT)
        GPIO.setup(self.config['pins']['LED1'], GPIO.OUT)
        GPIO.setup(self.config['pins']['LED2'], GPIO.OUT)
        GPIO.output(self.config['pins']['LED1'], GPIO.HIGH)

        self.aprs = APRS(self.config['callsign'], self.config['ssid'],
                         "idoroseman.com")
        self.modem = AFSK()
        self.gps = Ublox()
        self.gps.start()
        self.radio = Dorji(self.config['pins'])
        self.radio.init()
        self.radio_q = queue.Queue()
        self.radio_thread = threading.Thread(target=self.radio_worker)
        self.radio_thread.start()
        self.timers = Timers(self.config['timers'])
        self.sensors = Sensors()
        self.cam = Camera()
        self.ssdv = SSDV(self.config['callsign'], self.config['ssid'])
        self.sstv = SSTV()
        self.webserver = WebServer()
        self.radio_queue(self.config['frequencies']['APRS'],
                         'data/boatswain_whistle.wav')

        for item in ["APRS", "APRS-META", "Imaging", 'Capture']:
            self.timers.handle({item: self.config['timers'][item] > 0}, [])
        self.timers.handle({"Buzzer": False}, [])

        self.ledState = 1
        self.imaging_counter = 1
        self.state = "init"
        self.min_alt = sys.maxsize
        self.max_alt = 0
        self.prev_alt = 0
        self.send_bulltin()
        GPIO.output(self.config['pins']['LED1'], GPIO.LOW)
Exemple #2
0
class TestSSTV(unittest.TestCase):
    def setUp(self):
        self.s = SSTV(False, 48000, 16)
        self.s.VIS_CODE = 0x00
        self.s.SYNC = 7

    def test_horizontal_sync(self):
        horizontal_sync = self.s.horizontal_sync()
        expected = (1200, self.s.SYNC)
        actual = horizontal_sync.next()
        self.assertEqual(expected, actual)

    def test_gen_freq_bits(self):
        gen_freq_bits = self.s.gen_freq_bits()
        expected = [(1900, 300), (1200, 10), (1900, 300), (1200, 30),
                    (1300, 30), (1300, 30), (1300, 30), (1300, 30), (1300, 30),
                    (1300, 30), (1300, 30), (1300, 30), (1200, 30)]
        actual = list(islice(gen_freq_bits, 0, 1000))
        self.assertEqual(expected, actual)

    # FIXME: Instead of using a test fixture, 'expected' should be synthesized?
    def test_gen_values(self):
        gen_values = self.s.gen_values()
        expected = pickle.load(open("tests/assets/SSTV_gen_values.p"))
        for e, g in izip(expected, gen_values):
            self.assertAlmostEqual(e, g, delta=0.000000001)

    def test_gen_samples(self):
        gen_values = self.s.gen_samples()
        # gen_samples uses random to avoid quantization noise
        # by using additive noise, so there's always a chance
        # of running the code two consecutive times on the same machine
        # and having different results.
        # https://en.wikipedia.org/wiki/Quantization_%28signal_processing%29
        sstv.random = MagicMock(return_value=0.4)  # xkcd:221
        expected = pickle.load(open("tests/assets/SSTV_gen_samples.p"))
        actual = list(islice(gen_values, 0, 1000))
        self.assertEqual(expected, actual)

    def test_write_wav(self):
        self.maxDiff = None
        sio = StringIO()
        sio.close = MagicMock()  # ignore close() so we can .getvalue()
        mock_open = MagicMock(return_value=sio)
        with mock.patch('__builtin__.open', mock_open):
            self.s.write_wav('unittest.wav')
        expected = 'bf61c82e96aed1370d5c1753d87729db'
        data = sio.getvalue()
        actual = hashlib.md5(data).hexdigest()
        self.assertEqual(expected, actual)

    def test_init(self):
        self.assertEqual(self.s.image, False)
        self.assertEqual(self.s.samples_per_sec, 48000)
        self.assertEqual(self.s.bits, 16)
Exemple #3
0
    def setup(self):
        self.logger.info("--------------------------------------")
        self.logger.info("   Balloon Mission Computer V4.01     ")
        self.logger.info("--------------------------------------")
        self.logger.debug("setup")

        # setup files and directories
        with open('data/config.json') as fin:
            self.config = json.load(fin)
        self.images_dir = self.config["directories"][
            "images"] if "directories" in self.config and "images" in self.config[
                "directories"] else "./images"
        self.tmp_dir = self.config["directories"][
            "tmp"] if "directories" in self.config and "tmp" in self.config[
                "directories"] else "./tmp"

        if not os.path.exists(self.tmp_dir):
            os.makedirs(self.tmp_dir)
        if not os.path.exists(self.images_dir):
            os.makedirs(self.images_dir)

        # setup gpio
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)  # Broadcom pin-numbering scheme
        GPIO.setup(self.config['pins']['BUZZER'], GPIO.OUT)
        GPIO.setup(self.config['pins']['LED1'], GPIO.OUT)
        GPIO.setup(self.config['pins']['LED2'], GPIO.OUT)
        GPIO.output(self.config['pins']['LED1'], GPIO.HIGH)

        # modules
        self.aprs = APRS(self.config['callsign'], self.config['ssid'],
                         "idoroseman.com")
        self.modem = AFSK()
        try:
            self.gps = Ublox()
            self.gps.start()
        except:
            pass
        self.radio = Dorji(self.config['pins'])
        self.radio.init()
        self.radio_q = queue.Queue()
        self.radio_thread = threading.Thread(target=self.radio_worker)
        self.radio_thread.start()
        self.timers = Timers(self.config['timers'])
        self.sensors = Sensors()
        self.cam = Camera()
        self.ssdv = SSDV(self.config['callsign'], self.config['ssid'])
        self.sstv = SSTV()
        self.webserver = WebServer()
        self.radio_queue(self.config['frequencies']['APRS'],
                         'data/boatswain_whistle.wav')

        self.syslog = logging.getLogger()
        kh = MyLogHandler()
        kh._listeners.append(self.handle_log)
        kh.setLevel(logging.DEBUG)
        formatter2 = logging.Formatter('%(levelname)s: %(name)s - %(message)s')
        kh.setFormatter(formatter2)
        self.syslog.addHandler(kh)

        # timers
        for item in ["APRS", "APRS-META", "Imaging", 'Capture']:
            self.timers.set_state(item, self.config['timers'][item] > 0)
        self.timers.set_state("Buzzer", False)

        # lets go
        self.ledState = 1
        self.imaging_counter = 1
        self.state = "init"
        self.min_alt = sys.maxsize
        self.max_alt = 0
        self.prev_alt = 0
        self.send_bulltin()
        GPIO.output(self.config['pins']['LED1'], GPIO.LOW)
Exemple #4
0
 def setUp(self):
     self.s = SSTV(False, 48000, 16)
     self.s.VIS_CODE = 0x00
     self.s.SYNC = 7
Exemple #5
0
class TestSSTV(unittest.TestCase):

    def setUp(self):
        self.s = SSTV(False, 48000, 16)
        self.s.VIS_CODE = 0x00
        self.s.SYNC = 7

    def test_horizontal_sync(self):
        horizontal_sync = self.s.horizontal_sync()
        expected = (1200, self.s.SYNC)
        actual = horizontal_sync.next()
        self.assertEqual(expected, actual)

    def test_gen_freq_bits(self):
        gen_freq_bits = self.s.gen_freq_bits()
        expected = [(1900, 300),
                    (1200, 10),
                    (1900, 300),
                    (1200, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1300, 30),
                    (1200, 30)]
        actual = list(islice(gen_freq_bits, 0, 1000))
        self.assertEqual(expected, actual)

    # FIXME: Instead of using a test fixture, 'expected' should be synthesized?
    def test_gen_values(self):
        gen_values = self.s.gen_values()
        expected = pickle.load(open("tests/assets/SSTV_gen_values.p"))
        for e, g in izip(expected, gen_values):
            self.assertAlmostEqual(e, g, delta=0.000000001)

    def test_gen_samples(self):
        gen_values = self.s.gen_samples()
        # gen_samples uses random to avoid quantization noise
        # by using additive noise, so there's always a chance
        # of running the code two consecutive times on the same machine
        # and having different results.
        # https://en.wikipedia.org/wiki/Quantization_%28signal_processing%29
        sstv.random = MagicMock(return_value=0.4)  # xkcd:221
        expected = pickle.load(open("tests/assets/SSTV_gen_samples.p"))
        actual = list(islice(gen_values, 0, 1000))
        self.assertEqual(expected, actual)

    def test_write_wav(self):
        self.maxDiff = None
        sio = StringIO()
        sio.close = MagicMock()  # ignore close() so we can .getvalue()
        mock_open = MagicMock(return_value=sio)
        with mock.patch('__builtin__.open', mock_open):
            self.s.write_wav('unittest.wav')
        expected = 'bf61c82e96aed1370d5c1753d87729db'
        data = sio.getvalue()
        actual = hashlib.md5(data).hexdigest()
        self.assertEqual(expected, actual)

    def test_init(self):
        self.assertEqual(self.s.image, False)
        self.assertEqual(self.s.samples_per_sec, 48000)
        self.assertEqual(self.s.bits, 16)
Exemple #6
0
 def setUp(self):
     self.s = SSTV(False, 48000, 16)
     self.s.VIS_CODE = 0x00
     self.s.SYNC = 7