예제 #1
0
 def test_uninhibit(self, mock_output):
     exp_inhibit = 2
     exp_pins = [8, 3, 6, 10]
     d = Demux(exp_inhibit, exp_pins)
     mock_output.reset_mock()
     d.uninhibit()
     mock_output.assert_has_calls([call(exp_inhibit, GPIO.LOW)],
                                  any_order=True)
예제 #2
0
 def test_inhibit(self, mock_output):
     exp_inhibit = 12
     exp_pins = [4, 19, 1, 3]
     d = Demux(exp_inhibit, exp_pins)
     mock_output.reset_mock()
     d.inhibit()
     mock_output.assert_has_calls([call(exp_inhibit, GPIO.HIGH)],
                                  any_order=True)
예제 #3
0
 def test_reset(self, mock_output):
     exp_inhibit = 21
     exp_pins = [4, 5, 6, 8]
     d = Demux(exp_inhibit, exp_pins)
     mock_output.reset_mock()
     d.reset()
     mock_output.assert_has_calls([
         call(exp_pins[0], GPIO.LOW),
         call(exp_pins[1], GPIO.LOW),
         call(exp_pins[2], GPIO.LOW),
         call(exp_pins[3], GPIO.LOW)
     ],
                                  any_order=True)
예제 #4
0
    def __init__(self):
        self.boards = Demux()

        # Controller has a demux, but for now, doesn't add much to methods.
        self.get = self.boards.get
        self.set = self.boards.set
        self.load = self.boards.load
        self.unload = self.boards.unload
        self.profiles = self.boards.profiles
        self.parameters = self.boards.parameters
        self.send = self.boards.send
예제 #5
0
class Controller(Agent):
    def __init__(self):
        self.boards = Demux()

        # Controller has a demux, but for now, doesn't add much to methods.
        self.get = self.boards.get
        self.set = self.boards.set
        self.load = self.boards.load
        self.unload = self.boards.unload
        self.profiles = self.boards.profiles
        self.parameters = self.boards.parameters
        self.send = self.boards.send

    def arm(self):
        set_result = self.set(['BEE2/FPGA2/GUPPi_PIPES_ARM'], ['1'])
        time.sleep(1)
        clr_result = self.set(['BEE2/FPGA2/GUPPi_PIPES_ARM'], ['0'])
        result = set_result == success and clr_result == success
        return (str(result),)

    def update_with_gbtstatus(self):
        return self.boards.update_with_gbtstatus()

    def gbt_arm(self):
        if self.update_with_gbtstatus() == success:
            time.sleep(0.5)
            return self.arm()
        else:
            return failure

    def power_cycle(self, wait=3):
        results = []
        bofs = self.unload()
        results += self.unload(bofs)
        results += self.set(['POWER/group/ibobs'], ['Off'])
        time.sleep(wait)
        results += self.set(['POWER/group/ibobs'], ['On'])
        results += self.load(bofs)
        # for now, just return failure or error if any one failed
        if 'False' in results:
            return failure
        elif 'Error' in results:
            return ['Error']
        else:
            return success
예제 #6
0
 def test_signal(self, mock_output):
     exp_inhibit = 21
     exp_pins = [4, 5, 6, 8]
     d = Demux(exp_inhibit, exp_pins)
     mock_output.reset_mock()
     d.signal(3)
     mock_output.assert_has_calls(
         [call(exp_pins[0], GPIO.HIGH),
          call(exp_pins[1], GPIO.HIGH)],
         any_order=True)
     mock_output.reset_mock()
     d.signal(8)
     mock_output.assert_has_calls([call(exp_pins[3], GPIO.HIGH)],
                                  any_order=True)
예제 #7
0
 def test_init(self, mock_output):
     with patch("FakeRPi.GPIO.setup", autospec=True) as mock_setup:
         exp_inhibit = 12
         exp_pins = [4, 19, 1, 3]
         d = Demux(exp_inhibit, exp_pins)
         self.assertEqual(exp_inhibit, d._inhibit_pin)
         self.assertEqual(exp_pins, d._data_pins)
         mock_output.assert_has_calls([
             call(exp_inhibit, GPIO.HIGH),
             call(exp_pins[0], GPIO.LOW),
             call(exp_pins[1], GPIO.LOW),
             call(exp_pins[2], GPIO.LOW),
             call(exp_pins[3], GPIO.LOW)
         ],
                                      any_order=True)
         mock_setup.assert_has_calls([
             call(exp_inhibit, GPIO.OUT),
             call(exp_pins[0], GPIO.OUT),
             call(exp_pins[1], GPIO.OUT),
             call(exp_pins[2], GPIO.OUT),
             call(exp_pins[3], GPIO.OUT)
         ],
                                     any_order=True)
예제 #8
0
 def test_init_fails_without_four_pins(self, mock_output):
     exp_inhibit = 12
     exp_pins = [4, 19, 1]
     with self.assertRaises(ValueError):
         Demux(exp_inhibit, exp_pins)
예제 #9
0
import web
import time
from demux import Demux

urls = ('/', 'index', '/launch/(\d+)', 'launch')

t_globals = {'datestr': web.datestr}
render = web.template.render('templates', base='base', globals=t_globals)

demultiplexer = [
    Demux(3, [5, 7, 8, 10]),
    Demux(11, [12, 13, 15, 16]),
    Demux(18, [19, 21, 22, 23])
]


class index:
    def GET(self):
        return render.index()


class launch:
    def POST(self, id):
        fire(int(id))
        raise web.seeother('/')


def fire(num):
    r = num / 16
    d = demultiplexer[r]
    d.signal(num - r * 16)